FastLED 3.9.15
Loading...
Searching...
No Matches

◆ update() [2/2]

void fl::audio::detector::Vocal::update ( shared_ptr< Context > context)
overridevirtual

Implements fl::audio::Detector.

Definition at line 26 of file vocal.cpp.hpp.

26 {
27 mSampleRate = context->getSampleRate();
28 // Dual FFT: high-resolution formant analysis + broad spectral features.
29 // Formant FFT: 64 CQ bins in 200-3500 Hz — concentrates resolution on
30 // F1/F2/F3 formants (94% bin utilization vs 73% with full-range).
31 // Broad FFT: 16 LOG_REBIN bins in 174.6-4698.3 Hz — full spectral
32 // coverage for flatness, density, flux, and vocal presence ratio.
33 mRetainedFormantFFT = context->getFFT(64, 200.0f, 3500.0f);
34 mRetainedBroadFFT = context->getFFT(16, 174.6f, 4698.3f);
35 const fft::Bins& formantFft = *mRetainedFormantFFT;
36 const fft::Bins& broadFft = *mRetainedBroadFFT;
37 mFormantNumBins = static_cast<int>(formantFft.raw().size());
38 mBroadNumBins = static_cast<int>(broadFft.raw().size());
39
40 // Formant ratio from high-res narrow FFT
41 computeFormantRatio(formantFft);
42 // Broad spectral features (flatness, density, flux) from wide FFT
44
45 // Vocal presence ratio from broad FFT linear bins (needs 200-4000 Hz coverage)
47 mSpectralVariance = mSpectralVarianceFilter.update(broadFft.raw());
48
49 // Calculate time-domain features from raw PCM
50 span<const i16> pcm = context->getPCM();
51 const float dt = computeAudioDt(pcm.size(), context->getSampleRate());
52 // Fused pass: envelope jitter + zero-crossing CV in one PCM traversal
58
59 // Calculate raw confidence and apply time-aware smoothing
60 float rawConfidence = calculateRawConfidence(
63 float smoothedConfidence = mConfidenceSmoother.update(rawConfidence, dt);
64
65 // Hysteresis: use separate on/off thresholds to prevent chattering
66 bool wantActive;
67 if (mVocalActive) {
68 wantActive = (smoothedConfidence >= mOffThreshold);
69 } else {
70 wantActive = (smoothedConfidence >= mOnThreshold);
71 }
72
73 // Debounce: require state to persist for MIN_FRAMES_TO_TRANSITION frames
74 if (wantActive != mVocalActive) {
77 mVocalActive = wantActive;
79 }
80 } else {
82 }
83
84 // Track state changes for fireCallbacks
86}
ExponentialSmoother< float > mZcCVSmoother
Definition vocal.h:71
float calculateVocalPresenceRatio(const fft::Bins &broadFft)
ExponentialSmoother< float > mEnvelopeJitterSmoother
Definition vocal.h:69
static constexpr int MIN_FRAMES_TO_TRANSITION
Definition vocal.h:57
shared_ptr< const fft::Bins > mRetainedFormantFFT
Definition vocal.h:83
ExponentialSmoother< float > mConfidenceSmoother
Definition vocal.h:55
void computePCMTimeDomainFeatures(span< const i16 > pcm)
SpectralVariance< float > mSpectralVarianceFilter
Definition vocal.h:74
ExponentialSmoother< float > mAcfIrregularitySmoother
Definition vocal.h:70
float calculateAutocorrelationIrregularity(span< const i16 > pcm)
float mAutocorrelationIrregularity
Definition vocal.h:67
void computeFormantRatio(const fft::Bins &formantFft)
shared_ptr< const fft::Bins > mRetainedBroadFFT
Definition vocal.h:84
void computeBroadSpectralFeatures(const fft::Bins &broadFft)
float calculateRawConfidence(float formantRatio, float spectralFlatness, float harmonicDensity, float vocalPresenceRatio, float spectralFlux, float spectralVariance)
float computeAudioDt(fl::size pcmSize, int sampleRate) FL_NOEXCEPT
Compute the time delta (in seconds) for an audio buffer.

References Vocal(), calculateAutocorrelationIrregularity(), calculateRawConfidence(), calculateVocalPresenceRatio(), fl::audio::computeAudioDt(), computeBroadSpectralFeatures(), computeFormantRatio(), computePCMTimeDomainFeatures(), mAcfIrregularitySmoother, mAutocorrelationIrregularity, mBroadNumBins, mConfidenceSmoother, mEnvelopeJitter, mEnvelopeJitterSmoother, mFormantNumBins, mFormantRatio, mFramesInState, mHarmonicDensity, MIN_FRAMES_TO_TRANSITION, mOffThreshold, mOnThreshold, mPreviousVocalActive, mRetainedBroadFFT, mRetainedFormantFFT, mSampleRate, mSpectralFlatness, mSpectralFlux, mSpectralVariance, mSpectralVarianceFilter, mStateChanged, mVocalActive, mVocalPresenceRatio, mZcCVSmoother, mZeroCrossingCV, fl::audio::fft::Bins::raw(), fl::span< T, Extent >::size(), and update().

Referenced by ~Vocal(), update(), and update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: