Reputation: 5699
Is it possible to write the audio buffers with an offset(delay) to generate a flat echo effect ?
The following piece of code outputs my audio buffers :
for(s=0; s<inNumberFrames; s++) {
ioBuffer[s] = audioBuffer[audioBufferReadPos];
}
Is it possible for me to do something like this within the for loop :
tempBuffer[s] = audioBuffer[audioBufferReadPos];
--- Then somehow offset tempBuffer[] as bufferWithOffset[] ---
ioBuffer[s] = audioBuffer[audioBufferReadPos] + bufferWithOffset[];
Any guidance in this regard will be highly appreciated.
Thanks.
Upvotes: 3
Views: 1117
Reputation: 5699
Finally got it to work, thanks to Hollance on RW Forums for explaining all of this to me.
[ http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=2864 ]
I still have a lot of crashing issues, caused most probably by memory leaks. But the logic works.
Initialized a temporary buffer with 22050 zero samples :
(SInt16 *)tempBuffer = (SInt16*)calloc(22050, sizeof(SInt16));
Initialized a long counter with zero :
long d=0;
Then within the for loop fed the temporary buffer mixed with the current sample :
for(s=0; s<inNumberFrames; s++) {
ioBuffer[s] = tempBuffer[d] + audioBuffer[audioBufferReadPos];
Added the current sample to the tempBuffer :
tempBuffer[d] = audioBuffer[audioBufferReadPos];
d++;
Reset the counter to zero if the limit of the tempBuffer is reached :
if(d >= 22050)
d=0;
}
Assuming that the sampling rate is 44100 Hz, this will create a delay of 0.5 seconds.
UPDATE :
Changed
ioBuffer[s] = tempBuffer[d] + audioBuffer[audioBufferReadPos];
To
ioBuffer[s] = 0.6*tempBuffer[d] + 0.4*audioBuffer[audioBufferReadPos];
And that fixed the crashing.
Upvotes: 3