Various filters

This commit is contained in:
Gordon JC Pearce 2024-07-28 01:40:15 +01:00
parent f95a2f2c1a
commit bce9ecc2d0
2 changed files with 83 additions and 12 deletions

View File

@ -20,36 +20,104 @@
START_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO
BarrVerb::BarrVerb() : Plugin(kParameterCount, 1, 0) { // two parameters, one program, no states BarrVerb::BarrVerb() : Plugin(kParameterCount, 1, 0) { // two parameters, one program, no states
// dummy lowpass = new float[getBufferSize()];
deactivate();
/*
// 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 // Initialisation functions
void BarrVerb::initAudioPort(bool input, uint32_t index, AudioPort &port) { void BarrVerb::initAudioPort(bool input, uint32_t index, AudioPort &port) {
port.groupId = kPortGroupStereo; port.groupId = kPortGroupStereo;
Plugin::initAudioPort(input, index, port); Plugin::initAudioPort(input, index, port);
} }
void BarrVerb::initProgramName(uint32_t index, String &programName) { void BarrVerb::initProgramName(uint32_t index, String &programName) {
programName="Default Reverb"; programName = "Default Reverb";
} }
// Processing functions // Processing functions
void BarrVerb::activate() { void BarrVerb::activate() {
// calculate filter coefficients // calculate filter coefficients
printf("called activate()\n");
} }
void BarrVerb::deactivate() { 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) { 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 // create the plugin
Plugin* createPlugin() { return new BarrVerb(); } Plugin *createPlugin() { return new BarrVerb(); }
END_NAMESPACE_DISTRHO END_NAMESPACE_DISTRHO

View File

@ -52,7 +52,10 @@ class BarrVerb : public Plugin {
void run(const float **inputs, float **outputs, uint32_t frames) override; void run(const float **inputs, float **outputs, uint32_t frames) override;
private: 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); DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BarrVerb);
}; };