1
$\begingroup$

I'm searching for a simple low pass filter code in C with this constraints

  • a modulable frequency cutoff (how can I convert all these crazy coefficients into a frequency?) I could change with a slider.
  • a dB/Octave I can change in my code.
  • a resonance I can change in my code.

the graphical result will be a simple slider moving from 0-44Khz. So far I've only managed to cut a bit of the high ends of my sounds by doing

int i = 0;
while (i < x.size - 1)
{   
    y[i] = (x[i] + x[i+1]) / 2;
    i++;
}

where x is the input buffer (depends of the settings but it goes from 32 to 2048 samples) and y is the output buffer.

$\endgroup$
  • 1
    $\begingroup$ It's not clear what you are asking. You want code to design a filter? You also want some kind of GUI code? Google would probably be the place to start. $\endgroup$ – AnonSubmitter85 Mar 8 '18 at 4:45
2
$\begingroup$

check out the music-dsp source code archive here: http://www.musicdsp.org/showmany.php

I recommend a "Chamberlin" State-Variable Filter (which is 12dB/oct) which gives you other flavors (highpass, bandpass, etc) for free. If you cascade two of them you can get 24dB/oct, etc.

$\endgroup$
  • $\begingroup$ So if I understan well with the chamberlin's algorithm I get 4 different outputs that are interdependant where the input sample only is used in the highpass filter? $\endgroup$ – JSmith Mar 12 '18 at 16:01
  • $\begingroup$ not sure what you mean exactly, but yes you will get multiple outputs from the same filter structure. As I recall generally highpass = input - lowpass. $\endgroup$ – David Lowenfels Mar 12 '18 at 18:04
  • $\begingroup$ what I meant was you only use the pure input signal for the Highpass. David one other thing btw. I use a slider to cutoff in lowpass mode from 0 to 48000 Hz but I get a bug when the Frequency value reaches around 8200. I see in the spectrum the High ends going slowly up and then my filter starts beeing instables an my whole track in live just mutes with a level meter saturing. Do you have any idea where this could come from? $\endgroup$ – JSmith Mar 12 '18 at 18:22
  • 1
    $\begingroup$ @JSmith, try lowering Q if it's higher than 0.5, otherwise you might be able to fix it by making multiple passes (for LPF at least; doesn't seem to work for BP). It's a great little filter, but wants to blow up at high Fc / high Q. Have considered using some kind of damping somewhere to keep mine from blowing up, but not sure where to apply it. $\endgroup$ – Guest Mar 13 '18 at 15:07
  • 1
    $\begingroup$ Also as David says, HPF is not just the input signal, it's the input signal minus the LPF, minus the "times q" ... check the block diagram again :) $\endgroup$ – Guest Mar 13 '18 at 15:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.