SynthMaker

State Variable Filter for Synthmaker

Archive · 2005 14 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

stefan ·

Thought I'd share this with everyone, here goes nothing!

polyin input; polyin cutoff; polyin resonance;

polyout lowpass; polyout highpass; polyout bandpass; polyout notch; polyout peak; float rez; rez = 1.0 - resonance; lowpass = lowpass + cutoff * bandpass; highpass = input - lowpass - rez * bandpass; bandpass = cutoff * highpass + bandpass; notch = highpass + lowpass; peak = input + bandpass;

Based on a filter I derived from musicdsp.org several years ago iirc. Doesn't need too much explanation: cutoff and resonance input goes from 0.0 to 1.0, the resonance goes into self oscillation at 1.0. Due to all the outputs you can easily put several filters in parallel or cascade them.

If you find this useful, feel free to reply and tell everybody how you used it.

Cheers!

lalo ·

amazing stephan!!! many thanks! lalo

stefan ·

triple-sampled version, stable up to nyquist Tunable without any sin1() call:

polyin input; polyin cutoff; polyin resonance;

polyout lowpass; polyout highpass; polyout bandpass; polyout notch; polyout peak; float rez, f; float lp1, hp1, bp1; float multi, x, x2, x3, x4, x5, x6, x7; multi = 1.0 / 3.0;

rez = 1.0 - resonance; cutoff = max(cutoff, 20.0 / 44100); // tunable version //f = 2 * sin1((3.141592 * (cutoff / 36.0))); // taylor series version of 2 * sin(x) x = 3.141592 * (cutoff / 36.0) * 2 * 3.141592; x2 = x*x; x3 = x2*x; x4 = x3*x; x5 = x4*x; x6 = x5*x; x7 = x6*x; f = 2.0 * (x - (x3 / 6.0) + (x5 / 120.0) - ( x7 / 5040.0));

lp1 = lp1 + f * bp1; hp1 = input - lp1 - rez * bp1; bp1 = f * hp1 + bp1; lowpass = lp1 * multi; highpass = hp1 * multi; bandpass = bp1 * multi;

lp1 = lp1 + f * bp1; hp1 = input - lp1 - rez * bp1; bp1 = f * hp1 + bp1; lowpass = lowpass + lp1 * multi; highpass = highpass + hp1 * multi; bandpass = bandpass + bp1 * multi;

lp1 = lp1 + f * bp1; hp1 = input - lp1 - rez * bp1; bp1 = f * hp1 + bp1; lowpass = lowpass + lp1 * multi; highpass = highpass + hp1 * multi; bandpass = bandpass + bp1 * multi;

peak = input + bandpass; notch = lowpass + highpass;

Dunno if the compiler atm does stuff like translating x / 40 to x * (1/40) etc, but I doubt it. I'll probably nag at jorge and malc about it anyway 🙂

lalo ·

great stefan! sorry if i ask again...can you do a little tutorial on the basics things that are happening math-wise... for example ..how can you obtain the 3x oversampling? i can't really understand it from the code....i think i lack some fundamental dsp concept about filtering

thanx lalo

stefan ·

As you may notice, a part of the code is repeated three times. That is the oversampling part. Also I correct the cutoff frequency for a sampling frequency three times as high compared to the normal one.

Btw, change x = 3.141592 * (cutoff / 36.0) * 2 * 3.141592; into x = 3.141592 * (cutoff / 38.0) * 2 * 3.141592; for a better tuning and frequency response. I will do the correct maths later to see what actually is the exact formula.

lalo ·

..argh what a dummy am i....i see now...so the calculation is done 3 times per sample..thanx lalo

malc ·

Thanks Stefan, great to see you trying things out.

lalo ·

hi stefan! is the 0..1 range of cutoff linear to the 0...22050 range? i ask you cause i'd like to have it mapped as log scale (am i right?) in other words as our ear perceive frequency/pitch.

thanx lalo

stefan ·

lalo wrote: hi stefan! is the 0..1 range of cutoff linear to the 0...22050 range? i ask you cause i'd like to have it mapped as log scale (am i right?) in other words as our ear perceive frequency/pitch.

thanx lalo

yes it is, I'd recommend that you for instance multiply the cutoff with 144 and then use a pitch to frequency converter to make it "linear for the ear" 🙂 Also, you can then add midi poly pitch to the cutoff (after you've multiplied the cutoff but before the conversion to frequency). It is tunable after all. Still haven't checked if the maths for the tuning is correct though, but I think they'll work just fine if you use the /38.0 version (see my earlier posts in this thread).

lalo ·

many thanx stefan 🙂

bManic ·

Just wanted to say thanks to stefan for his continued input and code!

Cheers! bManic

stefan ·

Just give me some more days and I will have something real to show you guys 🙂 Thanks bManic 🙂

lalo ·

stefancrs wrote: Just give me some more days and I will have something real to show you guys 🙂 Thanks bManic 🙂

😀 😀 watch out guys 🙂 thank you very much stefan!!

lalo

Tom7777 ·

Thanks 🙂

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.