On Tue, Mar 19, 2013 at 04:46:10PM +0100, Tim Goetze wrote:
However, I still take issue with the rather
exaggerated claim that
using a biquad to smoothen gain changes would be "giant overkill". It
may be slightly less efficient than your now optimised version, but
certainly not enough to substantiate this claim.
A biquad is overkill because it has 5 free parameters, while the
filter that is required only has 3: frequency, damping, and gain
(and those map almost 1 to 1 to w, a, b). Also, unless the user
computes the filter by hand and discovers it can be simplified,
he/she would probably use a library routine, i.e. a function call
for each sample.
BTW, at the cost of that one extra multiplication, the
biquad is more
versatile if you run the gain filter permanently: you can simply feed
it the current knob value and it will automatically produce a nice,
smooth curve, without needing to be set up again for every gain
change.
Exactly the same with the form I proposed, w, a, b need to be computed
just once, not for every gain change. In fact only w depends on the
sample rate, a and b are fixed constants. So actually you would code
it as:
gm = 1.07 * gt;
for (i = 0; i < nframes; i++)
{
g1 += w * (gm - g1 - 0.07f * g2);
g2 += w * (g2 - g1);
out [i] = g2 * in [i];
}
Without the '-0.07f * g2' it would just be two
first order LP filters in series.
Ciao,
--
FA
A world of exhaustive, reliable metadata would be an utopia.
It's also a pipe-dream, founded on self-delusion, nerd hubris
and hysterically inflated market opportunities. (Cory Doctorow)