Skip to content

Commit 01b8f69

Browse files
xenkapcyn0x8AbnormalPoof
authored
[BUGFIX] Fix Audio/Visual Offset causing skips on song start (#3732)
* Fix audio offset interactions with song start Don't use combined offset here-- using it will cause the instrumental to skip forwards due to your offset. Just use instrumental offset, and don't play it when the song starts-- let resyncVocals do that * Alter countdown + conductor behavior Conductor's minimum songPosition when music is playing is now combinedOffset. resyncVocals is also no longer used when the song starts, as it complicates matters and causes weird double-upping whatever due to the song being played, paused, and then played again * Update source/funkin/Conductor.hx thank you https://github.com/cyn0x8 for reminding me FlxMath.bound exists Co-Authored-By: cyn <[email protected]> * Oops, don't need this here Thank you @NotHyper-474! * Fixed instrumentalOffset goofiness :D --------- Co-authored-by: cyn <[email protected]> Co-authored-by: Abnormal <[email protected]>
1 parent fd53ff8 commit 01b8f69

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

source/funkin/Conductor.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class Conductor
428428
// If the song is playing, limit the song position to the length of the song or beginning of the song.
429429
if (FlxG.sound.music != null && FlxG.sound.music.playing)
430430
{
431-
this.songPosition = Math.min(currentLength, Math.max(0, songPos));
431+
this.songPosition = FlxMath.bound(Math.min(this.combinedOffset, 0), songPos, currentLength);
432432
this.songPositionDelta += FlxG.elapsed * 1000 * FlxG.sound.music.pitch;
433433
}
434434
else

source/funkin/play/PlayState.hx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ class PlayState extends MusicBeatSubState
847847
// Reset music properly.
848848
if (FlxG.sound.music != null)
849849
{
850-
FlxG.sound.music.time = startTimestamp - Conductor.instance.combinedOffset;
851-
FlxG.sound.music.pitch = playbackRate;
852850
FlxG.sound.music.pause();
851+
FlxG.sound.music.time = startTimestamp;
852+
FlxG.sound.music.pitch = playbackRate;
853853
}
854854

855855
if (!overrideMusic)
@@ -864,7 +864,7 @@ class PlayState extends MusicBeatSubState
864864
}
865865
}
866866
vocals.pause();
867-
vocals.time = 0 - Conductor.instance.combinedOffset;
867+
vocals.time = startTimestamp - Conductor.instance.instrumentalOffset;
868868

869869
if (FlxG.sound.music != null) FlxG.sound.music.volume = 1;
870870
vocals.volume = 1;
@@ -2094,9 +2094,9 @@ class PlayState extends MusicBeatSubState
20942094
FlxG.sound.music.onComplete = function() {
20952095
if (mayPauseGame) endSong(skipEndingTransition);
20962096
};
2097-
// A negative instrumental offset means the song skips the first few milliseconds of the track.
2098-
// This just gets added into the startTimestamp behavior so we don't need to do anything extra.
2099-
FlxG.sound.music.play(true, Math.max(0, startTimestamp - Conductor.instance.combinedOffset));
2097+
2098+
FlxG.sound.music.pause();
2099+
FlxG.sound.music.time = startTimestamp;
21002100
FlxG.sound.music.pitch = playbackRate;
21012101

21022102
// Prevent the volume from being wrong.
@@ -2105,13 +2105,17 @@ class PlayState extends MusicBeatSubState
21052105

21062106
trace('Playing vocals...');
21072107
add(vocals);
2108-
vocals.play();
2109-
vocals.volume = 1.0;
2108+
2109+
vocals.time = startTimestamp - Conductor.instance.instrumentalOffset;
21102110
vocals.pitch = playbackRate;
2111-
vocals.time = FlxG.sound.music.time;
2111+
vocals.volume = 1.0;
2112+
2113+
// trace('STARTING SONG AT:');
21122114
// trace('${FlxG.sound.music.time}');
21132115
// trace('${vocals.time}');
2114-
resyncVocals();
2116+
2117+
FlxG.sound.music.play();
2118+
vocals.play();
21152119

21162120
#if FEATURE_DISCORD_RPC
21172121
// Updating Discord Rich Presence (with Time Left)
@@ -2149,8 +2153,10 @@ class PlayState extends MusicBeatSubState
21492153
// Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.)
21502154
if (!(FlxG.sound.music?.playing ?? false)) return;
21512155

2152-
var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.combinedOffset));
2156+
var timeToPlayAt:Float = Math.min(FlxG.sound.music.length,
2157+
Math.max(Math.min(Conductor.instance.combinedOffset, 0), Conductor.instance.songPosition) - Conductor.instance.combinedOffset);
21532158
trace('Resyncing vocals to ${timeToPlayAt}');
2159+
21542160
FlxG.sound.music.pause();
21552161
vocals.pause();
21562162

0 commit comments

Comments
 (0)