Sound Config - Sample rate config

This commit is contained in:
andres.delikat 2011-05-25 02:00:44 +00:00
parent 77afbe240d
commit 47b9487bd3
4 changed files with 64 additions and 6 deletions

View File

@ -133,6 +133,7 @@
public bool SoundEnabled = true;
public bool MuteFrameAdvance = true;
public int SoundVolume = 100; //Range 0-100
public int SoundSampleRateIndex = 2; //0 = 22050, 1 = 32000, 2 = 44100, 3 = 48000, 4 = 960000
// Lua Console
public RecentFiles RecentLua = new RecentFiles(8);

View File

@ -161,7 +161,7 @@ namespace BizHawk.MultiClient
if (vol < 0)
vol = 0;
if (Global.Config.SoundEnabled)
SoundEnabledChanged();
UpdateSoundSettings();
else
DSoundBuffer.Volume = 0 - ((100 - Global.Config.SoundVolume) * 50);
@ -170,12 +170,33 @@ namespace BizHawk.MultiClient
/// <summary>
/// Uses Global.Config.SoundEnabled, this just notifies the object to read it
/// </summary>
public void SoundEnabledChanged()
public void UpdateSoundSettings()
{
int vol = Global.Config.SoundVolume;
if (Global.Config.SoundEnabled)
vol = -5000;
DSoundBuffer.Volume = 0 - ((100 - Global.Config.SoundVolume) * 50);
switch (Global.Config.SoundSampleRateIndex)
{
case 0:
DSoundBuffer.Format.SamplesPerSecond = 22050;
break;
case 1:
DSoundBuffer.Format.SamplesPerSecond = 32000;
break;
default:
case 2:
DSoundBuffer.Format.SamplesPerSecond = 44100;
break;
case 3:
DSoundBuffer.Format.SamplesPerSecond = 48000;
break;
case 4:
DSoundBuffer.Format.SamplesPerSecond = 96000;
break;
}
}
}
}

View File

@ -35,9 +35,12 @@
this.SoundVolGroup = new System.Windows.Forms.GroupBox();
this.SoundVolBar = new System.Windows.Forms.TrackBar();
this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown();
this.SampleRateCombo = new System.Windows.Forms.ComboBox();
this.SampleRateBox = new System.Windows.Forms.GroupBox();
this.SoundVolGroup.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit();
this.SampleRateBox.SuspendLayout();
this.SuspendLayout();
//
// Cancel
@ -115,6 +118,31 @@
this.SoundVolNumeric.TabIndex = 0;
this.SoundVolNumeric.ValueChanged += new System.EventHandler(this.SoundVolNumeric_ValueChanged);
//
// SampleRateCombo
//
this.SampleRateCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SampleRateCombo.FormattingEnabled = true;
this.SampleRateCombo.Items.AddRange(new object[] {
"22050",
"32000",
"44100",
"48000",
"96000"});
this.SampleRateCombo.Location = new System.Drawing.Point(6, 19);
this.SampleRateCombo.Name = "SampleRateCombo";
this.SampleRateCombo.Size = new System.Drawing.Size(121, 21);
this.SampleRateCombo.TabIndex = 5;
//
// SampleRateBox
//
this.SampleRateBox.Controls.Add(this.SampleRateCombo);
this.SampleRateBox.Location = new System.Drawing.Point(127, 71);
this.SampleRateBox.Name = "SampleRateBox";
this.SampleRateBox.Size = new System.Drawing.Size(135, 53);
this.SampleRateBox.TabIndex = 6;
this.SampleRateBox.TabStop = false;
this.SampleRateBox.Text = "Sample Rate";
//
// SoundConfig
//
this.AcceptButton = this.OK;
@ -122,6 +150,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.Cancel;
this.ClientSize = new System.Drawing.Size(355, 286);
this.Controls.Add(this.SampleRateBox);
this.Controls.Add(this.SoundVolGroup);
this.Controls.Add(this.MuteFrameAdvance);
this.Controls.Add(this.SoundOnCheckBox);
@ -135,6 +164,7 @@
this.SoundVolGroup.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).EndInit();
this.SampleRateBox.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -149,5 +179,7 @@
private System.Windows.Forms.GroupBox SoundVolGroup;
private System.Windows.Forms.NumericUpDown SoundVolNumeric;
private System.Windows.Forms.TrackBar SoundVolBar;
private System.Windows.Forms.ComboBox SampleRateCombo;
private System.Windows.Forms.GroupBox SampleRateBox;
}
}

View File

@ -22,7 +22,8 @@ namespace BizHawk.MultiClient
MuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance;
SoundVolBar.Value = Global.Config.SoundVolume;
SoundVolNumeric.Value = Global.Config.SoundVolume;
SetEnabledState();
SampleRateCombo.SelectedIndex = Global.Config.SoundSampleRateIndex;
UpdateSoundDialog();
}
private void OK_Click(object sender, EventArgs e)
@ -31,7 +32,8 @@ namespace BizHawk.MultiClient
Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked;
Global.Config.SoundVolume = SoundVolBar.Value;
Global.Sound.ChangeVolume(Global.Config.SoundVolume);
Global.Sound.SoundEnabledChanged();
Global.Config.SoundSampleRateIndex = SampleRateCombo.SelectedIndex;
Global.Sound.UpdateSoundSettings();
Global.Sound.StartSound();
this.Close();
}
@ -53,19 +55,21 @@ namespace BizHawk.MultiClient
private void SoundOnCheckBox_CheckedChanged(object sender, EventArgs e)
{
SetEnabledState();
UpdateSoundDialog();
}
private void SetEnabledState()
private void UpdateSoundDialog()
{
if (SoundOnCheckBox.Checked)
{
SoundVolGroup.Enabled = true;
SampleRateBox.Enabled = true;
MuteFrameAdvance.Enabled = true;
}
else
{
SoundVolGroup.Enabled = false;
SampleRateBox.Enabled = false;
MuteFrameAdvance.Enabled = false;
}
}