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

Identity-phase-locked STFT analysis/synthesis core (internal). More...

#include <PhaseVocoderEngine.h>

Classes

struct  Params
 The control-published parameter set (adopted as ONE unit). More...
 

Public Member Functions

bool prepare (double sampleRate, int numChannels, int fftSize, bool resampleCompensation, bool separationSupport=false, bool transientLockedHop=false, bool spectralFluxDetector=false)
 Allocates all rings and spectral state.
 
void reset () noexcept
 Clears all signal state and re-adopts the latest published parameters (jump, no glide). Stream owner only.
 
void publishParams (const Params &p) noexcept
 Publishes a whole parameter set (control thread only).
 
int samplesToNextHop () const noexcept
 
void pushInput (int ch, const T *src, int count) noexcept
 Writes count samples (count <= samplesToNextHop()) into channel ch's analysis ring. Positions advance in commitInput().
 
void commitInput (int count, int numActiveChannels) noexcept
 Advances the shared input position by count samples and runs one analysis->synthesis hop when the analysis boundary is reached.
 
double activeRatio () const noexcept
 
Params activeParams () const noexcept
 
const T * olaData (int ch) const noexcept
 
int64_t olaMask () const noexcept
 
int olaSize () const noexcept
 
int64_t writeHead () const noexcept
 
int fftSize () const noexcept
 
int synthHop () const noexcept
 

Detailed Description

template<FloatType T>
class dspark::detail::PhaseVocoderEngine< T >

Identity-phase-locked STFT analysis/synthesis core (internal).

Template Parameters
TSample type (float or double).

Definition at line 183 of file PhaseVocoderEngine.h.

Member Function Documentation

◆ activeParams()

template<FloatType T>
Params dspark::detail::PhaseVocoderEngine< T >::activeParams ( ) const
inlinenoexcept
Returns
The currently ADOPTED parameter set (audio thread / stream owner only: these are the audio-thread-private active copies, not the staged words). Changes only at hop boundaries or reset().

Definition at line 528 of file PhaseVocoderEngine.h.

◆ activeRatio()

template<FloatType T>
double dspark::detail::PhaseVocoderEngine< T >::activeRatio ( ) const
inlinenoexcept
Returns
The glided active stretch ratio (updates once per hop).

Definition at line 523 of file PhaseVocoderEngine.h.

◆ commitInput()

template<FloatType T>
void dspark::detail::PhaseVocoderEngine< T >::commitInput ( int  count,
int  numActiveChannels 
)
inlinenoexcept

Advances the shared input position by count samples and runs one analysis->synthesis hop when the analysis boundary is reached.

Parameters
countSamples pushed to every channel since the last commit (count <= samplesToNextHop()).
numActiveChannelsChannels to synthesize this hop (<= prepared).

Definition at line 511 of file PhaseVocoderEngine.h.

◆ fftSize()

template<FloatType T>
int dspark::detail::PhaseVocoderEngine< T >::fftSize ( ) const
inlinenoexcept
Returns
Prepared frame size (0 before a successful prepare()).

Definition at line 558 of file PhaseVocoderEngine.h.

◆ olaData()

template<FloatType T>
const T * dspark::detail::PhaseVocoderEngine< T >::olaData ( int  ch) const
inlinenoexcept
Returns
Channel ch's OLA accumulator ring (owner read access).

Definition at line 540 of file PhaseVocoderEngine.h.

◆ olaMask()

template<FloatType T>
int64_t dspark::detail::PhaseVocoderEngine< T >::olaMask ( ) const
inlinenoexcept
Returns
Index mask of the OLA accumulator ring (size - 1).

Definition at line 546 of file PhaseVocoderEngine.h.

◆ olaSize()

template<FloatType T>
int dspark::detail::PhaseVocoderEngine< T >::olaSize ( ) const
inlinenoexcept
Returns
OLA accumulator ring size in samples (4 * fftSize).

Definition at line 552 of file PhaseVocoderEngine.h.

◆ prepare()

template<FloatType T>
bool dspark::detail::PhaseVocoderEngine< T >::prepare ( double  sampleRate,
int  numChannels,
int  fftSize,
bool  resampleCompensation,
bool  separationSupport = false,
bool  transientLockedHop = false,
bool  spectralFluxDetector = false 
)
inline

Allocates all rings and spectral state.

Invalid arguments (non-positive/non-finite rate, channel count < 1, or an fftSize that is not a power of two in [256, 1 << 20]) are rejected: nothing is touched and false is returned.

Parameters
sampleRateSample rate in Hz.
numChannelsChannel count (>= 1).
fftSizeSTFT frame size, power of two in [256, 1<<20].
resampleCompensationTrue for owners that resample the synthesis stream back by ratio (PitchShifter): the engine then tapers bins that would land above Nyquist after resampling, and the formant pre-warp targets env(k*ratio).
separationSupportTrue to allocate the harmonic/percussive median history, which is what lets an owner turn params.percussiveSplit on and off while streaming without ever allocating again. False leaves those buffers empty and the split permanently off.
transientLockedHopTrue to force the analysis hop to Rs across a detected attack (see the file doc). Only an owner that reads the synthesis stream directly may ask for it. An owner that resamples the synthesis stream back advances its reader by ratio per input sample and so assumes Ra = Rs/ratio every hop; a locked hop breaks that assumption for the length of the lock and the reader runs past the write head into ring content no frame has written yet. Measured on a click train, which is 84% silence - 48 kHz, 10 s at 120 BPM, a 2048-sample frame, over -12 to +12 semitones: locking the hop under a resample-back reader raises the output RMS by 0.8 to 5.9 dB, which is energy appearing in the silence. How far it rises is a property of that bed - a sparser one has more silence to fill - so the range is a reading and not a bound. The lock also buys such an owner nothing, because resampling puts the strike back where it started whatever the analysis hop did.
spectralFluxDetectorTrue to detect onsets by log-filterbank spectral flux, false to keep the broadband frame-energy test (see the file doc). It is the owner's choice and not the engine's, and it defaults to the energy test, because the detector decides where phase is reset and so it is part of an owner's rendering: an owner whose output has already been released cannot change detector without changing renders its users already have. On strikes over sustained material the flux detector fires earlier and more often: that is the point of it, and the cost is that each extra reset loosens the strike and smears energy ahead of the attack, which is audible as pre-echo. How much of either depends on the material and on the estimator it is measured with, so the trade is named here and its size is left to the owner that asks for it. Only an owner that needs onsets its schedule can act on - which the energy test cannot supply over sustained material - should ask for it, and its own acceptance measurements then cover it. False also leaves the filterbank unallocated and the flux front end permanently off.
Returns
true if the engine (re)allocated and is ready for reset().

Definition at line 280 of file PhaseVocoderEngine.h.

◆ publishParams()

template<FloatType T>
void dspark::detail::PhaseVocoderEngine< T >::publishParams ( const Params &  p)
inlinenoexcept

Publishes a whole parameter set (control thread only).

Canonical seqlock publish; see the file doc for the fence derivation. The set is adopted as one unit at the next analysis hop (or at reset()); the active shift then glides toward the target at up to 0.5 semitones per hop. May be called before prepare().

Definition at line 465 of file PhaseVocoderEngine.h.

◆ pushInput()

template<FloatType T>
void dspark::detail::PhaseVocoderEngine< T >::pushInput ( int  ch,
const T *  src,
int  count 
)
inlinenoexcept

Writes count samples (count <= samplesToNextHop()) into channel ch's analysis ring. Positions advance in commitInput().

Definition at line 492 of file PhaseVocoderEngine.h.

◆ reset()

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

Clears all signal state and re-adopts the latest published parameters (jump, no glide). Stream owner only.

Definition at line 422 of file PhaseVocoderEngine.h.

◆ samplesToNextHop()

template<FloatType T>
int dspark::detail::PhaseVocoderEngine< T >::samplesToNextHop ( ) const
inlinenoexcept
Returns
Samples the owner may push before the next analysis hop fires.

Definition at line 485 of file PhaseVocoderEngine.h.

◆ synthHop()

template<FloatType T>
int dspark::detail::PhaseVocoderEngine< T >::synthHop ( ) const
inlinenoexcept
Returns
Synthesis hop Rs = fftSize / 4.

Definition at line 561 of file PhaseVocoderEngine.h.

◆ writeHead()

template<FloatType T>
int64_t dspark::detail::PhaseVocoderEngine< T >::writeHead ( ) const
inlinenoexcept
Returns
Absolute write head of the OLA ring (advances Rs per hop).

Definition at line 555 of file PhaseVocoderEngine.h.


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