OpenShot Audio Library | OpenShotAudio: juce_AudioProcessLoadMeasurer.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.3.0

Loading...
Searching...
No Matches
juce_AudioProcessLoadMeasurer.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
11 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12 27th April 2017).
13
14 End User License Agreement: www.juce.com/juce-5-licence
15 Privacy Policy: www.juce.com/juce-5-privacy-policy
16
17 Or: You may also use this code under the terms of the GPL v3 (see
18 www.gnu.org/licenses).
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30AudioProcessLoadMeasurer::AudioProcessLoadMeasurer() {}
31AudioProcessLoadMeasurer::~AudioProcessLoadMeasurer() {}
32
33 void AudioProcessLoadMeasurer::reset()
34{
35 reset (0, 0);
36}
37
38 void AudioProcessLoadMeasurer::reset (double sampleRate, int blockSize)
39{
40 cpuUsageMs = 0;
41 xruns = 0;
42
43 if (sampleRate > 0.0 && blockSize > 0)
44 {
45 msPerBlock = 1000.0 * blockSize / sampleRate;
46 timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
47 }
48 else
49 {
50 msPerBlock = 0;
51 timeToCpuScale = 0;
52 }
53}
54
55 void AudioProcessLoadMeasurer::registerBlockRenderTime (double milliseconds)
56{
57 const double filterAmount = 0.2;
58 cpuUsageMs += filterAmount * (milliseconds - cpuUsageMs);
59
60 if (milliseconds > msPerBlock)
61 ++xruns;
62}
63
64 double AudioProcessLoadMeasurer::getLoadAsProportion() const { return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs); }
65 double AudioProcessLoadMeasurer::getLoadAsPercentage() const { return 100.0 * getLoadAsProportion(); }
66
67 int AudioProcessLoadMeasurer::getXRunCount() const { return xruns; }
68
69AudioProcessLoadMeasurer::ScopedTimer::ScopedTimer (AudioProcessLoadMeasurer& p)
70 : owner (p), startTime (Time::getMillisecondCounterHiRes())
71{
72}
73
74AudioProcessLoadMeasurer::ScopedTimer::~ScopedTimer()
75{
76 owner.registerBlockRenderTime (Time::getMillisecondCounterHiRes() - startTime);
77}
78
79} // namespace juce
juce::AudioProcessLoadMeasurer
Definition: juce_AudioProcessLoadMeasurer.h:38
juce::AudioProcessLoadMeasurer::~AudioProcessLoadMeasurer
~AudioProcessLoadMeasurer()
Definition: juce_AudioProcessLoadMeasurer.cpp:31
juce::AudioProcessLoadMeasurer::getLoadAsPercentage
double getLoadAsPercentage() const
Definition: juce_AudioProcessLoadMeasurer.cpp:65
juce::AudioProcessLoadMeasurer::registerBlockRenderTime
void registerBlockRenderTime(double millisecondsTaken)
Definition: juce_AudioProcessLoadMeasurer.cpp:55
juce::AudioProcessLoadMeasurer::getXRunCount
int getXRunCount() const
Definition: juce_AudioProcessLoadMeasurer.cpp:67
juce::AudioProcessLoadMeasurer::reset
void reset()
Definition: juce_AudioProcessLoadMeasurer.cpp:33
juce::AudioProcessLoadMeasurer::getLoadAsProportion
double getLoadAsProportion() const
Definition: juce_AudioProcessLoadMeasurer.cpp:64
juce::Time
Definition: juce_Time.h:37
juce::Time::getMillisecondCounterHiRes
static double getMillisecondCounterHiRes() noexcept