mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
49 lines
1.1 KiB
Objective-C
49 lines
1.1 KiB
Objective-C
/*!
|
|
@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
|