Core engine (wauvio/core)

env.hpp — envelopes

Namespace wauvio::env.

See it in action: Your first tone · FM synthesis

ADSR

Fields attack (0.01 s), decay (0.05 s), sustain (0.7, a level), release (0.1 s). Constructor ADSR(a, d, s, r).

  • apply(buf, total_seconds, note_off = -1, sample_rate) multiplies a buffer by the envelope. If note_off < 0 the release begins at total_seconds − release; after the release the buffer is silenced.
  • tick(State&, sample_rate) is the stateful per-sample form used by voices. State carries the phase (ATTACK, DECAY, SUSTAIN, RELEASE, DONE) and value; note_off_trigger() starts the release.

DAHDSR

Adds pre_delay (silence before attack) and hold (time at peak). Constructor order: (pre_delay, attack, hold, decay, sustain, release). Offline apply() only; no stateful tick.

LoopableEnvelope

Attack→decay cycle that repeats while loop is true, behaving as a shaped slow LFO; with loop = false it settles at sustain. Stateful tick(State&, sample_rate) only.

Full API listing

wauvio/core/env.hpp

wauvio::env::class ADSR

//  §9  ADSR ENVELOPE  (unchanged from v1, retained for compatibility)
class ADSR
public:
    double attack  = 0.01;
    double decay   = 0.05;
    double sustain = 0.7;
    double release = 0.1;
    ADSR() = default;
    ADSR(double a, double d, double s, double r)
        : attack(a), decay(d), sustain(s), release(r) {}
    void apply(Buffer& buf, double total_seconds,
               double note_off = -1.0, int sample_rate = 0) const

    /// Sample-by-sample stateful version (for voice systems).
    struct State
        enum Phase { ATTACK, DECAY, SUSTAIN, RELEASE, DONE } phase = ATTACK;
        double value    = 0.0;
        double note_off = -1.0;  ///< Call note_off() to trigger release
        size_t sample   = 0;
        void note_off_trigger() { phase = RELEASE; }
    float tick(State& st, int sample_rate) const noexcept

wauvio::env::class DAHDSR

//  §10  AHDSR / DAHDSR MULTI-STAGE ENVELOPE
//  Hold stage between attack and decay.
//  Optional pre-delay (D = initial delay before attack).
class DAHDSR
public:
    double pre_delay = 0.0;   ///< D: seconds of silence before attack
    double attack    = 0.01;
    double hold      = 0.0;   ///< H: seconds at peak before decay
    double decay     = 0.05;
    double sustain   = 0.7;
    double release   = 0.1;
    DAHDSR() = default;
    DAHDSR(double d, double a, double h, double dec, double s, double r)
        : pre_delay(d), attack(a), hold(h), decay(dec), sustain(s), release(r) {}
    void apply(Buffer& buf, double total_seconds,
               double note_off = -1.0, int sample_rate = 0) const

wauvio::env::class LoopableEnvelope

//  §11  LOOPABLE ENVELOPE
//  Loops the attack→decay→sustain cycle indefinitely - behaves like a
//  slow LFO with a shaped waveform.
class LoopableEnvelope
public:
    double attack  = 0.1;
    double decay   = 0.2;
    double sustain = 0.5;   ///< Level held between decay and next attack
    bool   loop    = true;
    struct State
        enum Phase { ATT, DEC, SUS } phase = ATT;
        double value = 0.0;
    float tick(State& st, int sample_rate) const noexcept