From 83a7cdc57f456853bf0d7502deb4e8902a875713 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Sun, 29 Dec 2024 22:44:21 -0800 Subject: [PATCH] 6 band eq --- .../Effect-Modules/base_effect_module.h | 2 + .../GuitarPedal/Effect-Modules/eq_module.cpp | 149 ++++++++++++++++++ .../GuitarPedal/Effect-Modules/eq_module.h | 29 ++++ Software/GuitarPedal/guitar_pedal.cpp | 4 +- 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 Software/GuitarPedal/Effect-Modules/eq_module.cpp create mode 100644 Software/GuitarPedal/Effect-Modules/eq_module.h diff --git a/Software/GuitarPedal/Effect-Modules/base_effect_module.h b/Software/GuitarPedal/Effect-Modules/base_effect_module.h index d384c69..1377f93 100644 --- a/Software/GuitarPedal/Effect-Modules/base_effect_module.h +++ b/Software/GuitarPedal/Effect-Modules/base_effect_module.h @@ -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 diff --git a/Software/GuitarPedal/Effect-Modules/eq_module.cpp b/Software/GuitarPedal/Effect-Modules/eq_module.cpp new file mode 100644 index 0000000..bdc8b6c --- /dev/null +++ b/Software/GuitarPedal/Effect-Modules/eq_module.cpp @@ -0,0 +1,149 @@ +#include "eq_module.h" +#include + +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(minGain), + maxValue : static_cast(maxGain) + }, + { + name : "200", + valueType : ParameterValueType::Float, + valueBinCount : 0, + defaultValue : {.float_value = 0.0f}, + knobMapping : 1, + midiCCMapping : -1, + minValue : static_cast(minGain), + maxValue : static_cast(maxGain) + }, + { + name : "400", + valueType : ParameterValueType::Float, + valueBinCount : 0, + defaultValue : {.float_value = 0.0f}, + knobMapping : 2, + midiCCMapping : -1, + minValue : static_cast(minGain), + maxValue : static_cast(maxGain) + }, + { + name : "800", + valueType : ParameterValueType::Float, + valueBinCount : 0, + defaultValue : {.float_value = 0.0f}, + knobMapping : 3, + midiCCMapping : -1, + minValue : static_cast(minGain), + maxValue : static_cast(maxGain) + }, + { + name : "1600", + valueType : ParameterValueType::Float, + valueBinCount : 0, + defaultValue : {.float_value = 0.0f}, + knobMapping : 4, + midiCCMapping : -1, + minValue : static_cast(minGain), + maxValue : static_cast(maxGain) + }, + { + name : "3200", + valueType : ParameterValueType::Float, + valueBinCount : 0, + defaultValue : {.float_value = 0.0f}, + knobMapping : 5, + midiCCMapping : -1, + minValue : static_cast(minGain), + maxValue : static_cast(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; + } +} \ No newline at end of file diff --git a/Software/GuitarPedal/Effect-Modules/eq_module.h b/Software/GuitarPedal/Effect-Modules/eq_module.h new file mode 100644 index 0000000..c205f82 --- /dev/null +++ b/Software/GuitarPedal/Effect-Modules/eq_module.h @@ -0,0 +1,29 @@ +#pragma once +#ifndef EQ_MODULE_H +#define EQ_MODULE_H + +#include + +#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 diff --git a/Software/GuitarPedal/guitar_pedal.cpp b/Software/GuitarPedal/guitar_pedal.cpp index 4e8fdf4..d08fd7c 100644 --- a/Software/GuitarPedal/guitar_pedal.cpp +++ b/Software/GuitarPedal/guitar_pedal.cpp @@ -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" @@ -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(); @@ -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);