The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1KB

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