Remove GlobalWin.Config by cleaning up Sound

This commit is contained in:
YoshiRulz 2020-11-30 20:37:11 +10:00
parent 0a9f93c433
commit c3a7ec047f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 19 additions and 19 deletions

View File

@ -1,12 +1,8 @@
using BizHawk.Client.Common;
// ReSharper disable StyleCop.SA1401 // ReSharper disable StyleCop.SA1401
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public static class GlobalWin public static class GlobalWin
{ {
public static Sound Sound; public static Sound Sound;
public static Config Config { get; set; }
} }
} }

View File

@ -919,7 +919,7 @@ namespace BizHawk.Client.EmuHawk
if (form.ApplyNewSoundDevice) if (form.ApplyNewSoundDevice)
{ {
Sound.Dispose(); Sound.Dispose();
Sound = new Sound(Handle, Config.SoundOutputMethod, Config.SoundDevice, Emulator.VsyncRate); Sound = new Sound(Handle, Config, Emulator.VsyncRate);
Sound.StartSound(); Sound.StartSound();
} }
else else

View File

@ -416,7 +416,7 @@ namespace BizHawk.Client.EmuHawk
InputManager.AutofireStickyXorAdapter.SetOnOffPatternFromConfig(Config.AutofireOn, Config.AutofireOff); InputManager.AutofireStickyXorAdapter.SetOnOffPatternFromConfig(Config.AutofireOn, Config.AutofireOff);
try try
{ {
GlobalWin.Sound = new Sound(Handle, Config.SoundOutputMethod, Config.SoundDevice, Emulator.VsyncRate); GlobalWin.Sound = new Sound(Handle, Config, Emulator.VsyncRate);
} }
catch catch
{ {
@ -429,7 +429,7 @@ namespace BizHawk.Client.EmuHawk
MessageBox.Show(message, "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(message, "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Config.SoundOutputMethod = ESoundOutputMethod.Dummy; Config.SoundOutputMethod = ESoundOutputMethod.Dummy;
GlobalWin.Sound = new Sound(Handle, Config.SoundOutputMethod, Config.SoundDevice, Emulator.VsyncRate); GlobalWin.Sound = new Sound(Handle, Config, Emulator.VsyncRate);
} }
Sound.StartSound(); Sound.StartSound();
@ -861,7 +861,7 @@ namespace BizHawk.Client.EmuHawk
private new Config Config private new Config Config
{ {
get => _config; get => _config;
set => GlobalWin.Config = base.Config = _config = value; set => base.Config = _config = value;
} }
private readonly IGL GL; private readonly IGL GL;
@ -2796,6 +2796,7 @@ namespace BizHawk.Client.EmuHawk
InputManager.SyncControls(Emulator, MovieSession, Config); InputManager.SyncControls(Emulator, MovieSession, Config);
Tools.Restart(Config, Emulator, Game); Tools.Restart(Config, Emulator, Game);
ExtToolManager.Restart(Config.PathEntries); ExtToolManager.Restart(Config.PathEntries);
Sound.Config = Config;
DisplayManager.UpdateGlobals(Config, Emulator); DisplayManager.UpdateGlobals(Config, Emulator);
AddOnScreenMessage($"Config file loaded: {iniPath}"); AddOnScreenMessage($"Config file loaded: {iniPath}");
} }

View File

@ -27,29 +27,32 @@ namespace BizHawk.Client.EmuHawk
private readonly BufferedAsync _bufferedAsync = new BufferedAsync(); // Buffer for Async sources 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 private IBufferedSoundProvider _bufferedProvider; // One of the preceding buffers, or null if no source is set
public int ConfigBufferSizeMs => GlobalWin.Config.SoundBufferSizeMs; public Config Config;
public Sound(IntPtr mainWindowHandle, ESoundOutputMethod soundOutputMethod, string soundDevice, Func<double> getCoreVsyncRateCallback) public int ConfigBufferSizeMs => Config.SoundBufferSizeMs;
public Sound(IntPtr mainWindowHandle, Config config, Func<double> getCoreVsyncRateCallback)
{ {
BlockAlign = BytesPerSample * ChannelCount; BlockAlign = BytesPerSample * ChannelCount;
_getCoreVsyncRateCallback = getCoreVsyncRateCallback; _getCoreVsyncRateCallback = getCoreVsyncRateCallback;
_outputProvider = new SoundOutputProvider(_getCoreVsyncRateCallback); _outputProvider = new SoundOutputProvider(_getCoreVsyncRateCallback);
Config = config;
if (OSTailoredCode.IsUnixHost) if (OSTailoredCode.IsUnixHost)
{ {
// if DirectSound or XAudio is chosen, use OpenAL, otherwise comply with the user's choice // if DirectSound or XAudio is chosen, use OpenAL, otherwise comply with the user's choice
_outputDevice = soundOutputMethod == ESoundOutputMethod.Dummy _outputDevice = config.SoundOutputMethod == ESoundOutputMethod.Dummy
? (ISoundOutput) new DummySoundOutput(this) ? (ISoundOutput) new DummySoundOutput(this)
: new OpenALSoundOutput(this, soundDevice); : new OpenALSoundOutput(this, config.SoundDevice);
} }
else else
{ {
_outputDevice = soundOutputMethod switch _outputDevice = config.SoundOutputMethod switch
{ {
ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, soundDevice), ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, config.SoundDevice),
ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, soundDevice), ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, config.SoundDevice),
ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, soundDevice), ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, config.SoundDevice),
_ => new DummySoundOutput(this) _ => new DummySoundOutput(this)
}; };
} }
@ -76,7 +79,7 @@ namespace BizHawk.Client.EmuHawk
public void StartSound() public void StartSound()
{ {
if (_disposed) return; if (_disposed) return;
if (!GlobalWin.Config.SoundEnabled) return; if (!Config.SoundEnabled) return;
if (IsStarted) return; if (IsStarted) return;
_outputDevice.StartSound(); _outputDevice.StartSound();
@ -150,7 +153,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateSound(float atten, bool isSecondaryThrottlingDisabled) public void UpdateSound(float atten, bool isSecondaryThrottlingDisabled)
{ {
if (!GlobalWin.Config.SoundEnabled || !IsStarted || _bufferedProvider == null || _disposed) if (!Config.SoundEnabled || !IsStarted || _bufferedProvider == null || _disposed)
{ {
_bufferedProvider?.DiscardSamples(); _bufferedProvider?.DiscardSamples();
return; return;
@ -175,7 +178,7 @@ namespace BizHawk.Client.EmuHawk
} }
else if (_bufferedProvider == _outputProvider) else if (_bufferedProvider == _outputProvider)
{ {
if (GlobalWin.Config.SoundThrottle) if (Config.SoundThrottle)
{ {
_outputProvider.BaseSoundProvider.GetSamplesSync(out samples, out sampleCount); _outputProvider.BaseSoundProvider.GetSamplesSync(out samples, out sampleCount);
sampleOffset = 0; sampleOffset = 0;