diff --git a/BizHawk.MultiClient/Sound.cs b/BizHawk.MultiClient/Sound.cs index c76766aeb3..afb80d11a9 100644 --- a/BizHawk.MultiClient/Sound.cs +++ b/BizHawk.MultiClient/Sound.cs @@ -32,12 +32,12 @@ namespace BizHawk.MultiClient var desc = new SoundBufferDescription(); desc.Format = format; - desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2; + desc.Flags = BufferFlags.GlobalFocus | BufferFlags.Software | BufferFlags.GetCurrentPosition2 | BufferFlags.ControlVolume; desc.SizeInBytes = BufferSize; - DSoundBuffer = new SecondarySoundBuffer(device, desc); + ChangeVolume(Global.Config.SoundVolume); SoundBuffer = new byte[BufferSize]; - + disposed = false; } @@ -52,7 +52,6 @@ namespace BizHawk.MultiClient needDiscard = true; DSoundBuffer.Write(SoundBuffer, 0, LockFlags.EntireBuffer); - DSoundBuffer.CurrentPlayPosition = 0; DSoundBuffer.Play(0, PlayFlags.Looping); } @@ -150,5 +149,18 @@ namespace BizHawk.MultiClient soundoffset += samplesNeeded * 2; soundoffset %= BufferSize; } + + /// + /// Range: 0-100 + /// + /// + public void ChangeVolume(int vol) + { + if (vol > 100) + vol = 100; + if (vol < 0) + vol = 0; + DSoundBuffer.Volume = 0 - ((100 - Global.Config.SoundVolume) * 50); + } } } \ No newline at end of file diff --git a/BizHawk.MultiClient/config/SoundConfig.Designer.cs b/BizHawk.MultiClient/config/SoundConfig.Designer.cs index 47e1737d73..3133d04312 100644 --- a/BizHawk.MultiClient/config/SoundConfig.Designer.cs +++ b/BizHawk.MultiClient/config/SoundConfig.Designer.cs @@ -33,11 +33,11 @@ this.SoundOnCheckBox = new System.Windows.Forms.CheckBox(); this.MuteFrameAdvance = new System.Windows.Forms.CheckBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown(); this.SoundVolBar = new System.Windows.Forms.TrackBar(); + this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown(); this.groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit(); this.SuspendLayout(); // // Cancel @@ -94,14 +94,6 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Volume"; // - // SoundVolNumeric - // - this.SoundVolNumeric.Location = new System.Drawing.Point(16, 190); - this.SoundVolNumeric.Name = "SoundVolNumeric"; - this.SoundVolNumeric.Size = new System.Drawing.Size(59, 20); - this.SoundVolNumeric.TabIndex = 0; - this.SoundVolNumeric.ValueChanged += new System.EventHandler(this.SoundVolNumeric_ValueChanged); - // // SoundVolBar // this.SoundVolBar.LargeChange = 10; @@ -109,11 +101,19 @@ this.SoundVolBar.Maximum = 100; this.SoundVolBar.Name = "SoundVolBar"; this.SoundVolBar.Orientation = System.Windows.Forms.Orientation.Vertical; - this.SoundVolBar.Size = new System.Drawing.Size(45, 164); + this.SoundVolBar.Size = new System.Drawing.Size(42, 164); this.SoundVolBar.TabIndex = 1; this.SoundVolBar.TickFrequency = 10; this.SoundVolBar.Scroll += new System.EventHandler(this.trackBar1_Scroll); // + // SoundVolNumeric + // + this.SoundVolNumeric.Location = new System.Drawing.Point(16, 190); + this.SoundVolNumeric.Name = "SoundVolNumeric"; + this.SoundVolNumeric.Size = new System.Drawing.Size(59, 20); + this.SoundVolNumeric.TabIndex = 0; + this.SoundVolNumeric.ValueChanged += new System.EventHandler(this.SoundVolNumeric_ValueChanged); + // // SoundConfig // this.AcceptButton = this.OK; @@ -127,12 +127,13 @@ this.Controls.Add(this.OK); this.Controls.Add(this.Cancel); this.Name = "SoundConfig"; + this.ShowIcon = false; this.Text = "Sound Configuration"; this.Load += new System.EventHandler(this.SoundConfig_Load); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/BizHawk.MultiClient/config/SoundConfig.cs b/BizHawk.MultiClient/config/SoundConfig.cs index 164d70f8ff..9c9c3dd31d 100644 --- a/BizHawk.MultiClient/config/SoundConfig.cs +++ b/BizHawk.MultiClient/config/SoundConfig.cs @@ -20,6 +20,8 @@ namespace BizHawk.MultiClient { SoundOnCheckBox.Checked = Global.Config.SoundEnabled; MuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance; + SoundVolBar.Value = Global.Config.SoundVolume; + SoundVolNumeric.Value = Global.Config.SoundVolume; } private void OK_Click(object sender, EventArgs e) @@ -27,6 +29,7 @@ namespace BizHawk.MultiClient Global.Config.SoundEnabled = SoundOnCheckBox.Checked; Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked; Global.Config.SoundVolume = SoundVolBar.Value; + Global.Sound.ChangeVolume(Global.Config.SoundVolume); Global.Sound.StartSound(); this.Close(); }