# Pseudocode for an echo using recursion

Using pseudocode, what would the code for an echo using recursion be?

UPDATE: Appears I should have been more clear. By echo I mean the pattern sound exhibits when it echos, not echo as in repeatly add one to self where self equals zero. Any thought on what the code would look like for a "real" echo? For example, I'd thought about "echo(reduce-volume();exit-if-silent;echo())" but was sure if the logic made sense.

UPDATE-2: Working through my own logic above an noticed it lacks a way to account for "positive feedback", which I'm guessing is required.

http://en.wikipedia.org/wiki/Positive_feedback

-

``````echo sound clip S at volume V:
if V is zero, done. (Exit recursion.)
start playing S.
V = V * F.
Wait for time T.
echo sound clip S at volume V.
``````

`F` is the attenuation factor, and I suppose a good value for it would be 0.5

`T` is the delay between repetitions of the echo, it simulates the distance of the echoing wall.

Note: of course, this is just tail recursion, so it can be trivially converted into a loop. However, it is possible to extend it to simulate multiple echoing walls at different distances, in which case the recursion might be the best way to do it.

Positive feedback cannot be accounted for without working with the individual samples that the waveform is composed of, which calls for an altogether different, and far more complicated solution.

-
``````how to echo:
write it
echo everything else
``````
-
+1 Thanks, guess I should have been more clear. By echo I mean the pattern sound exhibits when it echos, not echo as in repeatly add one to self where self equals zero. Any thought on what the code would look like for a "real" echo? For example, I'd thought about "echo(reduce-volume();exit-if-silent;echo())" but was sure if the logic was made sense. –  blunders Jan 8 '12 at 6:22
Ok. Sadly I know nothing about audio –  Winston Ewert Jan 8 '12 at 8:14
+1 Okay, fair enough - thanks for the response to my comment! –  blunders Jan 8 '12 at 8:25
``````Line1