This project has moved. For the latest updates, please go here.

Simple Pitch Shifting (non-realtime)

Nov 17, 2014 at 10:02 PM
Anyone have an idea on how I can just do some simple pitch shifting (basically just play back an audio file faster or slower..)?

In a wavestream read method, can I control how quickly things get "read."?

Nov 19, 2014 at 7:29 PM
Edited Nov 19, 2014 at 7:31 PM
After a lot of research, I found that I need to implement some sort of sample interpolation to get this to work. I tried creating a pitchshift class that inherits from a WaveProvider32. Trying to send my floating point audio buffer into the Read method doesn't really seem to do anything.

I want to implement something like this:

return y[0] + x*(y[1]-y[0]);

but am totally lost on how to do it. I am a new programmer and am entirely self taught, so sometimes I get stuck.

Also, I want the resulting WaveFormat to be 48000, 32, 1, but it seems that the WaveProvider32 wants to make everything 44100.

If anyone has any clue, how do I make this work?:

public override int Read(float[] buffer, int offset, int sampleCount)
        // Basically just trying to double the length of the buffer and replace every second value with a zero which should theoretically half the pitch
        float[] downshifted = new float[sampleCount * 2];
        for (int i = 0; i < downshifted.Length; i += 2)
            downshifted[i] = buffer[i];

            downshifted[i + 1] = 0.0f;
        buffer = new float[downshifted.Length];
        buffer = downshifted;

        return sampleCount;
Nov 19, 2014 at 7:39 PM
you need to write into the buffer passed into Read. Also, you need to read from your source provider to get the input data. It would also be easier to implement this as an ISampleProvider than a WaveProvider32
Nov 19, 2014 at 9:34 PM
Why would it be easier with a ISampleProvider?
Nov 28, 2014 at 4:09 PM
ISampleProvider is designed for this type of situation, where you are performing your algorithms with floating point samples.