|
| | NoiseSourceT () |
| | A default-constructed source is immediately usable at 44.1 kHz, so a voice that forgets to call prepare() produces noise rather than silence and the mistake is audible instead of subtle.
|
| void | prepare (double sample_rate) |
| | Fixes the sample rate and re-measures the per-colour normalisation.
|
| void | set_color (NoiseColor c) |
| | Selects the spectral tilt.
|
| NoiseColor | color () const |
| void | set_seed (std::uint32_t seed) |
| | Sets the seed used by reset().
|
| std::uint32_t | seed () const |
| void | reset () |
| | Rewinds the generator to its seed and clears the colour filter state.
|
| SampleType | process () |
| | Next sample, normalised so every colour has approximately the same RMS.
|
| void | process (SampleType *buffer, int num_samples) |
| SampleType | white () |
| | Raw uniform white sample in [-1, 1), bypassing the colour filter and the normalisation.
|
template<typename SampleType = float>
class pulp::signal::NoiseSourceT< SampleType >
A deterministic, colourable noise generator.
Two properties matter for percussion and any other one-shot voice:
- Determinism. reset() rewinds the generator to its seed, so the same (seed, colour, sample rate) always produces the same sample sequence. A drum voice that reseeds on every hit therefore renders bit-identically for a given parameter set, which is what makes golden-file tests and offline bounces reproducible. Voices that want per-hit variation advance the seed deliberately (set_seed) rather than relying on a free-running generator.
- Sample-rate independence. The colour filters are specified in Hz, not in per-sample coefficients, so the measured spectral slope is the same at 44.1 kHz and at 192 kHz. Output level is equalised across colours by a normalisation constant measured during prepare(), so switching colour does not jump the level.
The generator is a 32-bit xorshift, chosen because its state is one word: a voice can snapshot and restore it, and a whole drum kit's worth of generators costs nothing.
RT contract: prepare() and set_color() measure the normalisation constant by rendering a fixed-length burst. They allocate nothing, but they are bounded work rather than constant work, so call them from prepare() or a parameter-change path, not per sample. process(), white(), reset(), and set_seed() allocate nothing and take no locks.