SynthMaker

Biquad Filter

Archive · 2005 25 old posts

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

Tom7777 ·

I don't know what im doing wrong, can someone help me please 🙂

monoin input; monoout output; monoin cutoff; monoin reso;

float in; float c; float r; float f; float sr; float pi; float a1; float a2; float a3; float b1; float b2; float n; float out;

in = input; out = output; f = 1.0; c = cutoff; r = reso; pi = 3.1415926535; // basically pi sr = 44100; // sample rate n = 40000;

c = 1.0 / tan1(pi * f / sr); a1 = 1.0 / ( 1.0 + r * c + c * c); a2 = 2.0* a1; a3 = a1; b1 = 2.0 * ( 1.0 - c * c) * a1; b2 = ( 1.0 - r * c + c * c) * a1;

c = tan1(pi * f / sr);

a1 = 1.0 / ( 1.0 + r * c + c * c); a2 = -2.0*a1; a3 = a1; b1 = 2.0 * ( c*c - 1.0) * a1; b2 = ( 1.0 - r * c + c * c) * a1;

out = a1 * in + a2 * in &(n-1.0) + a3 * in&(n-2.0) - b1*out &(n-1.0) - b2*out&(n-2.0);

I changed a few things than when i first wrote it to try and make it run but no luck. 🙁

unkargherth ·

These are the things i would change:

1.- c = 1/ tan1(pi*f/sr)

i think should be:

c = 1/tan1(f/sr)

Cause tan1 func assumes an entry range 0..1

2.- Don't now for sure but all of these n-1, n-2, i think it should be previous value of n , not value of n minus - 1

so you should define vars for the previous values and remind to actualize it

ie: at begin of code

float im1, im2, om1,om2

at end of code

out=a1*in+a2*im1+a3*im2-b1*om1-b2*om2; im2=im1;im1=in; om2=om1;om1=out;

3.- I suggest, for clarity, you use standard names for coeffs: a0,a2,a2, b0,b1,b2

4.- And for last, set sr as polyin and input the sample reate instead of defining as constant

Comment. this seems some kind of biquad ( Zoeltzer maybe ?), but i cannot identify it. Can you point me in some direction ?

Tom7777 ·

Hi thanks, it was a custom biquad filter i was trying to make from http://www.musicdsp.org by editing two things together slightly and just customizing it in my own way. Thanks for your tips i will see what i can do. 🙂

Shifrin ·

unkargherth wrote: These are the things i would change:

1.- c = 1/ tan1(pi*f/sr)

i think should be:

c = 1/tan1(f/sr)

Cause tan1 func assumes an entry range 0..1

Yeah Unk's right about the entry range, it runs 0..1 instead of 0..2pi!

That said, shouldn't the line 1/tan(pi * f/sr) map to 1/tan(0.5 * f/sr)? Then again maybe I'm just being slow 😉

Shif.

unkargherth ·

Shifrin wrote: Yeah Unk's right about the entry range, it runs 0..1 instead of 0..2pi!

That said, shouldn't the line 1/tan(pi * f/sr) map to 1/tan(0.5 * f/sr)? Then again maybe I'm just being slow 😉

Shif.

Looking again seems amnother mistake i faled to see last time

In fact line shoudl look as

c = 1.0 / tan1(0.5* f);

Divideing by SR it's only a step to NORMALIZE freqency. But In SM, frequencies, gets normalized by default ( your input frequency range is 0..1, not 0..samplerate/2 ) . So we only need to dive by two ( or better, multiply by 0.5)

Shifrin ·

unkargherth wrote: Divideing by SR it's only a step to NORMALIZE freqency. But In SM, frequencies, gets normalized by default ( your input frequency range is 0..1, not 0..samplerate/2 ) . So we only need to dive by two ( or better, multiply by 0.5)

Yep, well spotted!

Shif.

Tom7777 ·

Hi, thanks everyone, did anyone get this working, i can't code so i am having a bit of trouble still, next time if i try to copy some filter to SM i think i will just stick with the 1 filter and not a mod of 2. 🙂

unkargherth ·

What are exactly you're trying to do ?

Tom7777 ·

just get the audio to pass through and be effected in some way. I don't get any sound still 🙁

unkargherth ·

simple do nothing effect

polyin i; polyout o; o=i;

Is this waht you're looking for?

Or is really a problem with filter you posted some messages ago?

If answer to 2.- is YES, please post the current code you're using

Tom7777 ·

Yeah i mean for the biquad filter code i posted, i know how to do simple stuff already. I mean i updated the code to do what everyone said but i still hear nothing, i can't post the code right now sorry but im guessing that im doing it the wrong way maybe.

Nu Audio Science ·

The code at the top Tom ? Sorry i cant help i'm just trying to keep up with the thread as im trying to learn to port a few bits from music DSP myself 🙂

Tom7777 ·

Yeah the first post i made. I still can't get it to work at the moment.

Nu Audio Science ·

I hope you dont mind if i have a little poke around with it Tom ? Like i said i cant help but it may help me 😉

Tom7777 ·

Yeah thats fine, but it won't make any audio at the moment, if you get it working please PM me the code or something 🙂

Nu Audio Science ·

I tell you what Tom, If i get it working i'll be that excited i'll drive the bloody thing upto you on a Cdrom 🙂 (Theres not much chance 🙂 )

Tom7777 ·

Well im still learning too, i guess i should have started with some simpler stuff first 🙂

Nu Audio Science ·

Took me nearly a week to build a DC blocker and then i had a line of code wrong DOH

Shifrin ·

Tom7777 wrote: Yeah thats fine, but it won't make any audio at the moment, if you get it working please PM me the code or something 🙂

There is a fundamental flaw in your code, you're outputing the final calculation to 'out', which is only a variable in the code. Your correct output should be to the polyout 'output'. So, that's why you've not had any output from it at all!

Also, I had a mess around and got an OK lowpass resonant filter sound from it, needed a few hacks though, and some scaling of the cutoff/reso input values. Give me a shout if you want the .osm!

Shif.

Nu Audio Science ·

Yeah i'll have a little look 😉

Tom7777 ·

Give me a shout if you want the .osm!

Yeah that would be great 🙂 Thanks Shifrin

Shifrin ·

Here it is :- Tom.osm

You'll notice a few chages, I change 'r = reso' to 'r = 1.0 - reso' as when I increased the reso value the resonance dropped! I made the input to 'tan1()' simply be 'c'. I removed unused variables and whatnot. Basically hack it to get it to work 😉

Also the reso and cutoff knobs do scaling of their output inside the knob, do have a look in the knobs to see that.

As it is now, you could connect a sound source to it and it sounds not too bad 🙂

Shif.

unkargherth ·

Well. at least now it works. Still can't fully understand the maths ( well, i know waht they do, but don't know why), But it sounds like a lowpass ( abit stange, but ok)

Anyway : two points

1.- The math conversion you've done in knpobs, better do it in filter module. This way anybody could use standard knobs

2.- the filter becomes a bit unstable at cutoff around 0.005 and resonance over 0.95. Dont know exactly why

Tom7777 ·

Thanks Shifrin 🙂

Shifrin ·

unkargherth wrote: Well. at least now it works. Still can't fully understand the maths ( well, i know waht they do, but don't know why), But it sounds like a lowpass ( abit stange, but ok)

Yeah, I know *what* the maths does, but not sure how it was derived! It does indeed sound like a lowpass!

unkargherth wrote: 1.- The math conversion you've done in knpobs, better do it in filter module. This way anybody could use standard knobs

Yeah, it would be far better to have those calculations done in code, and a standard 0..1 input for cutoff/res etc. I just hacked around basically, the inputs are sensitive!

unkargherth wrote: 2.- the filter becomes a bit unstable at cutoff around 0.005 and resonance over 0.95. Dont know exactly why

Me neither! Still, it's something to fiddle with eh 🙂

Shif.

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.