Rework offset+vocal sync handling to fix the "Swing Mode" bug

This commit is contained in:
EliteMasterEric 2024-09-21 06:33:47 -04:00
parent f9186b67a7
commit 2c73b241e8
2 changed files with 24 additions and 8 deletions

View file

@ -275,6 +275,13 @@ class Conductor
return Save.instance.options.audioVisualOffset; return Save.instance.options.audioVisualOffset;
} }
public var combinedOffset(get, never):Float;
function get_combinedOffset():Float
{
return instrumentalOffset + audioVisualOffset + inputOffset;
}
/** /**
* The number of beats in a measure. May be fractional depending on the time signature. * The number of beats in a measure. May be fractional depending on the time signature.
*/ */

View file

@ -861,7 +861,7 @@ class PlayState extends MusicBeatSubState
// Reset music properly. // Reset music properly.
if (FlxG.sound.music != null) if (FlxG.sound.music != null)
{ {
FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset; FlxG.sound.music.time = startTimestamp - Conductor.instance.combinedOffset;
FlxG.sound.music.pitch = playbackRate; FlxG.sound.music.pitch = playbackRate;
FlxG.sound.music.pause(); FlxG.sound.music.pause();
} }
@ -878,7 +878,7 @@ class PlayState extends MusicBeatSubState
} }
} }
vocals.pause(); vocals.pause();
vocals.time = 0; vocals.time = 0 - Conductor.instance.combinedOffset;
if (FlxG.sound.music != null) FlxG.sound.music.volume = 1; if (FlxG.sound.music != null) FlxG.sound.music.volume = 1;
vocals.volume = 1; vocals.volume = 1;
@ -919,7 +919,7 @@ class PlayState extends MusicBeatSubState
{ {
// Do NOT apply offsets at this point, because they already got applied the previous frame! // Do NOT apply offsets at this point, because they already got applied the previous frame!
Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false); Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false);
if (Conductor.instance.songPosition >= (startTimestamp + Conductor.instance.instrumentalOffset)) if (Conductor.instance.songPosition >= (startTimestamp + Conductor.instance.combinedOffset))
{ {
trace("started song at " + Conductor.instance.songPosition); trace("started song at " + Conductor.instance.songPosition);
startSong(); startSong();
@ -1401,7 +1401,7 @@ class PlayState extends MusicBeatSubState
if (FlxG.sound.music != null) if (FlxG.sound.music != null)
{ {
var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); var correctSync:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.combinedOffset));
if (!startingSong && (Math.abs(FlxG.sound.music.time - correctSync) > 5 || Math.abs(vocals.checkSyncError(correctSync)) > 5)) if (!startingSong && (Math.abs(FlxG.sound.music.time - correctSync) > 5 || Math.abs(vocals.checkSyncError(correctSync)) > 5))
{ {
@ -1411,6 +1411,13 @@ class PlayState extends MusicBeatSubState
trace(correctSync); trace(correctSync);
resyncVocals(); resyncVocals();
} }
else
{
trace("NO VOCAL SYNC NEEDED");
if (vocals != null) trace(vocals.checkSyncError(correctSync));
trace(FlxG.sound.music.time);
trace(correctSync);
}
} }
// Only bop camera if zoom level is below 135% // Only bop camera if zoom level is below 135%
@ -1967,7 +1974,7 @@ class PlayState extends MusicBeatSubState
}; };
// A negative instrumental offset means the song skips the first few milliseconds of the track. // A negative instrumental offset means the song skips the first few milliseconds of the track.
// This just gets added into the startTimestamp behavior so we don't need to do anything extra. // This just gets added into the startTimestamp behavior so we don't need to do anything extra.
FlxG.sound.music.play(true, startTimestamp - Conductor.instance.instrumentalOffset); FlxG.sound.music.play(true, Math.max(0, startTimestamp - Conductor.instance.combinedOffset));
FlxG.sound.music.pitch = playbackRate; FlxG.sound.music.pitch = playbackRate;
// Prevent the volume from being wrong. // Prevent the volume from being wrong.
@ -1979,7 +1986,9 @@ class PlayState extends MusicBeatSubState
vocals.play(); vocals.play();
vocals.volume = 1.0; vocals.volume = 1.0;
vocals.pitch = playbackRate; vocals.pitch = playbackRate;
vocals.time = startTimestamp; vocals.time = FlxG.sound.music.time;
trace('${FlxG.sound.music.time}');
trace('${vocals.time}');
resyncVocals(); resyncVocals();
#if FEATURE_DISCORD_RPC #if FEATURE_DISCORD_RPC
@ -1989,7 +1998,7 @@ class PlayState extends MusicBeatSubState
if (startTimestamp > 0) if (startTimestamp > 0)
{ {
// FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset; // FlxG.sound.music.time = startTimestamp - Conductor.instance.combinedOffset;
handleSkippedNotes(); handleSkippedNotes();
} }
@ -2006,7 +2015,7 @@ class PlayState extends MusicBeatSubState
// Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.) // Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.)
if (!(FlxG.sound.music?.playing ?? false)) return; if (!(FlxG.sound.music?.playing ?? false)) return;
var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.instrumentalOffset)); var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.combinedOffset));
trace('Resyncing vocals to ${timeToPlayAt}'); trace('Resyncing vocals to ${timeToPlayAt}');
FlxG.sound.music.pause(); FlxG.sound.music.pause();
vocals.pause(); vocals.pause();