From 343a8ac7ed6acecce6131b6d54fce04fe43311d4 Mon Sep 17 00:00:00 2001 From: Karol Suprynowicz Date: Fri, 21 Feb 2025 19:11:47 +0100 Subject: [PATCH] Fix audio selection issue --- interface/src/scripting/Audio.h | 4 ++++ interface/src/scripting/AudioDevices.cpp | 9 +++++---- libraries/audio-client/src/AudioClient.cpp | 8 +++++--- libraries/audio-client/src/HifiAudioDeviceInfo.cpp | 2 +- libraries/audio-client/src/HifiAudioDeviceInfo.h | 2 ++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/interface/src/scripting/Audio.h b/interface/src/scripting/Audio.h index a8778fcc2d..2b106d71fe 100644 --- a/interface/src/scripting/Audio.h +++ b/interface/src/scripting/Audio.h @@ -24,6 +24,10 @@ using MutedGetter = std::function; using MutedSetter = std::function; +#define OVERTE_AUDIO_STRING "Audio" +#define OVERTE_AUDIO_HMD_STRING "VR" +#define OVERTE_AUDIO_DESKTOP_STRING "Desktop" + namespace scripting { class Audio : public AudioScriptingInterface, protected ReadWriteLockable { diff --git a/interface/src/scripting/AudioDevices.cpp b/interface/src/scripting/AudioDevices.cpp index 500cedcb09..6629d77bc5 100644 --- a/interface/src/scripting/AudioDevices.cpp +++ b/interface/src/scripting/AudioDevices.cpp @@ -22,13 +22,14 @@ #include "AudioClient.h" #include "Audio.h" #include "UserActivityLogger.h" +#include "HifiAudioDeviceInfo.h" using namespace scripting; -static Setting::Handle desktopInputDeviceSetting { QStringList { Audio::AUDIO, Audio::DESKTOP, "INPUT" }}; -static Setting::Handle desktopOutputDeviceSetting { QStringList { Audio::AUDIO, Audio::DESKTOP, "OUTPUT" }}; -static Setting::Handle hmdInputDeviceSetting { QStringList { Audio::AUDIO, Audio::HMD, "INPUT" }}; -static Setting::Handle hmdOutputDeviceSetting { QStringList { Audio::AUDIO, Audio::HMD, "OUTPUT" }}; +static Setting::Handle desktopInputDeviceSetting { QStringList { OVERTE_AUDIO_STRING, OVERTE_AUDIO_DESKTOP_STRING, "INPUT" }, HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME}; +static Setting::Handle desktopOutputDeviceSetting { QStringList { OVERTE_AUDIO_STRING, OVERTE_AUDIO_DESKTOP_STRING, "OUTPUT" }, HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME}; +static Setting::Handle hmdInputDeviceSetting { QStringList { OVERTE_AUDIO_STRING, OVERTE_AUDIO_HMD_STRING, "INPUT" }, HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME}; +static Setting::Handle hmdOutputDeviceSetting { QStringList { OVERTE_AUDIO_STRING, OVERTE_AUDIO_HMD_STRING, "OUTPUT" }, HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME}; Q_DECLARE_METATYPE(HifiAudioDeviceInfo); diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 16b217bc53..8caf6b6f89 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -343,6 +343,7 @@ AudioClient::AudioClient() { defaultAudioDeviceName(QAudio::AudioInput); defaultAudioDeviceName(QAudio::AudioOutput); + checkDevices(); // start a thread to detect any device changes _checkDevicesTimer = new QTimer(this); const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000; @@ -807,9 +808,10 @@ void AudioClient::start() { inputName = _hmdInputName; outputName = _hmdOutputName; } - - //initialize input to the dummy device to prevent starves - switchInputToAudioDevice(HifiAudioDeviceInfo()); + + // Input was originally set to HifiAudioDeviceInfo(), but that was causing trouble. + //Original comment: initialize input to the dummy device to prevent starves + switchInputToAudioDevice(defaultAudioDeviceForMode(QAudio::AudioInput, QString())); switchOutputToAudioDevice(defaultAudioDeviceForMode(QAudio::AudioOutput, QString())); #if defined(Q_OS_ANDROID) diff --git a/libraries/audio-client/src/HifiAudioDeviceInfo.cpp b/libraries/audio-client/src/HifiAudioDeviceInfo.cpp index 2a4c9065f4..ed3d94f2b8 100644 --- a/libraries/audio-client/src/HifiAudioDeviceInfo.cpp +++ b/libraries/audio-client/src/HifiAudioDeviceInfo.cpp @@ -12,7 +12,7 @@ #include "HifiAudioDeviceInfo.h" -const QString HifiAudioDeviceInfo::DEFAULT_DEVICE_NAME = "default "; +const QString HifiAudioDeviceInfo::DEFAULT_DEVICE_NAME = HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME; void HifiAudioDeviceInfo::setDevice(QAudioDeviceInfo devInfo) { _audioDeviceInfo = devInfo; diff --git a/libraries/audio-client/src/HifiAudioDeviceInfo.h b/libraries/audio-client/src/HifiAudioDeviceInfo.h index ddf5493241..dee7d20b23 100644 --- a/libraries/audio-client/src/HifiAudioDeviceInfo.h +++ b/libraries/audio-client/src/HifiAudioDeviceInfo.h @@ -19,6 +19,8 @@ #include #include +#define HIFI_AUDIO_DEVICE_INFO_DEFAULT_DEVICE_NAME "default " + class HifiAudioDeviceInfo : public QObject { Q_OBJECT