|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
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 formant preservation (default off): the shifter's cepstral envelope pre-warp in the default engine, pitch-synchronous overlap-add in the low-latency one. In the low-latency engine a change restarts the stream at the next processBlock(), as reset() does. | |
| void | setLowLatency (bool on) noexcept |
| Selects the low-latency engine (default off). | |
| bool | getLowLatency () const noexcept |
| 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, low latency off. | |
| int | getLatency () const noexcept |
| Reports the signal latency in samples. Default engine: 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. Low-latency engine: half the detector's window, 1024 samples at 44.1/48 kHz (about 21 ms at every 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. | |
Scale-aware monophonic retune over the framework's YIN detector and phase-vocoder shifter.
| T | Sample type (float or double). |
Definition at line 319 of file PitchCorrector.h.
|
inlinenoexcept |
Definition at line 502 of file PitchCorrector.h.
|
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 546 of file PitchCorrector.h.
|
inlinenoexcept |
Reports the signal latency in samples. Default engine: 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. Low-latency engine: half the detector's window, 1024 samples at 44.1/48 kHz (about 21 ms at every rate). Zero before prepare().
Definition at line 539 of file PitchCorrector.h.
|
inlinenoexcept |
Definition at line 476 of file PitchCorrector.h.
|
inlinenoexcept |
Definition at line 496 of file PitchCorrector.h.
|
inlinenoexcept |
Definition at line 489 of file PitchCorrector.h.
|
inlinenoexcept |
Definition at line 482 of file PitchCorrector.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 508 of file PitchCorrector.h.
|
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.
| spec | Audio environment specification. |
| fftSize | Analysis 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. The low-latency engine sizes itself from the detector's window instead, so this frame does not change its latency. |
Definition at line 353 of file PitchCorrector.h.
|
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.
| buffer | Audio block. |
Definition at line 562 of file PitchCorrector.h.
|
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 387 of file PitchCorrector.h.
|
inlinenoexcept |
Enables formant preservation (default off): the shifter's cepstral envelope pre-warp in the default engine, pitch-synchronous overlap-add in the low-latency one. In the low-latency engine a change restarts the stream at the next processBlock(), as reset() does.
Definition at line 454 of file PitchCorrector.h.
|
inlinenoexcept |
Selects the low-latency engine (default off).
On: the pitch-synchronous splice engine described in the file overview, with a latency of half the detector's analysis window (1024 samples at 44.1/48 kHz, 21.3 ms at 48 kHz) instead of the phase vocoder's twice the frame. Formant preservation selects its pitch-synchronous overlap-add rendering (see the file overview). A change of either flag takes effect at the next processBlock() as a restart of the stream, as reset() does: re-read getLatency() after it.
Definition at line 470 of file PitchCorrector.h.
|
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 443 of file PitchCorrector.h.
|
inlinenoexcept |
Selects the scale the output snaps to.
| scaleBitmask | 12-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. |
| rootPitchClass | Root as semitones above C; any integer folds into 0..11. |
Definition at line 422 of file PitchCorrector.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids). A missing field restores its default: chromatic from C, hard snap, formants off, low latency off.
Definition at line 522 of file PitchCorrector.h.