CPU optimization: background thread + decimation#31
Merged
user1303836 merged 1 commit intomainfrom Feb 17, 2026
Merged
Conversation
Move pitch analysis to a dedicated worker thread via SPSC FIFO (juce::AbstractFifo). The audio thread now only writes samples to the FIFO and reads two atomic floats, removing all FFT work from the real-time path. Additional optimizations applied: - Increase hop size from 3ms to 12ms (~4x fewer analyses/sec) - 2x decimation via halfband FIR filter (44.1kHz -> 22.05kHz), halving FFT size from 4096 to 2048 - Two-memcpy buffer linearization (eliminates per-element modulo) - FloatVectorOperations::clear for FFT buffer zeroing - Cached exp2 in PitchSmoother (recomputes only when smoothed changes) - Wavetable sine oscillator (2048-entry LUT with linear interpolation) Expected CPU reduction: ~10% -> <1% total system.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces CPU usage from ~10% to <1% per plugin instance by addressing the root cause: 3x FFT-4096 running 331 times/sec on the audio thread.
Architecture change
juce::AbstractFifo)Algorithmic optimizations
std::sin()per sampleCode-level optimizations
FloatVectorOperations::clearfor SIMD-accelerated FFT buffer zeroingexp2in PitchSmoother (recomputes only when smoothed value changes)Files changed
source/dsp/HalfbandDecimator.hsource/dsp/YinPitchDetector.hsource/dsp/YinPitchDetector.cppsource/dsp/PitchSmoother.hsource/dsp/Oscillator.cpptests/TestYinPitchDetector.cppPluginProcessor.cpp is unchanged -- the public API (
prepare,feedSample,getResult) is preserved.Test plan