From c40c5d78c8db6e6d7e5ef0312ece8e830e89814e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 24 Jun 2014 08:50:39 -0700 Subject: [PATCH] Fix default audio devices on Windows Windows 8 provides the full friendly device name, not just the first 31 characters. --- interface/src/Audio.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index a0a85f8888..65912f83e8 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -218,9 +218,14 @@ QAudioDeviceInfo defaultAudioDeviceForMode(QAudio::Mode mode) { hr = pPropertyStore->GetValue(PKEY_Device_FriendlyName, &pv); pPropertyStore->Release(); pPropertyStore = NULL; - //QAudio devices seems to only take the 31 first characters of the Friendly Device Name. - const DWORD QT_WIN_MAX_AUDIO_DEVICENAME_LEN = 31; - deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal).left(QT_WIN_MAX_AUDIO_DEVICENAME_LEN); + deviceName = QString::fromWCharArray((wchar_t*)pv.pwszVal); + const DWORD WINDOWS7_MAJOR_VERSION = 6; + const DWORD WINDOWS7_MINOR_VERSION = 1; + if (osvi.dwMajorVersion <= WINDOWS7_MAJOR_VERSION && osvi.dwMinorVersion <= WINDOWS7_MINOR_VERSION) { + // Windows 7 provides only the 31 first characters of the device name. + const DWORD QT_WIN7_MAX_AUDIO_DEVICENAME_LEN = 31; + deviceName = deviceName.left(QT_WIN7_MAX_AUDIO_DEVICENAME_LEN); + } qDebug() << (mode == QAudio::AudioOutput ? "output" : "input") << " device:" << deviceName; PropVariantClear(&pv); }