diff --git a/src/BizHawk.Bizware.DirectX/XAudio2SoundOutput.cs b/src/BizHawk.Bizware.DirectX/XAudio2SoundOutput.cs index e142cccdcf..bf0fe176a1 100644 --- a/src/BizHawk.Bizware.DirectX/XAudio2SoundOutput.cs +++ b/src/BizHawk.Bizware.DirectX/XAudio2SoundOutput.cs @@ -20,16 +20,19 @@ namespace BizHawk.Bizware.DirectX private BufferPool _bufferPool; private long _runningSamplesQueued; - public XAudio2SoundOutput(IHostAudioManager sound) + public XAudio2SoundOutput(IHostAudioManager sound, string chosenDeviceName) { _sound = sound; _device = new XAudio2(); - int? deviceIndex = Enumerable.Range(0, _device.DeviceCount) - .Select(n => (int?)n) - .FirstOrDefault(n => _device.GetDeviceDetails(n.Value).DisplayName == _sound.ConfigDevice); - _masteringVoice = deviceIndex == null ? - new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate) : - new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate, deviceIndex.Value); + for (int i = 0, l = _device.DeviceCount; i < l; i++) + { + if (_device.GetDeviceDetails(i).DisplayName == chosenDeviceName) + { + _masteringVoice = new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate, i); + return; + } + } + _masteringVoice = new MasteringVoice(_device, _sound.ChannelCount, _sound.SampleRate); } public void Dispose() diff --git a/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs b/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs index 1ce93997f9..2632c8ae32 100644 --- a/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs +++ b/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs @@ -10,8 +10,6 @@ namespace BizHawk.Client.Common int ConfigBufferSizeMs { get; } - string ConfigDevice { get; } - int SampleRate { get; } void HandleInitializationOrUnderrun(bool isUnderrun, ref int samplesNeeded); diff --git a/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs b/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs index 8b0ebcec00..8797dee6c8 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs @@ -19,11 +19,13 @@ namespace BizHawk.Client.EmuHawk private int _currentSamplesQueued; private short[] _tempSampleBuffer; - public OpenALSoundOutput(IHostAudioManager sound) + public OpenALSoundOutput(IHostAudioManager sound, string chosenDeviceName) { _sound = sound; - string deviceName = GetDeviceNames().FirstOrDefault(n => n == _sound.ConfigDevice); - _context = new AudioContext(deviceName, _sound.SampleRate); + _context = new AudioContext( + GetDeviceNames().Contains(chosenDeviceName) ? chosenDeviceName : null, + _sound.SampleRate + ); } public void Dispose() diff --git a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs index 0d6b97bc7f..bfa9f1e127 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -27,8 +27,6 @@ namespace BizHawk.Client.EmuHawk public int ConfigBufferSizeMs => GlobalWin.Config.SoundBufferSizeMs; - public string ConfigDevice => GlobalWin.Config.SoundDevice; - public Sound(IntPtr mainWindowHandle) { BlockAlign = BytesPerSample * ChannelCount; @@ -38,15 +36,15 @@ namespace BizHawk.Client.EmuHawk // if DirectSound or XAudio is chosen, use OpenAL, otherwise comply with the user's choice _outputDevice = GlobalWin.Config.SoundOutputMethod == ESoundOutputMethod.Dummy ? (ISoundOutput) new DummySoundOutput(this) - : new OpenALSoundOutput(this); + : new OpenALSoundOutput(this, GlobalWin.Config.SoundDevice); } else { _outputDevice = GlobalWin.Config.SoundOutputMethod switch { ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, GlobalWin.Config.SoundDevice), - ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this), - ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this), + ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, GlobalWin.Config.SoundDevice), + ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, GlobalWin.Config.SoundDevice), _ => new DummySoundOutput(this) }; }