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

Method update

src/fl/audio/detector/silence.cpp.hpp:29–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27Silence::~Silence() FL_NOEXCEPT = default;
28
29void Silence::update(shared_ptr<Context> context) {
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 {
38 mRMSHistory[mHistoryIndex] = mCurrentRMS;
39 mHistoryIndex = (mHistoryIndex + 1) % mHistorySize;
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) {
60 mPendingEvent = PendingSilenceEvent::kEnd;
61 mPendingDuration = duration;
62 }
63
64 mIsSilent = false;
65 mPreviousSilent = false;
66 mSilenceStartTime = 0;
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;
74 mPendingEvent = PendingSilenceEvent::kStart;
75 }
76
77 // Check if we've exceeded maximum duration
78 if (mIsSilent && mMaxSilenceDuration > 0 && duration >= mMaxSilenceDuration) {
79 mPendingEvent = PendingSilenceEvent::kMaxDuration;
80 mPendingDuration = duration;
81 }
82 }
83}
84
85void Silence::fireCallbacks() {
86 switch (mPendingEvent) {

Callers

nothing calls this directly

Calls 4

getRMSMethod · 0.45
getTimestampMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected