From 56d5d1ef5a2368705306a577f53c16a2c9d5277e Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 2 Jun 2013 00:49:40 +0000 Subject: [PATCH] direct sound: you can now choose which of your devices to play out of. note that although you can make the change in the UI at any time, you actually have to restart the whole bizhawk to initialize on the new device. --- BizHawk.MultiClient/Config.cs | 1 + BizHawk.MultiClient/Program.cs | 2 +- BizHawk.MultiClient/Sound.cs | 25 ++++++++++++++ .../config/SoundConfig.Designer.cs | 34 ++++++++++++++++--- BizHawk.MultiClient/config/SoundConfig.cs | 23 ++++++++----- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index cb14d69845..4de4970b3a 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -436,6 +436,7 @@ namespace BizHawk.MultiClient public bool MuteFrameAdvance = true; public int SoundVolume = 100; //Range 0-100 public bool SoundThrottle = false; + public string SoundDevice = ""; // Log Window public bool LogWindowSaveWindowPosition = true; diff --git a/BizHawk.MultiClient/Program.cs b/BizHawk.MultiClient/Program.cs index d24d1e8a86..f8d3790d06 100644 --- a/BizHawk.MultiClient/Program.cs +++ b/BizHawk.MultiClient/Program.cs @@ -60,7 +60,7 @@ namespace BizHawk.MultiClient Global.Config = ConfigService.Load(PathManager.DefaultIniPath, new Config()); #if WINDOWS - try { Global.DSound = new DirectSound(); } + try { Global.DSound = SoundEnumeration.Create(); } catch { MessageBox.Show("Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 41khz instead of 48khz in mmsys.cpl.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/BizHawk.MultiClient/Sound.cs b/BizHawk.MultiClient/Sound.cs index d1aa366c7f..e1b17d38aa 100644 --- a/BizHawk.MultiClient/Sound.cs +++ b/BizHawk.MultiClient/Sound.cs @@ -1,5 +1,6 @@ using System; using BizHawk.Emulation.Sound; +using System.Collections.Generic; #if WINDOWS using SlimDX.DirectSound; using SlimDX.Multimedia; @@ -8,6 +9,30 @@ using SlimDX.Multimedia; namespace BizHawk.MultiClient { #if WINDOWS + public static class SoundEnumeration + { + public static DirectSound Create() + { + var dc = DirectSound.GetDevices(); + foreach (var dev in dc) + { + if (dev.Description == Global.Config.SoundDevice) + return new DirectSound(dev.DriverGuid); + } + return new DirectSound(); + } + + public static IEnumerable DeviceNames() + { + var ret = new List(); + var dc = DirectSound.GetDevices(); + foreach (var dev in dc) + ret.Add(dev.Description); + return ret; + } + } + + public class Sound : IDisposable { public bool needDiscard; diff --git a/BizHawk.MultiClient/config/SoundConfig.Designer.cs b/BizHawk.MultiClient/config/SoundConfig.Designer.cs index aa62ba0565..75a3affa9d 100644 --- a/BizHawk.MultiClient/config/SoundConfig.Designer.cs +++ b/BizHawk.MultiClient/config/SoundConfig.Designer.cs @@ -36,6 +36,8 @@ this.SoundVolBar = new System.Windows.Forms.TrackBar(); this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown(); this.ThrottlecheckBox = new System.Windows.Forms.CheckBox(); + this.listBoxSoundDevices = new System.Windows.Forms.ListBox(); + this.label1 = new System.Windows.Forms.Label(); this.SoundVolGroup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit(); @@ -45,7 +47,7 @@ // this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.Cancel.Location = new System.Drawing.Point(200, 209); + this.Cancel.Location = new System.Drawing.Point(317, 209); this.Cancel.Name = "Cancel"; this.Cancel.Size = new System.Drawing.Size(75, 23); this.Cancel.TabIndex = 0; @@ -57,7 +59,7 @@ // this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.OK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.OK.Location = new System.Drawing.Point(119, 209); + this.OK.Location = new System.Drawing.Point(236, 209); this.OK.Name = "OK"; this.OK.Size = new System.Drawing.Size(75, 23); this.OK.TabIndex = 1; @@ -67,7 +69,6 @@ // // SoundOnCheckBox // - this.SoundOnCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.SoundOnCheckBox.AutoSize = true; this.SoundOnCheckBox.Location = new System.Drawing.Point(147, 12); this.SoundOnCheckBox.Name = "SoundOnCheckBox"; @@ -79,7 +80,6 @@ // // MuteFrameAdvance // - this.MuteFrameAdvance.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.MuteFrameAdvance.AutoSize = true; this.MuteFrameAdvance.Location = new System.Drawing.Point(147, 35); this.MuteFrameAdvance.Name = "MuteFrameAdvance"; @@ -129,13 +129,35 @@ this.ThrottlecheckBox.Text = "Sound Throttle"; this.ThrottlecheckBox.UseVisualStyleBackColor = true; // + // listBoxSoundDevices + // + this.listBoxSoundDevices.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.listBoxSoundDevices.FormattingEnabled = true; + this.listBoxSoundDevices.Location = new System.Drawing.Point(108, 108); + this.listBoxSoundDevices.Name = "listBoxSoundDevices"; + this.listBoxSoundDevices.Size = new System.Drawing.Size(284, 95); + this.listBoxSoundDevices.TabIndex = 6; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(108, 92); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(78, 13); + this.label1.TabIndex = 7; + this.label1.Text = "Sound Device:"; + // // SoundConfig // this.AcceptButton = this.OK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.Cancel; - this.ClientSize = new System.Drawing.Size(287, 244); + this.ClientSize = new System.Drawing.Size(404, 244); + this.Controls.Add(this.label1); + this.Controls.Add(this.listBoxSoundDevices); this.Controls.Add(this.ThrottlecheckBox); this.Controls.Add(this.SoundVolGroup); this.Controls.Add(this.MuteFrameAdvance); @@ -166,5 +188,7 @@ private System.Windows.Forms.NumericUpDown SoundVolNumeric; private System.Windows.Forms.TrackBar SoundVolBar; private System.Windows.Forms.CheckBox ThrottlecheckBox; + private System.Windows.Forms.ListBox listBoxSoundDevices; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/config/SoundConfig.cs b/BizHawk.MultiClient/config/SoundConfig.cs index 2aa133ab74..c99e1af3df 100644 --- a/BizHawk.MultiClient/config/SoundConfig.cs +++ b/BizHawk.MultiClient/config/SoundConfig.cs @@ -25,15 +25,19 @@ namespace BizHawk.MultiClient SoundVolNumeric.Value = Global.Config.SoundVolume; UpdateSoundDialog(); - // to be removed - //if (MainForm.INTERIM) - //{ - // ThrottlecheckBox.Visible = true; - //} - //else - //{ - ThrottlecheckBox.Visible = false; - //} + // vestigal + ThrottlecheckBox.Visible = false; + + + var dd = SoundEnumeration.DeviceNames(); + listBoxSoundDevices.Items.Add(""); + listBoxSoundDevices.SelectedIndex = 0; + foreach (var d in dd) + { + listBoxSoundDevices.Items.Add(d); + if (d == Global.Config.SoundDevice) + listBoxSoundDevices.SelectedItem = d; + } } private void OK_Click(object sender, EventArgs e) @@ -42,6 +46,7 @@ namespace BizHawk.MultiClient Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked; Global.Config.SoundVolume = SoundVolBar.Value; Global.Config.SoundThrottle = ThrottlecheckBox.Checked; + Global.Config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? ""; Global.Sound.ChangeVolume(Global.Config.SoundVolume); Global.Sound.UpdateSoundSettings(); Global.Sound.StartSound();