# Pitch shift using circular buffers



## ste2425 (Apr 15, 2013)

Hi all

Im attempting to perform a very basic pitch shift by writing audio samples into a circular buffer then reading them at a faster or slower speed to effectively raise or lower the pitch, i understand all of the sound quality issues with this method. I have my circular buffer set up and im already using them playing with creating echo effects using the following commands


```
CIRC_WRITE(echo,0,x,dm);
CIRC_READ(echo,0,y,dm;
CIRC_MODIFY(echo,z);
```

with x being my incomeing sample, y being my sample to output and z being a delay value, and echo is the name of the specific buffer im storing values to.

With these commands ive been able to setup quite a nice reverb/echo with multiple voices and reverberations or reflections with different decay times but i just cannot get my head around how i could output from my circular buffer at a faster or slower speed them im writing to it?


----------



## FordGT90Concept (Apr 15, 2013)

If it is a RIFF WAVE, wouldn't you only have to change the sample rate in the header?  If it is 48 kHz and you played it at 96 kHz, it would sound like it is going twice as fast.  If it is 48 kHz and you played it at 24 kHz, it would sound like it was half as fast.


----------



## ste2425 (Apr 15, 2013)

sorry im working on a dsp board, a Analog DEvices adsp-21065l EZ-lab







I don't know how or if i can change the samplerate it inputs at differently to that it outputs at plus im using it to create a bit of a multi effects thing, got wah wah, chorus, echo/reverb, tremolo and auto pan already running on it and you can switch between them and change values for the different effects, wouldn't changing the boards samplerate on the fly cause glitches, if you can even do that?

sorry i should have added that in the op


----------



## FordGT90Concept (Apr 15, 2013)

I have no experience with the hardware you're working with so I can't tell you anything specific but, you should be able to simulate the effect.  To make it sound like it's playing twice as fast, only play every other sample.  To make it sound like it is playing at half speed, play every sample twice.


----------



## ste2425 (Apr 15, 2013)

done it



```
count5++;
CIRC_MODIFY(echo,count5+1);
CIRC_READ(echo,0,L,dm);
CIRC_MODIFY(echo,L1-count5);
CIRC_WRITE(echo,0,x,dm);


if(count5==3000){
count5=0;}
```

need to add a window and a few other things as it sounds quite awful at the moment


----------

