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

Real-time phase-vocoder pitch shifter (+-12 semitones, stereo-linked). More...

#include <PitchShifter.h>

Public Member Functions

void prepare (const AudioSpec &spec, int fftSize=2048)
 Allocates all rings and spectral state.
 
void reset () noexcept
 Clears all signal state (keeps parameters). Safe on the audio thread.
 
void setSemitones (T st) noexcept
 Sets the pitch shift in semitones, clamped to +-12.
 
void setPitchRatio (T ratio) noexcept
 Sets the pitch shift as a frequency ratio, clamped to [0.5, 2]. Non-finite values are ignored.
 
void setMix (T mix) noexcept
 Dry/wet mix, [0, 1]. The dry path is latency-compensated and the mix is smoothed linearly over one block (the wet stream is decorrelated from the dry, so an unsmoothed step would click). Non-finite values are ignored.
 
void setTransientPreserve (bool enabled) noexcept
 Enables phase reset on detected transients (default on).
 
void setFormantPreserve (bool enabled) noexcept
 Keeps formants (vocal timbre) in place while pitch moves.
 
getSemitones () const noexcept
 
getMix () const noexcept
 
bool getTransientPreserve () const noexcept
 
bool getFormantPreserve () const noexcept
 
int getLatency () const noexcept
 Reports total latency in samples (2 * fftSize, measured exact at unity ratio; ~85 ms at the default 2048 frame and 48 kHz).
 
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 audio in-place.
 

Detailed Description

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

Real-time phase-vocoder pitch shifter (+-12 semitones, stereo-linked).

Template Parameters
TSample type (float or double).

Definition at line 82 of file PitchShifter.h.

Member Function Documentation

◆ getFormantPreserve()

template<FloatType T>
bool dspark::PitchShifter< T >::getFormantPreserve ( ) const
inlinenoexcept
Returns
Whether formant preservation is enabled.

Definition at line 266 of file PitchShifter.h.

◆ getLatency()

template<FloatType T>
int dspark::PitchShifter< T >::getLatency ( ) const
inlinenoexcept

Reports total latency in samples (2 * fftSize, measured exact at unity ratio; ~85 ms at the default 2048 frame and 48 kHz).

Definition at line 273 of file PitchShifter.h.

◆ getMix()

template<FloatType T>
T dspark::PitchShifter< T >::getMix ( ) const
inlinenoexcept
Returns
Current dry/wet mix.

Definition at line 257 of file PitchShifter.h.

◆ getSemitones()

template<FloatType T>
T dspark::PitchShifter< T >::getSemitones ( ) const
inlinenoexcept
Returns
Current shift in semitones.

Definition at line 251 of file PitchShifter.h.

◆ getState()

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

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

Definition at line 276 of file PitchShifter.h.

◆ getTransientPreserve()

template<FloatType T>
bool dspark::PitchShifter< T >::getTransientPreserve ( ) const
inlinenoexcept
Returns
Whether transient phase reset is enabled.

Definition at line 260 of file PitchShifter.h.

◆ prepare()

template<FloatType T>
void dspark::PitchShifter< T >::prepare ( const AudioSpec spec,
int  fftSize = 2048 
)
inline

Allocates all rings and spectral state.

Invalid specs (non-positive/non-finite rate, block size or channel count) and fftSize values that are not a power of two in [256, 1 << 20] are ignored: the previous state is kept and an unprepared instance stays pass-through.

Parameters
specAudio environment specification.
fftSizeSTFT frame size, power of two (default 2048). Smaller sizes lower latency and favour transients; larger sizes favour low-pitched material.

Definition at line 100 of file PitchShifter.h.

◆ processBlock()

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

Processes audio in-place.

Pass-through until prepare() succeeds. Channels beyond the prepared count are left untouched.

Parameters
bufferAudio block; all prepared channels are processed.

Definition at line 308 of file PitchShifter.h.

◆ reset()

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

Clears all signal state (keeps parameters). Safe on the audio thread.

Definition at line 168 of file PitchShifter.h.

◆ setFormantPreserve()

template<FloatType T>
void dspark::PitchShifter< T >::setFormantPreserve ( bool  enabled)
inlinenoexcept

Keeps formants (vocal timbre) in place while pitch moves.

A cepstral lift extracts the smooth spectral envelope of each frame (quefrencies below ~1 ms) and the synthesis magnitudes are pre-warped by env(k*ratio)/env(k), so after the output resampler the envelope lands back where it started - the classic anti-chipmunk correction. Costs two extra FFTs per frame. Default off.

Definition at line 245 of file PitchShifter.h.

◆ setMix()

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

Dry/wet mix, [0, 1]. The dry path is latency-compensated and the mix is smoothed linearly over one block (the wet stream is decorrelated from the dry, so an unsmoothed step would click). Non-finite values are ignored.

Definition at line 224 of file PitchShifter.h.

◆ setPitchRatio()

template<FloatType T>
void dspark::PitchShifter< T >::setPitchRatio ( ratio)
inlinenoexcept

Sets the pitch shift as a frequency ratio, clamped to [0.5, 2]. Non-finite values are ignored.

Definition at line 212 of file PitchShifter.h.

◆ setSemitones()

template<FloatType T>
void dspark::PitchShifter< T >::setSemitones ( st)
inlinenoexcept

Sets the pitch shift in semitones, clamped to +-12.

The active shift glides toward the target at up to 0.5 semitones per analysis hop (a few ms at the default frame size), so live changes are click-free. Non-finite values are ignored.

Definition at line 204 of file PitchShifter.h.

◆ setState()

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

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

Definition at line 287 of file PitchShifter.h.

◆ setTransientPreserve()

template<FloatType T>
void dspark::PitchShifter< T >::setTransientPreserve ( bool  enabled)
inlinenoexcept

Enables phase reset on detected transients (default on).

Definition at line 231 of file PitchShifter.h.


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