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

Constant-Hz frequency shift optimized via Quadrature Oscillator. More...

#include <FrequencyShifter.h>

Public Member Functions

void prepare (const AudioSpec &spec)
 Prepares the frequency shifter state and allocates internal buffers.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes audio in-place applying the frequency shift.
 
void reset () noexcept
 Resets internal filter states and phase accumulator.
 
void setShift (T hz) noexcept
 Sets the frequency shift amount in Hz.
 
void setMix (T mix) noexcept
 Sets the dry/wet mix. Smoothed internally.
 
getShift () const noexcept
 
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).
 

Static Public Member Functions

static constexpr int getLatency () noexcept
 Reports the processing latency in samples.
 

Detailed Description

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

Constant-Hz frequency shift optimized via Quadrature Oscillator.

Uses a recursive rotation matrix to generate the complex carrier, avoiding expensive per-sample trigonometric calls; the oscillator state is re-anchored from the double-precision phase accumulator at every block, so rounding drift never accumulates past one block.

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 61 of file FrequencyShifter.h.

Member Function Documentation

◆ getLatency()

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

Reports the processing latency in samples.

The Hilbert transformer delays BOTH the dry (real branch) and shifted paths by its FIR group delay; report this for plugin delay compensation.

Definition at line 217 of file FrequencyShifter.h.

◆ getMix()

template<FloatType T>
T dspark::FrequencyShifter< T >::getMix ( ) const
inlinenoexcept
Returns
The current dry/wet mix ratio.

Definition at line 209 of file FrequencyShifter.h.

◆ getShift()

template<FloatType T>
T dspark::FrequencyShifter< T >::getShift ( ) const
inlinenoexcept
Returns
The current frequency shift amount in Hz.

Definition at line 206 of file FrequencyShifter.h.

◆ getState()

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

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

Definition at line 223 of file FrequencyShifter.h.

◆ prepare()

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

Prepares the frequency shifter state and allocates internal buffers.

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

Parameters
specAudio environment specification (sample rate, num channels).

Definition at line 73 of file FrequencyShifter.h.

◆ processBlock()

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

Processes audio in-place applying the frequency shift.

Parameters
bufferAudio data view.

Definition at line 94 of file FrequencyShifter.h.

◆ reset()

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

Resets internal filter states and phase accumulator.

Definition at line 173 of file FrequencyShifter.h.

◆ setMix()

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

Sets the dry/wet mix. Smoothed internally.

Parameters
mixRange [0.0, 1.0], clamped. 0.0 = pure dry (phase-aligned), 1.0 = fully shifted. Non-finite values are ignored.

Definition at line 199 of file FrequencyShifter.h.

◆ setShift()

template<FloatType T>
void dspark::FrequencyShifter< T >::setShift ( hz)
inlinenoexcept

Sets the frequency shift amount in Hz.

Parameters
hzShift in Hz (negative shifts frequencies down). There is no range clamp: carriers beyond Nyquist alias by design. Non-finite values are ignored (a NaN here would poison the phase accumulator permanently).

Definition at line 188 of file FrequencyShifter.h.

◆ setState()

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

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

Definition at line 234 of file FrequencyShifter.h.


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