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

Scale-aware monophonic retune over the framework's YIN detector and phase-vocoder shifter. More...

#include <PitchCorrector.h>

Public Member Functions

void prepare (const AudioSpec &spec, int fftSize=0)
 Allocates the detector and shifter state (setup thread).
 
void reset () noexcept
 Clears all signal state and keeps the parameters (stream owner).
 
void setScale (std::uint16_t scaleBitmask, int rootPitchClass) noexcept
 Selects the scale the output snaps to.
 
void setRetuneSpeedMs (T ms) noexcept
 Sets the retune speed: the time constant, in milliseconds, of the glide from the sung pitch to the target note.
 
void setFormantPreserve (bool on) noexcept
 Enables the shifter's cepstral formant preservation (the anti-chipmunk envelope pre-warp). Default off.
 
std::uint16_t getScaleMask () const noexcept
 
int getRootPitchClass () const noexcept
 
T getRetuneSpeedMs () const noexcept
 
bool getFormantPreserve () 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). A missing field restores its default: chromatic from C, hard snap, formants off.
 
int getLatency () const noexcept
 Reports the signal latency in samples: twice the analysis frame, which is 4096 samples at 44.1/48 kHz and about 85 ms at every supported rate, since the frame follows the rate. Zero before prepare().
 
int getFrameSize () const noexcept
 The analysis frame in effect, in samples: the automatic choice for this rate, or the rounded explicit request. Zero before prepare().
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes audio in-place. Pass-through until prepare() succeeds.
 

Detailed Description

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

Scale-aware monophonic retune over the framework's YIN detector and phase-vocoder shifter.

Template Parameters
TSample type (float or double).

Definition at line 252 of file PitchCorrector.h.

Member Function Documentation

◆ getFormantPreserve()

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

Definition at line 397 of file PitchCorrector.h.

◆ getFrameSize()

template<FloatType T>
int dspark::PitchCorrector< T >::getFrameSize ( ) const
inlinenoexcept

The analysis frame in effect, in samples: the automatic choice for this rate, or the rounded explicit request. Zero before prepare().

Definition at line 437 of file PitchCorrector.h.

◆ getLatency()

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

Reports the signal latency in samples: twice the analysis frame, which is 4096 samples at 44.1/48 kHz and about 85 ms at every supported rate, since the frame follows the rate. Zero before prepare().

Definition at line 430 of file PitchCorrector.h.

◆ getRetuneSpeedMs()

template<FloatType T>
T dspark::PitchCorrector< T >::getRetuneSpeedMs ( ) const
inlinenoexcept
Returns
The retune speed in milliseconds (0 = hard snap).

Definition at line 391 of file PitchCorrector.h.

◆ getRootPitchClass()

template<FloatType T>
int dspark::PitchCorrector< T >::getRootPitchClass ( ) const
inlinenoexcept
Returns
The root pitch class in effect (0 = C .. 11 = B).

Definition at line 384 of file PitchCorrector.h.

◆ getScaleMask()

template<FloatType T>
std::uint16_t dspark::PitchCorrector< T >::getScaleMask ( ) const
inlinenoexcept
Returns
The scale mask as passed to setScale() (root-relative).

Definition at line 377 of file PitchCorrector.h.

◆ getState()

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

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

Definition at line 403 of file PitchCorrector.h.

◆ prepare()

template<FloatType T>
void dspark::PitchCorrector< T >::prepare ( const AudioSpec &  spec,
int  fftSize = 0 
)
inline

Allocates the detector and shifter state (setup thread).

Invalid specifications and non-finite sample rates are ignored and the previous state is kept; an unprepared instance passes audio through untouched. The detector uses its own automatic window policy, which holds its analysis span constant across rates; the shifter's frame follows the policy documented above.

Parameters
specAudio environment specification.
fftSizeAnalysis frame for the internal shifter. Values <= 0 (the default) select the AUTOMATIC frame: the smallest power of two in [512, 32768] spanning at least 2048/48000 s (42.7 ms) at this rate - 2048 at 44.1/48 kHz, 4096 at 88.2/96 kHz, 8192 at 176.4/192 kHz. Read it back with getFrameSize(). An explicit request is rounded up to a power of two and clamped to [256, 1 << 20]; going below the automatic value buys settling time and costs the low register, in the proportions the frame note above states.

Definition at line 284 of file PitchCorrector.h.

◆ processBlock()

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

Processes audio in-place. Pass-through until prepare() succeeds.

Channels beyond the prepared count are left untouched, as in the shifter. Detection reads channel 0; every processed channel receives the same correction.

Parameters
bufferAudio block.

Definition at line 453 of file PitchCorrector.h.

◆ reset()

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

Clears all signal state and keeps the parameters (stream owner).

The applied correction restarts at zero: a fresh stream has no note history worth continuing to correct.

Definition at line 314 of file PitchCorrector.h.

◆ setFormantPreserve()

template<FloatType T>
void dspark::PitchCorrector< T >::setFormantPreserve ( bool  on)
inlinenoexcept

Enables the shifter's cepstral formant preservation (the anti-chipmunk envelope pre-warp). Default off.

Definition at line 371 of file PitchCorrector.h.

◆ setRetuneSpeedMs()

template<FloatType T>
void dspark::PitchCorrector< T >::setRetuneSpeedMs ( T  ms)
inlinenoexcept

Sets the retune speed: the time constant, in milliseconds, of the glide from the sung pitch to the target note.

0 selects the hard snap (the full correction at once, quantized character). Values are clamped to [0, 10000]; non-finite values are ignored.

Definition at line 362 of file PitchCorrector.h.

◆ setScale()

template<FloatType T>
void dspark::PitchCorrector< T >::setScale ( std::uint16_t  scaleBitmask,
int  rootPitchClass 
)
inlinenoexcept

Selects the scale the output snaps to.

Parameters
scaleBitmask12-bit harmony::NoteSet: bit k is the scale degree k semitones above the root (the harmony::allScales layout). Bits above the low 12 are ignored, and an empty mask disables correction.
rootPitchClassRoot as semitones above C; any integer folds into 0..11.

Definition at line 341 of file PitchCorrector.h.

◆ setState()

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

Restores parameters from a blob (tolerant; rejects foreign ids). A missing field restores its default: chromatic from C, hard snap, formants off.

Definition at line 416 of file PitchCorrector.h.


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