Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio lag fix #3866

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Empty file added firmware.zip
Empty file.
Empty file added lua.zip
FredTheHunterProgrammer marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
6 changes: 6 additions & 0 deletions src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ public void ResolveDefaults()
public string SoundDevice { get; set; } = "";
public int SoundBufferSizeMs { get; set; } = 100;

public bool MuteInBG { get; set; } = false;

public bool MuteOnLag { get; set; } = false;

public int FPSThresholdPercentage { get; set; } = 90;

// Lua
public RecentFiles RecentLua { get; set; } = new RecentFiles(8);
public RecentFiles RecentLuaSession { get; set; } = new RecentFiles(8);
Expand Down
22 changes: 22 additions & 0 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3302,6 +3302,28 @@ private void StepRunLoop_Core(bool force = false)
UpdateToolsAfter();
}

// Mutes the game if EmuHawk is unfocused or minimized
// An option in the sound settings needs to be turned on for this to work.
if (Config.MuteInBG && (WindowState == FormWindowState.Minimized || Form.ActiveForm == null))
{
Sound.StopSound();
}
else
{
Sound.StartSound();
}

// Mutes the game if the current FPS reaches the threshold chosen by the user or lower
// An option in the sound settings needs to be turned on for this to work.
if (Config.MuteOnLag && _lastFps <= 60 * ((double)Config.FPSThresholdPercentage / 100))
{
Sound.StopSound();
}
else
{
Sound.StartSound();
}
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved

Sound.UpdateSound(atten, DisableSecondaryThrottling);
}

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static Program()
// This needs to be done before the warnings/errors show up
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// Quickly check if the user is running this as a 32 bit process somehow
// TODO: We may want to remove this sometime, EmuHawk should be able to run somewhat as 32 bit if the user really wants to
// (There are no longer any hard 64 bit deps, i.e. SlimDX is no longer around)
Expand Down
1 change: 0 additions & 1 deletion src/BizHawk.Client.EmuHawk/Sound/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public void UpdateSound(float atten, bool isSecondaryThrottlingDisabled)
{
return;
}

int samplesPerMs = SampleRate / 1000;
int outputThresholdMs = 20;
while (sampleCount > samplesNeeded)
Expand Down
687 changes: 385 additions & 302 deletions src/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/BizHawk.Client.EmuHawk/config/SoundConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ private void SoundConfig_Load(object sender, EventArgs e)
nudNormal.Value = _config.SoundVolume;
tbRWFF.Value = _config.SoundVolumeRWFF;
nudRWFF.Value = _config.SoundVolumeRWFF;
cbMuteInBG.Checked = _config.MuteInBG;
cbMuteOnLag.Checked = _config.MuteOnLag;
FpsThresholdNumeric.Value = _config.FPSThresholdPercentage;
FpsThresholdNumeric.Enabled = _config.MuteOnLag;
UpdateSoundDialog();

_programmaticallyChangingValue = false;
}

Expand Down Expand Up @@ -76,6 +79,9 @@ private void Ok_Click(object sender, EventArgs e)
_config.SoundVolume = tbNormal.Value;
_config.SoundVolumeRWFF = tbRWFF.Value;
_config.SoundDevice = (string)listBoxSoundDevices.SelectedItem ?? "<default>";
_config.MuteInBG = cbMuteInBG.Checked;
_config.MuteOnLag = cbMuteOnLag.Checked;
_config.FPSThresholdPercentage = (int)FpsThresholdNumeric.Value;
DialogResult = DialogResult.OK;
}

Expand Down Expand Up @@ -145,5 +151,10 @@ private void nudRWFF_ValueChanged(object sender, EventArgs e)
{
tbRWFF.Value = (int)nudRWFF.Value;
}

private void muteOnLag_CheckedChanged(object sender, EventArgs e)
{
FpsThresholdNumeric.Enabled = ((CheckBox)sender).Checked;
}
}
}