diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 5ea44aa0c2..3cd810bb5b 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -2,8 +2,10 @@ using System; using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Windows.Forms; +using BizHawk.Bizware.DirectX; using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.CustomControls; using BizHawk.Client.EmuHawk.ToolExtensions; @@ -899,7 +901,14 @@ namespace BizHawk.Client.EmuHawk private void SoundMenuItem_Click(object sender, EventArgs e) { - using var form = new SoundConfig(Config) { Owner = this }; + static IEnumerable GetDeviceNamesCallback(ESoundOutputMethod outputMethod) => outputMethod switch + { + ESoundOutputMethod.DirectSound => DirectSoundSoundOutput.GetDeviceNames(), + ESoundOutputMethod.XAudio2 => XAudio2SoundOutput.GetDeviceNames(), + ESoundOutputMethod.OpenAL => OpenALSoundOutput.GetDeviceNames(), + _ => Enumerable.Empty() + }; + using var form = new SoundConfig(Config, GetDeviceNamesCallback) { Owner = this }; if (form.ShowDialog().IsOk()) { Sound.StartSound(); diff --git a/src/BizHawk.Client.EmuHawk/config/SoundConfig.cs b/src/BizHawk.Client.EmuHawk/config/SoundConfig.cs index ed6f152891..c6fe467cd4 100644 --- a/src/BizHawk.Client.EmuHawk/config/SoundConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/SoundConfig.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; -using BizHawk.Bizware.DirectX; using BizHawk.Client.Common; using BizHawk.Common; @@ -12,11 +10,15 @@ namespace BizHawk.Client.EmuHawk public partial class SoundConfig : Form { private readonly Config _config; + + private readonly Func> _getDeviceNamesCallback; + private bool _programmaticallyChangingValue; - public SoundConfig(Config config) + public SoundConfig(Config config, Func> getDeviceNamesCallback) { _config = config; + _getDeviceNamesCallback = getDeviceNamesCallback; InitializeComponent(); } @@ -49,6 +51,17 @@ namespace BizHawk.Client.EmuHawk _programmaticallyChangingValue = false; } + private ESoundOutputMethod GetSelectedOutputMethod() + { + if (!OSTailoredCode.IsUnixHost) + { + if (rbOutputMethodDirectSound.Checked) return ESoundOutputMethod.DirectSound; + if (rbOutputMethodXAudio2.Checked) return ESoundOutputMethod.XAudio2; + } + if (rbOutputMethodOpenAL.Checked) return ESoundOutputMethod.OpenAL; + return ESoundOutputMethod.Dummy; + } + private void Ok_Click(object sender, EventArgs e) { if (rbOutputMethodDirectSound.Checked && (int)BufferSizeNumeric.Value < 60) @@ -62,9 +75,7 @@ namespace BizHawk.Client.EmuHawk _config.SoundEnabledNormal = cbEnableNormal.Checked; _config.SoundEnabledRWFF = cbEnableRWFF.Checked; _config.MuteFrameAdvance = cbMuteFrameAdvance.Checked; - if (rbOutputMethodDirectSound.Checked) _config.SoundOutputMethod = ESoundOutputMethod.DirectSound; - if (rbOutputMethodXAudio2.Checked) _config.SoundOutputMethod = ESoundOutputMethod.XAudio2; - if (rbOutputMethodOpenAL.Checked) _config.SoundOutputMethod = ESoundOutputMethod.OpenAL; + _config.SoundOutputMethod = GetSelectedOutputMethod(); _config.SoundBufferSizeMs = (int)BufferSizeNumeric.Value; _config.SoundVolume = tbNormal.Value; _config.SoundVolumeRWFF = tbRWFF.Value; @@ -87,18 +98,10 @@ namespace BizHawk.Client.EmuHawk private void PopulateDeviceList() { - IEnumerable deviceNames = Enumerable.Empty(); - if (!OSTailoredCode.IsUnixHost) - { - if (rbOutputMethodDirectSound.Checked) deviceNames = DirectSoundSoundOutput.GetDeviceNames(); - if (rbOutputMethodXAudio2.Checked) deviceNames = XAudio2SoundOutput.GetDeviceNames(); - } - if (rbOutputMethodOpenAL.Checked) deviceNames = OpenALSoundOutput.GetDeviceNames(); - listBoxSoundDevices.Items.Clear(); listBoxSoundDevices.Items.Add(""); listBoxSoundDevices.SelectedIndex = 0; - foreach (var name in deviceNames) + foreach (var name in _getDeviceNamesCallback(GetSelectedOutputMethod())) { listBoxSoundDevices.Items.Add(name); if (name == _config.SoundDevice)