Lab - Audio Processing
Theory:
Some interesting effects can be achieved by delaying audio samples. This introduces an echo effect to the audio samples. In listening spaces, the soundwaves reflect off surfaces and arrive at our ears with differing amounts of delay and gain. A single reflection or echo of a signal can be implemented by the following filter, which adds to the direct signal an attenuated and delayed copy of itself:
y(n) = x(n) + ax(n-D)
The following algorithm can accomplish the echo effect:
int delayMilliseconds = 500; // half a second
int delaySamples =
(int)((float)delayMilliseconds * 44.1f); // assumes 44100 Hz sample rate
float decay = 0.5f;
for (int i = 0; i < buffer.length - delaySamples; i++)
{
buffer[i + delaySamples] += (short)((float)buffer[i] * decay);
}
Lab:
Write an application to read a wav file into an array and introduce a delay. Reduce the gain of the delayed sample and feed it back into the input to create an echo effect.