Neutone / neutone_sdk

Join the community on Discord for more discussions around Neutone! https://discord.gg/VHSMzb8Wqp
GNU Lesser General Public License v2.1
465 stars 21 forks source link

[cm] 4-point cubic hermite resampling #56

Closed christhetree closed 10 months ago

christhetree commented 10 months ago

This PR adds a 4-point cubic hermite spline interpolation for better resampling.

The implementation is taken from "Polynomial Interpolators for High-Quality Resampling of Oversampled Audio" by Olli Niemitalo (http://yehar.com/blog/wp-content/uploads/2009/08/deip.pdf). Does not dynamically allocate memory and is only ~2x slower than the InplaceLinearResampler. For comparison, sinc interpolation is ~4.5x slower and requires dynamic memory allocations.

The 2nd, -2nd, and sometimes -1st samples will be slightly off since this interpolator requires 4 points, but we assume a repeated sample when these are not available at the ends rather than adding 2-samples of delay. The 0th sample is always the same as the original audio since its corresponding x value is always 0.

From some experiments in Ableton, the spectrum shows about ~20 dB of improvement for a single sine tone going from 44.1 to 48 kHz at 2048 buffer size. From the frequency response of the hermite interpolator compared to the linear interpolater, we should see ~3 dB improvement in attenuation in the higher frequencies above 10 kHz.

44.1 kHz to 48 kHz (previous linear interpolator) 44_to_48_linear

44.1 kHz to 48 kHz (hermite interpolator) 44_to_48_hermite

88.2 kHz to 48 kHz (previous linear interpolator) 88_to_48_linear

88.2 kHz to 48 kHz (hermite interpolator) 88_to_48_hermite

cc: @Fyfe93