diff --git a/win32/CWaveOut.cpp b/win32/CWaveOut.cpp index c0d3b70f..a1765905 100644 --- a/win32/CWaveOut.cpp +++ b/win32/CWaveOut.cpp @@ -40,7 +40,10 @@ bool CWaveOut::SetupSound() wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; wfx.cbSize = 0; - waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfx, (DWORD_PTR)WaveCallback, (DWORD_PTR)&bufferCount, CALLBACK_FUNCTION); + // subtract -1, we added "Default" as first index - Default will yield -1, which is WAVE_MAPPER + int device_index = FindDeviceIndex(GUI.AudioDevice) - 1; + + waveOutOpen(&hWaveOut, device_index, &wfx, (DWORD_PTR)WaveCallback, (DWORD_PTR)&bufferCount, CALLBACK_FUNCTION); UINT32 blockTime = GUI.SoundBufferSize / blockCount; singleBufferSamples = (Settings.SoundPlaybackRate * blockTime) / 1000; @@ -217,4 +220,42 @@ void CWaveOut::ProcessSound() S9xMixSamples((BYTE *)waveHeaders[writeOffset].lpData, availableSamples); partialOffset = availableSamples << 1; } -} \ No newline at end of file +} + +std::vector CWaveOut::GetDeviceList() +{ + std::vector device_list; + + UINT num_devices = waveOutGetNumDevs(); + + device_list.push_back(_T("Default")); + + for (unsigned int i = 0; i < num_devices; i++) + { + WAVEOUTCAPS caps; + if(waveOutGetDevCaps(i, &caps, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR) + { + device_list.push_back(caps.szPname); + } + } + + return device_list; +} + +int CWaveOut::FindDeviceIndex(TCHAR *audio_device) +{ + std::vector device_list = GetDeviceList(); + + int index = 0; + + for (int i = 0; i < device_list.size(); i++) + { + if (_tcsstr(device_list[i].c_str(), audio_device) != NULL) + { + index = i; + break; + } + } + + return index; +} diff --git a/win32/CWaveOut.h b/win32/CWaveOut.h index ac4e9dbb..833283bd 100644 --- a/win32/CWaveOut.h +++ b/win32/CWaveOut.h @@ -42,4 +42,6 @@ class CWaveOut : public IS9xSoundOutput void DeInitSoundOutput(void); bool SetupSound(void); void SetVolume(double volume); -}; \ No newline at end of file + std::vector GetDeviceList(); + int FindDeviceIndex(TCHAR *audio_device); +}; diff --git a/win32/CXAudio2.h b/win32/CXAudio2.h index 5021622d..ea520796 100644 --- a/win32/CXAudio2.h +++ b/win32/CXAudio2.h @@ -42,9 +42,6 @@ private: void DeInitXAudio2(void); int GetAvailableBytes(); - std::vector GetDeviceList(); - int FindDeviceIndex(TCHAR *audio_device); - public: CXAudio2(void); ~CXAudio2(void); @@ -64,6 +61,8 @@ public: void DeInitSoundOutput(void) { DeInitXAudio2(); } bool SetupSound(void); void SetVolume(double volume); + std::vector GetDeviceList(); + int FindDeviceIndex(TCHAR *audio_device); }; #endif