From 4c8bdf9851e3d9ba19afed1c90a98d26a3f07374 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Tue, 6 Oct 2020 07:48:34 +1000 Subject: [PATCH] Add properties to IHostAudioManager for accessing global config --- src/BizHawk.Client.Common/Sound/IHostAudioManager.cs | 4 ++++ .../Sound/Output/DirectSoundSoundOutput.cs | 4 ++-- src/BizHawk.Client.EmuHawk/Sound/Output/DummySoundOutput.cs | 2 +- src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs | 4 ++-- src/BizHawk.Client.EmuHawk/Sound/Output/XAudio2SoundOutput.cs | 4 ++-- src/BizHawk.Client.EmuHawk/Sound/Sound.cs | 4 ++++ 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs b/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs index 62f130324c..1ce93997f9 100644 --- a/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs +++ b/src/BizHawk.Client.Common/Sound/IHostAudioManager.cs @@ -8,6 +8,10 @@ namespace BizHawk.Client.Common int ChannelCount { get; } + 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/DirectSoundSoundOutput.cs b/src/BizHawk.Client.EmuHawk/Sound/Output/DirectSoundSoundOutput.cs index fa70abde49..51df1d0cc9 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Output/DirectSoundSoundOutput.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Output/DirectSoundSoundOutput.cs @@ -136,7 +136,7 @@ namespace BizHawk.Client.EmuHawk public void StartSound() { - BufferSizeSamples = _sound.MillisecondsToSamples(GlobalWin.Config.SoundBufferSizeMs); + BufferSizeSamples = _sound.MillisecondsToSamples(_sound.ConfigBufferSizeMs); // 35 to 65 milliseconds depending on how big the buffer is. This is a trade-off // between more frequent but less severe glitches (i.e. catching underruns before @@ -144,7 +144,7 @@ namespace BizHawk.Client.EmuHawk // severe glitches. At least on my Windows 8 machines, the distance between the // play and write cursors can be up to 30 milliseconds, so that would be the // absolute minimum we could use here. - int minBufferFullnessMs = Math.Min(35 + ((GlobalWin.Config.SoundBufferSizeMs - 60) / 2), 65); + int minBufferFullnessMs = Math.Min(35 + ((_sound.ConfigBufferSizeMs - 60) / 2), 65); MaxSamplesDeficit = BufferSizeSamples - _sound.MillisecondsToSamples(minBufferFullnessMs); StartPlaying(); diff --git a/src/BizHawk.Client.EmuHawk/Sound/Output/DummySoundOutput.cs b/src/BizHawk.Client.EmuHawk/Sound/Output/DummySoundOutput.cs index ae24a45f56..8f655cf086 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Output/DummySoundOutput.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Output/DummySoundOutput.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.EmuHawk public void StartSound() { - BufferSizeSamples = _sound.MillisecondsToSamples(GlobalWin.Config.SoundBufferSizeMs); + BufferSizeSamples = _sound.MillisecondsToSamples(_sound.ConfigBufferSizeMs); MaxSamplesDeficit = BufferSizeSamples; _lastWriteTime = 0; diff --git a/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs b/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs index c0f6b6a265..8b0ebcec00 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Output/OpenALSoundOutput.cs @@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk public OpenALSoundOutput(IHostAudioManager sound) { _sound = sound; - string deviceName = GetDeviceNames().FirstOrDefault(n => n == GlobalWin.Config.SoundDevice); + string deviceName = GetDeviceNames().FirstOrDefault(n => n == _sound.ConfigDevice); _context = new AudioContext(deviceName, _sound.SampleRate); } @@ -54,7 +54,7 @@ namespace BizHawk.Client.EmuHawk public void StartSound() { - BufferSizeSamples = _sound.MillisecondsToSamples(GlobalWin.Config.SoundBufferSizeMs); + BufferSizeSamples = _sound.MillisecondsToSamples(_sound.ConfigBufferSizeMs); MaxSamplesDeficit = BufferSizeSamples; _sourceID = AL.GenSource(); diff --git a/src/BizHawk.Client.EmuHawk/Sound/Output/XAudio2SoundOutput.cs b/src/BizHawk.Client.EmuHawk/Sound/Output/XAudio2SoundOutput.cs index 3e2156198a..c72b04e212 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Output/XAudio2SoundOutput.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Output/XAudio2SoundOutput.cs @@ -26,7 +26,7 @@ namespace BizHawk.Client.EmuHawk _device = new XAudio2(); int? deviceIndex = Enumerable.Range(0, _device.DeviceCount) .Select(n => (int?)n) - .FirstOrDefault(n => _device.GetDeviceDetails(n.Value).DisplayName == GlobalWin.Config.SoundDevice); + .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); @@ -64,7 +64,7 @@ namespace BizHawk.Client.EmuHawk public void StartSound() { - BufferSizeSamples = _sound.MillisecondsToSamples(GlobalWin.Config.SoundBufferSizeMs); + BufferSizeSamples = _sound.MillisecondsToSamples(_sound.ConfigBufferSizeMs); MaxSamplesDeficit = BufferSizeSamples; var format = new WaveFormat diff --git a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs index 055ac329c6..4c7a42a763 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -24,6 +24,10 @@ namespace BizHawk.Client.EmuHawk private readonly BufferedAsync _bufferedAsync = new BufferedAsync(); // Buffer for Async sources private IBufferedSoundProvider _bufferedProvider; // One of the preceding buffers, or null if no source is set + public int ConfigBufferSizeMs => GlobalWin.Config.SoundBufferSizeMs; + + public string ConfigDevice => GlobalWin.Config.SoundDevice; + public Sound(IntPtr mainWindowHandle) { BlockAlign = BytesPerSample * ChannelCount;