Simple LPF code?

Hello everyone!

Would anyone have some sample Lowpass Filter code for me to copy? I saw that rack has built-in filters (see here), but I’m looking for an example that I can follow to get me started.

I don’t know if I need a TRCFilter or TBiquadFilter? I don’t really know the difference.

To put this into context, I hope to add a lowpass filter to the Groovebox module.

I might eventually allow the user to select the filter type (Lowpass, Bandpass, Highpass), but in the short term I’m going to focus on lowpass.

1 Like

If you are ok with a simple biquad, the biquad cookbook lays it all out for you

If you want something more , vadims book on filter design also lays it all out for you. But is 300 pages of math :slight_smile:

From your description I would start with a simple biquad lpf per the first link.

If you are fine with gpl3 code happy to show you where the surge biquads are

1 Like

If you are fine with gpl3 code happy to show you where the surge biquads are

Sure! I’m most interested in concrete code examples. I’m not so interested in the math.

I want to be able to say:

LowpassFilter filter;

filter.cutoff = .5;
filter.resonance = .2;

float output = filter.process(inputs[AUDIO_INPUT].getVoltage());


I would go with a biquad. You can’t get any resonance with a one pole filter. I’ve used the rack biquads. Not in any library plugins, but they work fine. I think the are SSE friendly, also.

Sounds good to me. However, I can’t seem to find any examples of what the implementation would look like. Specifically what I’m looking for is a concrete code example of a lowpass filter in VCV Rack. :man_bowing:

Biquads work fine. I’ve only ever experienced a problem with them in super collider when no control smoothing was applied to the knobs. “hand” twisting caused some discontinuous “squeally/pop?”

Hi Bret, maybe you can have a look at Valleys Interzone module, it has a filter implemented.
You should find the code here:

Here’s the surge biquad

but a much nicer one is this SVF that Cytomic gave me when I was writing the clap demo synth earlier this year. clap-saw-demo/saw-voice.cpp at 1c01df4b9179146b3f14b413283b17e7363f0364 · surge-synthesizer/clap-saw-demo · GitHub that filter sounds great, is snappier than the biquads, and is still simple enough that you can read the code.

Thanks everyone! That’s probably enough to get me started. Out of curiosity, has anyone used by filters built-in to VCV rack, such as TBiquadFilter?

*** UPDATE ***

Never mind! I think that I can figure it out. I just wasn’t seeing the “process” function, but I found it:

I’ve found the opposite - so much junk comes out of most biquads if you try to modulate them. I usually use a cruddy “Chamerblain” filter when I need to modulate the parameters.

I thought the same when I read the post. They are derived assuming constant coefficient and resonance so modulating them is kinda cheating unless you do it “slowly.” Unit circle, complex plane, path between the poles, etc etc hand wave hand wave fake some math and blammo

One of the several problems with biquads in situstiins beyond more basic settings

That simper svf is quite nice though. Snappy and fun. And of course there’s that new module set with buckets of new filter models which just dropped too… :slight_smile:

yeah, the chamberlain filter is a two pole SVF. It has some well known limitations, but it works pretty well. I used it in a lot of modules. I only use biquads for fixed filters.

1 Like


I guess the takeaway for the original poster is: there’s a lot of filter algos with distinct characteristics. Not just a single low pass filter. And they can really impact the sound of your instrument. A simple high cut at a near static cutoff is probably fine with a biquad but a modulated filter sweep in a synth will benefit from more.

But I haven’t used groovebox so am not sure which case applies!

Are there any state variable (or Chamerblain) filters built into VCV Rack that people would recommend? Imagine that people are modulating the lowpass filter for different steps in a drum machine. Would there be a responsive lowpass filter that would be a good choice for this situation?


AFAIK vcv doesn’t have any, but I don’t really know. I never use the dsp in there. But I do have Chamberlain’s book fro the early 80’s.

Vult Stabile and Unstabile filters are state variable filters

LadyNina is a state variable filter. Code is open source, so you can have a look.

1 Like

The clap saw demo code I linked is 60 lines of code and is mit licensed. Just copy that!

Great, thanks everyone! I’ll give it a shot. @baconpaul, sorry I overlooked that. :slight_smile:

Hi @baconpaul ,

While copying over the clap saw demo code, I ran into this:

void SawDemoVoice::StereoSimperSVF::init()
    for (int c = 0; c < 2; ++c)
        ic1eq[c] = 0.f;
        ic2eq[c] = 0.f;

ic1eq and ic2eq are defined as:

float ic1eq[2]{0.f, 0.f}, ic2eq[2]{0.f, 0.f};

First, I apologize since I don’t know exactly what these arrays represent. But shouldn’t the for loop be using

for (int c = 0; c < 2; ++c)  <== incorrect ?
for (int c = 0; c < 2; c++)  <== correct ?

Otherwise, ic1eq and ic2eq are only being set to 0.f when c == 1 and skipping over index 0.

Cheers and thank you!