shorepine / amy

AMY - the Additive Music synthesizer librarY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filter Underflow Issues

dpwe opened this issue · comments

Filtering in fixed point is hard, because the dynamic range is unpredictable and data dependent. I've put a fair amount of work into trying to get the AMY filters.c low-pass behaving well in fixed-point, but it often has problematic behavior at the ends of notes when using Juno patches.

Juno voices use the same envelope generator for amplitude and filter control, so often as the voice releases away to zero amplitude, the filter will be sweeping down towards zero frequency, which is where the coefficients become most sensitive. The confusing phenomenon I'm seeing is nonlinear behavior -- wrapping and ramping. For example, here's the last 50ms of the TestFilter output, comparing floating-point and fixed-point calculation:

download

The blue line is the output with floating-point math, and the orange is the result of the fixed-point calculation. We see that just before 0.93 sec, the fixed-point system flips into a degenerate period ramp (of amplitude about 100 in int16-sample units). That's audible as a little noisy whistle on the end of the tone.

Looking at the block-floating-point scaling, at 0.929 sec it switches from 8 to 12 bits of shift-up. Clipping the shift-up to a max of 8 bits fixes this example, but probably causes other problems elsewhere.

These artifacts aren't always periodic, and sometimes they were more objectionable, but they still need to be better understood and suppressed. I think they have to be coming from the final feedback loop of one or other of the biquad LPF stages (whose coefficients at this point are b0=0.000497 b1=0.000994 b2=0.000497 a1=-1.992448 a2=0.994436 (where the b coefficients may be irrelevant since the input is zero), so I feel like I ought to be able to work out what's happening in the filter calculation by hand (or at least in model code) to get insight into where the oscillation comes from.

I think this is mostly or completely fixed by the better rounding on multiplies in a6f47cf.