shorepine / amy

AMY - the Additive Music synthesizer librarY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cubic Interpolation revisited

dpwe opened this issue · comments

When we first implemented the lookup table oscillators, I included "cubic interpolation", following the tab4~ operator of PureData, and in particular its optimized calculation.

On comparing this to the simpler linear interpolation, however, we decided to drop it in favor of the simpler linear interpolation. I thought I couldn't hear the difference.

But since listening to the unfiltered waveforms for the new test examples, I thought I was hearing some nasty aliasing in the pulse wave. So I reimplemented cubic interpolation and took a careful listen to the difference. Turns out, listening at moderate volume to au unfiltered, unmodulated pulse waveform, I can definitely hear the difference, and it's a very objectionable stray alias component below the fundamental (for the 1 kHz test tone).

Here's a plot comparing the spectrum, as calculated by Audacity, of the cubic-interpolation square wave (top pane) with the linear-interpolation version (bottom pane). Most obviously, we see that the lookup table oscillator has chosen a table that includes harmonics only up to 15 x f0 (i.e., 15 kHz for this 1 kHz note). However, there are some pretty visible components above that frequency in the linear-interpolation version, for instance at 19.3 kHz. The cubic-interpolation version is much cleaner.

Screenshot 2023-12-22 at 17 07 29

But I'm pretty sure I can't hear anything at 19.3 kHz. What I hear is a component below the 1 kHz fundamental, which I think must be the peak at 392 Hz highlighted with the red reticle. It's present in both signals, but it's 7 dB louder in the linear-interpolation version, and I think that's enough to make it audible. Because it's not harmonically related, and in the unmasked below-fundamental region, it's really objectionable.

So, I think we may need to go back to using cubic interpolation.

After discussion offline with bwhitman@, we agreed linear interpolation is good enough for sine oscillators (so, FM voices), but we need better interpolation for broadband waveshapes like pulse and saw. We implemented multiple versions of the lookup table oscillator to deal with these different situations. Net result is we can still do lots of FM voices but the PWM square-wave sounds clean too.