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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@
/packages

launchSettings.json

/Dist/copyBIOS.sh
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved
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 FPSThreshold { get; set; } = 56;
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved

// Lua
public RecentFiles RecentLua { get; set; } = new RecentFiles(8);
public RecentFiles RecentLuaSession { get; set; } = new RecentFiles(8);
Expand Down
29 changes: 29 additions & 0 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3302,7 +3302,36 @@ 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) {
if(WindowState == FormWindowState.Minimized || Form.ActiveForm == null) {
Sound.StopSound();
}
else {
Sound.StartSound();
}
} 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) {
if (_lastFps <= (double)Config.FPSThreshold)
{
Sound.StopSound();
}
else
{
Sound.StartSound();
}
}
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved


Sound.UpdateSound(atten, DisableSecondaryThrottling);

}

private void CalcFramerateAndUpdateDisplay(long currentTimestamp, bool isRewinding, bool isFastForwarding)
Expand Down
6 changes: 6 additions & 0 deletions src/BizHawk.Client.EmuHawk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ internal static class Program
static Program()
{
// This needs to be done before the warnings/errors show up

FredTheHunterProgrammer marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -89,6 +94,7 @@ static Program()
private static int Main(string[] args)
{
var exitCode = SubMain(args);

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Console.WriteLine("BizHawk has completed its shutdown routines, killing process...");
Expand Down
1 change: 1 addition & 0 deletions src/BizHawk.Client.EmuHawk/Sound/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void HandleInitializationOrUnderrun(bool isUnderrun, ref int samplesNeede

public void UpdateSound(float atten, bool isSecondaryThrottlingDisabled)
{

if (!Config.SoundEnabled || !IsStarted || _bufferedProvider == null || _disposed)
{
_bufferedProvider?.DiscardSamples();
Expand Down
687 changes: 385 additions & 302 deletions src/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/BizHawk.Client.EmuHawk/config/SoundConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public SoundConfig(IDialogController dialogController, Config config, Func<ESoun
_config = config;
_getDeviceNamesCallback = getDeviceNamesCallback;
DialogController = dialogController;

InitializeComponent();
}

Expand All @@ -44,6 +45,10 @@ 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.FPSThreshold;
FpsThresholdNumeric.Enabled = _config.MuteOnLag;
UpdateSoundDialog();

_programmaticallyChangingValue = false;
Expand Down Expand Up @@ -76,6 +81,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.FPSThreshold = (int)FpsThresholdNumeric.Value;
DialogResult = DialogResult.OK;
}

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

private void muteOnLag_CheckedChanged(object sender, EventArgs e)
{
if(cbMuteOnLag.Checked) {
FpsThresholdNumeric.Enabled = true;
} else {
FpsThresholdNumeric.Enabled = false;
}
FredTheHunterProgrammer marked this conversation as resolved.
Show resolved Hide resolved
}
}
}