mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-04 03:40:07 +00:00
Add xrun counter to device manager
This commit is contained in:
parent
3627603c83
commit
06c7fb5b01
2 changed files with 23 additions and 2 deletions
|
|
@ -731,6 +731,9 @@ void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelDat
|
|||
const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
|
||||
const double filterAmount = 0.2;
|
||||
cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
|
||||
|
||||
if (msTaken > msPerBlock)
|
||||
xruns++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -756,13 +759,14 @@ void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelDat
|
|||
void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
|
||||
{
|
||||
cpuUsageMs = 0;
|
||||
xruns = 0;
|
||||
|
||||
const double sampleRate = device->getCurrentSampleRate();
|
||||
const int blockSize = device->getCurrentBufferSizeSamples();
|
||||
|
||||
if (sampleRate > 0.0 && blockSize > 0)
|
||||
{
|
||||
const double msPerBlock = 1000.0 * blockSize / sampleRate;
|
||||
msPerBlock = 1000.0 * blockSize / sampleRate;
|
||||
timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
|
||||
}
|
||||
|
||||
|
|
@ -779,6 +783,7 @@ void AudioDeviceManager::audioDeviceStoppedInt()
|
|||
{
|
||||
cpuUsageMs = 0;
|
||||
timeToCpuScale = 0;
|
||||
xruns = 0;
|
||||
sendChangeMessage();
|
||||
|
||||
const ScopedLock sl (audioCallbackLock);
|
||||
|
|
@ -998,6 +1003,12 @@ void AudioDeviceManager::playTestSound()
|
|||
}
|
||||
}
|
||||
|
||||
int AudioDeviceManager::getXRunCount() const noexcept
|
||||
{
|
||||
auto deviceXRuns = (currentAudioDevice != nullptr ? currentAudioDevice->getXRunCount() : -1);
|
||||
return (deviceXRuns >= 0 ? deviceXRuns : xruns);
|
||||
}
|
||||
|
||||
double AudioDeviceManager::getCurrentInputLevel() const noexcept { return inputLevelMeter.getCurrentLevel(); }
|
||||
double AudioDeviceManager::getCurrentOutputLevel() const noexcept { return outputLevelMeter.getCurrentLevel(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -436,6 +436,15 @@ public:
|
|||
*/
|
||||
CriticalSection& getMidiCallbackLock() noexcept { return midiCallbackLock; }
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the number of under- or over runs reported.
|
||||
|
||||
This method will use the underlying device's native getXRunCount if it supports
|
||||
it. Otherwise it will estimate the number of under-/overruns by measuring the
|
||||
time it spent in the audio callback.
|
||||
*/
|
||||
int getXRunCount() const noexcept;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
OwnedArray<AudioIODeviceType> availableDeviceTypes;
|
||||
|
|
@ -468,7 +477,8 @@ private:
|
|||
ScopedPointer<AudioSampleBuffer> testSound;
|
||||
int testSoundPosition;
|
||||
|
||||
double cpuUsageMs, timeToCpuScale;
|
||||
double cpuUsageMs, timeToCpuScale, msPerBlock;
|
||||
int xruns;
|
||||
|
||||
struct LevelMeter
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue