Skip to content

Commit

Permalink
Allow toggling automatic audio hardware latency compensation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNathannator committed Jul 23, 2024
1 parent a229e36 commit 8c040ca
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Assets/Script/Gameplay/GameManager.Loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ private async void Start()

FinalizeChart();

// Get audio calibration
int audioCalibration = SettingsManager.Settings.AudioCalibration.Value;
if (SettingsManager.Settings.AccountForHardwareLatency.Value)
audioCalibration += GlobalAudioHandler.PlaybackLatency;

// Initialize song runner
_songRunner = new SongRunner(
_mixer,
GlobalVariables.State.SongSpeed,
SettingsManager.Settings.AudioCalibration.Value,
audioCalibration,
SettingsManager.Settings.VideoCalibration.Value,
Song.SongOffsetSeconds);

Expand Down
6 changes: 4 additions & 2 deletions Assets/Script/Menu/Calibrator/Calibrator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -218,7 +218,9 @@ private void CalculateAudioLatency()
double median = diffs.Count % 2 != 0 ? diffs[mid] : (diffs[mid] + diffs[mid - 1]) / 2f;

// Set calibration
int calibration = (int)Math.Round(median * 1000) - GlobalAudioHandler.PlaybackLatency;
int calibration = (int)Math.Round(median * 1000);
if (SettingsManager.Settings.AccountForHardwareLatency.Value)
calibration -= GlobalAudioHandler.PlaybackLatency;
SettingsManager.Settings.AudioCalibration.Value = calibration;

// Set text
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/Playback/SongRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public SongRunner(StemMixer mixer, float songSpeed = 1f, int audioCalibration =
_mixer = mixer;
SongSpeed = songSpeed;
VideoCalibration = -videoCalibration / 1000.0;
AudioCalibration = (-(audioCalibration + GlobalAudioHandler.PlaybackLatency) / 1000.0) - VideoCalibration;
AudioCalibration = (-audioCalibration / 1000.0) - VideoCalibration;

SongOffset = -songOffset;

Expand Down
2 changes: 2 additions & 0 deletions Assets/Script/Settings/SettingsManager.Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void OpenCalibrator()
public IntSetting AudioCalibration { get; } = new(0);
public IntSetting VideoCalibration { get; } = new(0);

public ToggleSetting AccountForHardwareLatency { get; } = new(true);

public void OpenVenueFolder()
{
FileExplorerHelper.OpenFolder(VenueLoader.VenueFolder.FullName);
Expand Down
1 change: 1 addition & 0 deletions Assets/Script/Settings/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static partial class SettingsManager
new ButtonRowMetadata(nameof(Settings.OpenCalibrator)),
nameof(Settings.AudioCalibration),
nameof(Settings.VideoCalibration),
nameof(Settings.AccountForHardwareLatency),

new HeaderMetadata("Venues"),
new ButtonRowMetadata(nameof(Settings.OpenVenueFolder)),
Expand Down
4 changes: 4 additions & 0 deletions Assets/StreamingAssets/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@
"Name": "Audio Calibration (ms)",
"Description": "Audio calibration in milliseconds. Use the calibrator to automatically calibrate. Higher values make the audio play earlier, while lower ones make the audio play later."
},
"AccountForHardwareLatency": {
"Name": "Account For Audio Hardware Latency",
"Description": "Automatically accounts for the detected playback latency of your audio hardware. This latency may be inaccurate, disable this setting if your audio calibration is negative."
},
"BassVolume": {
"Name": "Bass Volume",
"Description": "Adjusts the song's bass guitar track volume. Only does something if the song is multi-track."
Expand Down

0 comments on commit 8c040ca

Please sign in to comment.