1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Pitch shift using circular buffers

Discussion in 'Programming & Webmastering' started by ste2425, Apr 15, 2013.

  1. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,608 (1.18/day)
    Thanks Received:
    534
    Location:
    Huddersfield, uk
    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

    Code:
    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?
     
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    18,489 (6.36/day)
    Thanks Received:
    7,798
    Location:
    IA, USA
    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.
     
    Crunching for Team TPU
  3. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,608 (1.18/day)
    Thanks Received:
    534
    Location:
    Huddersfield, uk
    sorry im working on a dsp board, a Analog DEvices adsp-21065l EZ-lab

    [​IMG]

    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
     
  4. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    18,489 (6.36/day)
    Thanks Received:
    7,798
    Location:
    IA, USA
    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 says thanks.
    Crunching for Team TPU
  5. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,608 (1.18/day)
    Thanks Received:
    534
    Location:
    Huddersfield, uk
    done it


    Code:
    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 :p
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)