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.



source to share

1 answer

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

[ ]

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];


Reset counter to zero if tempBuffer limit is reached:

    if(d >= 22050)


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



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



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


And that fixed the crash.



All Articles