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: Karaoke no longer bakes silence into the song when Spotify is slow to load it

My-Name-Is-Jeffb1518231105f
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 46b44449..414853ff 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -257,7 +257,10 @@ Shared:
run a window (one that falls behind keeps its place); Runs on is Automatic or CPU only, the GPU and
Neural Engine choices stored before read as Automatic; the STFT around it on Accelerate,
and an engine that stands in Speed and pitch's chain between Spotify's mixer and its output
- (SGPlayerSetStage), pulls the mixer a few seconds ahead of what plays, separates two-second windows
+ (SGPlayerSetStage), pulls the mixer a few seconds ahead of what plays, never past sound Spotify has not
+ decoded yet (a part of a pull ahead its mixer marks silent is left out of the lead and read again at the
+ next render, so a slow network fills the lead more slowly and a stall plays through on it; "sing: read
+ ahead:" in the log, the first three times and then a count a minute), separates two-second windows
there on a worker thread and mixes the vocals down on the render thread. Spotify's clock has the lead
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
diff --git a/harness/sing/README.md b/harness/sing/README.md
index ea8132a8..7edcc623 100644
--- a/harness/sing/README.md
+++ b/harness/sing/README.md
@@ -36,6 +36,12 @@ the CPU copy and the Neural Engine copy. Each check prints a line:
the queue's last track): capped at 0, the lead held drains in twice its length with the mixer pulled at half speed,
then the mixer is pulled as it plays; 12 s capped while separating spends none of the 8 s budget; lifted, the lead
is built again; switched off with a cap of 1 s, the lead kept drains to it; every frame plays in order throughout;
+- reading ahead of a slow decoder, without the model (the mock mixer marks what is past the decoded sound silent and
+ does not move on there, as Spotify's does): decoded at 1.5 times what plays, the lead is the frames the decoder
+ handed over and not played, to the frame, none of the silence taken in; reading ahead stops at the decoder and tries
+ 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;
- 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
@@ -74,6 +80,11 @@ vocals scores; the harness built from before spatial voice passed right after it
2026-10-07, the lead's cap: `build/sing spatial` passes, the cap's checks with it: 2.75 s held drain in 5.52 s at 0.50x,
then at most 0 frames held, the budget unspent over 12 s capped, 2.75 s built again, 1.00 s kept off with a cap of 1 s.
+2026-10-07, reading ahead of a slow decoder: `build/sing spatial` passes, the new checks with it: off by 0 frames,
+reading ahead stopped 200 times by 6 s with 2.75 s held, the 2 s stall played through on the lead (down to 1.23 s),
+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-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 191b620b..b74b9b15 100644
--- a/harness/sing/main.m
+++ b/harness/sing/main.m
@@ -21,6 +21,9 @@
// lead held then, less what was dropped since.
// - the lead's cap, without the model: a lead held past it drains at half speed, every frame played and none of the
// budget spent, is built again once it is lifted, and drains with Sing switched off too.
+// - 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.
// - 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
@@ -397,16 +400,22 @@ static void describePlan(NSString *path, bool neural) {
typedef struct {
Audio source;
size_t pulled;
+ bool limited; // Spotify has decoded only up to `decoded`
+ size_t decoded;
} Source;
-static OSStatus pullSource(void *context, UInt32 frames, float *left, float *right) {
+// As Spotify's mixer: past what is decoded the sound is marked silent and does not move on, and a pull asked to stop
+// there (`sounding`) does.
+static OSStatus pullSource(void *context, UInt32 frames, float *left, float *right, UInt32 *sounding) {
Source *source = context;
+ size_t has = !source->limited ? frames : source->decoded > source->pulled ? MIN(frames, source->decoded - source->pulled) : 0;
+ if (sounding) *sounding = (UInt32)has;
for (UInt32 i = 0; i < frames; i++) {
size_t at = source->pulled + i;
- left[i] = at < source->source.frames ? source->source.left[at] : 0;
- right[i] = at < source->source.frames ? source->source.right[at] : 0;
+ left[i] = i < has && at < source->source.frames ? source->source.left[at] : 0;
+ right[i] = i < has && at < source->source.frames ? source->source.right[at] : 0;
}
- source->pulled += frames;
+ source->pulled += has;
return noErr;
}
@@ -687,6 +696,52 @@ static void checkCap(void) {
SGSingEngineDestroy(engine);
}
+// A decoder slower than the lead fills (Spotify on a slow network): its mixer marks what it has not decoded silent, and
+// none of that is taken into the lead; reading ahead stops there and tries again at the next render, so the lead fills
+// as fast as the decoder lets it. A stall of the decoder plays through on the lead, which is read again after it.
+static void checkStarved(void) {
+ size_t frames = 14 * 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 * 440 * 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, true, 0}, *pulled = &source;
+ __block double worst = 0, leadAt6 = 0, leastInStall = 100, leadAt12 = 0;
+ __block unsigned long long stopsAt6 = 0, stopsAt12 = 0;
+ malloc_logger = countAllocation;
+ Audio out = play(engine, tone, &source, 1024, 12.5, ^(double played) {
+ // Decoded at 1.5 times what plays from a quarter second in, stalled from 6 s to 8 s.
+ double decoding = played - fmin(fmax(played - 6, 0), 2);
+ pulled->decoded = (size_t)((0.25 + 1.5 * decoding) * kSGSingRate);
+ worst = fmax(worst, fabs(SGSingEngineLead(engine) - ((double)pulled->pulled - played * kSGSingRate) / kSGSingRate));
+ if (played >= 6 && !leadAt6) {
+ leadAt6 = SGSingEngineLead(engine);
+ stopsAt6 = SGSingEngineReadStats(engine).aheadStops;
+ }
+ if (played >= 6 && played < 8.1) leastInStall = fmin(leastInStall, SGSingEngineLead(engine));
+ if (played >= 12 && !leadAt12) {
+ leadAt12 = SGSingEngineLead(engine);
+ stopsAt12 = SGSingEngineReadStats(engine).aheadStops;
+ }
+ });
+ malloc_logger = NULL;
+ CHECK(worst < 0.5 / kSGSingRate, "a slow decoder: the lead is the frames the decoder handed over and not yet played, to the frame (off by %.0f at most): "
+ "none marked silent is taken in", worst * kSGSingRate);
+ CHECK(stopsAt6 > 100 && leadAt6 > 2, "reading ahead stopped at the decoder %llu times by 6 s and tried again each next render, the lead "
+ "filling as the decoder let it (%.2f s at 6 s)", stopsAt6, leadAt6);
+ CHECK(leastInStall > 0.5 && leastInStall < leadAt6 - 1, "a 2 s stall of the decoder at 6 s plays through on the lead (down to %.2f s)", leastInStall);
+ CHECK(leadAt12 > 2 && stopsAt12 > stopsAt6, "after it the lead is read again (%.2f s at 12 s, %llu stops)", leadAt12, stopsAt12);
+ double gap = 0;
+ for (size_t i = 0; i < 12 * kSGSingRate; i++) gap = fmax(gap, fabsf(out.left[i] - tone.left[i]));
+ CHECK(gap < 1e-6, "what plays is the song with no gap and every frame in order, the stall included (%.2g)", gap);
+ CHECK(atomic_load(&sg_renderAllocations) == 0, "a slow decoder: no allocation on the render thread (%u)", atomic_load(&sg_renderAllocations));
+ 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) {
@@ -1009,6 +1064,7 @@ int main(int argc, char **argv) {
sg_outDir = NSTemporaryDirectory();
checkHold();
checkCap();
+ checkStarved();
checkSpatial();
checkFront();
checkFallingBehind();
@@ -1073,6 +1129,7 @@ int main(int argc, char **argv) {
if (neural) checkNeuralFallback(modelPath);
checkHold();
checkCap();
+ checkStarved();
checkSpatial();
checkFront();
checkFallingBehind();
diff --git a/tweak/Sources/Shared/Player/SpeedPitch.h b/tweak/Sources/Shared/Player/SpeedPitch.h
index 7bdc9824..61bc98a5 100644
--- a/tweak/Sources/Shared/Player/SpeedPitch.h
+++ b/tweak/Sources/Shared/Player/SpeedPitch.h
@@ -59,8 +59,10 @@ void SGPlayerMenuSetAnimatedArtwork(BOOL on);
// A stage between Spotify's mixer and the rest of the chain (Sing's look-ahead, Shared/Sing): it fills the
// chain's buffers, pulling the mixer through `pull` as much as it likes. NULL passes the mixer straight on.
// Called on the render thread, and only on the music's output (below) while Spotify's connection to it is taken
-// over (SGPlayerSpeedAllowed). The buffers are in SGPlayerMusicClientFormat's format.
-typedef OSStatus (*SGPlayerPull)(void *context, UInt32 frames, AudioBufferList *data);
+// over (SGPlayerSpeedAllowed). The buffers are in SGPlayerMusicClientFormat's format. With `sounding` set, a pull stops
+// at the first part the mixer marks silent (Spotify has none of its sound there yet), leaves the rest silent unrendered
+// and sets the frames before it; without, every part is rendered, silent or not.
+typedef OSStatus (*SGPlayerPull)(void *context, UInt32 frames, AudioBufferList *data, UInt32 *sounding);
typedef OSStatus (*SGPlayerStage)(UInt32 frames, AudioBufferList *data, SGPlayerPull pull, void *context);
void SGPlayerSetStage(SGPlayerStage stage);
diff --git a/tweak/Sources/Shared/Player/SpeedPitch.x b/tweak/Sources/Shared/Player/SpeedPitch.x
index ea235ae7..8c39289d 100644
--- a/tweak/Sources/Shared/Player/SpeedPitch.x
+++ b/tweak/Sources/Shared/Player/SpeedPitch.x
@@ -166,14 +166,15 @@ static void silence(AudioBufferList *data) {
// The output's mixer's next `frames` frames into `data`, in chunks of at most its largest slice, each with a
// sample time of the output's own, so Spotify's units never see a time twice (an AU renders a time it has
-// seen from cache).
-static OSStatus pullSource(Output *output, AudioUnit source, const AudioTimeStamp *outputTime, UInt32 frames, AudioBufferList *data) {
+// seen from cache). With `sounding`, it stops at the first chunk marked silent (SGPlayerPull).
+static OSStatus pullSource(Output *output, AudioUnit source, const AudioTimeStamp *outputTime, UInt32 frames, AudioBufferList *data, UInt32 *sounding) {
enum { kMaxBuffers = 8 };
UInt32 chunk = atomic_load_explicit(&output->chunk, memory_order_relaxed);
if (data->mNumberBuffers > kMaxBuffers) chunk = frames;
for (UInt32 b = 0; b < data->mNumberBuffers; b++) if (!data->mBuffers[b].mData) chunk = frames;
UInt32 bytesPerFrame[kMaxBuffers];
for (UInt32 b = 0; b < data->mNumberBuffers && b < kMaxBuffers; b++) bytesPerFrame[b] = data->mBuffers[b].mDataByteSize / frames;
+ if (sounding) *sounding = frames;
for (UInt32 done = 0; done < frames;) {
UInt32 count = MIN(chunk, frames - done);
@@ -194,6 +195,15 @@ static OSStatus pullSource(Output *output, AudioUnit source, const AudioTimeStam
OSStatus status = AudioUnitRender(source, &flags, &time, output->sourceBus, count, target);
output->sourceTime += count;
if (status != noErr) return status;
+ // Asked to stop at silence: Spotify has none of its sound from here on yet, so the rest is not rendered.
+ if ((flags & kAudioUnitRenderAction_OutputIsSilence) && sounding) {
+ *sounding = done;
+ for (UInt32 b = 0; b < data->mNumberBuffers; b++) {
+ UInt32 per = data->mBuffers[b].mDataByteSize / frames;
+ if (data->mBuffers[b].mData) memset((char *)data->mBuffers[b].mData + done * per, 0, (frames - done) * per);
+ }
+ return noErr;
+ }
// A buffer marked silent may still hold what was in it before; nothing after this reads the mark.
if (flags & kAudioUnitRenderAction_OutputIsSilence) silence(target);
done += count;
@@ -211,15 +221,15 @@ typedef struct {
const AudioTimeStamp *time;
} MixerPull;
-static OSStatus pullMixer(void *context, UInt32 frames, AudioBufferList *data) {
+static OSStatus pullMixer(void *context, UInt32 frames, AudioBufferList *data, UInt32 *sounding) {
MixerPull *mixer = context;
- return pullSource(mixer->output, mixer->source, mixer->time, frames, data);
+ return pullSource(mixer->output, mixer->source, mixer->time, frames, data, sounding);
}
// The music's mixer's sound, through the stage when one is set.
static OSStatus pullChain(Output *output, AudioUnit source, const AudioTimeStamp *time, UInt32 frames, AudioBufferList *data) {
SGPlayerStage stage = atomic_load_explicit(&sg_stage, memory_order_acquire);
- if (!stage) return pullSource(output, source, time, frames, data);
+ if (!stage) return pullSource(output, source, time, frames, data, NULL);
MixerPull mixer = {output, source, time};
return stage(frames, data, pullMixer, &mixer);
}
@@ -260,7 +270,7 @@ static OSStatus feed(void *refCon, AudioUnitRenderActionFlags *flags, const Audi
*flags |= kAudioUnitRenderAction_OutputIsSilence;
} else if (output != music()) {
// Another chain plays as Spotify made it.
- status = pullSource(output, source, timestamp, frames, data);
+ status = pullSource(output, source, timestamp, frames, data, NULL);
} else {
SGTimePitch *unit = atomic_load(&sg_pull);
// A unit made for another rate passes the sound as it is, until the main thread makes one for the new rate.
diff --git a/tweak/Sources/Shared/Sing/SGSingEngine.h b/tweak/Sources/Shared/Sing/SGSingEngine.h
index 8e3f15a5..3d0510c1 100644
--- a/tweak/Sources/Shared/Sing/SGSingEngine.h
+++ b/tweak/Sources/Shared/Sing/SGSingEngine.h
@@ -2,7 +2,8 @@
//
// The model takes two seconds at a time and is far too slow for the render thread, so the engine stands
// between Spotify's mixer and its output and pulls the mixer ahead of what plays: up to twice what a
-// render asks for, until the sound it holds (the lead) is a window plus the model's time. A worker thread
+// render asks for, until the sound it holds (the lead) is a window plus the model's time, and never past sound Spotify
+// has not decoded yet (a part its mixer marks silent is left out, and read again at the next render). A worker thread
// takes the held sound two seconds at a time, every 1.5 s, runs the separator and writes the vocals into a
// second ring beside it, the half second the windows share crossfaded. Each render plays the held sound
// from the oldest frame on, the vocals turned down by the level once a hop of them is in ahead, and dry once fewer
@@ -36,8 +37,10 @@ enum {
typedef struct SGSingEngine SGSingEngine;
-// Fills `frames` frames of each channel with the next of Spotify's sound.
-typedef OSStatus (*SGSingPull)(void *context, UInt32 frames, float *left, float *right);
+// Fills `frames` frames of each channel with the next of Spotify's sound. With `sounding` set, it stops at the first
+// part Spotify's mixer marks silent (none of Spotify's sound there yet), leaves the rest silent and sets the frames
+// before it.
+typedef OSStatus (*SGSingPull)(void *context, UInt32 frames, float *left, float *right, UInt32 *sounding);
SGSingEngine *SGSingEngineCreate(void);
// Stops the worker and frees the engine; nothing may be rendering through it.
@@ -106,6 +109,7 @@ typedef struct {
double voiceAngle; // radians, as last set
unsigned long long windows, failures, dryFrames; // dry: frames played unseparated while separating
double dropped; // seconds of held sound never played (flushes), since the engine was made
+ unsigned long long aheadStops; // renders whose reading ahead stopped where Spotify's mixer had no sound yet
unsigned long long written, played; // frames pulled from Spotify's mixer and played, since the engine was made
bool mixing; // the vocals are turned down now (the hysteresis in SGSingEngine.m)
double budgetSpent; // seconds short of vocals since they were last in, of the 8 s it gives up after
diff --git a/tweak/Sources/Shared/Sing/SGSingEngine.m b/tweak/Sources/Shared/Sing/SGSingEngine.m
index 3982a2f3..dbc45d59 100644
--- a/tweak/Sources/Shared/Sing/SGSingEngine.m
+++ b/tweak/Sources/Shared/Sing/SGSingEngine.m
@@ -53,6 +53,7 @@ struct SGSingEngine {
atomic_bool budgetHeld; // a faster copy is on its way: falling behind spends no budget
_Atomic uint64_t spent; // the render's `recovering`, for the stats
_Atomic uint64_t dropped; // frames of held sound never played: flushes
+ _Atomic uint64_t aheadStops; // renders whose reading ahead stopped where Spotify's mixer had no sound yet
// What Spotify's clock had counted past what plays, at each render that changed it (written less played,
// plus dropped: a flush leaves it as it was), with when; `historyCount` counts the entries made.
struct { _Atomic double at; _Atomic uint64_t ahead; } history[kHistory];
@@ -115,12 +116,17 @@ static void startOver(SGSingEngine *engine) {
atomic_store(&engine->mixing, false);
}
-// `count` frames from the mixer into the rings at `at`, in up to two runs where the ring wraps.
-static OSStatus pullInto(SGSingEngine *engine, uint64_t at, uint64_t count, SGSingPull pull, void *context) {
+// `count` frames from the mixer into the rings at `at`, in up to two runs where the ring wraps. With `kept`, it stops
+// at the first part the mixer marks silent and sets the frames before it.
+static OSStatus pullInto(SGSingEngine *engine, uint64_t at, uint64_t count, SGSingPull pull, void *context, uint64_t *kept) {
+ if (kept) *kept = 0;
while (count) {
uint64_t index = at % kRing, run = MIN(count, kRing - index);
- OSStatus status = pull(context, (UInt32)run, engine->left + index, engine->right + index);
+ UInt32 sounding = (UInt32)run;
+ OSStatus status = pull(context, (UInt32)run, engine->left + index, engine->right + index, kept ? &sounding : NULL);
if (status != noErr) return status;
+ if (kept) *kept += sounding;
+ if (sounding < run) return noErr;
at += run;
count -= run;
}
@@ -168,10 +174,10 @@ static inline float middleBefore(SGSingEngine *engine, uint64_t position, uint64
OSStatus SGSingEngineRender(SGSingEngine *engine, UInt32 frames, float *left, float *right, SGSingPull pull, void *context) {
// Larger than any slice an output asks for, and more than the rings leave room for: passed as it is.
- if (frames > kSGSingRate / 4) return pull(context, frames, left, right);
+ if (frames > kSGSingRate / 4) return pull(context, frames, left, right, NULL);
bool on = atomic_load_explicit(&engine->on, memory_order_relaxed);
if (!engine->running) {
- if (!on) return pull(context, frames, left, right);
+ if (!on) return pull(context, frames, left, right, NULL);
engine->running = true;
startOver(engine);
atomic_store(&engine->flushAsked, false);
@@ -197,13 +203,21 @@ OSStatus SGSingEngineRender(SGSingEngine *engine, UInt32 frames, float *left, fl
count = MAX(count, (int64_t)frames - (int64_t)held);
count = MIN(count, (int64_t)(kRing - kSGSingWindowFrames) - (int64_t)held);
if (count > 0) {
- OSStatus status = pullInto(engine, written, (uint64_t)count, pull, context);
+ // What this render plays and the lead does not hold is pulled whatever it is. The rest reads ahead, and a part of
+ // it the mixer marks silent is sound Spotify has not decoded yet: it is not taken into the lead, and reading ahead
+ // stops there until the next render.
+ uint64_t need = (uint64_t)MIN(count, MAX(0, (int64_t)frames - (int64_t)held)), ahead = 0;
+ OSStatus status = pullInto(engine, written, need, pull, context, NULL);
+ if (status == noErr && (uint64_t)count > need) {
+ status = pullInto(engine, written + need, (uint64_t)count - need, pull, context, &ahead);
+ if (ahead < (uint64_t)count - need) atomic_fetch_add_explicit(&engine->aheadStops, 1, memory_order_relaxed);
+ }
if (status != noErr) {
memset(left, 0, frames * sizeof(float));
memset(right, 0, frames * sizeof(float));
return status;
}
- written += (uint64_t)count;
+ written += need + ahead;
atomic_store_explicit(&engine->written, written, memory_order_release);
}
@@ -569,6 +583,7 @@ SGSingEngineStats SGSingEngineReadStats(SGSingEngine *engine) {
.failures = atomic_load(&engine->failures),
.dryFrames = atomic_load(&engine->dryFrames),
.dropped = atomic_load(&engine->dropped) / (double)kSGSingRate,
+ .aheadStops = atomic_load(&engine->aheadStops),
.written = atomic_load(&engine->written),
.played = played,
.mixing = atomic_load(&engine->mixing),
diff --git a/tweak/Sources/Shared/Sing/Sing.x b/tweak/Sources/Shared/Sing/Sing.x
index 3841694b..cf4aa23c 100644
--- a/tweak/Sources/Shared/Sing/Sing.x
+++ b/tweak/Sources/Shared/Sing/Sing.x
@@ -98,15 +98,15 @@ typedef struct {
void *context;
} ChainPull;
-static OSStatus pullChain(void *context, UInt32 frames, float *left, float *right) {
+static OSStatus pullChain(void *context, UInt32 frames, float *left, float *right, UInt32 *sounding) {
ChainPull *chain = context;
struct { AudioBufferList list; AudioBuffer second; } buffers = {{2, {{1, frames * 4, left}}}, {1, frames * 4, right}};
- return chain->pull(chain->context, frames, &buffers.list);
+ return chain->pull(chain->context, frames, &buffers.list, sounding);
}
static OSStatus stage(UInt32 frames, AudioBufferList *data, SGPlayerPull pull, void *context) {
SGSingEngine *engine = atomic_load_explicit(&sg_engine, memory_order_acquire);
- if (!engine) return pull(context, frames, data);
+ if (!engine) return pull(context, frames, data, NULL);
atomic_store_explicit(&sg_staged, true, memory_order_relaxed);
atomic_store_explicit(&sg_rendered, true, memory_order_relaxed);
BOOL takes = atomic_load_explicit(&sg_formatTaken, memory_order_relaxed) && data->mNumberBuffers == 2;
@@ -115,7 +115,7 @@ static OSStatus stage(UInt32 frames, AudioBufferList *data, SGPlayerPull pull, v
}
if (!takes) {
atomic_store_explicit(&sg_formatRefused, true, memory_order_relaxed);
- return pull(context, frames, data);
+ return pull(context, frames, data, NULL);
}
ChainPull chain = {pull, context};
return SGSingEngineRender(engine, frames, data->mBuffers[0].mData, data->mBuffers[1].mData, pullChain, &chain);
@@ -765,6 +765,32 @@ static void logClock(SGSingEngine *engine) {
before = stats;
}
+// Reading ahead stopped where Spotify's mixer had no sound yet (SGSingEngineRender): the first few times a launch, then
+// how often a minute.
+static void logAheadStops(SGSingEngine *engine) {
+ static const int kTold = 3;
+ static int told;
+ static unsigned long long seen, atMinute;
+ static CFAbsoluteTime minute;
+ if (!engine) return;
+ unsigned long long stops = SGSingEngineReadStats(engine).aheadStops;
+ CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
+ if (stops > seen && told < kTold) {
+ told++;
+ SGLog(@"sing: read ahead: Spotify's mixer marked the sound past what plays silent (not decoded yet), so it is not "
+ @"taken into the lead and reading ahead stops until the next buffer (%llu so far, %.2f s held)", stops, SGSingEngineLead(engine));
+ }
+ seen = stops;
+ if (!minute) {
+ minute = now;
+ atMinute = stops;
+ } else if (now - minute >= 60) {
+ if (stops > atMinute) SGLog(@"sing: read ahead: stopped %llu times in the last minute where Spotify had not decoded the sound yet", stops - atMinute);
+ minute = now;
+ atMinute = stops;
+ }
+}
+
static void flush(NSString *why) {
SGSingEngine *engine = atomic_load(&sg_engine);
@@ -905,6 +931,7 @@ static void tick(void) {
if (sg_interrupted && rendered && playing && now - sg_interruptedAt > 1) interrupted(NO, @"is over: Spotify plays again");
SGSingEngine *engine = atomic_load(&sg_engine);
logClock(engine);
+ logAheadStops(engine);
if (state == SGSingStateSinging) sg_sangThisTrack = YES;
// A Neural Engine copy that failed a window (Core ML's error) is given up on for the launch. One that is only slow
// stays: falling behind is the budget's, as on any copy.