forked from juce-framework/JUCE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AUSilentTimeout.h
49 lines (40 loc) · 1.06 KB
/
AUSilentTimeout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
@file AudioUnitSDK/AUSilentTimeout.h
@copyright © 2000-2021 Apple Inc. All rights reserved.
*/
#ifndef AudioUnitSDK_AUSilentTimeout_h
#define AudioUnitSDK_AUSilentTimeout_h
#include <CoreFoundation/CFBase.h> // for UInt32
#include <algorithm>
namespace ausdk {
/*!
@class AUSilentTimeout
@brief Utility to assist in propagating a silence flag from signal-processing
input to output, factoring in a processing delay.
*/
class AUSilentTimeout {
public:
AUSilentTimeout() = default;
void Process(UInt32 inFramesToProcess, UInt32 inTimeoutLimit, bool& ioSilence)
{
if (ioSilence) {
if (mResetTimer) {
mTimeoutCounter = inTimeoutLimit;
mResetTimer = false;
}
if (mTimeoutCounter > 0) {
mTimeoutCounter -= std::min(inFramesToProcess, mTimeoutCounter);
ioSilence = false;
}
} else {
// signal to reset the next time we receive silence
mResetTimer = true;
}
}
void Reset() { mResetTimer = true; }
private:
UInt32 mTimeoutCounter{ 0 };
bool mResetTimer{ false };
};
} // namespace ausdk
#endif // AudioUnitSDK_AUSilentTimeout_h