DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::GranularProcessor< T > Class Template Reference

Granular clouds and spectral-freeze textures from live input. More...

#include <GranularProcessor.h>

Public Member Functions

void prepare (const AudioSpec &spec, double bufferSeconds=4.0)
 Allocates the capture ring and grain pool.
 
void reset () noexcept
 Kills all grains and clears the capture ring. RT-safe.
 
void setGrainSize (T ms) noexcept
 Grain duration in milliseconds [10, 500] (default 80). Non-finite values are ignored.
 
void setDensity (T perSecond) noexcept
 Grains per second [1, 200] (default 25). Non-finite values are ignored.
 
void setJitter (T amount) noexcept
 Position jitter [0, 1]: how far back grains may start (default 0.3). Non-finite values are ignored.
 
void setPitch (T semitones) noexcept
 Per-grain pitch shift in semitones [-24, +24] (default 0). Non-finite values are ignored.
 
void setPitchJitter (T semitones) noexcept
 Random pitch spread per grain in semitones [0, 12] (default 0). Non-finite values are ignored.
 
void setSpread (T amount) noexcept
 Stereo spread of grain panning [0, 1] (default 0.5). Non-finite values are ignored.
 
void setFreeze (bool frozen) noexcept
 Freezes capture: grains keep playing the held history.
 
void setMix (T mix) noexcept
 Dry/wet mix [0, 1] (default 1); smoothed linearly over one block. Non-finite values are ignored.
 
T getGrainSize () const noexcept
 
T getDensity () const noexcept
 
T getJitter () const noexcept
 
T getPitch () const noexcept
 
T getPitchJitter () const noexcept
 
T getSpread () const noexcept
 
bool getFreeze () const noexcept
 
T getMix () const noexcept
 
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).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a block in-place (1 or 2 channels). Pass-through until prepare() succeeds.
 

Static Public Member Functions

static constexpr int getLatency () noexcept
 Zero: the cloud is parallel to the dry path.
 

Static Public Attributes

static constexpr int kMaxGrains = 64
 

Detailed Description

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

Granular clouds and spectral-freeze textures from live input.

Template Parameters
TSample type (float or double).

Definition at line 65 of file GranularProcessor.h.

Member Function Documentation

◆ getDensity()

template<FloatType T>
T dspark::GranularProcessor< T >::getDensity ( ) const
inlinenoexcept

Definition at line 186 of file GranularProcessor.h.

◆ getFreeze()

template<FloatType T>
bool dspark::GranularProcessor< T >::getFreeze ( ) const
inlinenoexcept

Definition at line 191 of file GranularProcessor.h.

◆ getGrainSize()

template<FloatType T>
T dspark::GranularProcessor< T >::getGrainSize ( ) const
inlinenoexcept

Definition at line 185 of file GranularProcessor.h.

◆ getJitter()

template<FloatType T>
T dspark::GranularProcessor< T >::getJitter ( ) const
inlinenoexcept

Definition at line 187 of file GranularProcessor.h.

◆ getLatency()

template<FloatType T>
static constexpr int dspark::GranularProcessor< T >::getLatency ( )
inlinestaticconstexprnoexcept

Zero: the cloud is parallel to the dry path.

Definition at line 195 of file GranularProcessor.h.

◆ getMix()

template<FloatType T>
T dspark::GranularProcessor< T >::getMix ( ) const
inlinenoexcept

Definition at line 192 of file GranularProcessor.h.

◆ getPitch()

template<FloatType T>
T dspark::GranularProcessor< T >::getPitch ( ) const
inlinenoexcept

Definition at line 188 of file GranularProcessor.h.

◆ getPitchJitter()

template<FloatType T>
T dspark::GranularProcessor< T >::getPitchJitter ( ) const
inlinenoexcept

Definition at line 189 of file GranularProcessor.h.

◆ getSpread()

template<FloatType T>
T dspark::GranularProcessor< T >::getSpread ( ) const
inlinenoexcept

Definition at line 190 of file GranularProcessor.h.

◆ getState()

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

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

Definition at line 198 of file GranularProcessor.h.

◆ prepare()

template<FloatType T>
void dspark::GranularProcessor< T >::prepare ( const AudioSpec &  spec,
double  bufferSeconds = 4.0 
)
inline

Allocates the capture ring and grain pool.

Invalid specs (non-positive/non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through. A non-finite bufferSeconds falls back to the 4 s default.

Parameters
specAudio environment specification.
bufferSecondsCapture history length, clamped to [0.5, 16] s (default 4 s).

Definition at line 84 of file GranularProcessor.h.

◆ processBlock()

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

Processes a block in-place (1 or 2 channels). Pass-through until prepare() succeeds.

Definition at line 234 of file GranularProcessor.h.

◆ reset()

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

Kills all grains and clears the capture ring. RT-safe.

Definition at line 110 of file GranularProcessor.h.

◆ setDensity()

template<FloatType T>
void dspark::GranularProcessor< T >::setDensity ( T  perSecond)
inlinenoexcept

Grains per second [1, 200] (default 25). Non-finite values are ignored.

Definition at line 133 of file GranularProcessor.h.

◆ setFreeze()

template<FloatType T>
void dspark::GranularProcessor< T >::setFreeze ( bool  frozen)
inlinenoexcept

Freezes capture: grains keep playing the held history.

Definition at line 172 of file GranularProcessor.h.

◆ setGrainSize()

template<FloatType T>
void dspark::GranularProcessor< T >::setGrainSize ( T  ms)
inlinenoexcept

Grain duration in milliseconds [10, 500] (default 80). Non-finite values are ignored.

Definition at line 125 of file GranularProcessor.h.

◆ setJitter()

template<FloatType T>
void dspark::GranularProcessor< T >::setJitter ( T  amount)
inlinenoexcept

Position jitter [0, 1]: how far back grains may start (default 0.3). Non-finite values are ignored.

Definition at line 141 of file GranularProcessor.h.

◆ setMix()

template<FloatType T>
void dspark::GranularProcessor< T >::setMix ( T  mix)
inlinenoexcept

Dry/wet mix [0, 1] (default 1); smoothed linearly over one block. Non-finite values are ignored.

Definition at line 179 of file GranularProcessor.h.

◆ setPitch()

template<FloatType T>
void dspark::GranularProcessor< T >::setPitch ( T  semitones)
inlinenoexcept

Per-grain pitch shift in semitones [-24, +24] (default 0). Non-finite values are ignored.

Definition at line 149 of file GranularProcessor.h.

◆ setPitchJitter()

template<FloatType T>
void dspark::GranularProcessor< T >::setPitchJitter ( T  semitones)
inlinenoexcept

Random pitch spread per grain in semitones [0, 12] (default 0). Non-finite values are ignored.

Definition at line 157 of file GranularProcessor.h.

◆ setSpread()

template<FloatType T>
void dspark::GranularProcessor< T >::setSpread ( T  amount)
inlinenoexcept

Stereo spread of grain panning [0, 1] (default 0.5). Non-finite values are ignored.

Definition at line 165 of file GranularProcessor.h.

◆ setState()

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

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

Definition at line 215 of file GranularProcessor.h.

Member Data Documentation

◆ kMaxGrains

template<FloatType T>
constexpr int dspark::GranularProcessor< T >::kMaxGrains = 64
staticconstexpr

Definition at line 68 of file GranularProcessor.h.


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