How to change pitch (sample rate) at run-time with portaudio?

1.8k views Asked by At

How to change pitch (samplerate) at run-time with portaudio ? Many thanks.

1

There are 1 answers

0
Ross Bencina On

Resampling is not a capability of PortAudio. Like the native audio i/o APIs that PortAudio wraps, PA streams run at a constant sample rate. To change the pitch (playback rate) of a sample you need perform on the fly sample rate conversion. You can do this by interpolating the original signal using a phase index that increments at some non-unity rate.

Depending on your requirements you can investigate either resampling/interpolation or pitch-time modification.

Commonly used low to medium quality high performance polynomial interpolation algorithms for audio are linear interpolation and cubic hermite interpolation. Higher quality interpolation can be performed with some variant of windowed sinc interpolation. A library you could use for sinc interpolation is Secret Rabbit Code.

For pitch/time transformation (a.k.a. pitch-shifting or time stretching) you might consider using the DIRAC library, which has an open source version for mono signals. There are other commercial libraries available e.g. from z-plane research.