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

[BUGFIX] Fix Audio/Visual Offset causing skips on song start #3732

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/funkin/Conductor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class Conductor
// If the song is playing, limit the song position to the length of the song or beginning of the song.
if (FlxG.sound.music != null && FlxG.sound.music.playing)
{
this.songPosition = Math.min(currentLength, Math.max(0, songPos));
this.songPosition = Math.min(currentLength, Math.max(Math.min(this.combinedOffset, 0), songPos));
xenkap marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand Down
20 changes: 12 additions & 8 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ class PlayState extends MusicBeatSubState
}

Conductor.instance.mapTimeChanges(currentChart.timeChanges);
var pre:Float = (Conductor.instance.beatLengthMs * -5) + startTimestamp;
var pre:Float = (Conductor.instance.beatLengthMs * -5) + startTimestamp + Conductor.instance.combinedOffset;

trace('Attempting to start at ' + pre);

Expand Down Expand Up @@ -860,9 +860,9 @@ class PlayState extends MusicBeatSubState
// Reset music properly.
if (FlxG.sound.music != null)
{
FlxG.sound.music.time = startTimestamp - Conductor.instance.combinedOffset;
FlxG.sound.music.pitch = playbackRate;
FlxG.sound.music.pause();
FlxG.sound.music.time = startTimestamp - Conductor.instance.instrumentalOffset;
FlxG.sound.music.pitch = playbackRate;
}

if (!overrideMusic)
Expand All @@ -877,7 +877,7 @@ class PlayState extends MusicBeatSubState
}
}
vocals.pause();
vocals.time = 0 - Conductor.instance.combinedOffset;
vocals.time = -Conductor.instance.instrumentalOffset;

if (FlxG.sound.music != null) FlxG.sound.music.volume = 1;
vocals.volume = 1;
Expand Down Expand Up @@ -2081,7 +2081,8 @@ class PlayState extends MusicBeatSubState
};
// 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.
FlxG.sound.music.play(true, Math.max(0, startTimestamp - Conductor.instance.combinedOffset));
FlxG.sound.music.pause();
FlxG.sound.music.time = Math.max(0, startTimestamp - Conductor.instance.instrumentalOffset);
FlxG.sound.music.pitch = playbackRate;

// Prevent the volume from being wrong.
Expand All @@ -2090,13 +2091,15 @@ class PlayState extends MusicBeatSubState

trace('Playing vocals...');
add(vocals);
vocals.play();

vocals.volume = 1.0;
vocals.pitch = playbackRate;
vocals.time = FlxG.sound.music.time;
// trace('${FlxG.sound.music.time}');
// trace('${vocals.time}');
resyncVocals();

FlxG.sound.music.play();
vocals.play();

#if FEATURE_DISCORD_RPC
// Updating Discord Rich Presence (with Time Left)
Expand Down Expand Up @@ -2130,8 +2133,9 @@ class PlayState extends MusicBeatSubState
// Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.)
if (!(FlxG.sound.music?.playing ?? false)) return;

var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(0, Conductor.instance.songPosition - Conductor.instance.combinedOffset));
var timeToPlayAt:Float = Math.min(FlxG.sound.music.length, Math.max(Math.min(Conductor.instance.combinedOffset, 0), Conductor.instance.songPosition) - Conductor.instance.combinedOffset);
trace('Resyncing vocals to ${timeToPlayAt}');

FlxG.sound.music.pause();
vocals.pause();

Expand Down
Loading