Skip to content

Commit

Permalink
Merge pull request #46 from bkshepherd/6bandeq
Browse files Browse the repository at this point in the history
6 band EQ module added
  • Loading branch information
xconverge authored Dec 30, 2024
2 parents 3a0bfc2 + 83a7cdc commit 315de9a
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Software/GuitarPedal/Effect-Modules/base_effect_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ class BaseEffectModule {
*/
virtual void ParameterChanged(int parameter_id);

float GetSampleRate() const { return m_sampleRate; }

const char *m_name; // Name of the Effect
int m_paramCount; // Number of Effect Parameters
int m_presetCount; // Number of Stored Presets
Expand Down
149 changes: 149 additions & 0 deletions Software/GuitarPedal/Effect-Modules/eq_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include "eq_module.h"
#include <q/fx/biquad.hpp>

constexpr uint8_t NUM_FILTERS = 6;

using namespace bkshepherd;

const float minGain = -15.f;
const float maxGain = 15.f;

const float centerFrequency[NUM_FILTERS] = {100.f, 200.f, 400.f, 800.f, 1600.f, 3200.f};
const float q[NUM_FILTERS] = {0.7f, 0.8f, 1.1f, 1.4f, 1.6f, 1.8f};

cycfi::q::peaking filter[NUM_FILTERS] = {{0, centerFrequency[0], 48000, q[0]}, {0, centerFrequency[1], 48000, q[1]},
{0, centerFrequency[2], 48000, q[2]}, {0, centerFrequency[3], 48000, q[3]},
{0, centerFrequency[4], 48000, q[4]}, {0, centerFrequency[5], 48000, q[5]}};

static constexpr uint8_t s_paramCount = NUM_FILTERS;
static const ParameterMetaData s_metaData[s_paramCount] = {
{
name : "100",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 0,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
{
name : "200",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 1,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
{
name : "400",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 2,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
{
name : "800",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 3,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
{
name : "1600",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 4,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
{
name : "3200",
valueType : ParameterValueType::Float,
valueBinCount : 0,
defaultValue : {.float_value = 0.0f},
knobMapping : 5,
midiCCMapping : -1,
minValue : static_cast<int>(minGain),
maxValue : static_cast<int>(maxGain)
},
};

// Default Constructor
EQModule::EQModule() : BaseEffectModule() {
// Set the name of the effect
m_name = "EQ";

// Setup the meta data reference for this Effect
m_paramMetaData = s_metaData;

// Initialize Parameters for this Effect
this->InitParams(s_paramCount);
}

// Destructor
EQModule::~EQModule() {
// No Code Needed
}

void EQModule::Init(float sample_rate) {
BaseEffectModule::Init(sample_rate);

for (uint8_t i = 0; i < NUM_FILTERS; i++) {
filter[i].config(GetParameterAsFloat(i), centerFrequency[i], sample_rate, q[i]);
}
}

void EQModule::ProcessMono(float in) {
float out = in;

for (uint8_t i = 0; i < NUM_FILTERS; i++) {
out = filter[i](out);
}

m_audioLeft = out;
m_audioRight = m_audioLeft;
}

void EQModule::ProcessStereo(float inL, float inR) {
// Calculate the mono effect
ProcessMono(inL);
}

void EQModule::ParameterChanged(int parameter_id) {
filter[parameter_id].config(GetParameterAsFloat(parameter_id), centerFrequency[parameter_id], GetSampleRate(), q[parameter_id]);
}

void EQModule::DrawUI(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn, bool isEditing) {

const int width = boundsToDrawIn.GetWidth();
const int barWidth = 10;

const int stepWidth = (width / NUM_FILTERS);

int top = 30;

int x = 0;
for (int i = 0; i < NUM_FILTERS; i++) {
bool positive = GetParameterAsFloat(i) > 0.0f;
float magnitude = std::abs(GetParameterAsFloat(i));
if (positive) {
Rectangle r(x, top - magnitude, barWidth, magnitude);
display.DrawRect(r, true, true);
} else {
Rectangle r(x, top, barWidth, magnitude);
display.DrawRect(r, true, true);
}
x += stepWidth;
}
}
29 changes: 29 additions & 0 deletions Software/GuitarPedal/Effect-Modules/eq_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#ifndef EQ_MODULE_H
#define EQ_MODULE_H

#include <stdint.h>

#include "base_effect_module.h"

#ifdef __cplusplus

/** @file eq_module.h */

namespace bkshepherd {

class EQModule : public BaseEffectModule {
public:
EQModule();
~EQModule();

void Init(float sample_rate) override;
void ProcessMono(float in) override;
void ProcessStereo(float inL, float inR) override;
void ParameterChanged(int parameter_id) override;
void DrawUI(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn,
bool isEditing) override;
};
} // namespace bkshepherd
#endif
#endif
4 changes: 3 additions & 1 deletion Software/GuitarPedal/guitar_pedal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Effect-Modules/chopper_module.h"
#include "Effect-Modules/chorus_module.h"
#include "Effect-Modules/compressor_module.h"
#include "Effect-Modules/eq_module.h"
#include "Effect-Modules/looper_module.h"
#include "Effect-Modules/metro_module.h"
#include "Effect-Modules/multi_delay_module.h"
Expand Down Expand Up @@ -546,7 +547,7 @@ int main(void) {
crossFaderTransitionTimeInSamples = hardware.GetNumberOfSamplesForTime(crossFaderTransitionTimeInSeconds);

// Init the Effects Modules
availableEffectsCount = 12;
availableEffectsCount = 13;
availableEffects = new BaseEffectModule *[availableEffectsCount];
availableEffects[0] = new ModulatedTremoloModule();
availableEffects[1] = new OverdriveModule();
Expand All @@ -560,6 +561,7 @@ int main(void) {
availableEffects[9] = new PitchShifterModule();
availableEffects[10] = new CompressorModule();
availableEffects[11] = new LooperModule();
availableEffects[12] = new EQModule();

for (int i = 0; i < availableEffectsCount; i++) {
availableEffects[i]->Init(sample_rate);
Expand Down

0 comments on commit 315de9a

Please sign in to comment.