# synth module ## Owned files - Wavetable.h, Wavetable.cpp - Oscillator.h, Oscillator.cpp - SubOscillator.h, SubOscillator.cpp - NoiseOscillator.h, NoiseOscillator.cpp - Envelope.h, Envelope.cpp - LFO.h, LFO.cpp - Filter.h, Filter.cpp - FilterBank.h, FilterBank.cpp - SynthVoice.h, SynthVoice.cpp ## Rules - Use `noexcept` on every per-sample DSP path and cheap getter. - Use `std::array` for fixed-size state and `std::vector` for delay lines and table buffers. - Size every buffer and delay line in `prepare()`, never in `process` or `render`. - Clamp filter and envelope state so extreme settings cannot produce NaN or inf. - Use `juce::MathConstants::pi` and `twoPi` instead of raw pi literals. - Use `(size_t)` casts when indexing containers with int loop variables. - Pass global per-block state into voices as a `const RenderContext&`. - Never allocate memory in the audio path. - Keep oscillator phase when changing held-note parameters. LFO phase offsets are separate from the running phase. ## IF-THEN - Wavetables are prebuilt during Engine construction. Audio and GUI code read them without triggering generation. - IF a parameter is read every block THEN snapshot it into a struct (`OscParams`, `RenderContext`) instead of reading the APVTS per sample. ## Examples ```cpp // BAD: lazy table build reached from the render path allocates on the audio thread const Wavetable& wt = library.getTable (wave); ``` ```cpp // GOOD: build once in the Engine constructor, then only read const references library.prebuild(); // in the Engine constructor const Wavetable& wt = library.getTable (wave); // lookup, no allocation ``` ```cpp // BAD: raw pi literal duplicated across files const double step = 6.28318530717958647692 * freq / sr; ``` ```cpp // GOOD: single source const double step = juce::MathConstants::twoPi * freq / sr; ``` This file overrides /AGENTS.md where they conflict.