Cosine interpolation option in ResamplingAudioSource?


#1

Has anyone tried to use cosine interpolation in ResamplingAudioSource? It would be fairly easy to use. I wonder why no one else has tried it?


#2

Nope, I use the HIIR code from Laurent de Soras. I only use it for factor of 2 oversampling, but IIRC it can do non-integer resampling also.


#3

I tried this. It worked:

juce_ResamplingAudioSource.cpp

*destBuffers[channel]++ = srcBuffers[channel][bufferPos] +
  ((1-std::cos(alpha*3.14159265358979))/2) *
    (srcBuffers[channel][nextPos] - srcBuffers[channel][bufferPos]);

What are the advantages / disadvantages?


#4

I’m not familiar with the characteristics of cosine interpolation, but the things to look for are how flat the pass band is and the amount of rejection of aliasing. See chapter 2 of The Quest For The Perfect Resampler for more pros/cons.

Actually, just checked HIIR again and it doesn’t support rational resampling. :oops:


#5

I’m very skeptical about this interpolation for AudioSources, it may look cool for your eyes, but isn’t the right approach for audio.
The only right (when it should something with sin), and perfect interpolation method is sinc-interpolation, but this will introduce latency to the signal.


#6

Well if you’re skeptical about cosine interpolation, I can only imagine how you feel about linear interpolation (the current implementation).


#7

linear interpolation is far from perfect, of course it adds additional harmonics, its a compromise, but the fastest way between two values is a line and not a curve. The more important part of the resampler is the pre-filtering (to prevent aliasing) and post filtering (to remove additional harmonics).

Why should a cos-function between two sample values should be better, it can’t be better,…
Imagine a saw-tooth which will be heavily up sampled with this kind of pseudo-resampling, it will have lots of bumps,…


#8

Why should a cos-function between two sample values should be better, it can’t be better,…[/quote]
It may be better in terms of aliasing. Naively speaking, the sharper a change in a signal, then the higher frequency the partials need to be to generate that signal. So by using a smoother interpolation, the generated harmonics may not extend as high as for linear.

On the other hand, it may well be worse than linear for introduced noise. See here for a comparison based on image processing.