realtime sound throttling. i don't think this implementation is very good, but hopefully it's a starting point. to test it, disable other forms of throttling first (vsync, frame limit).
This commit is contained in:
parent
d4f5ed2f50
commit
66dd752f77
|
@ -251,6 +251,7 @@ namespace BizHawk.MultiClient
|
|||
public bool SoundEnabled = true;
|
||||
public bool MuteFrameAdvance = true;
|
||||
public int SoundVolume = 100; //Range 0-100
|
||||
public bool SoundThrottle = false;
|
||||
|
||||
// Log Window
|
||||
public bool LogWindowSaveWindowPosition = true;
|
||||
|
|
|
@ -130,18 +130,41 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
|
||||
int samplesNeeded = SNDDXGetAudioSpace() * 2;
|
||||
if (samplesNeeded == 0)
|
||||
return;
|
||||
short[] samples;
|
||||
|
||||
short[] samples = new short[samplesNeeded];
|
||||
if (Global.Config.SoundThrottle)
|
||||
{
|
||||
if (DSoundBuffer == null) return; // can cause SNDDXGetAudioSpace() = 0
|
||||
int samplesWanted = 2 * (int) (44100.0 / Global.Emulator.CoreOutputComm.VsyncRate);
|
||||
|
||||
while (samplesNeeded < samplesWanted)
|
||||
{
|
||||
System.Threading.Thread.Yield(); // TODO: much better sleeping
|
||||
samplesNeeded = SNDDXGetAudioSpace() * 2;
|
||||
}
|
||||
samplesNeeded = samplesWanted;
|
||||
samples = new short[samplesNeeded];
|
||||
// no semisync
|
||||
if (!Muted)
|
||||
soundProvider.GetSamples(samples);
|
||||
else
|
||||
soundProvider.DiscardSamples();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (samplesNeeded == 0)
|
||||
return;
|
||||
samples = new short[samplesNeeded];
|
||||
if (soundProvider != null && Muted == false)
|
||||
{
|
||||
semisync.BaseSoundProvider = soundProvider;
|
||||
semisync.GetSamples(samples);
|
||||
}
|
||||
else soundProvider.DiscardSamples();
|
||||
}
|
||||
|
||||
//Console.WriteLine(samplesNeeded/2);
|
||||
|
||||
if (soundProvider != null && Muted == false)
|
||||
{
|
||||
semisync.BaseSoundProvider = soundProvider;
|
||||
semisync.GetSamples(samples);
|
||||
}
|
||||
else soundProvider.DiscardSamples();
|
||||
|
||||
int cursor = soundoffset;
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
this.SoundVolGroup = new System.Windows.Forms.GroupBox();
|
||||
this.SoundVolBar = new System.Windows.Forms.TrackBar();
|
||||
this.SoundVolNumeric = new System.Windows.Forms.NumericUpDown();
|
||||
this.ThrottlecheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.SoundVolGroup.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.SoundVolBar)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.SoundVolNumeric)).BeginInit();
|
||||
|
@ -117,6 +118,16 @@
|
|||
this.SoundVolNumeric.TabIndex = 0;
|
||||
this.SoundVolNumeric.ValueChanged += new System.EventHandler(this.SoundVolNumeric_ValueChanged);
|
||||
//
|
||||
// ThrottlecheckBox
|
||||
//
|
||||
this.ThrottlecheckBox.AutoSize = true;
|
||||
this.ThrottlecheckBox.Location = new System.Drawing.Point(147, 58);
|
||||
this.ThrottlecheckBox.Name = "ThrottlecheckBox";
|
||||
this.ThrottlecheckBox.Size = new System.Drawing.Size(96, 17);
|
||||
this.ThrottlecheckBox.TabIndex = 5;
|
||||
this.ThrottlecheckBox.Text = "Sound Throttle";
|
||||
this.ThrottlecheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// SoundConfig
|
||||
//
|
||||
this.AcceptButton = this.OK;
|
||||
|
@ -124,6 +135,7 @@
|
|||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.Cancel;
|
||||
this.ClientSize = new System.Drawing.Size(287, 244);
|
||||
this.Controls.Add(this.ThrottlecheckBox);
|
||||
this.Controls.Add(this.SoundVolGroup);
|
||||
this.Controls.Add(this.MuteFrameAdvance);
|
||||
this.Controls.Add(this.SoundOnCheckBox);
|
||||
|
@ -152,5 +164,6 @@
|
|||
private System.Windows.Forms.GroupBox SoundVolGroup;
|
||||
private System.Windows.Forms.NumericUpDown SoundVolNumeric;
|
||||
private System.Windows.Forms.TrackBar SoundVolBar;
|
||||
private System.Windows.Forms.CheckBox ThrottlecheckBox;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
SoundOnCheckBox.Checked = Global.Config.SoundEnabled;
|
||||
MuteFrameAdvance.Checked = Global.Config.MuteFrameAdvance;
|
||||
ThrottlecheckBox.Checked = Global.Config.SoundThrottle;
|
||||
SoundVolBar.Value = Global.Config.SoundVolume;
|
||||
SoundVolNumeric.Value = Global.Config.SoundVolume;
|
||||
UpdateSoundDialog();
|
||||
|
@ -30,6 +31,7 @@ namespace BizHawk.MultiClient
|
|||
Global.Config.SoundEnabled = SoundOnCheckBox.Checked;
|
||||
Global.Config.MuteFrameAdvance = MuteFrameAdvance.Checked;
|
||||
Global.Config.SoundVolume = SoundVolBar.Value;
|
||||
Global.Config.SoundThrottle = ThrottlecheckBox.Checked;
|
||||
Global.Sound.ChangeVolume(Global.Config.SoundVolume);
|
||||
Global.Sound.UpdateSoundSettings();
|
||||
Global.Sound.StartSound();
|
||||
|
@ -64,11 +66,13 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
SoundVolGroup.Enabled = true;
|
||||
MuteFrameAdvance.Enabled = true;
|
||||
ThrottlecheckBox.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundVolGroup.Enabled = false;
|
||||
MuteFrameAdvance.Enabled = false;
|
||||
ThrottlecheckBox.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue