Effect, Chain and DSP utilities
Effect (abstract base)
Header fx/core/fx_effect.hpp. Pure virtuals: name(), reset(), process(float* L, float* R, size_t n) (in place, streaming). Overridable: tail_seconds() (how long the output rings after silence), latency_samples() (lookahead delay), on_prepare().
bypass— honoured byChain, which then ignores the effect's latency and tail.prepare(sr)— allocate for a sample rate and reset; mandatory before calling the raw-pointerprocess().ensure_prepared(sr),sample_rate(),prepared().process(StereoBuffer&, sr)— whole buffer, in place, auto-prepares; no tail extension, latency not compensated.process(Buffer&, sr)runs as dual-mono and returns the channel average.
Chain
An ordered, owning list of effects. add<E>(args…) constructs in place and returns E& so parameters can be set immediately; add(unique_ptr), at(i), size(), empty(), clear(), reset(). latency_samples() and tail_seconds() sum the non-bypassed effects. process(buf, sr, keep_tail = true) runs from a clean state, removes the total latency so output stays aligned with input, and (with keep_tail) lengthens the buffer by tail_seconds() so reverb/delay tails survive. Chains are move-only.
DSP utilities (fx_common.hpp)
| Item | Description |
|---|---|
db_to_lin, lin_to_db, flush_denormal | Level conversion (floor 1e-12) and denormal flush |
div::whole … sixteenth, dotted(), triplet() | Beat-length constants (quarter = 1.0) and modifiers |
beats_to_seconds(bpm, beats) | Tempo helper |
Rng | Deterministic xorshift-style PRNG: reseed, next_u64, uniform [0,1), bipolar, gaussian |
FilterType, BiquadCoef, design_biquad, biquad_magnitude, Biquad | LowPass, HighPass, BandPass, Notch, Peak, LowShelf, HighShelf, AllPass designs; magnitude response; processing section |
DCBlocker | One-pole DC removal |
time_coef | Time-constant to smoothing coefficient |
LfoShape, lfo_eval | Sine, Triangle, Square, SoftSquare |
is_pow2, next_pow2, fft | FFT helpers (in-place complex FFT/IFFT) |
Audio file input (fx_io.hpp)
read_wav(path) → AudioData {sample_rate, channels (vector of vectors), frames()}; resample_linear(in, from_sr, to_sr). Used by ConvolutionReverb::load_ir.
Full API listing
wauvio/fx/core/fx_effect.hpp
wauvio::fx::class Effect
/// Base class for every wauvio::fx processor.
///
/// Parameters are plain public fields (like the rest of Wauvio) and are re-read
/// at the start of every process() call, so they can be changed between calls.
/// The raw-pointer process() is the streaming entry point (call prepare() first);
/// the StereoBuffer / Buffer overloads prepare automatically.
class Effect
public:
virtual ~Effect() = default;
bool bypass = false; ///< honoured by Chain (skips the effect and its latency/tail)
virtual std::string name() const = 0;
virtual void reset() = 0; ///< clear internal state (keeps parameters)
virtual void process(float* L, float* R, size_t n) = 0; ///< in place, streaming
virtual double tail_seconds() const { return 0.0; } ///< how long the output rings after silence
virtual size_t latency_samples() const { return 0; } ///< lookahead / FIR delay in samples
/// Allocates for `sr` and resets. Must be called before the raw process().
void prepare(int sr) { sr_ = sr > 0 ? sr : global_config().sample_rate; prepared_ = true; on_prepare(); reset(); }
int sample_rate() const noexcept { return sr_; }
bool prepared() const noexcept { return prepared_; }
void ensure_prepared(int sr) { if (sr <= 0) sr = global_config().sample_rate; if (!prepared_ || sr != sr_) prepare(sr); }
/// Convenience: whole-buffer, in place, no tail extension, latency NOT compensated.
void process(StereoBuffer& b, int sr = 0)
/// Mono convenience: runs as dual-mono and returns the channel average.
void process(Buffer& m, int sr = 0)
wauvio::fx::class Chain
/// An ordered list of effects. Whole-buffer processing with automatic
/// latency compensation and tail extension.
class Chain
public:
Chain() = default;
Chain(Chain&&) = default;
Chain& operator=(Chain&&) = default;
/// Construct an effect in place and return a reference so you can set parameters:
/// auto& c = chain.add<Compressor>(); c.threshold_db = -20;
template <class E, class... A>
E& add(A&&... a)
auto p = std::make_unique<E>(std::forward<A>(a)...);
E& ref = *p; fx_.push_back(std::move(p)); return ref;
template <class E>
E& add(std::unique_ptr<E> p) { E& ref = *p; fx_.push_back(std::move(p)); return ref; }
size_t size() const noexcept { return fx_.size(); }
bool empty() const noexcept { return fx_.empty(); }
Effect& at(size_t i) { return *fx_.at(i); }
const Effect& at(size_t i) const { return *fx_.at(i); }
void clear() { fx_.clear(); }
size_t latency_samples() const { size_t t = 0; for (auto& e : fx_) if (!e->bypass) t += e->latency_samples(); return t; }
double tail_seconds() const { double t = 0; for (auto& e : fx_) if (!e->bypass) t += e->tail_seconds(); return t; }
void reset() { for (auto& e : fx_) e->reset(); }
/// Process a whole buffer from a clean state. Output is aligned with the input
/// (latency removed) and, if keep_tail, extended by tail_seconds() so reverb and
/// delay tails are not cut off.
void process(StereoBuffer& buf, int sr = 0, bool keep_tail = true)
void process(Buffer& mono, int sr = 0, bool keep_tail = true)
wauvio/fx/core/fx_common.hpp
wauvio::fx::Free functions, constants and aliases
inline double db_to_lin(double db) noexcept { return std::pow(10.0, db / 20.0); }
inline double lin_to_db(double lin) noexcept { return 20.0 * std::log10(std::max(lin, 1e-12)); }
inline float flush_denormal(float x) noexcept { return (std::fabs(x) < 1e-20f) ? 0.0f : x; }
constexpr double whole = 4.0, half = 2.0, quarter = 1.0, eighth = 0.5, sixteenth = 0.25;
constexpr double dotted(double beats) noexcept { return beats * 1.5; }
constexpr double triplet(double beats) noexcept { return beats * 2.0 / 3.0; }
inline double beats_to_seconds(double bpm, double beats) noexcept
wauvio::fx::class Rng
class Rng
public:
explicit Rng(uint64_t seed = 0x9E3779B97F4A7C15ull) { reseed(seed); }
void reseed(uint64_t seed) { s_ = seed ? seed : 0x9E3779B97F4A7C15ull; for (int i = 0; i < 4; ++i) next_u64(); }
uint64_t next_u64() noexcept { s_ ^= s_ >> 12; s_ ^= s_ << 25; s_ ^= s_ >> 27; return s_ * 0x2545F4914F6CDD1Dull; }
double uniform() noexcept { return (next_u64() >> 11) * (1.0 / 9007199254740992.0); } // [0,1)
double bipolar() noexcept { return uniform() * 2.0 - 1.0; } // [-1,1)
double gaussian() noexcept { // N(0,1), Box-Muller
wauvio::fx::enum class FilterType
enum class FilterType { LowPass, HighPass, BandPass, Notch, Peak, LowShelf, HighShelf, AllPass };
wauvio::fx::struct BiquadCoef
struct BiquadCoef { double b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0; };
inline BiquadCoef design_biquad(FilterType t, double fs, double f0, double q, double gain_db = 0.0)
inline double biquad_magnitude(const BiquadCoef& c, double fs, double f)
wauvio::fx::class Biquad
class Biquad
public:
void set(const BiquadCoef& c) noexcept { c_ = c; }
const BiquadCoef& coef() const noexcept { return c_; }
float tick(float x) noexcept
void reset() noexcept { z1_ = z2_ = 0.0; }
wauvio::fx::class DCBlocker
class DCBlocker
public:
float tick(float x) noexcept { const float y = x - x1_ + 0.9982f * y1_; x1_ = x; y1_ = flush_denormal(y); return y; }
void reset() noexcept { x1_ = y1_ = 0.0f; }
inline double time_coef(double ms, double sr) noexcept
wauvio::fx::enum class LfoShape
enum class LfoShape { Sine, Triangle, Square, SoftSquare };
inline double lfo_eval(LfoShape s, double phase) noexcept
inline bool is_pow2(size_t n) noexcept { return n && !(n & (n - 1)); }
inline size_t next_pow2(size_t n) noexcept { size_t p = 1; while (p < n) p <<= 1; return p; }
inline void fft(std::vector<std::complex<float>>& a, bool inverse)
wauvio/fx/core/fx_io.hpp
wauvio::fx::struct AudioData
struct AudioData
int sample_rate = 44100;
std::vector<std::vector<float>> channels;
size_t frames() const { return channels.empty() ? 0 : channels[0].size(); }
inline AudioData read_wav(const std::string& path)
inline std::vector<float> resample_linear(const std::vector<float>& in, int from_sr, int to_sr)