From bce9ecc2d00cb5213a181f1ea12a47625c5249f6 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Sun, 28 Jul 2024 01:40:15 +0100 Subject: [PATCH] Various filters --- plugin/barrverb.cpp | 88 +++++++++++++++++++++++++++++++++++++++------ plugin/barrverb.hpp | 7 ++-- 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/plugin/barrverb.cpp b/plugin/barrverb.cpp index 139be90..5be9d61 100644 --- a/plugin/barrverb.cpp +++ b/plugin/barrverb.cpp @@ -20,36 +20,104 @@ START_NAMESPACE_DISTRHO -BarrVerb::BarrVerb() : Plugin(kParameterCount, 1, 0) { // two parameters, one program, no states - // dummy - deactivate(); +BarrVerb::BarrVerb() : Plugin(kParameterCount, 1, 0) { // two parameters, one program, no states + lowpass = new float[getBufferSize()]; + +/* + // calculate SVF params + // hardcoded values for now + float fc = 5019; + float F = fc / 48000; // assume 48kHz + float w = 2 * tan(3.14159 * F); + float a = w / 0.7845; // 1dB Chebyshev, 2-pole + float b = w * w; + + // "corrected" SVF params, per Fons Adriaensen + c1_1 = (a + b) / (1 + a / 2 + b / 4); + c2_1 = b / (a + b); + d0_1 = c1_1 * c2_1 / 4; + + fc = 9433; + F = fc / 48000; // assume 48kHz + w = 2 * tan(3.14159 * F); + a = w / 3.5594; // 1dB Chebyshev, 2-pole + b = w * w; + + c1_2 = (a + b) / (1 + a / 2 + b / 4); + c2_2 = b / (a + b); + d0_2 = c1_2 * c2_2 / 4;*/ + // calculate SVF params + // hardcoded values for now + + float fc = 10000; + float F = fc / 48000; // assume 48kHz + float w = 2 * tan(3.14159 * F); + float a = w / 0.5412; // 1dB Chebyshev, 2-pole + float b = w * w; + + // "corrected" SVF params, per Fons Adriaensen + c1_1 = (a + b) / (1 + a / 2 + b / 4); + c2_1 = b / (a + b); + d0_1 = c1_1 * c2_1 / 4; + + fc = 10000; + F = fc / 48000; // assume 48kHz + w = 2 * tan(3.14159 * F); + a = w / 1.3065; // 1dB Chebyshev, 2-pole + b = w * w; + + c1_2 = (a + b) / (1 + a / 2 + b / 4); + c2_2 = b / (a + b); + d0_2 = c1_2 * c2_2 / 4; } // Initialisation functions void BarrVerb::initAudioPort(bool input, uint32_t index, AudioPort &port) { - port.groupId = kPortGroupStereo; - Plugin::initAudioPort(input, index, port); + port.groupId = kPortGroupStereo; + Plugin::initAudioPort(input, index, port); } void BarrVerb::initProgramName(uint32_t index, String &programName) { - programName="Default Reverb"; + programName = "Default Reverb"; } // Processing functions void BarrVerb::activate() { - // calculate filter coefficients + // calculate filter coefficients + printf("called activate()\n"); } void BarrVerb::deactivate() { - // zero out the outputs, maybe + // zero out the outputs, maybe + printf("called deactivate()\n"); } void BarrVerb::run(const float **inputs, float **outputs, uint32_t frames) { + // actual effects here + + float x, o; + + for (uint32_t i = 0; i < frames; i++) { + // smash to mono + lowpass[i] = (inputs[0][i] + inputs[1][i]) / 2; + + // 10kHz lowpass filter, 2x oversampling + x = lowpass[i] - in_z1 - in_z2; + in_z2 += c2_1 * in_z1; + in_z1 += c1_1 * x; + + x = (d0_1 * x + in_z2) - in_z12 - in_z22; + in_z22 += c2_2 * in_z12; + in_z12 += c1_2 * x; + lowpass[i] = d0_2 * x + in_z22; + + outputs[0][i] = lowpass[i]; + outputs[1][i] = lowpass[i]; + } } // create the plugin -Plugin* createPlugin() { return new BarrVerb(); } +Plugin *createPlugin() { return new BarrVerb(); } END_NAMESPACE_DISTRHO - diff --git a/plugin/barrverb.hpp b/plugin/barrverb.hpp index 9543c6c..5cd8285 100644 --- a/plugin/barrverb.hpp +++ b/plugin/barrverb.hpp @@ -45,14 +45,17 @@ class BarrVerb : public Plugin { // Initialisation void initAudioPort(bool input, uint32_t index, AudioPort &port) override; void initProgramName(uint32_t index, String &programName) override; - + // Processing void activate() override; void deactivate() override; void run(const float **inputs, float **outputs, uint32_t frames) override; private: - float c1, c2, d0, in_z1, in_z2, out_z1, out_z2; + float c1_1, c2_1, d0_1, c1_2, c2_2, d0_2, in_z1, in_z2, in_z12,in_z22, out_z1, out_z2; + + float *lowpass; + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BarrVerb); };