I'm looking for a simple or commented reverb algorithm, even in pseudocode would help a lot.
I've found a couple, but the code tends to be rather esoteric and hard to follow.
An algorithmic reverb's first order of business is to generate the effect of early reflections. The dry signal is run through several delay lines, which create a few rapid and closely-spaced delays of the original signal. This is done based on reverb settings that relate to the theoretical room's size and shape.
A reverb effect, or reverb, is an audio effect applied to a sound signal to simulate reverberation. It may be created through physical means, such as echo chambers, or electronically through audio signal processing.
Convolution reverb is an effects plugin that uses a recording of a physical space to generate frequency specific reverberation. It is created through the use of a sine wave sweep or fast impact sound that measures how the room responds to audio which is then edited and fed into a plugin.
What is the definition of reverb? Reverb is created when a sound occurs in a space, sending sound waves out in all directions. These waves reflect off surfaces in the space, decaying in amplitude until the reflections eventually die off.
Here is a very simple implementation of a "delay line" which will produce a reverb effect in an existing array (C#, buffer
is short[]
):
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++) { // WARNING: overflow potential buffer[i + delaySamples] += (short)((float)buffer[i] * decay); }
Basically, you take the value of each sample, multiply it by the decay parameter and add the result to the value in the buffer delaySamples
away.
This will produce a true "reverb" effect, as each sound will be heard multiple times with declining amplitude. To get a simpler echo effect (where each sound is repeated only once) you use basically the same code, only run the for
loop in reverse.
Update: the word "reverb" in this context has two common usages. My code sample above produces a classic reverb effect common in cartoons, whereas in a musical application the term is used to mean reverberation, or more generally the creation of artificial spatial effects.
A big reason the literature on reverberation is so difficult to understand is that creating a good spatial effect requires much more complicated algorithms than my sample method here. However, most electronic spatial effects are built up using multiple delay lines, so this sample hopefully illustrates the basics of what's going on. To produce a really good effect, you can (or should) also muddy the reverb's output using FFT or even simple blurring.
Update 2: Here are a few tips for multiple-delay-line reverb design:
Choose delay values that won't positively interfere with each other (in the wave sense). For example, if you have one delay at 500ms and a second at 250ms, there will be many spots that have echoes from both lines, producing an unrealistic effect. It's common to multiply a base delay by different prime numbers in order to help ensure that this overlap doesn't happen.
In a large room (in the real world), when you make a noise you will tend to hear a few immediate (a few milliseconds) sharp echoes that are relatively undistorted, followed by a larger, fainter "cloud" of echoes. You can achieve this effect cheaply by using a few backwards-running delay lines to create the initial echoes and a few full reverb lines plus some blurring to create the "cloud".
The absolute best trick (and I almost feel like I don't want to give this one up, but what the hell) only works if your audio is stereo. If you slightly vary the parameters of your delay lines between the left and right channels (e.g. 490ms for the left channel and 513ms for the right, or .273 decay for the left and .2631 for the right), you'll produce a much more realistic-sounding reverb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With