Browse Source

Add xrun counter to device manager

tags/2021-05-28
hogliux 8 years ago
parent
commit
06c7fb5b01
2 changed files with 23 additions and 2 deletions
  1. +12
    -1
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  2. +11
    -1
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h

+ 12
- 1
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -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(); }


+ 11
- 1
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.h View File

@@ -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…
Cancel
Save