0110.be logo

~ Echo or Delay Audio Effect in Java With TarsosDSP

The DSP library for Taros, aptly named TarsosDSP, now includes an implementation of an audio echo effect. An echo effect is very simple to implement digitally and can serve as a good example of a DSP operation.

"![Echo or delay effect in Java](/files/attachments/398/echo_or_delay_effect.png "Echo or delay effect in Java")":\[Delay.jar\]

The implementation of the effect can be seen below. As can be seen, to achieve an echo one simply needs to mix the current sample i with a delayed sample present in echoBuffer with a certain decay factor. The length of the buffer and the decay are the defining parameters for the sound of the echo. To fill the echo buffer the current sample is stored (line 4). Looping through the echo buffer is done by incrementing the position pointer and resetting it at the correct time (lines 6-9).

```java\ //output is the input added with the decayed echo\ audioFloatBuffer[i] = audioFloatBuffer[i] + echoBuffer[position] * decay;\ //store the sample in the buffer;\ echoBuffer[position] = audioFloatBuffer[i];\ //increment the echo buffer position\ position;\ //loop in the echo buffer\ if(position == echoBuffer.length)\ position = 0;\ ```

To test the application, download and execute the “Delay.jar”:[Delay.jar] file and start singing in a microphone.

The source code of the Java implementation can be found on the TarsosDSP github page.