Echo Effect: Write Offset Sound Buffers?

Is it possible to write audio buffers with offset (delay) to create a flat echo effect?

The following code snippet outputs my sound buffers:

for(s=0; s<inNumberFrames; s++) {
    ioBuffer[s] = audioBuffer[audioBufferReadPos];
}

      

Is it possible for me to do something like this in a for loop :

tempBuffer[s] = audioBuffer[audioBufferReadPos];
--- Then somehow offset tempBuffer[] as bufferWithOffset[] --- 
ioBuffer[s] = audioBuffer[audioBufferReadPos] + bufferWithOffset[];

      

Any advice in this regard would be much appreciated.

Thank.

+3


source to share


1 answer


Finally he got the job, thanks to Hollance on the RW Forums for explaining the whole thing to me.

[ http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=2864 ]

I still have a lot of problems most likely caused by memory leaks. But the logic works.


Initialized a temporary buffer with 22050 zeros:

(SInt16 *)tempBuffer = (SInt16*)calloc(22050, sizeof(SInt16));

      

Initialized a long counter with zero:

long d=0;

      

Then a temporary buffer was added in the for loop , mixed with the current pattern:

for(s=0; s<inNumberFrames; s++) {
    ioBuffer[s] = tempBuffer[d] + audioBuffer[audioBufferReadPos];

      

Added current sample to tempBuffer:



    tempBuffer[d] = audioBuffer[audioBufferReadPos];
    d++;

      

Reset counter to zero if tempBuffer limit is reached:

    if(d >= 22050)
    d=0;
}

      

Assuming the sampling rate is 44100 Hz, this will create a 0.5 second delay.


UPDATE:

Modified

    ioBuffer[s] = tempBuffer[d] + audioBuffer[audioBufferReadPos];

      

For

    ioBuffer[s] = 0.6*tempBuffer[d] + 0.4*audioBuffer[audioBufferReadPos];

      

And that fixed the crash.

+3


source







All Articles