What's the most basic implementation of resonant lowpass filter?
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
Hey, sorry if this has been asked before. Similar questions may have been asked, but I'm looking for something very specific:
1. Least possible code
2. Efficiency doesn't matter
3. Don't pre-calculate anything, that just adds to the amount of code, see #2.
4. Sound doesn't matter, it can sound like crap.
5. Probably needs to be 1 pole since 2 poles would require typing some more.
Thank you!
1. Least possible code
2. Efficiency doesn't matter
3. Don't pre-calculate anything, that just adds to the amount of code, see #2.
4. Sound doesn't matter, it can sound like crap.
5. Probably needs to be 1 pole since 2 poles would require typing some more.
Thank you!
- KVRAF
- 5131 posts since 22 Jul, 2006 from Tasmania, Australia
Here's one without resonance, but it has cut->
streamin in;
streamout out;
streamin cut;
out = out * (1 - cut) + in * cut;
streamin in;
streamout out;
streamin cut;
out = out * (1 - cut) + in * cut;
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
That's good for parameter smoothing.... Is there a super-simple addition to that piece of code to make it a resonant lowpass? Or is a resonant filter just not possible to make so simply?
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
Found this on musicdsp, I think this fits the bill:
http://www.musicdsp.org/showArchiveComm ... chiveID=29
http://www.musicdsp.org/showArchiveComm ... chiveID=29
Code: Select all
//set feedback amount given f and q between 0 and 1
fb = q + q/(1.0 - f);
//for each sample...
buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1));
buf1 = buf1 + f * (buf0 - buf1);
out = buf1;
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
http://www.elanhickler.com/_/simple_res_filter.wav
implemented in jesusonic, sounds fine to me.... is there a simple way to add nonlinearity / resonance overdrive / clipping? Maybe you don't need to type out the code but a short explanation would be sweet!
implemented in jesusonic, sounds fine to me.... is there a simple way to add nonlinearity / resonance overdrive / clipping? Maybe you don't need to type out the code but a short explanation would be sweet!
- KVRAF
- 2206 posts since 25 Sep, 2014 from Specific Northwest
This actually sounds good, but any filter in this style tends to break at the edges, especially below 100hz.Architeuthis wrote:Found this on musicdsp, I think this fits the bill:
http://www.musicdsp.org/showArchiveComm ... chiveID=29
Code: Select all
//set feedback amount given f and q between 0 and 1 fb = q + q/(1.0 - f); //for each sample... buf0 = buf0 + f * (in - buf0 + fb * (buf0 - buf1)); buf1 = buf1 + f * (buf0 - buf1); out = buf1;
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
-
- KVRian
- 633 posts since 4 Apr, 2010
1&2: "Least code possible" and "efficiency doesn't matter"...if it's least code it's probably optimized and efficient...Architeuthis wrote:1. Least possible code
2. Efficiency doesn't matter
3. Don't pre-calculate anything, that just adds to the amount of code, see #2.
4. Sound doesn't matter, it can sound like crap.
5. Probably needs to be 1 pole since 2 poles would require typing some more.
!
3: OK
4: Um...too vague...I suppose you don't want it to sound like such crap that it's not the resonant filter you asked for...
5: You need two poles to be resonant. You're not going to get up AND down with one pole/zero.
I can't imagine why you aren't just using a biquad, source code everywhere, and do whatever you feel like to minimize setting or initializing (too vague to answer that part—do you just want to hard code the coefficients? Go ahead. Otherwise, it's unclear how you want to trade off the ability to set it accurately versus code size).
Throw away parts you don't want:
http://www.earlevel.com/main/2012/11/26 ... urce-code/
My audio DSP blog: earlevel.com
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
I just wanted the least code possible because I'm trying to understand how digital filters work... or... more specifically I want to know how simple you can get and still have the appearance of a filter... uhh... something like that
-
- KVRian
- 633 posts since 4 Apr, 2010
OK, that makes sense...Architeuthis wrote:I just wanted the least code possible because I'm trying to understand how digital filters work... or... more specifically I want to know how simple you can get and still have the appearance of a filter... uhh... something like that
So, you need a second-order filter to get a resonance, the simplest would be the direct forms. You can see the basic "direct form" structure here; the transposed direct form II is the best for floating point—the block diagram may look a little more complicated, but it isn't really (see my code that I linked to last time), but go with any form you like:
http://www.earlevel.com/main/2003/02/28/biquads/
As you can see, a very simple filter. Then you only need to calculate the coefficients. You want simple, so you could just set or hardcode them from the coefficient calculator:
http://www.earlevel.com/main/2013/10/13 ... ulator-v2/
My audio DSP blog: earlevel.com
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
So there are problems in low frequency with biquads and high frequency with state variable.
How about this:
what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)
How about this:
Code: Select all
out = out * (1 - cut) + in * cut;
-
- KVRian
- 633 posts since 4 Apr, 2010
It's a quantization issue with the direct forms at low frequency, but much less so with floating point. Not an issue with audio, especially double precision, and the transposed DFII addresses a negative aspect of floating point. It is a big deal with fixed point, even at 24-bit by 56-bit accumulation (56k, for instance). With the Chamberlin state variable, the limit is absolute—you need to change the architecture (like Andy Simper's trapezoidal integrated version), oversample, or just don't go up against the limits.Architeuthis wrote:So there are problems in low frequency with biquads and high frequency with state variable.
Well, you just said it—it is what it is. Here's my article on the one-pole, fwiw:How about this:
what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)Code: Select all
out = out * (1 - cut) + in * cut;
http://www.earlevel.com/main/2012/12/15 ... le-filter/
My audio DSP blog: earlevel.com
- KVRAF
- 5131 posts since 22 Jul, 2006 from Tasmania, Australia
Sorry mate,
filters are one of the areas I am hazy on,
so I can't put a q on it myself.
I think I will try and turn it into a hi pass though for my own learning purposes.
I think EarLevel has your tail though.
Yeah, it is usually used for smooth,
but when you can do that with applicability to a frequency like this it is handy.
filters are one of the areas I am hazy on,
so I can't put a q on it myself.
I think I will try and turn it into a hi pass though for my own learning purposes.
I think EarLevel has your tail though.
Yeah, it is usually used for smooth,
but when you can do that with applicability to a frequency like this it is handy.
- KVRAF
- 9077 posts since 28 May, 2005 from Netherneverlands
Code: Select all
// Coefficient computation
// Cutoff and reso are [0,128) integers
c = 0.5^[(128-Cutoff) / 16.0]
r = 0.5^[( 24+Reso) / 16.0]
v0 = (1.0 - r*c)*v0 - c*v1 + c*input
v1 = (1.0 - r*c)*v1 + c*v0
No band limits, aliasing is the noise of freedom!
- KVRAF
- Topic Starter
- 3417 posts since 28 Jan, 2006 from Phoenix, AZ
Nielzie, it works. I used 0 to 150 for cutoff to get a bit more frequency. It explodes near the end of that, but a clipper on v0 solves it, just like a clipper on buf0 solves explosions for the previous resonant filter.
Nice, thank you! Hey EarLevel, are there any filter algorithms that use oscillators for resonance?earlevel wrote:Well, you just said it—it is what it is. Here's my article on the one-pole, fwiw:Architeuthis wrote:what's the disadvantage? (ignore the fact it doesn't resonate and it's only 1 pole)
http://www.earlevel.com/main/2012/12/15 ... le-filter/