diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 1dfaff737f..7dff3035df 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -273,7 +273,7 @@ namespace BizHawk.Client.EmuHawk CloseRomContextMenuItem.Image = Properties.Resources.Close; } - public MainForm(Config config, IGL gl, string[] args, out IMovieSession movieSession) + public MainForm(Config config, IGL gl, Action updateGlobalSound, string[] args, out IMovieSession movieSession) { //do this threaded stuff early so it has plenty of time to run in background Database.InitializeDatabase(Path.Combine(PathUtils.ExeDirectoryPath, "gamedb", "gamedb.txt")); @@ -281,6 +281,7 @@ namespace BizHawk.Client.EmuHawk Config = config; GL = gl; + _updateGlobalSound = updateGlobalSound; InputManager = new InputManager { @@ -894,10 +895,15 @@ namespace BizHawk.Client.EmuHawk public GameInfo Game { get; private set; } + /// don't use this, use + private Sound _sound; + + private readonly Action _updateGlobalSound; + private Sound Sound { - get => Sound.Instance; - set => Sound.Instance = value; + get => _sound; + set => _updateGlobalSound(_sound = value); } public CheatCollection CheatList { get; } diff --git a/src/BizHawk.Client.EmuHawk/Program.cs b/src/BizHawk.Client.EmuHawk/Program.cs index c909c94f51..dc5415af28 100644 --- a/src/BizHawk.Client.EmuHawk/Program.cs +++ b/src/BizHawk.Client.EmuHawk/Program.cs @@ -194,6 +194,8 @@ namespace BizHawk.Client.EmuHawk var workingGL = TryInitIGL(initialConfig.DispMethod); + Sound globalSound = null; + if (!OSTC.IsUnixHost) { //WHY do we have to do this? some intel graphics drivers (ig7icd64.dll 10.18.10.3304 on an unknown chip on win8.1) are calling SetDllDirectory() for the process, which ruins stuff. @@ -212,7 +214,7 @@ namespace BizHawk.Client.EmuHawk { try { - InitAndRunSingleInstance(initialConfig, workingGL, i => exitCode = i, args); + InitAndRunSingleInstance(initialConfig, workingGL, newSound => globalSound = newSound, i => exitCode = i, args); } catch (ObjectDisposedException) { @@ -221,7 +223,7 @@ namespace BizHawk.Client.EmuHawk } else { - var mf = new MainForm(initialConfig, workingGL, args, out var movieSession); + var mf = new MainForm(initialConfig, workingGL, newSound => globalSound = newSound, args, out var movieSession); // var title = mf.Text; mf.Show(); // mf.Text = title; @@ -252,8 +254,7 @@ namespace BizHawk.Client.EmuHawk } finally { - Sound.Instance?.Dispose(); - Sound.Instance = null; + globalSound?.Dispose(); workingGL.Dispose(); Input.Instance?.Adapter?.DeInitAll(); } @@ -322,13 +323,16 @@ namespace BizHawk.Client.EmuHawk private readonly Action _setExitCode; + private readonly Action _updateGlobalSound; + private readonly string[] cmdArgs; - public SingleInstanceController(Config config, IGL gl, Action setExitCode, string[] args) + public SingleInstanceController(Config config, IGL gl, Action updateGlobalSound, Action setExitCode, string[] args) { _config = config; _gl = gl; _setExitCode = setExitCode; + _updateGlobalSound = updateGlobalSound; cmdArgs = args; IsSingleInstance = true; StartupNextInstance += this_StartupNextInstance; @@ -344,7 +348,7 @@ namespace BizHawk.Client.EmuHawk protected override void OnCreateMainForm() { - MainForm = new MainForm(_config, _gl, cmdArgs, out _); + MainForm = new MainForm(_config, _gl, _updateGlobalSound, cmdArgs, out _); var title = MainForm.Text; MainForm.Show(); MainForm.Text = title; @@ -352,7 +356,7 @@ namespace BizHawk.Client.EmuHawk } } - private static void InitAndRunSingleInstance(Config config, IGL gl, Action setExitCode, string[] args) - => new SingleInstanceController(config, gl, setExitCode, args).Run(); + private static void InitAndRunSingleInstance(Config config, IGL gl, Action updateGlobalSound, Action setExitCode, string[] args) + => new SingleInstanceController(config, gl, updateGlobalSound, setExitCode, args).Run(); } } diff --git a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs index 0fc20f1dda..a6dfea1bd1 100644 --- a/src/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/src/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -11,8 +11,6 @@ namespace BizHawk.Client.EmuHawk /// TODO rename to HostAudioManager public class Sound : IHostAudioManager, IDisposable { - public static Sound Instance; - public int SampleRate { get; } = 44100; public int BytesPerSample { get; } = 2;