Guides & examples

FX guide

The FX suite processes finished audio. The core idea is the Chain: add effects in order, then process() a stereo buffer. Include wauvio/fx/ext.hpp (this also gives you the music layer, so you can process instrument output directly).

g++ -std=c++17 -O2 -I/path/to/wauvio-repo NAME.cpp -o NAME && ./NAME

1. An effect chain

chain.add<Effect>() creates the effect in place and returns a reference, so you can set parameters right away. The chain removes latency (e.g. limiter lookahead) so audio stays in time, and extends the buffer to keep reverb tails.

// Build an effect chain: effects run in the order you add them.
#include "wauvio/fx/ext.hpp"
using namespace wauvio;

int main() {
    // Make some audio to process (a chord on an instrument from the music layer).
    instruments::Wurlitzer200A keys;
    music::Arrangement a;
    a.add_track([&]{ music::Track t(keys); t.add_chord({{57, 60, 64, 67}, 2.0}); t.add_chord({{53, 57, 60, 64}, 2.0}); return t; }());
    StereoBuffer audio = a.render();

    fx::Chain chain;
    chain.add<fx::EQ>().highpass(80).peak(250, -2.0, 1.0).high_shelf(8000, 2.0);   // clean up lows, add air

    auto& comp = chain.add<fx::Compressor>();                                        // keep a reference to tweak settings
    comp.threshold_db = -22; comp.ratio = 3.0; comp.attack_ms = 15; comp.release_ms = 120;

    auto& sat = chain.add<fx::Saturator>();
    sat.mode = fx::Saturator::Mode::Tape; sat.drive_db = 6; sat.mix = 0.6;

    chain.add<fx::StereoChorus>().mix = 0.3;
    auto& verb = chain.add<fx::FdnReverb>(); verb.decay_s = 2.2; verb.mix = 0.2;

    // process() removes latency so the result stays in time, and keeps reverb tails by lengthening the buffer.
    chain.process(audio, 44100);

    fx::write_wav(audio, "fx_01_effect_chain.wav");
}

Download fx_01_effect_chain.cpp

Try this: move the reverb before the compressor and listen to how the sound changes: order matters.

2. Mixing: inserts, buses, sends, sidechain, mastering

The Mixer combines tracks. An insert processes one track, a bus is a shared channel (here a reverb), a send feeds some of a track into it, and the sidechain makes the kick duck the pad. set_mastering finishes with loudness-targeted mastering.

// A mini mix: sources, per-source inserts, a reverb bus with sends, sidechain "pumping", and mastering.
#include "wauvio/fx/ext.hpp"
using namespace wauvio;

static StereoBuffer play(music::Instrument& i, music::Melody m) {
    music::Track t(i); t.add(m); return t.render();
}

int main() {
    instruments::Kit808 kit; instruments::SynthLead lead_i; instruments::SynthPad pad_i;
    StereoBuffer kick, pad, lead;

    // Four-on-the-floor kick (note 36) for 8 beats at 120 BPM, as one buffer.
    std::vector<std::pair<double,int>> hits;
    for (int b = 0; b < 16; ++b) hits.push_back({b * 0.5, 36});
    kick = kit.render_pattern(hits, 8.0, music::Dynamics::f);

    pad  = play(pad_i,  {{57, 8.0, music::Dynamics::mp}});
    lead = play(lead_i, {{69, 0.5}, {72, 0.5}, {76, 1.0}, {74, 0.5}, {72, 0.5}, {69, 1.0}, music::rest(4.0)});

    fx::Mixer mix(44100);
    int iKick = mix.add_source({"kick", kick, 0.0, 1.0});
    int iPad  = mix.add_source({"pad",  pad,  0.0, 0.7});
    int iLead = mix.add_source({"lead", lead, 0.0, 0.6});

    mix.insert(iPad).add<fx::EQ>().highpass(120);                 // per-source insert effects
    int verbBus = mix.add_bus("reverb");
    mix.bus(verbBus).add<fx::FdnReverb>().mix = 1.0;               // 100% wet: the bus is the reverb
    mix.send(iLead, verbBus, 0.35);                                // send some lead to it
    mix.send(iPad,  verbBus, 0.25);

    fx::SidechainSettings sc; sc.threshold_db = -35; sc.ratio = 8; sc.release_ms = 180;
    mix.sidechain(iPad, iKick, sc);                                // kick ducks the pad

    mix.set_mastering(fx::master_for_genre("house"));              // loudness target, EQ, glue, limiter
    StereoBuffer out = mix.render();
    fx::write_wav(out, "fx_02_mixer_sidechain.wav");
}

Download fx_02_mixer_sidechain.cpp

Try this: change the genre string to "jazz" or "metal" to hear different mastering targets.

3. Measure and set loudness

measure_loudness reports integrated LUFS and true peak; normalize_loudness brings audio to a target without exceeding a peak ceiling, using a limiter if needed.

// Measure and set loudness (LUFS), the way streaming platforms do.
#include "wauvio/fx/ext.hpp"
#include <cstdio>
using namespace wauvio;

int main() {
    instruments::Trumpet t; music::Arrangement a;
    a.add(t, {{67, 1.0, music::Dynamics::mf}, {72, 1.0, music::Dynamics::f}, {71, 2.0, music::Dynamics::mp}});
    StereoBuffer audio = a.render();

    fx::LoudnessReport before = fx::measure_loudness(audio, 44100);
    std::printf("before: %.1f LUFS integrated, true peak %.1f dBTP\n", before.integrated_lufs, before.true_peak_db);

    // Gain (and a limiter if needed) to reach -14 LUFS without exceeding -1 dBTP.
    fx::LoudnessReport after = fx::normalize_loudness(audio, 44100, -14.0, -1.0);
    std::printf("after:  %.1f LUFS integrated, true peak %.1f dBTP\n", after.integrated_lufs, after.true_peak_db);

    fx::write_wav(audio, "fx_03_loudness.wav");
}

Download fx_03_loudness.cpp

Try this: try a target of −9 for a loud master and see how the peak behaves.

4. Reverb: algorithmic and convolution

FdnReverb is a flexible algorithmic reverb. ConvolutionReverb imitates a real space from an impulse response, generated here from presets (room, chamber, hall, cathedral, plate) or loaded from your own WAV with load_ir.

// Reverb two ways: algorithmic (FdnReverb) and convolution with a generated room impulse response.
#include "wauvio/fx/ext.hpp"
using namespace wauvio;

int main() {
    // A short percussive sound is the best test signal for a reverb.
    instruments::Woodblock wb; music::Arrangement a;
    a.add(wb, {{72, 0.3}, {72, 0.3}, {79, 0.6}});
    StereoBuffer dry = a.render();

    // 1. Algorithmic reverb.
    StereoBuffer algo = dry;
    fx::Chain c1; auto& v = c1.add<fx::FdnReverb>(); v.decay_s = 3.0; v.size = 1.4; v.mix = 0.4;
    c1.process(algo, 44100);
    fx::write_wav(algo, "fx_04_reverb_algorithmic.wav");

    // 2. Convolution: set_ir(ir::Params) generates an impulse response. Presets: room, chamber, hall, cathedral, plate.
    for (auto [name, params] : { std::pair<const char*, fx::ir::Params>{"room", fx::ir::room()},
                                 {"cathedral", fx::ir::cathedral()} }) {
        StereoBuffer wet = dry;
        fx::Chain c2; auto& conv = c2.add<fx::ConvolutionReverb>();
        conv.set_ir(params); conv.mix = 0.4;
        c2.process(wet, 44100);
        fx::write_wav(wet, std::string("fx_04_reverb_conv_") + name + ".wav");
    }
    // To use a real recorded space instead: conv.load_ir("my_hall.wav");
}

Download fx_04_reverb_spaces.cpp

Try this: compare the room and cathedral outputs on a short percussive sound.

5. Creative effects

Tempo-synced ping-pong delay, tremolo, auto-pan and bit-crushing. Most time-based effects can lock to a tempo (sync_bpm).

// Creative effects: tempo-synced ping-pong delay, tremolo, auto-pan and bitcrushing.
#include "wauvio/fx/ext.hpp"
using namespace wauvio;

int main() {
    instruments::SynthLead lead; music::Arrangement a;
    a.add(lead, {{69, 0.25}, music::rest(0.25), {72, 0.25}, music::rest(0.25), {76, 0.5}});
    StereoBuffer audio = a.render();

    fx::Chain c;
    auto& d = c.add<fx::StereoDelay>();
    d.sync_bpm = 120; d.sync_beats_left = 0.75;     // dotted eighth, locked to 120 BPM
    d.ping_pong = true; d.feedback = 0.5; d.highcut_hz = 4500; d.mix = 0.4;

    auto& t = c.add<fx::Tremolo>(); t.rate_hz = 6; t.depth = 0.3;
    auto& p = c.add<fx::AutoPan>(); p.rate_hz = 0.4; p.depth = 0.6;
    auto& b = c.add<fx::Bitcrusher>(); b.bits = 10; b.downsample = 2; b.mix = 0.25;

    c.process(audio, 44100);
    fx::write_wav(audio, "fx_05_creative.wav");
}

Download fx_05_creative.cpp

Try this: set the bitcrusher to 6 bits for a lo-fi sound.

Next

See every effect’s parameters in the FX reference.