synth.hpp — FM and polyphony
Namespace wauvio::synth.
FMSynth
Two-operator FM. Fields carrier_freq, modulator_freq, mod_index, amplitude; render(seconds) returns a mono buffer.
Voice
One polyphonic voice: two oscillators (osc, detuned osc2), an ADSR with its State, an SVFilter, plus active, frequency, velocity, birth_sample (used for stealing) and current_amp. trigger(freq, vel, env, shape1, shape2, detune_hz, timestamp, sr) starts a note, release() begins the release, tick(sr) returns the next sample.
VoiceManager
16-voice allocator (MAX_VOICES). Patch fields: shape1 (Sawtooth), shape2 (Square), detune_hz (2.5), adsr (0.01/0.08/0.7/0.15), filter_proto (copied to each voice). note_on(freq, velocity) takes a free voice or steals one when full; note_off(freq), all_notes_off(), tick(sr), render(seconds), active_voices().
Full API listing
wauvio/core/synth.hpp
wauvio::synth::class FMSynth
// §15 FM SYNTHESIS (unchanged from v1)
class FMSynth
public:
double carrier_freq = 440.0;
double modulator_freq = 440.0;
double mod_index = 1.0;
double amplitude = 1.0;
Buffer render(double seconds, int sample_rate = 0) const
wauvio::synth::struct Voice
// §23 POLYPHONIC VOICE SYSTEM
/// One voice in a polyphonic synth patch.
struct Voice
bool active = false;
double frequency = 440.0;
double velocity = 1.0;
uint64_t birth_sample = 0; ///< When was this voice triggered (for stealing)
float current_amp = 0.0f;
wauvio::osc::Oscillator osc;
wauvio::osc::Oscillator osc2; ///< Optional second oscillator (detune layer)
wauvio::env::ADSR adsr;
wauvio::env::ADSR::State adsr_state;
wauvio::filter::SVFilter filt;
void trigger(double freq, double vel, const wauvio::env::ADSR& env,
wauvio::osc::WaveShape shape1, wauvio::osc::WaveShape shape2,
double detune_hz, uint64_t timestamp, int /*sample_rate*/)
void release() { adsr_state.note_off_trigger(); }
/// Returns next sample (mono).
float tick(int sample_rate) noexcept
wauvio::synth::class VoiceManager
/// Polyphonic voice manager - allocates voices, handles stealing.
class VoiceManager
public:
static constexpr int MAX_VOICES = 16;
wauvio::osc::WaveShape shape1 = wauvio::osc::WaveShape::Sawtooth;
wauvio::osc::WaveShape shape2 = wauvio::osc::WaveShape::Square;
double detune_hz = 2.5;
wauvio::env::ADSR adsr = {0.01, 0.08, 0.7, 0.15};
wauvio::filter::SVFilter filter_proto; ///< Prototype filter settings copied per voice
void note_on(double freq, double velocity = 1.0)
void note_off(double freq)
void all_notes_off()
float tick(int sample_rate) noexcept
Buffer render(double seconds, int sample_rate = 0)
int active_voices() const