MCPcopy Create free account
hub / github.com/FastLED/FastLED / update

Method update

src/fl/audio/detector/pitch.cpp.hpp:32–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30Pitch::~Pitch() FL_NOEXCEPT = default;
31
32void Pitch::update(shared_ptr<Context> context) {
33 // Get PCM data from context
34 span<const i16> pcm = context->getPCM();
35 size numSamples = pcm.size();
36
37 // Compute dt from actual audio buffer duration
38 mLastDt = computeAudioDt(pcm.size(), static_cast<int>(mSampleRate));
39
40 // Need at least 2x max period for autocorrelation
41 if (numSamples < static_cast<size>(mMaxPeriod * 2)) {
42 // Not enough samples for reliable pitch detection
43 mConfidence = 0.0f;
44 mIsVoiced = false;
45
46 mVoicedStateChanged = (mIsVoiced != mPreviousVoiced);
47 return;
48 }
49
50 // Calculate autocorrelation and find pitch
51 float detectedPitch = calculateAutocorrelation(pcm.data(), numSamples);
52
53 // Check if pitch is valid and confidence is sufficient
54 if (detectedPitch > 0.0f && mConfidence >= mConfidenceThreshold) {
55 mIsVoiced = true;
56 mCurrentPitch = detectedPitch;
57 updatePitchSmoothing(detectedPitch);
58 mFirePitch = true;
59
60 if (shouldReportPitchChange(detectedPitch)) {
61 mFirePitchChange = true;
62 mPreviousPitch = detectedPitch;
63 }
64 } else {
65 mIsVoiced = false;
66 mCurrentPitch = 0.0f;
67 mFirePitch = false;
68 }
69
70 mVoicedStateChanged = (mIsVoiced != mPreviousVoiced);
71}
72
73void Pitch::fireCallbacks() {
74 if (mFirePitch) {

Callers 1

updatePitchSmoothingMethod · 0.45

Calls 4

computeAudioDtFunction · 0.85
getPCMMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected