views:

907

answers:

4

Is there any good C or C-like source code for an audio reverb (besides Freeverb). There are endless examples of low-pass filters that sound great, but it's terribly difficult to find source for a good-sounding reverb.

Why is that? Is it a hard enough problem that the good implementations are held onto and not published?

+5  A: 
Robert Harvey
Does freeverb3 provide tools for you to go out and measure the impulse response yourself, or does it just use data they measured to generate the reverb effects?
MusiGenesis
Yes. I'm aware of that project. I'd like to see at least one other project for ideas, as I don't just want to copy code.
Nosredna
@MusiGenesis, there are a lot of libraries of impulses. I don't know if freeverb3 includes a way to generate them, but there are plenty of tools for that. Some people have traveled to great churches to get impulses.
Nosredna
No, Freeverb3 just processes the samples. It takes a lot of specialized equipment to produce good impulse response samples, see http://web.arch.usyd.edu.au/~basse_j/auditoria.html. But there are apparently plenty of third-party sources for these samples, see http://freeverb3.sourceforge.net/
Robert Harvey
Have you seen this article? http://www.soundonsound.com/sos/Oct01/articles/advancedreverb1.asp If it's as easy to create algorithms for this stuff as MusiGenesis claims it is, you should do well with these ideas.
Robert Harvey
I printed that article out about five years ago but had since forgotten it. Thanks. Printed again. :-)
Nosredna
Great article. Thanks.
MusiGenesis
Well, clearly I'm going to go from Freeverb3 at least in part. Any other source code pointers are welcome. For now, I'll accept this answer.
Nosredna
A: 

Are you kidding? Reverb is the easiest thing in the world to do programatically:

for (int i = 0; i < input.Length; i++)
{
    output[i] += input[i];
    output[i + delay] += input[i] * decay; 
}

I write this kind of stuff full time now, so maybe it just seems easy. Do you mean you're looking for more general echo or spatial effects, that might include frequency-modulated delay lines and chorusing and so on?

MusiGenesis
Will this produce a realistic reverb sound? Most people listen with two ears; how do you spread it across the spatial field?
Robert Harvey
A simple trick is to just slightly vary the delay and decay parameters on the left and right channels.
MusiGenesis
The result of the above function is "realistic" in the sense that it sounds like an analog reverb device, which means it does not sound like a real space. You can create a more realistic spatial echo sound by producing a few discrete echoes (single echoes instead of reverb) at short distances and then blurring all the echoes together in a variety of ways.
MusiGenesis
Real-world echo effects usually consist of a few sharp, relatively undistorted repeats of the original sound, followed by a muddy pitch-shifted cloud of echoes.
MusiGenesis
I'm not kidding. Most of the algorithms I try sound inferior to good hardware reverbs. Often metallic. There are entire conversations on musicdsp and kvraudio about how hard it is to get a good musical-sounding reverb.Traditional way includes multiple allpass filters.And in my experience, you need to modulate the delay lines in various ways.Basically, I have the feeling there's black art involved in the best reverbs, and I'm looking for some hints.So I'm not looking for the "easiest reverb in the world." I'm looking for some inspiration from other people's good code.
Nosredna
It is definitely a black art. Check out my website (the link is in my profile - I subscribe to the "no self-serving links on SO" policy). MusiGenesis has three different "reverb" settings that all use variations of the above reverb method. One of the basic tricks is to match the delay times of the reverb lines to the tempo of the music.
MusiGenesis
I've heard that the delay taps should be prime numbers so they don't clump up. Do you do that? Do you happen to have any source code to show?
Nosredna
Modulating the delay lines is also critical, as you pointed out. The "black art" part is picking modulation frequencies and depths that either don't reinforce each other or reinforce each other in the way that you want. The usual consquence of picking the wrong values is phase effects.
MusiGenesis
@Nosdredna: sorry, my stuff is all proprietary, and it might not be useful to you anyway. Most people that do audio are interested in real-time synthesis, whereas my code all works on full recorded samples. I enjoy discussing this stuff in principle, though, and I'll be happy to stear you towards any resources I know about. Harmony-Central is an excellent site for this stuff (or it was 10 years ago).
MusiGenesis
Do you use all-pass filters to correct phase changes that come from the first stage?
Nosredna
I've tried the prime number thing, although my algorithms are more like what I mentioned in my 3rd comment - with single echoes, it doesn't matter whether they're prime or not. My usual approach to designing reverb is like most of what I do: I try stuff out randomly until I find something that happens to work.
MusiGenesis
That's OK. My ears are open to hints and experiences, despite my preference for working code to play with. :-)
Nosredna
"I try stuff out randomly until I find something that happens to work." OK. That's what I suspected. I've heard that some people have found ways to choose the values to get good sounds. Especially important if you support multiple samplerates.
Nosredna
I generally avoid using FFT wherever possible, so filters are sort of rare in my programs, which are meant to run on Windows Mobile smartphones. Most of what I do involves fast "tricks" on time-domain data.
MusiGenesis
I'd love to share my code, but I'm trying to make a living from it, so... Maybe I'll open-source my project and rake in millions from Google ads. I actually have this fantasy once in a while, along with winning the lottery.
MusiGenesis
+1 for a good discussion, albeit no source code (boo hoo) :)
Robert Harvey
Actually, filters don't have the use FFT. Most DSP filters are IRR for speed. Example: http://www.musicdsp.org/showone.php?id=24
Nosredna
A simple thing I figured out for designing a chorus effect (which is multiple delay lines with different modulating frequencies and depths) is to just plot the modulators on a single graph in an additive way, so that the graph is bright if all modulators are near 1 at the point, and dark of all modulators are near -1. If the combined graph is relatively smooth (without a lot of peaks and valleys) the chorus will sound good.
MusiGenesis
@Robert Harvey. I'm counting on you to pull out 30 lines of angelic C code at any moment. :-)
Nosredna
@Robert: hey, there's a little bit of source code up at the top, here. And it does produce an undeniable reverb effect. :)
MusiGenesis
@Nosredna: that might be the best link anyone has ever sent me. I've been trying to emulate the Moog (with limited success), and I can't wait to see what effect that method has. Tomorrow should be a fun morning.
MusiGenesis
@MusicGenesis: Skim through the whole musicmsp archive. You'll love it. And hang out at kvr with the dsp programmers... http://www.kvraudio.com/forum/viewforum.php?f=33
Nosredna
Ah, the joys of the occasional random down-vote. :)
MusiGenesis
+3  A: 

You could do a lot worse than read John Dattorro's paper on the subject found here, on his homepage. Dattorro worked at Lexicon and the paper I've referenced includes extensive discussion on the design of high quality reverb.

Outside of this, the various links at musicdsp, and scant reference in the literature, the design of great reverb is shrouded in secrecy. The finest reverbs are designed either by people who have worked with the designers of the last generation of great reverbs, or by obsessives who invest extraordinary quantities of time into the subject. In either case, the designers seem to become quite tight-lipped regarding their methodologies.

Dave Gamble
Yeah. That one I already have in a notebook.
Nosredna
+2  A: 

realistic reverberation algorithms are a bit of the 'holy grail' of audio DSP programming... there are two basic approaches in the pro-audio market today:

  • convolution reverb (using impulse responses)
  • delay/feedback/dampening networks

the main challenge behind impulse response convolution has been the efficiency versus quality tradeoff (incl. latency!). whereas the main challenge behind delay matrix networks has been generating vast lattices of delays with little harmonic re-inforcement.

professionals pay vast amounts of money for realistic sounding reverbs... a "good" sounding reverberator can retail for $2000+, and "really good" ones for much more.

welcome to the pro-audio industry...

kent
I guess that's the answer I expected. It's a hard problem.
Nosredna