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

◆ update()

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

Implements fl::audio::Detector.

Definition at line 29 of file silence.cpp.hpp.

29 {
30 mCurrentRMS = context->getRMS();
31 u32 timestamp = context->getTimestamp();
32 mLastUpdateTime = timestamp;
33
34 // Build history
35 if (mRMSHistory.size() < static_cast<fl::size>(mHistorySize)) {
36 mRMSHistory.push_back(mCurrentRMS);
37 } else {
40 }
41
42 // Get smoothed RMS
43 float smoothedRMS = getSmoothedRMS();
44
45 // Check silence condition with hysteresis
46 bool nowSilent = checkSilenceCondition(smoothedRMS);
47
48 // State transition logic
49 if (nowSilent && !mPreviousSilent) {
50 // Entering silence
51 mSilenceStartTime = timestamp;
52 mPreviousSilent = true;
53 } else if (!nowSilent && mPreviousSilent) {
54 // Exiting silence
55 mSilenceEndTime = timestamp;
56 u32 duration = mSilenceEndTime - mSilenceStartTime;
57
58 // Only fire callbacks if minimum duration was met
59 if (mIsSilent && duration >= mMinSilenceDuration) {
61 mPendingDuration = duration;
62 }
63
64 mIsSilent = false;
65 mPreviousSilent = false;
67 } else if (nowSilent && mPreviousSilent) {
68 // Continuing silence
69 u32 duration = timestamp - mSilenceStartTime;
70
71 // Check if we've reached minimum duration and should fire start event
72 if (!mIsSilent && duration >= mMinSilenceDuration) {
73 mIsSilent = true;
75 }
76
77 // Check if we've exceeded maximum duration
78 if (mIsSilent && mMaxSilenceDuration > 0 && duration >= mMaxSilenceDuration) {
80 mPendingDuration = duration;
81 }
82 }
83}
PendingSilenceEvent mPendingEvent
Definition silence.h:60
bool checkSilenceCondition(float smoothedRMS)
vector< float > mRMSHistory
Definition silence.h:55

References Silence(), checkSilenceCondition(), getSmoothedRMS(), kEnd, kMaxDuration, kStart, mCurrentRMS, mHistorySize, mIsSilent, mLastUpdateTime, mMaxSilenceDuration, mMinSilenceDuration, mPendingDuration, mPendingEvent, mPreviousSilent, mRMSHistory, mSilenceEndTime, mSilenceStartTime, and update().

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

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