From 86b4fd72a0214fcc6079212315a2fd9458294cd6 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 24 Oct 2018 10:33:14 +0100 Subject: [PATCH] Added support for extremely high sample rates to audio devices --- .../native/juce_mac_CoreAudio.cpp | 11 ++++++----- .../juce_audio_devices/native/juce_win32_ASIO.cpp | 8 +++----- .../native/juce_win32_WASAPI.cpp | 14 ++++++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp index 9bcd77940f..9891f55409 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp @@ -289,15 +289,16 @@ public: if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, nullptr, &size, ranges))) { - static const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0, 352800.0, 384000.0 }; - - for (int i = 0; i < numElementsInArray (possibleRates); ++i) + for (auto r : { 44100, 48000, 88200, 96000, 176400, + 192000, 352800, 384000, 705600, 768000 }) { + auto rate = (double) r; + for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;) { - if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2) + if (rate >= ranges[j].mMinimum - 2 && rate <= ranges[j].mMaximum + 2) { - newSampleRates.add (possibleRates[i]); + newSampleRates.add (rate); break; } } diff --git a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp index 95cc81ee39..2d1e7407fb 100644 --- a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp +++ b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp @@ -346,11 +346,9 @@ public: if (asioObject != nullptr) { - const int possibleSampleRates[] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000 }; - - for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index) - if (asioObject->canSampleRate ((double) possibleSampleRates[index]) == 0) - newRates.add ((double) possibleSampleRates[index]); + for (auto rate : { 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000, 705600, 768000 }) + if (asioObject->canSampleRate ((double) rate) == 0) + newRates.add ((double) rate); } if (newRates.isEmpty()) diff --git a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp index 62908fed4d..8e70fafd46 100644 --- a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp +++ b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp @@ -387,21 +387,19 @@ public: // Got a format that is supported by the device so we can ask what sample rates are supported (in whatever format) } - static const int ratesToTest[] = { 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000 }; - - for (int i = 0; i < numElementsInArray (ratesToTest); ++i) - { - if (rates.contains (ratesToTest[i])) + for (auto rate : { 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000, 705600, 768000 }) + { + if (rates.contains (rate)) continue; - format.Format.nSamplesPerSec = (DWORD) ratesToTest[i]; + format.Format.nSamplesPerSec = (DWORD) rate; format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * format.Format.nChannels * format.Format.wBitsPerSample / 8); if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, 0))) - if (! rates.contains (ratesToTest[i])) - rates.addUsingDefaultSort (ratesToTest[i]); + if (! rates.contains (rate)) + rates.addUsingDefaultSort (rate); } }