From d117e0adaa02e5f5318e5ea7ecb3d626dde11bea Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 27 Mar 2013 20:56:18 +0000 Subject: [PATCH] Added a small pause when switching between audio device types. --- .../audio_io/juce_AudioDeviceManager.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp index d16bf420b8..cc4637e567 100644 --- a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp +++ b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp @@ -373,6 +373,13 @@ void AudioDeviceManager::setCurrentAudioDeviceType (const String& type, if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type && currentDeviceType != type) { + if (currentAudioDevice != nullptr) + { + closeAudioDevice(); + Thread::sleep (1500); // allow a moment for OS devices to sort themselves out, to help + // avoid things like DirectSound/ASIO clashes + } + currentDeviceType = type; AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i)); @@ -389,8 +396,8 @@ void AudioDeviceManager::setCurrentAudioDeviceType (const String& type, AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const { for (int i = 0; i < availableDeviceTypes.size(); ++i) - if (availableDeviceTypes[i]->getTypeName() == currentDeviceType) - return availableDeviceTypes[i]; + if (availableDeviceTypes.getUnchecked(i)->getTypeName() == currentDeviceType) + return availableDeviceTypes.getUnchecked(i); return availableDeviceTypes[0]; } @@ -446,7 +453,9 @@ String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName); if (currentAudioDevice == nullptr) - error = "Can't open the audio device!\n\nThis may be because another application is currently using the same device - if so, you should close any other applications and try again!"; + error = "Can't open the audio device!\n\n" + "This may be because another application is currently using the same device - " + "if so, you should close any other applications and try again!"; else error = currentAudioDevice->getLastError();