SFX guide
The SFX engine produces sound effects (risers, impacts, glitches, textures, bass FX, percussion, and more) from 190 presets. You pick a preset, tweak parameters, and render. Include wauvio/sfx.hpp. The whole catalog is in the preset catalog.
g++ -std=c++17 -O2 -I/path/to/wauvio-repo NAME.cpp -o NAME && ./NAME1. Find a preset and tweak it
Search the catalog, read a preset’s parameters and ranges, set values, and render. Values outside a range throw an error that explains the problem. A fixed seed makes the audio repeatable.
// Find a preset, see what it can do, change its parameters, render it.
#include "wauvio/sfx.hpp"
#include <cstdio>
namespace sfx = wauvio::sfx;
int main() {
// 1. Search the catalog (ids, names, tags and descriptions are searched).
for (const sfx::Preset* p : sfx::search("riser"))
std::printf("%-22s %s\n", p->id.c_str(), p->name.c_str());
// 2. find() looks at a preset's metadata: every parameter with its default and allowed range.
const sfx::Preset* info = sfx::find("noise_riser");
for (const sfx::ParamSpec& s : info->params)
std::printf(" %-12s default %-6g range %g..%g %s\n", s.name.c_str(), s.def, s.min, s.max, s.description.c_str());
// make() gives you an Effect: the preset plus its current parameter values, ready to tweak and render.
sfx::Effect e = sfx::make("noise_riser");
// 3. set() validates: a value outside the allowed range throws sfx::Error (nothing is silently clamped).
e.set("duration", 4.0).set("intensity", 0.8).set("brightness", 0.5);
e.seed(2024); // same seed = same audio every time
try { e.set("intensity", 5.0); } catch (const sfx::Error& err) { std::printf("rejected: %s\n", err.what()); }
// 4. Render and save. Output is stereo 44.1 kHz, peak-normalised to -1 dBFS unless you change RenderSettings.
sfx::Rendered audio = e.render();
std::printf("%.2f s, peak %.1f dB\n", audio.seconds(), audio.stats().peak_db());
audio.save("sfx_01_find_and_tweak.wav");
}Download sfx_01_find_and_tweak.cpp
Try this: replace riser with impact or glitch and explore.
2. Layer effects on a timeline
Layered mixes several presets: position them in seconds or beats, set relative gain, transpose, pan, or reverse. This builds a riser that lands exactly on an impact.
// Layered: combine several effects on a timeline (riser into impact, with a reversed tail).
#include "wauvio/sfx.hpp"
namespace sfx = wauvio::sfx;
int main() {
sfx::Layered fx;
fx.tempo(120).seed(99);
// Riser builds for 4 beats (2 s at 120 BPM)...
fx.add("noise_riser", sfx::LayerOpts().dur(2.0).gain(-3));
// ...impact lands exactly on beat 4, a bit louder and an octave lower...
fx.add("cinematic_impact", sfx::LayerOpts().at_beats(4).transpose(-12).gain(0));
// ...and a reversed version of the same impact leads into it, panned left.
fx.add("cinematic_impact", sfx::LayerOpts().at_beats(2).flip().gain(-9).place(-0.6).with_seed(5));
sfx::Rendered out = fx.render();
out.save("sfx_02_layering.wav");
}Try this: change the tempo and see everything stay locked to the beat grid.
3. Build a sound from scratch
When no preset fits, write a Recipe: layers, each with one source (oscillator, noise, modal, grain…) and a chain of processors. Traj describes how a value changes over a layer’s length. See the recipe reference for every source and processor.
// Build a sound from scratch with the recipe language: a laser "zap".
// A Recipe has layers; each layer = one source -> envelope -> processors -> level/pan.
#include "wauvio/sfx.hpp"
namespace sfx = wauvio::sfx;
using sfx::Traj;
int main() {
sfx::Recipe r;
r.name = "zap";
r.duration = 0.6;
r.tail = 0.4; // extra time for reverb/echo to ring out
// Layer 1: a sawtooth sweeping from 2 kHz down to 120 Hz (Traj describes change over the layer's length).
auto& body = r.add("body");
body.osc(sfx::Wave::Saw, Traj::pitch_hz(2000, 120, sfx::Interp::Exp))
.shape(Traj::decay(0.001)) // fast exponential fade-out
.lp(Traj::linear(9000, 600), 2.0) // filter closes as it falls
.drive(0.4)
.gain(0.8);
// Layer 2: a quick burst of noise for the "crack" at the start.
auto& crack = r.add("crack");
crack.noise(sfx::NoiseColor::White)
.shape(Traj::ar(0.02, 1.0, 0.0))
.len(0.08)
.hp(Traj(3000.0))
.gain(0.4);
r.layers[0].echo(0.12, 0.35, 0.25).reverb(0.8, 0.5, 0.2); // processors apply in the order written
sfx::Rendered out = sfx::render(r, /*seed=*/1);
out.save("sfx_03_custom_recipe.wav");
}Download sfx_03_custom_recipe.cpp
Try this: change Wave::Saw to Square, or lengthen the pitch sweep.
4. Variations from seeds
The same preset with different seeds yields a family of similar-but-different sounds, handy for game audio where repetition is noticeable.
// Same preset, different seeds = a family of related-but-different sounds (great for games: no two footsteps alike).
#include "wauvio/sfx.hpp"
#include <string>
namespace sfx = wauvio::sfx;
int main() {
for (int i = 0; i < 5; ++i) {
sfx::Effect e = sfx::make("cinematic_impact");
e.set("duration", 1.0).seed(1000 + i);
e.render().save("sfx_04_variation_" + std::to_string(i) + ".wav");
}
}Download sfx_04_variations.cpp
Try this: vary a parameter and the seed together for even more variety.
5. Render a whole category
Loop over a category to audition or export it all. Error handling is per preset.
// Render every preset in a category (like `wauvio_sfx_tool render-category risers`).
#include "wauvio/sfx.hpp"
#include <cstdio>
#include <cstdlib>
namespace sfx = wauvio::sfx;
int main() {
std::system("mkdir -p sfx_risers");
for (const sfx::Preset* p : sfx::presets_in(sfx::Category::Risers)) {
try {
sfx::make(p->id).render().save("sfx_risers/" + p->id + ".wav");
std::printf("ok %s\n", p->id.c_str());
} catch (const sfx::Error& e) {
std::printf("FAIL %s: %s\n", p->id.c_str(), e.what());
}
}
}Download sfx_05_batch_category.cpp
Try this: use Category::Impacts or list all with sfx::all_presets().
No code? Use the command-line tool
g++ -std=c++17 -O2 -I/path/to/wauvio-repo wauvio/sfx/tools/wauvio_sfx_tool.cpp -o wauvio_sfx_tool
./wauvio_sfx_tool search riser
./wauvio_sfx_tool info noise_riser
./wauvio_sfx_tool render noise_riser --duration 4 --set intensity=0.8 --out my_sfx
./wauvio_sfx_tool render-category impacts --out my_sfxDetails: tool reference. More complete programs: the eight bundled examples.