DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::NoiseGenerator< T > Class Template Reference

Generates decorellated noise (white, pink, brown) across multiple channels. More...

#include <NoiseGenerator.h>

Public Types

enum class  Type { White , Pink , Brown }
 

Public Member Functions

void prepare (const AudioSpec &spec)
 Prepares the noise generator and allocates internal state.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Fills the buffer with generated noise.
 
void reset () noexcept
 Resets the internal PRNG and filter states.
 
void setType (Type type) noexcept
 Sets the noise spectrum type.
 
void setLevel (T levelDb) noexcept
 Sets the output level in decibels. Thread-safe.
 
void setGain (T gain) noexcept
 Sets the output level as linear gain. Thread-safe.
 
Type getType () const noexcept
 Retrieves the currently requested noise type.
 
getGain () const noexcept
 Retrieves the current target gain in linear scale.
 
std::vector< uint8_t > getState () const
 Serializes the parameter state (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores parameters from a blob (tolerant; rejects foreign ids).
 

Detailed Description

template<FloatType T>
class dspark::NoiseGenerator< T >

Generates decorellated noise (white, pink, brown) across multiple channels.

Ensures cache-friendly memory layout and lock-free thread safety. Implements block-level linear gain smoothing to prevent audio artifacts (zipper noise) upon parameter changes.

Template Parameters
TSample type (float or double).

Definition at line 62 of file NoiseGenerator.h.

Member Enumeration Documentation

◆ Type

template<FloatType T>
enum class dspark::NoiseGenerator::Type
strong
Enumerator
White 
Pink 
Brown 

Definition at line 65 of file NoiseGenerator.h.

Member Function Documentation

◆ getGain()

template<FloatType T>
T dspark::NoiseGenerator< T >::getGain ( ) const
inlinenoexcept

Retrieves the current target gain in linear scale.

Returns
The linear gain coefficient.

Definition at line 240 of file NoiseGenerator.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::NoiseGenerator< T >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 247 of file NoiseGenerator.h.

◆ getType()

template<FloatType T>
Type dspark::NoiseGenerator< T >::getType ( ) const
inlinenoexcept

Retrieves the currently requested noise type.

Returns
The active NoiseGenerator::Type.

Definition at line 231 of file NoiseGenerator.h.

◆ prepare()

template<FloatType T>
void dspark::NoiseGenerator< T >::prepare ( const AudioSpec spec)
inline

Prepares the noise generator and allocates internal state.

An invalid spec (non-positive or non-finite fields) is a no-op that keeps the previous state.

Parameters
specAudio environment specification containing sample rate and channel count.

Definition at line 80 of file NoiseGenerator.h.

◆ processBlock()

template<FloatType T>
void dspark::NoiseGenerator< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Fills the buffer with generated noise.

Overwrites all existing data in the buffer. Applies smoothed gain changes transparently. Real-time safe (lock-free, zero allocations).

Parameters
bufferAudio buffer view to fill.

Definition at line 118 of file NoiseGenerator.h.

◆ reset()

template<FloatType T>
void dspark::NoiseGenerator< T >::reset ( )
inlinenoexcept

Resets the internal PRNG and filter states.

Restores the per-channel deterministic seeds too, so an offline render after reset() reproduces the exact same noise sequence (the generator's own reset() only clears filter state; the PRNG would otherwise continue from wherever it was).

Definition at line 176 of file NoiseGenerator.h.

◆ setGain()

template<FloatType T>
void dspark::NoiseGenerator< T >::setGain ( gain)
inlinenoexcept

Sets the output level as linear gain. Thread-safe.

Parameters
gainLinear gain coefficient (1.0 = unity). Non-finite values are ignored.

Definition at line 221 of file NoiseGenerator.h.

◆ setLevel()

template<FloatType T>
void dspark::NoiseGenerator< T >::setLevel ( levelDb)
inlinenoexcept

Sets the output level in decibels. Thread-safe.

Parameters
levelDbLevel in dB (0 = unity, -inf = silence). NaN and +inf are ignored; -inf maps to gain 0 as documented.

Definition at line 210 of file NoiseGenerator.h.

◆ setState()

template<FloatType T>
bool dspark::NoiseGenerator< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids).

Definition at line 256 of file NoiseGenerator.h.

◆ setType()

template<FloatType T>
void dspark::NoiseGenerator< T >::setType ( Type  type)
inlinenoexcept

Sets the noise spectrum type.

Thread-safe and lock-free. The update is deferred to the audio thread during the next processBlock() call to avoid mutating filter states mid-read.

Parameters
typeNoise color (White, Pink, or Brown).

Definition at line 196 of file NoiseGenerator.h.


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