Recursive AI

Apply audio reverb in C#

oneaudio is a free, open-source audio library for .NET from Recursive AI. MIT or Apache-2.0, no bundled native binaries.

Reverb adds a decaying sound after the source. Render beyond the end of the source to keep that tail in the output.

Terminal
dotnet add package RecursiveAI.OneAudio

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneAudio;
 
var clip = Audio.Load("impulse.wav");
int channels = clip.Format.Channels;
var mixer = new AudioMixer(new MixerOptions
    { SampleRate = 48000, Channels = channels });
if (!mixer.SetBusReverb(AudioMixer.MasterBus,
    new ReverbSettings { Wet = 0.3f, Dry = 1 }, rampFrames: 0))
    throw new InvalidOperationException("Queue full.");
mixer.Play(new PlayParams(clip));
int frames = checked((int)Math.Ceiling(
    clip.Frames * 48000.0 / clip.Format.SampleRate) + 48000 * 3);
var output = new float[frames * channels];
mixer.Render(output);
using (var wav = new WavEncoder(File.Create("reverb.wav"),
    new AudioFormat(48000, channels), leaveOpen: false))
    wav.Write(output);
Console.WriteLine($"Saved reverb.wav: {frames} frames");

impulse.wav in the zip contains a single half-amplitude impulse followed by silence. Replace impulse.wav with your own file name. The snippet saves the clip plus three seconds of tail to reverb.wav, at 48000 Hz with the source’s channel count. rampFrames: 0 applies settings without a glide; false means the command queue is full, so the snippet throws “Queue full.” instead of continuing without the effect.

Text
Saved reverb.wav: 148800 frames

Unzip the example, then dotnet run.

The full program

The full program creates the impulse in memory, sets every reverb control explicitly, and writes reverb.wav including the tail. A full command queue returns false; exhausting MaxReverbs throws InvalidOperationException naming that limit.

C#
using OneAudio;
 
const int rate = 48000;
var impulse = new float[rate / 10];
impulse[0] = 0.5f;
var mixer = new AudioMixer(new MixerOptions { SampleRate = rate, Channels = 1, MaxReverbs = 1 });
if (!mixer.SetBusReverb(AudioMixer.MasterBus, new ReverbSettings
{
    RoomSize = 0.5f, DecaySeconds = 1.5f, Damping = 0.4f,
    PreDelayMilliseconds = 10, Wet = 0.3f, Dry = 1
}, rampFrames: 0))
    throw new InvalidOperationException("Command queue full.");
mixer.Play(new PlayParams(new AudioClip(new AudioFormat(rate, 1), impulse)));
var output = new float[rate * 3];
mixer.Render(output);
using (var wav = new WavEncoder(File.Create("reverb.wav"), new AudioFormat(rate, 1), leaveOpen: false))
    wav.Write(output);
Console.WriteLine("reverb.wav: 144000 frames, mono");
Console.WriteLine($"Tail after 0.1 s: {output.Skip(rate / 10).Any(x => x != 0)}");
Console.WriteLine($"Free reverb slots: {mixer.FreeReverbSlots}");
Text
reverb.wav: 144000 frames, mono
Tail after 0.1 s: True
Free reverb slots: 0

Variations

For only the reverberated signal, replace Dry = 1 with Dry = 0 in the full program’s settings:

C#
Dry = 0

The printed output remains the same: the WAV still has 144000 frames and a nonzero tail. The direct impulse is no longer mixed into it.

The short answer

Use AudioMixer.SetBusReverb with ReverbSettings, queue a source on that bus, and call Render for the source plus the decay tail. The master bus applies the effect to the complete mix. A numbered bus lets you process selected voices instead. Save the rendered PCM with WavEncoder for offline output; playback hardware is not needed.

The example is an impulse response: one nonzero input sample followed by silence. That makes it easy to separate the original signal from the later reverb. The output check examines samples after the short input has ended. A nonzero tail confirms that rendering did not stop with the dry source.

How to put reverb on audio?

Load or construct an AudioClip, choose the mixer’s output format, and apply the effect before queuing the source. The short snippet keeps the input channel count and renders at 48000 Hz. The mixer resamples a source whose rate differs. If you choose a different output channel layout, matching speakers pass through, missing speakers fold into available speakers, and LFE is dropped unless the output has one; mono is panned across the output’s front pair. These rules are documented under channel mapping and resampling in the mixer reference. In the full program it is created directly in memory, so every sample used in the example is visible in the code.

The effects reference describes an eight-line feedback-delay-network reverb behind four allpass diffusers. Its controls include room size, decay, damping, pre-delay and independent wet and dry gains. On a bus, processing order is filters, reverb, then bus gain. Filtering the bus therefore changes what excites the reverb, not just the final tail.

Allocate enough output for what you want to hear after the source stops. The source in the zip lasts a tenth of a second. The short snippet adds three seconds of tail, producing 3.1 seconds; the full program renders three seconds total. The decay setting is not an automatic file-length selector. Your render loop or buffer length decides when the WAV ends. For longer sources, include their duration as well as the tail you need.

What do wet and dry mean in reverb?

The settings reference defines Wet as the linear gain of the reverberated signal and Dry as the linear gain of the unprocessed signal. They are separate gains, not two complementary percentages that must add to one. Both accept values from zero to four.

Here Dry = 1 retains the direct signal and Wet = 0.3f adds the reverberated signal. The wet-only variation sets Dry to zero. This is useful when you need to hear the effect on its own rather than judge it underneath the impulse. Summing dry and wet can change peaks; reverb is not a peak limiter.

DecaySeconds specifies RT60 at low frequencies: the time for the tail to fall by 60 dB. Damping changes high-frequency decay, and pre-delay delays the tail’s onset. Room size changes delay-line lengths, not the decay-time setting itself. Set room size before use where possible; the settings docs note that changes glide and bend the pitch of a ringing tail.

Is reverb basically echo?

This API’s reverb builds a distributed tail rather than exposing a single repeat with a delay and feedback control. Pre-delay is the gap before that tail starts, not an instruction to repeat the whole recording at regular intervals. For a less direct sound, adjust Wet and Dry; for a longer tail, adjust DecaySeconds and render enough output to retain it.

The mixer reserves effect slots according to MixerOptions.MaxReverbs, which defaults to two. This program reserves one and assigns it to the master, so FreeReverbSlots prints zero. Reusing that bus’s reverb does not require a new slot, but adding reverb on another bus can fail when the pool is exhausted.

All oneaudio recipes