win32: add device selection to WaveOut

This commit is contained in:
OV2 2019-02-12 19:41:44 +01:00
parent 28f8ac8341
commit 3c28cbf514
3 changed files with 48 additions and 6 deletions

View File

@ -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;
@ -218,3 +221,41 @@ void CWaveOut::ProcessSound()
partialOffset = availableSamples << 1;
}
}
std::vector<std::wstring> CWaveOut::GetDeviceList()
{
std::vector<std::wstring> 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<std::wstring> 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;
}

View File

@ -42,4 +42,6 @@ class CWaveOut : public IS9xSoundOutput
void DeInitSoundOutput(void);
bool SetupSound(void);
void SetVolume(double volume);
std::vector<std::wstring> GetDeviceList();
int FindDeviceIndex(TCHAR *audio_device);
};

View File

@ -42,9 +42,6 @@ private:
void DeInitXAudio2(void);
int GetAvailableBytes();
std::vector<std::wstring> 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<std::wstring> GetDeviceList();
int FindDeviceIndex(TCHAR *audio_device);
};
#endif