DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::AnalogRandom::Generator< Real > Class Template Reference

Main generator class for analog-style random modulation. More...

#include <AnalogRandom.h>

Public Member Functions

 Generator () noexcept
 
 Generator (std::uint64_t seed) noexcept
 
 Generator (Generator &&other) noexcept
 
Generator & operator= (Generator &&other) noexcept
 
 Generator (const Generator &)=delete
 
Generator & operator= (const Generator &)=delete
 
void prepare (double sampleRate) noexcept
 Prepare the generator with the audio sample rate.
 
void reset () noexcept
 Reset internal state (phase, smoothing, noise states).
 
void reseed (std::uint64_t newSeed) noexcept
 Request a lock-free reseed of the internal PRNG.
 
Real getNextSample () noexcept
 Generate and return the next modulation sample.
 
void getNextBlock (std::span< Real > outputBuffer) noexcept
 Generate a block of modulation samples.
 
Real getCurrentValue () const noexcept
 Last published output value. Lock-free readout, any thread (relaxed atomic; updated once per getNextSample() and once per getNextBlock() block).
 
Real getPhase () const noexcept
 Last published LFO phase in [0, 1). Lock-free readout, any thread (relaxed atomic; same publication points as getCurrentValue()). Independent word: it may be one sample newer or older than getCurrentValue() (benign for displays).
 
void setNoiseType (NoiseType type) noexcept
 
void setRateHz (Real rateInHz) noexcept
 Free-running retrigger rate in Hz; non-finite values are ignored (a NaN or infinite rate froze the phase as NaN for good).
 
void setRateBPM (double bpm, BpmDivision division) noexcept
 
void updateBPM (double newBpm) noexcept
 
template<typename T >
void setRange (T min, T max) noexcept
 Set the output range for values. Safe from tearing.
 
void setSmoothing (bool shouldBeEnabled, Real timeInMs=static_cast< Real >(50.0)) noexcept
 Enables one-pole smoothing of the held targets.
 
void setQuantization (Real step) noexcept
 
void setAnalogDefault (AnalogComponent component) noexcept
 
template<typename Int >
Int getNextDiscrete (Int imin, Int imax) noexcept
 
int getNextDiscreteInt (int imin, int imax) noexcept
 

Detailed Description

template<typename Real = float>
class dspark::AnalogRandom::Generator< Real >

Main generator class for analog-style random modulation.

Template Parameters
RealFloating point type to represent values (float or double).

Definition at line 173 of file AnalogRandom.h.

Constructor & Destructor Documentation

◆ Generator() [1/4]

template<typename Real = float>
dspark::AnalogRandom::Generator< Real >::Generator ( )
inlinenoexcept

Definition at line 179 of file AnalogRandom.h.

◆ Generator() [2/4]

template<typename Real = float>
dspark::AnalogRandom::Generator< Real >::Generator ( std::uint64_t  seed)
inlineexplicitnoexcept

Definition at line 184 of file AnalogRandom.h.

◆ Generator() [3/4]

template<typename Real = float>
dspark::AnalogRandom::Generator< Real >::Generator ( Generator< Real > &&  other)
inlinenoexcept

Definition at line 194 of file AnalogRandom.h.

◆ Generator() [4/4]

template<typename Real = float>
dspark::AnalogRandom::Generator< Real >::Generator ( const Generator< Real > &  )
delete

Member Function Documentation

◆ getCurrentValue()

template<typename Real = float>
Real dspark::AnalogRandom::Generator< Real >::getCurrentValue ( ) const
inlinenoexcept

Last published output value. Lock-free readout, any thread (relaxed atomic; updated once per getNextSample() and once per getNextBlock() block).

Definition at line 419 of file AnalogRandom.h.

◆ getNextBlock()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::getNextBlock ( std::span< Real >  outputBuffer)
inlinenoexcept

Generate a block of modulation samples.

Parameters
outputBufferC++20 span representing the destination buffer.
Note
Highly optimized SIMD/Cache-friendly path.

Definition at line 357 of file AnalogRandom.h.

◆ getNextDiscrete()

template<typename Real = float>
template<typename Int >
Int dspark::AnalogRandom::Generator< Real >::getNextDiscrete ( Int  imin,
Int  imax 
)
inlinenoexcept

Definition at line 540 of file AnalogRandom.h.

◆ getNextDiscreteInt()

template<typename Real = float>
int dspark::AnalogRandom::Generator< Real >::getNextDiscreteInt ( int  imin,
int  imax 
)
inlinenoexcept

Definition at line 563 of file AnalogRandom.h.

◆ getNextSample()

template<typename Real = float>
Real dspark::AnalogRandom::Generator< Real >::getNextSample ( )
inlinenoexcept

Generate and return the next modulation sample.

Returns
Next modulation value mapped into [min, max].
Note
Safe for real-time audio thread. Mitigates denormals dynamically.

Definition at line 306 of file AnalogRandom.h.

◆ getPhase()

template<typename Real = float>
Real dspark::AnalogRandom::Generator< Real >::getPhase ( ) const
inlinenoexcept

Last published LFO phase in [0, 1). Lock-free readout, any thread (relaxed atomic; same publication points as getCurrentValue()). Independent word: it may be one sample newer or older than getCurrentValue() (benign for displays).

Definition at line 428 of file AnalogRandom.h.

◆ operator=() [1/2]

template<typename Real = float>
Generator & dspark::AnalogRandom::Generator< Real >::operator= ( const Generator< Real > &  )
delete

◆ operator=() [2/2]

template<typename Real = float>
Generator & dspark::AnalogRandom::Generator< Real >::operator= ( Generator< Real > &&  other)
inlinenoexcept

Definition at line 222 of file AnalogRandom.h.

◆ prepare()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::prepare ( double  sampleRate)
inlinenoexcept

Prepare the generator with the audio sample rate.

Parameters
sampleRateSample rate in Hz (must be > 0).

Definition at line 262 of file AnalogRandom.h.

◆ reseed()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::reseed ( std::uint64_t  newSeed)
inlinenoexcept

Request a lock-free reseed of the internal PRNG.

Parameters
newSeedNew seed value. Applied on the next audio tick.

Definition at line 291 of file AnalogRandom.h.

◆ reset()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::reset ( )
inlinenoexcept

Reset internal state (phase, smoothing, noise states).

Definition at line 275 of file AnalogRandom.h.

◆ setAnalogDefault()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setAnalogDefault ( AnalogComponent  component)
inlinenoexcept

Definition at line 502 of file AnalogRandom.h.

◆ setNoiseType()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setNoiseType ( NoiseType  type)
inlinenoexcept

Definition at line 437 of file AnalogRandom.h.

◆ setQuantization()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setQuantization ( Real  step)
inlinenoexcept

Definition at line 495 of file AnalogRandom.h.

◆ setRange()

template<typename Real = float>
template<typename T >
void dspark::AnalogRandom::Generator< Real >::setRange ( T  min,
T  max 
)
inlinenoexcept

Set the output range for values. Safe from tearing.

Definition at line 470 of file AnalogRandom.h.

◆ setRateBPM()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setRateBPM ( double  bpm,
BpmDivision  division 
)
inlinenoexcept

Definition at line 452 of file AnalogRandom.h.

◆ setRateHz()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setRateHz ( Real  rateInHz)
inlinenoexcept

Free-running retrigger rate in Hz; non-finite values are ignored (a NaN or infinite rate froze the phase as NaN for good).

Definition at line 445 of file AnalogRandom.h.

◆ setSmoothing()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::setSmoothing ( bool  shouldBeEnabled,
Real  timeInMs = static_cast<Real>(50.0) 
)
inlinenoexcept

Enables one-pole smoothing of the held targets.

Parameters
shouldBeEnabledTrue to smooth, false for hard steps.
timeInMsTime constant in ms; zero, negative or NaN means instantaneous. Stored as a time, so it stays correct across a later prepare() at another rate.

Definition at line 487 of file AnalogRandom.h.

◆ updateBPM()

template<typename Real = float>
void dspark::AnalogRandom::Generator< Real >::updateBPM ( double  newBpm)
inlinenoexcept

Definition at line 460 of file AnalogRandom.h.


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