From c2b9b0941899e151d2073881cf75b8dfb0afba33 Mon Sep 17 00:00:00 2001 From: teejusb <5017202+teejusb@users.noreply.github.com> Date: Fri, 17 Feb 2023 17:44:00 -0800 Subject: [PATCH] Allow Windows users to select a device to use with WaveOut --- src/arch/Sound/RageSoundDriver_WaveOut.cpp | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/arch/Sound/RageSoundDriver_WaveOut.cpp b/src/arch/Sound/RageSoundDriver_WaveOut.cpp index 355bbdc3ad..a38420e9be 100644 --- a/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -124,9 +124,30 @@ RString RageSoundDriver_WaveOut::Init() fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8; fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign; - MMRESULT ret = waveOutOpen( &m_hWaveOut, WAVE_MAPPER, &fmt, (DWORD_PTR) m_hSoundEvent, NULL, CALLBACK_EVENT ); - if( ret != MMSYSERR_NOERROR ) + std::vector deviceIds; + if (!PREFSMAN->m_iSoundDevice.Get().empty()) { + std::vector portNames; + split(PREFSMAN->m_iSoundDevice.Get(), ",", portNames, true); + for (const RString& device : portNames) { + int id = StringToInt(device, /*pos=*/0, /*base=*/10, /*exceptVal=*/-1); + if (id != -1) { + deviceIds.push_back(id); + } + } + } + deviceIds.push_back(WAVE_MAPPER); // Fallback to WAVE_MAPPER + + MMRESULT ret = MMSYSERR_ERROR; + for (UINT id : deviceIds) { + ret = waveOutOpen( &m_hWaveOut, id, &fmt, (DWORD_PTR) m_hSoundEvent, NULL, CALLBACK_EVENT ); + if (ret == MMSYSERR_NOERROR) { + break; + } + } + if (ret != MMSYSERR_NOERROR) { return wo_ssprintf( ret, "waveOutOpen failed" ); + } + ZERO( m_aBuffers ); for(int b = 0; b < num_chunks; ++b)