I am unsure if you are asking how to do this in code, or by using the module, but as this question is in the development section, I shall assume code.
The code linked in the original post is for a four-stage ladder filter. Varying filter modes can be obtained by mixing the outputs from each stage. The following diagram I made for another project shows this, with the coefficients for each stage shown as A, B, C, D, E.
The coefficients for some of the various modes (provided by electric druid) are
- 12dB lowpass {0, 0, 1, 0, 0}
- 24dB lowpass {0, 0, 0, 0, 1}
- 12dB highpass {1, 2, 1, 0, 0}
- 24dB highpass {1, 4, 6, 4, 1}
- 12dB bandpass {0, 1, 1, 0, 0}
- 24dB bandpass {0, 0, 1, 2, 1}
if we look at the code https://github.com/VCVRack/Fundamental/blob/v2/src/VCF.cpp#L60
we can see this function:
T highpass() {
return clip((input - resonance * state[3]) - 4 * state[0] + 6 * state[1] - 4 * state[2] + state[3]);
}
if we break this down
(input - resonance * state[3])
is the input and resonance feedback, shown as stage A above.- 4 * state[0]
stage B+ 6 * state[1]
stage C- 4 * state[2]
stage D+ state[3]
stage E
As the phases change by 180 degrees on each phase, you may notice the coefficients have alternating signs, it is important that this is maintained.
The coefficients for the highpass as implemented are {1,4,6,4,1) and these match the coefficients given for a 24dB highpass.
Now you can update that function to become a 24dB bandpass by using {0, 0, 1, 2, 1}
return clip(0 *(input - resonance * state[3]) - 0 * state[0] + 1 * state[1] - 2 * state[2] + 1 * state[3]);
If you want some more reading on pole mixing filters I can recommend https://electricdruid.net/multimode-filters-part-2-pole-mixing-filters/
Or for those that would prefer a book or to just read about the digital domain: Designing Software Synthesizer Plug-ins in C++, Pirkle, 2015, Amazon.co.uk
If you want to try out various coefficients and experiment with ladder filters, you could try one of my modules, Bascom, along with its expander.
If you place the expander to the right of Bascom, right-click the expander module, and look at the presets, this can be used to quickly select the coefficients.