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

Signal x carrier ring modulation with mix control and zero-latency smoothing. More...

#include <RingModulator.h>

Public Types

enum class  Mode { Classic , GeometricMean }
 Modulation mathematical mode. More...
 

Public Member Functions

void prepare (const AudioSpec &spec) noexcept
 Prepares the modulator for audio processing.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a block of audio in-place.
 
void reset () noexcept
 Resets the internal phase of the carrier oscillator.
 
void setFrequency (T hz) noexcept
 Sets the target carrier frequency. Smoothed internally.
 
void setMix (T mix) noexcept
 Sets the target dry/wet mix. Smoothed internally.
 
void setMode (Mode m) noexcept
 Sets the modulation mode.
 
void setSoar (T amount) noexcept
 Sets the soar threshold for Geometric Mean mode.
 
getFrequency () const noexcept
 
getMix () const noexcept
 
Mode getMode () const noexcept
 
getSoar () 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).
 

Detailed Description

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

Signal x carrier ring modulation with mix control and zero-latency smoothing.

Uses a single shared carrier oscillator for all channels ensuring phase coherence. The shared carrier is precomputed serially chunk by chunk (the phase accumulator is recursive); the per-channel apply loops are branch-free and auto-vectorizable.

Channels beyond those passed to prepare() are left untouched (pass-through), as is the whole buffer before prepare().

Template Parameters
TSample type (float or double).

Definition at line 66 of file RingModulator.h.

Member Enumeration Documentation

◆ Mode

template<FloatType T>
enum class dspark::RingModulator::Mode
strong

Modulation mathematical mode.

Enumerator
Classic 

Standard multiplication (sum & difference frequencies).

GeometricMean 

Geometric-mean mode: sqrt(|in|*|carrier|) * sign - richer, more musical.

Definition at line 70 of file RingModulator.h.

Member Function Documentation

◆ getFrequency()

template<FloatType T>
T dspark::RingModulator< T >::getFrequency ( ) const
inlinenoexcept

Definition at line 260 of file RingModulator.h.

◆ getMix()

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

Definition at line 261 of file RingModulator.h.

◆ getMode()

template<FloatType T>
Mode dspark::RingModulator< T >::getMode ( ) const
inlinenoexcept

Definition at line 262 of file RingModulator.h.

◆ getSoar()

template<FloatType T>
T dspark::RingModulator< T >::getSoar ( ) const
inlinenoexcept

Definition at line 263 of file RingModulator.h.

◆ getState()

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

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

Definition at line 266 of file RingModulator.h.

◆ prepare()

template<FloatType T>
void dspark::RingModulator< T >::prepare ( const AudioSpec spec)
inlinenoexcept

Prepares the modulator for audio processing.

Settles the parameter smoothing state on the published targets. An invalid spec (non-positive or non-finite fields) is a no-op that keeps the previous state.

Parameters
specAudio specification including sample rate and channels.

Definition at line 85 of file RingModulator.h.

◆ processBlock()

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

Processes a block of audio in-place.

Parameters
bufferView of the audio buffer to process.

Definition at line 104 of file RingModulator.h.

◆ reset()

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

Resets the internal phase of the carrier oscillator.

Definition at line 201 of file RingModulator.h.

◆ setFrequency()

template<FloatType T>
void dspark::RingModulator< T >::setFrequency ( hz)
inlinenoexcept

Sets the target carrier frequency. Smoothed internally.

Parameters
hzFrequency in Hertz. Negative values are legal (identical spectrum, inverted carrier phase); there is no upper clamp (carriers beyond Nyquist alias by design). Non-finite values are ignored.

Definition at line 209 of file RingModulator.h.

◆ setMix()

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

Sets the target dry/wet mix. Smoothed internally.

Parameters
mixMix value from 0.0 (100% dry) to 1.0 (100% wet), clamped. Non-finite values are ignored.

Definition at line 220 of file RingModulator.h.

◆ setMode()

template<FloatType T>
void dspark::RingModulator< T >::setMode ( Mode  m)
inlinenoexcept

Sets the modulation mode.

Applied per block without crossfade (an instantaneous timbre change). Out-of-range values are clamped so the getter stays honest.

Parameters
mThe chosen structural mode (Classic or GeometricMean).

Definition at line 234 of file RingModulator.h.

◆ setSoar()

template<FloatType T>
void dspark::RingModulator< T >::setSoar ( amount)
inlinenoexcept

Sets the soar threshold for Geometric Mean mode.

Prevents cross-zero dropouts. The value is internally scaled by the input amplitude to prevent static DC offsets during silence. The floor it puts under the carrier's zero crossings turns the dropout into a small step there (the audible trade-off of filling the notch). Applied per block (not smoothed).

Parameters
amount0 = strict geometric mean, 0.01 = subtle, 0.1 = strong. Floored at 0; non-finite values are ignored.

Definition at line 254 of file RingModulator.h.

◆ setState()

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

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

Definition at line 279 of file RingModulator.h.


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