Audio plugin host https://kx.studio/carla
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.

juce_AudioProcessLoadMeasurer.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /**
  21. Maintains an ongoing measurement of the proportion of time which is being
  22. spent inside an audio callback.
  23. @tags{Audio}
  24. */
  25. class JUCE_API AudioProcessLoadMeasurer
  26. {
  27. public:
  28. /** */
  29. AudioProcessLoadMeasurer();
  30. /** Destructor. */
  31. ~AudioProcessLoadMeasurer();
  32. //==============================================================================
  33. /** Resets the state. */
  34. void reset();
  35. /** Resets the counter, in preparation for use with the given sample rate and block size. */
  36. void reset (double sampleRate, int blockSize);
  37. /** Returns the current load as a proportion 0 to 1.0 */
  38. double getLoadAsProportion() const;
  39. /** Returns the current load as a percentage 0 to 100.0 */
  40. double getLoadAsPercentage() const;
  41. /** Returns the number of over- (or under-) runs recorded since the state was reset. */
  42. int getXRunCount() const;
  43. //==============================================================================
  44. /** This class measures the time between its construction and destruction and
  45. adds it to an AudioProcessLoadMeasurer.
  46. e.g.
  47. @code
  48. {
  49. AudioProcessLoadMeasurer::ScopedTimer timer (myProcessLoadMeasurer);
  50. myCallback->doTheCallback();
  51. }
  52. @endcode
  53. @tags{Audio}
  54. */
  55. struct JUCE_API ScopedTimer
  56. {
  57. ScopedTimer (AudioProcessLoadMeasurer&);
  58. ~ScopedTimer();
  59. private:
  60. AudioProcessLoadMeasurer& owner;
  61. double startTime;
  62. JUCE_DECLARE_NON_COPYABLE (ScopedTimer)
  63. };
  64. /** Can be called manually to add the time of a callback to the stats.
  65. Normally you probably would never call this - it's simpler and more robust to
  66. use a ScopedTimer to measure the time using an RAII pattern.
  67. */
  68. void registerBlockRenderTime (double millisecondsTaken);
  69. private:
  70. double cpuUsageMs = 0, timeToCpuScale = 0, msPerBlock = 0;
  71. int xruns = 0;
  72. };
  73. } // namespace juce