0
0

Hi –

I’m using the Soundtouch library to pitch-shift an audio stream with a DSP callback. The problem is that this library has up to a 100ms latency for pitch-shifting…so when I try to play the audio stream, it sounds like only some samples are being shifted.

Is there a way I can deal with this in FMOD? Here’s my DSP callback function. I’m trying to use some modified code that was posted by Adion at
http://52.88.2.202/forum/viewtopic.php … 208f3f56d5

[code:o2z0mq0n]
short pitch_BufOut[40960];
short sampleBuffer[2048];
int pitch_BufOutPosWrite = 0;
int pitch_BufOutPosRead = 0;

void * DSP_ReverbCallback(void *originalbuffer, void *newbuffer, int length, void *param)
{
pitch_BufOutPosWrite = 0;
pitch_BufOutPosRead = 0;

// Get the soundtouch object
SoundTouch* pSoundTouch = (SoundTouch*)param;
int bytesPerSample = 2; // 16 bits mono = 2 bytes per sample

int nSamples = 0;

signed short *srcleft, *srcright;

srcleft   = ((signed short *)newbuffer);
srcright  = ((signed short *)newbuffer)+1;

sound.putSamples(srcleft, length);

do 
{
    nSamples = sound.receiveSamples(sampleBuffer, 1024);

    for (int i = 0; i < nSamples*bytesPerSample; i+=2)
    {
        pitch_BufOut[pitch_BufOutPosWrite++] = sampleBuffer[i];
        pitch_BufOut[pitch_BufOutPosWrite++] = sampleBuffer[i+1];
        if (pitch_BufOutPosWrite >= 40960)
            pitch_BufOutPosWrite = 0;
    }
} while (nSamples != 0);

//*** MAIN LOOP ***
for (int count = 0; count < length; count += 2)
{
    int l = srcleft[count];
    int r = srcright[count];

    if (pitch_BufOutPosWrite != pitch_BufOutPosRead)
    {
        l = pitch_BufOut[pitch_BufOutPosRead++];
        r = pitch_BufOut[pitch_BufOutPosRead++];
        if (pitch_BufOutPosRead == 40960)
            pitch_BufOutPosRead = 0;
    } else {
        l = 0;
        r = 0;
    }

    //Clip and write new values
    if      (l < -32768) l = -32768;
    else if (l >  32767) l =  32767;
    if      (r < -32768) r = -32768;
    else if (r >  32767) r =  32767;

    srcleft[count] = l;
    srcright[count]= r;
}

return newbuffer;

}
[/code:o2z0mq0n]

Thanks so much!

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.