DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
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.
 
T getShift () 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).
 

Static Public Member Functions

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

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 65 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: none.

The allpass-pair network has no bulk delay (the FIR transformer it replaced cost 95 samples). Its frequency-dependent phase is common to the dry (real branch) and shifted paths.

Definition at line 220 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 211 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 208 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 226 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 77 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 97 of file FrequencyShifter.h.

◆ reset()

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

Resets internal filter states and phase accumulator.

Definition at line 175 of file FrequencyShifter.h.

◆ setMix()

template<FloatType T>
void dspark::FrequencyShifter< T >::setMix ( T  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 201 of file FrequencyShifter.h.

◆ setShift()

template<FloatType T>
void dspark::FrequencyShifter< T >::setShift ( T  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 190 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 237 of file FrequencyShifter.h.


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