Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: the lyrics and the scrubber start the next song when its audio does

My-Name-Is-Jeff815ed2005437
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 414853ff..9867920b 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -265,7 +265,9 @@ Shared:
taken off (SPTPlayerState's positionAsOfTimestamp): the lead held when that line of the clock began
(the same position run on at the same speed, however often a state is stamped again), less what was
dropped since, as the player reports on a change and not as it plays (SGSingLeadOf, read by every
- correction; every 5 s a "sing: clock:" log line sets Spotify's clock against what the engine pulled
+ correction); run on (-position), the lead comes off after running on and never below 0, so a track
+ reached as the last one ends, reported while the lead still holds that end, stays at 0 until its first
+ frame plays rather than running on from the title change (every 5 s a "sing: clock:" log line sets Spotify's clock against what the engine pulled
and played, and every lyrics seek logs where it was sent and where it landed), and a seek, a skip or a stop drops it.
Until the seek or skip lands (Spotify reports the target or the new track, or 5 s pass) nothing is
read ahead, as Spotify's mixer still hands over what came before it; the queue's next track arriving
@@ -293,7 +295,7 @@ Shared:
audio. The Spatial voice page's preview (SGSpatialPreview.m) turns a disc of dots under the listener by
the same front (SGSpatialVoiceAngle, SGSingEngine.h), on Core Animation alone and only while the page
shows. The mic is on the redesign's lyrics (Redesigned/Lyrics/SGRSingButton.m). Tested on the Mac
- against harness/sing/ (the lead, its cap, spatial voice and its front without the model: `build/sing spatial`; the
+ against harness/sing/ (the lead, its cap, a slow decoder, a track boundary, spatial voice and its front without the model: `build/sing spatial`; the
model as both copies with `ane`, as the CPU's alone with `cpu`), the download against its download/
(`update` for the old model kept until it, `dev` for the dev folder), the pages in the simulator against harness/spatial-page/
Haptics/ Vibrations (Haptics.h lists its files): a tap of UIKit's feedback generators for the player's and the now
diff --git a/harness/sing/README.md b/harness/sing/README.md
index 7edcc623..11b8f42b 100644
--- a/harness/sing/README.md
+++ b/harness/sing/README.md
@@ -42,6 +42,10 @@ the CPU copy and the Neural Engine copy. Each check prints a line:
again at the next render, so the lead still fills; a 2 s stall of the decoder plays through on the lead, which is
read again after it; what plays is the song with no gap, every frame in order; nothing is allocated on the render
thread;
+- a track reached as the last one ends, without the model: Spotify reports it 0.1 s after its first frame is handed
+ over, with the last one's end still held; its position as Sing.x's -position takes it (Spotify's own run on from the
+ report, less the lead held then, never below 0) starts where its first frame plays and reads 2 s two seconds on,
+ where the lead taken off before running on, as it was, started it at the report, the lead early;
- spatial voice, without the model (a separator that hands each window back whole as vocals, so what plays is the
vocals placed): a 440 Hz tone at level 1 plays exactly as it came straight ahead; set 90 degrees right, the right
ear has it 7.75 dB louder (the narrowed pan's 7.66 and the far ear's low-pass) at the same power, and the left ear
@@ -85,6 +89,10 @@ reading ahead stopped 200 times by 6 s with 2.75 s held, the 2 s stall played th
nothing skipped. The same checks against the engine before the change fail: 66939 frames of silence counted into the
lead, and a gap in what plays.
+2026-10-07, a track boundary: `build/sing spatial` passes, the new checks with it: reported 0.11 s into the next track
+with 2.75 s held, its position starts at 8.011 s played (its first frame at 8.000 s) and reads 2.005 s two seconds on;
+taken off before running on, it started at 5.39 s, 2.61 s early. The simulator harness builds with the hook; not run.
+
2026-10-05, a MacBook with an M4, macOS 27: everything passes under `gpu` and under ThreadSanitizer.
| compute units | Core ML's plan | a window, warm |
diff --git a/harness/sing/main.m b/harness/sing/main.m
index b74b9b15..d9b776ff 100644
--- a/harness/sing/main.m
+++ b/harness/sing/main.m
@@ -24,6 +24,9 @@
// - reading ahead of a slow decoder, without the model: past what Spotify has decoded its mixer marks the sound silent;
// that is never taken into the lead, reading ahead tries again at the next render, and a stall of the decoder plays
// through on the lead, so what plays is the song with no gap, every frame in order.
+// - a track reached as the last one ends, without the model: Spotify reports it a moment after its first frame is
+// handed over; its position (Sing.x's -position: Spotify's run on less the lead held at the report, never below 0)
+// starts where its first frame plays, not at the report.
// - spatial voice, without the model: a separator that hands the whole window back as vocals, so what plays is
// the vocals placed. A tone straight ahead plays exactly as it came; at 90 degrees right the right ear has it
// louder by the pan's 7.7 dB at the same power and the left ear late by the delay around the head; at 90
@@ -742,6 +745,47 @@ static void checkStarved(void) {
SGSingEngineDestroy(engine);
}
+// A track reached as the last one ends: Spotify reports it 0.1 s after its first frame is handed over, the last one's
+// end still in the lead. Its position as Sing.x's -position takes it, Spotify's own run on from the report less the lead
+// held then and never below 0, starts at the frame where its audio starts; with the lead taken off before running on,
+// as it was, it ran from the report.
+static void checkBoundary(void) {
+ size_t frames = 14 * kSGSingRate, boundary = 8 * kSGSingRate;
+ Audio tone = makeAudio(frames);
+ for (size_t i = 0; i < frames; i++) tone.left[i] = tone.right[i] = (float)(0.5 * sin(2 * M_PI * (i < boundary ? 440 : 660) * i / kSGSingRate));
+ SGSingEngine *engine = SGSingEngineCreate();
+ SGPacedSeparator *steady = [[SGPacedSeparator alloc] initWithModel:nil];
+ steady.fastWindows = INT_MAX;
+ SGSingEngineSetSeparator(engine, steady);
+ SGSingEngineSetLevel(engine, 1);
+ SGSingEngineSetOn(engine, true);
+ Source source = {tone, 0}, *pulled = &source;
+ __block CFAbsoluteTime reported = 0;
+ __block double handed = 0, leadThen = 0, starts = -1, startedBefore = -1, at2 = -1;
+ play(engine, tone, &source, 1024, 12, ^(double played) {
+ CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
+ if (!reported && pulled->pulled >= boundary + kSGSingRate / 10) {
+ reported = now;
+ handed = (double)(pulled->pulled - boundary) / kSGSingRate;
+ // Read soon after the report, as Sing.x's tick reads it.
+ leadThen = SGSingEngineLeadAt(engine, reported);
+ }
+ if (!reported) return;
+ double lead = SGSingEngineLeadAt(engine, reported), since = now - reported;
+ double heard = fmax(0, handed + since - lead), before = fmax(0, handed - lead) + since;
+ if (heard > 0 && starts < 0) starts = played;
+ if (before > 0 && startedBefore < 0) startedBefore = played;
+ if (played >= 10 && at2 < 0) at2 = heard;
+ });
+ double edge = (double)boundary / kSGSingRate;
+ CHECK(fabs(starts - edge) < 0.05, "the next track reported %.2f s into it with %.2f s held: its position starts with %.3f s played, where its "
+ "first frame plays (%.3f s)", handed, leadThen, starts, edge);
+ CHECK(fabs(at2 - 2) < 0.05, "and reads %.3f s as 2 s of it have played", at2);
+ CHECK(startedBefore >= 0 && startedBefore < edge - 2, "with the lead taken off before running on, it started at the report, %.2f s played, "
+ "%.2f s early", startedBefore, edge - startedBefore);
+ SGSingEngineDestroy(engine);
+}
+
// A model that keeps up for a while and then falls behind: the vocals fade out once, not at every window, and
// after 8 s short of them the engine gives up and gives the lead back. And a NaN from the model never plays.
static void checkFallingBehind(void) {
@@ -1065,6 +1109,7 @@ int main(int argc, char **argv) {
checkHold();
checkCap();
checkStarved();
+ checkBoundary();
checkSpatial();
checkFront();
checkFallingBehind();
@@ -1130,6 +1175,7 @@ int main(int argc, char **argv) {
checkHold();
checkCap();
checkStarved();
+ checkBoundary();
checkSpatial();
checkFront();
checkFallingBehind();
diff --git a/tweak/Sources/Shared/Sing/Sing.x b/tweak/Sources/Shared/Sing/Sing.x
index cf4aa23c..60c9ad91 100644
--- a/tweak/Sources/Shared/Sing/Sing.x
+++ b/tweak/Sources/Shared/Sing/Sing.x
@@ -16,8 +16,11 @@
// reported position less the lead held when that line of the clock began, less what was dropped since, and not
// less the lead now: a lead filling after a report does not move what is heard, and taking it off lagged the lyrics
// by it. A state stamped again on the same line (the same position run on at the same speed) is the same report, so
-// the lead is looked up by the line, not by the state's stamp (SGSingLeadOf). positionAsOfTimestamp is hooked to take
-// that off: the scrubber, the lyrics, the Live Activity and the lock screen follow what is heard. A seek, a
+// the lead is looked up by the line, not by the state's stamp (SGSingLeadOf). positionAsOfTimestamp and position are
+// hooked to take that off: the scrubber, the lyrics, the Live Activity and the lock screen follow what is heard. Run on
+// (position), the lead comes off after running on and never below 0: the next track is reported as its first frames
+// are handed over, with the last one's end still held, and its clock holds at 0 until that end has played rather than
+// running on from the title change. A seek, a
// skip or a stop drops the lead (-[SPTEsperantoPlayer seekTo:...] and skipTo...TrackWithOptions:track:loggingParams:
// in the binary's method list, each returning Spotify's own result for the command; the shorter skips are
// trampolines into those two through objc_msgSend, 0x1096da9e4-0x1096daa08), and so does a track changing well
@@ -640,9 +643,10 @@ static _Atomic CFAbsoluteTime sg_lastFlush; // Sing.x's own flushes: each come
static __thread BOOL sg_rawPosition; // the hook below hands Spotify's own value back
static double rawPosition(SPTPlayerState *state) {
+ BOOL was = sg_rawPosition;
sg_rawPosition = YES;
double position = state.position;
- sg_rawPosition = NO;
+ sg_rawPosition = was;
return position;
}
@@ -1038,12 +1042,23 @@ static void readHeat(void) {
#pragma mark - Spotify's clock and commands
%hook SPTPlayerState
+// For a paused state, which holds still there.
- (double)positionAsOfTimestamp {
double position = %orig;
if (sg_rawPosition || position < 0) return position;
double lead = SGSingLeadOf(self);
return lead != 0 ? MAX(0, position - lead) : position;
}
+// Run on, the lead is taken off after, not before: a track reached as the last one ends is reported with less of it
+// handed over than the lead holds, and its clock stays at 0 until its first frame plays rather than running on from the
+// title change.
+- (double)position {
+ if (sg_rawPosition) return %orig;
+ double position = rawPosition(self);
+ if (position < 0) return position;
+ double lead = SGSingLeadOf(self);
+ return lead != 0 ? MAX(0, position - lead) : position;
+}
%end
// The lock screen's elapsed time, when Spotify gives it its own count, which runs off what is heard by the state's