I’ve been looking at sample playback. The main issue here is changing the pitch of the sample without introducing (too many) artifacts. When we pitch a sample up, any frequencies that go over the Nyquist frequency will fold back and we will have aliasing. When we pitch a sample down, we also pitch down the image of the sample centred at the sample rate Fs, and some of it will enter the audible range. On top of this the choice of interpolation method, if it’s not perfect, will introduce some noise/distortion.
The (or a) perfect way to do this is described in this very nice paper, The Quest for the Perfect Resampler: https://ldesoras.fr/doc/articles/resampler-en.pdf
- use a windowed sinc interpolator
- oversample the input 2x and downsample at the end: this way we can trash the top half of the band when pitching up without worrying about aliasing
- to pitch up even further: by analogy to textures in 3D graphics, precompute a mipmap of the sample, with one level per octave. As each level is half the size of the previous one, the total mipmap size doesn’t exceed twice the original sample size.
- there is a way to deal with pitching down by using an extra pre-oversampled mipmap level. Not looked too much at this yet.
Will this be practical to implement on the RP2350? Quite possibly not, we shall see. It’s nice to know what the ideal solution is, and if that doesn’t work then compromises can be made. Bog-standard linear interpolation, maybe combined with oversampling, filtering, or mipmaps, might be fine.
some resources:
- https://jeskola.net/xs1/content/test/ tests of various samplers using a 15khz sine wave. you can see which ones use linear interpolation and which use sinc, and which are able to anti-alias
- https://www.discodsp.com/bliss/aliasing/ more tests
- https://yehar.com/blog/?p=197 Polynomial Interpolators for High-Quality Resampling of Oversampled Audio
- https://www.musicdsp.org/en/latest/Other/93-hermite-interpollation.html hermite interpolation. a bit better than linear
- https://www.dsprelated.com/freebooks/pasp/Windowed_Sinc_Interpolation.html windowed sinc interpolation