From 1f90ecf6e3ba598910fc347c6ae2bd7bb93760bd Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 20 Sep 2023 19:17:33 +0100 Subject: [PATCH] WASAPI: Allow querying default layouts --- .../audio_io/juce_AudioIODevice.h | 15 +++++++++++++ .../native/juce_WASAPI_windows.cpp | 22 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/juce_audio_devices/audio_io/juce_AudioIODevice.h b/modules/juce_audio_devices/audio_io/juce_AudioIODevice.h index c5cbba3f2a..e66d7b649c 100644 --- a/modules/juce_audio_devices/audio_io/juce_AudioIODevice.h +++ b/modules/juce_audio_devices/audio_io/juce_AudioIODevice.h @@ -174,6 +174,21 @@ public: */ virtual StringArray getInputChannelNames() = 0; + //============================================================================== + /** For devices that support a default layout, returns the channels that are enabled in the + default layout. + + Returns nullopt if the device doesn't supply a default layout. + */ + virtual std::optional getDefaultOutputChannels() const { return {}; } + + /** For devices that support a default layout, returns the channels that are enabled in the + default layout. + + Returns nullopt if the device doesn't supply a default layout. + */ + virtual std::optional getDefaultInputChannels() const { return {}; } + //============================================================================== /** Returns the set of sample-rates this device supports. @see getCurrentSampleRate diff --git a/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp b/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp index 413f302b7e..d226f97ff9 100644 --- a/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp +++ b/modules/juce_audio_devices/native/juce_WASAPI_windows.cpp @@ -527,6 +527,16 @@ public: isActive = true; } + std::optional getDefaultLayout() const + { + if (countNumberOfBits ((uint64) defaultFormatChannelMask) == defaultNumChannels) + return BigInteger ((int64) defaultFormatChannelMask); + + BigInteger integer; + integer.setRange (0, defaultNumChannels, true); + return integer; + } + //============================================================================== ComSmartPtr device; ComSmartPtr client; @@ -635,7 +645,7 @@ private: if (! check (client->GetMixFormat (&mixFormat))) return {}; - WAVEFORMATEXTENSIBLE format; + WAVEFORMATEXTENSIBLE format{}; copyWavFormat (format, mixFormat); CoTaskMemFree (mixFormat); @@ -1338,6 +1348,16 @@ public: String getLastError() override { return lastError; } int getXRunCount() const noexcept override { return inputDevice != nullptr ? inputDevice->xruns : -1; } + std::optional getDefaultOutputChannels() const override + { + return outputDevice != nullptr ? outputDevice->getDefaultLayout() : std::nullopt; + } + + std::optional getDefaultInputChannels() const override + { + return inputDevice != nullptr ? inputDevice->getDefaultLayout() : std::nullopt; + } + String open (const BigInteger& inputChannels, const BigInteger& outputChannels, double sampleRate, int bufferSizeSamples) override {