Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::NoiseSourceT< SampleType > Class Template Reference

A deterministic, colourable noise generator. More...

#include <noise_source.hpp>

Public Member Functions

 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.

Static Public Attributes

static constexpr std::uint32_t default_seed = 0x1D872B41u
 Default seed.

Detailed Description

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:

  1. 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.
  2. 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.

Constructor & Destructor Documentation

◆ NoiseSourceT()

template<typename SampleType = float>
pulp::signal::NoiseSourceT< SampleType >::NoiseSourceT ( )
inline

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.

Member Function Documentation

◆ color()

template<typename SampleType = float>
NoiseColor pulp::signal::NoiseSourceT< SampleType >::color ( ) const
inline

◆ prepare()

template<typename SampleType = float>
void pulp::signal::NoiseSourceT< SampleType >::prepare ( double sample_rate)
inline

Fixes the sample rate and re-measures the per-colour normalisation.

Leaves the generator rewound to its seed.

◆ process() [1/2]

template<typename SampleType = float>
SampleType pulp::signal::NoiseSourceT< SampleType >::process ( )
inline

Next sample, normalised so every colour has approximately the same RMS.

◆ process() [2/2]

template<typename SampleType = float>
void pulp::signal::NoiseSourceT< SampleType >::process ( SampleType * buffer,
int num_samples )
inline

◆ reset()

template<typename SampleType = float>
void pulp::signal::NoiseSourceT< SampleType >::reset ( )
inline

Rewinds the generator to its seed and clears the colour filter state.

◆ seed()

template<typename SampleType = float>
std::uint32_t pulp::signal::NoiseSourceT< SampleType >::seed ( ) const
inline

◆ set_color()

template<typename SampleType = float>
void pulp::signal::NoiseSourceT< SampleType >::set_color ( NoiseColor c)
inline

Selects the spectral tilt.

prepare() measures every colour at the current sample rate, so this RT setter only selects the cached gain and rewinds the colour-filter state.

◆ set_seed()

template<typename SampleType = float>
void pulp::signal::NoiseSourceT< SampleType >::set_seed ( std::uint32_t seed)
inline

Sets the seed used by reset().

Does not itself rewind — call reset() (or note_on-equivalent) to take the new seed into use.

◆ white()

template<typename SampleType = float>
SampleType pulp::signal::NoiseSourceT< SampleType >::white ( )
inline

Raw uniform white sample in [-1, 1), bypassing the colour filter and the normalisation.

Voices that want an unfiltered burst (a click, a modal exciter) use this so they do not pay for a filter they will replace.

Member Data Documentation

◆ default_seed

template<typename SampleType = float>
std::uint32_t pulp::signal::NoiseSourceT< SampleType >::default_seed = 0x1D872B41u
staticconstexpr

Default seed.

Any non-zero value works; xorshift is degenerate at zero, so set_seed(0) is remapped to this value.


The documentation for this class was generated from the following file: