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: Speed and pitch makes its unit again when the output's format changes while it runs

My-Name-Is-Jeff0d46ab75ee80
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 4dbe10a6..d155042e 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -131,7 +131,9 @@ Shared:
(SpeedPitchMenu.x, SpeedPitch.x, SGTimePitch.m). Pitch follows speed (on until switched off,
spotifyglass.speed.pitchFollows) plays the speed through Apple's Varispeed instead, faster and higher
together like a record; Varispeed also carries 1x while it is on, so a return to normal speed changes
- nothing, and the stretch is left for pitch alone at 1x, the two swapped only through a reset. Under the
+ nothing, and the stretch is left for pitch alone at 1x, the two swapped only through a reset. A new
+ format on either side of the output while it runs (a route to another rate, Spotify handing it
+ another one) makes the unit again for it, and until then the sound passes as it is. Under the
sliders a Reverb slider sets the audio effects' reverb amount (spotifyglass.dsp.reverb.amount), turning
the effects and the reverb on with it. The block goes into Spotify's own context menu sheet
and is drawn from its own measures, not the Kit's, so it sits there under either look. Tested on the
diff --git a/harness/speed/README.md b/harness/speed/README.md
index 0540ceb1..14d14378 100644
--- a/harness/speed/README.md
+++ b/harness/speed/README.md
@@ -8,8 +8,15 @@ computes -position the way Spotify's does.
THEOS=$HOME/theos ./build.sh
xcrun simctl install booted build/SpeedHarness.app
- xcrun simctl launch --console-pty booted com.vojta.speedharness
+ xcrun simctl launch --console-pty booted com.vojta.speedharness [rate]
The script plays a quiet sine and steps through normal, 1.5x, 1.5x at +3 semitones, 0.75x and back,
logging how fast the converter's callback (the decoder) was drained and how far the state's position is
from the content played. 2026-09-18: drained 1.00x, 1.50x, 1.50x, 0.75x, 1.00x; position within 12 ms.
+
+`rate` sets the output's input side to 48 kHz while it runs, halfway through the 1.5x step, with no new
+`AudioOutputUnitStart`. The mod's format listener reads the new format and makes the chain's unit again
+(`a unit in the chain for 48000 Hz, 2 channels`); until then a unit made for another rate passes the
+sound as it is. 2026-10-05: the unit was made again at 48 kHz at once, with 0 underruns. The drain
+figures after the change read about 1.09 times the speed, because the harness's mixer stays at 44.1 kHz
+and the output now takes 48 kHz from it.
diff --git a/harness/speed/build.sh b/harness/speed/build.sh
index 4ef83be5..3cab5ca2 100755
--- a/harness/speed/build.sh
+++ b/harness/speed/build.sh
@@ -9,7 +9,7 @@ rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/SpeedHarness.app"
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O1 \
-I"$SRC" -I"$SRC/Shared/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
- "$(dirname "$0")/main.m" "$OUT"/gen/*.m "$SRC"/Shared/Player/SGTimePitch.m "$SRC"/Core/SGRebind.m \
+ "$(dirname "$0")/main.m" "$(dirname "$0")/../scene.m" "$OUT"/gen/*.m "$SRC"/Shared/Player/SGTimePitch.m "$SRC"/Core/SGRebind.m \
"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGUIMode.m "$SRC"/Core/SGFlagForce.m \
-framework UIKit -framework QuartzCore -framework AudioToolbox -framework AVFoundation -framework Foundation \
-o "$OUT/SpeedHarness.app/SpeedHarness"
@@ -23,7 +23,15 @@ cat > "$OUT/SpeedHarness.app/Info.plist" <<'PLIST'
<key>CFBundleVersion</key><string>1</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
<key>UILaunchScreen</key><dict/>
-<key>UIApplicationSceneManifest</key><dict><key>UIApplicationSupportsMultipleScenes</key><false/></dict>
+<key>UIApplicationSceneManifest</key><dict>
+ <key>UIApplicationSupportsMultipleScenes</key><false/>
+ <key>UISceneConfigurations</key><dict>
+ <key>UIWindowSceneSessionRoleApplication</key><array><dict>
+ <key>UISceneConfigurationName</key><string>Default</string>
+ <key>UISceneDelegateClassName</key><string>SGRHarnessScene</string>
+ </dict></array>
+ </dict>
+</dict>
</dict></plist>
PLIST
echo "built $OUT/SpeedHarness.app"
diff --git a/harness/speed/main.m b/harness/speed/main.m
index bb2668f3..230a02e8 100644
--- a/harness/speed/main.m
+++ b/harness/speed/main.m
@@ -5,7 +5,10 @@
// how fast the song is drained at each speed, and how far a mock player state's position drifts from it.
//
// THEOS=$HOME/theos ./build.sh && xcrun simctl install booted build/SpeedHarness.app
-// xcrun simctl launch --console-pty booted com.vojta.speedharness
+// xcrun simctl launch --console-pty booted com.vojta.speedharness [rate]
+//
+// `rate` hands the running output a 48 kHz format halfway through the 1.5x step, with no new start: the
+// mod's format listener must make its unit again for 48 kHz (`a unit in the chain for 48000 Hz`).
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@@ -61,6 +64,7 @@ static void check(OSStatus status, const char *what) {
@implementation SGRHarnessDelegate {
SPTPlayerState *_state;
+ AudioUnit _output;
uint64_t _lastDecoded;
NSTimeInterval _lastAt, _startedAt;
}
@@ -87,6 +91,14 @@ static void check(OSStatus status, const char *what) {
for (int i = 0; i < 3; i++) check(AudioUnitSetProperty(units[i], kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &slice, sizeof slice), "slice");
for (int i = 0; i < 3; i++) check(AudioUnitInitialize(units[i]), "initialize");
check(AudioOutputUnitStart(output), "start");
+ _output = output;
+}
+
+// Spotify's side of the output at another rate while it runs, the way a file at another rate may bring one.
+- (void)changeRate {
+ AudioStreamBasicDescription format = {48000, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved, 4, 1, 4, 2, 32, 0};
+ OSStatus status = AudioUnitSetProperty(_output, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof format);
+ NSLog(@"[harness] output's input set to 48000 Hz while running: status %d", (int)status);
}
- (void)report:(NSString *)what {
@@ -137,6 +149,7 @@ static void check(OSStatus status, const char *what) {
// A report mid step, the way Spotify's player reports now and then.
[self after:[step[0] doubleValue] + 1.5 do:^{ [self playerReports]; }];
}
+ if ([NSProcessInfo.processInfo.arguments containsObject:@"rate"]) [self after:7.5 do:^{ [self changeRate]; }];
[self after:21 do:^{
[self report:label];
exit(0);
diff --git a/tweak/Sources/Shared/Player/SpeedPitch.x b/tweak/Sources/Shared/Player/SpeedPitch.x
index d906e921..64bf4bed 100644
--- a/tweak/Sources/Shared/Player/SpeedPitch.x
+++ b/tweak/Sources/Shared/Player/SpeedPitch.x
@@ -73,6 +73,13 @@ static BOOL tapped(void) {
return atomic_load(&sg_source) != NULL;
}
+static double rateOf(Format *format) {
+ uint64_t bits = atomic_load_explicit(&format->rateBits, memory_order_relaxed);
+ double rate;
+ memcpy(&rate, &bits, sizeof rate);
+ return rate;
+}
+
static float loadFloat(atomic_uint *slot) {
uint32_t bits = atomic_load(slot);
float value;
@@ -175,7 +182,10 @@ static OSStatus feed(void *refCon, AudioUnitRenderActionFlags *flags, const Audi
atomic_store(&sg_busy, true);
OSStatus status = -1;
SGTimePitch *unit = atomic_load(&sg_pull);
- if (atomic_load(&sg_engaged) && unit && fitsUnit(data, frames, unit)) status = SGTimePitchRender(unit, frames, data);
+ // A unit made for another rate passes the sound as it is, until the main thread makes one for the new rate.
+ if (atomic_load(&sg_engaged) && unit && fitsUnit(data, frames, unit) && SGTimePitchSampleRate(unit) == rateOf(&sg_client)) {
+ status = SGTimePitchRender(unit, frames, data);
+ }
if (status != noErr) status = pullChain(source, timestamp, frames, data);
atomic_store(&sg_busy, false);
return status;
@@ -250,7 +260,7 @@ static OSStatus rendered(void *refCon, AudioUnitRenderActionFlags *flags, const
if (tapped() || !atomic_load(&sg_engaged)) return noErr;
atomic_store(&sg_busy, true);
SGTimePitch *unit = atomic_load(&sg_inPlace);
- if (atomic_load(&sg_engaged) && unit) shiftInPlace(unit, flags, frames, data);
+ if (atomic_load(&sg_engaged) && unit && SGTimePitchSampleRate(unit) == rateOf(&sg_hardware)) shiftInPlace(unit, flags, frames, data);
atomic_store(&sg_busy, false);
return noErr;
}
@@ -326,15 +336,31 @@ static void readFormat(AudioUnit unit) {
static void apply(void);
+// A speed or pitch chosen before the output started, or kept across a new format, applies now: apply()
+// makes the unit again when the rate or the channels changed.
+static void applyToFormat(void) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (sg_speed != 1 || sg_semitones != 0) apply();
+ });
+}
+
+// Either side of element 0 changing under a running unit: the hardware's on a route to a device at
+// another rate, Spotify's when it hands the unit another format without starting it again.
+static void formatChanged(void *refCon, AudioUnit unit, AudioUnitPropertyID property, AudioUnitScope scope, AudioUnitElement element) {
+ if (property != kAudioUnitProperty_StreamFormat || element != 0) return;
+ if (scope != kAudioUnitScope_Input && scope != kAudioUnitScope_Output) return;
+ readFormat(unit);
+ applyToFormat();
+}
+
static OSStatus startOutput(AudioUnit unit) {
if (unit && isRemoteIO(unit)) {
readFormat(unit);
AudioUnitRemoveRenderNotify(unit, rendered, NULL);
AudioUnitAddRenderNotify(unit, rendered, NULL);
- // A speed or pitch chosen before the output started, or kept across a new format, applies now.
- dispatch_async(dispatch_get_main_queue(), ^{
- if (sg_speed != 1 || sg_semitones != 0) apply();
- });
+ AudioUnitRemovePropertyListenerWithUserData(unit, kAudioUnitProperty_StreamFormat, formatChanged, NULL);
+ AudioUnitAddPropertyListener(unit, kAudioUnitProperty_StreamFormat, formatChanged, NULL);
+ applyToFormat();
}
return sg_startOutput(unit);
}
@@ -352,9 +378,7 @@ static void disengage(void) {
static SGTimePitch *unitForFormat(void) {
BOOL pull = tapped();
Format *format = pull ? &sg_client : &sg_hardware;
- double rate;
- uint64_t bits = atomic_load(&format->rateBits);
- memcpy(&rate, &bits, sizeof rate);
+ double rate = rateOf(format);
UInt32 channels = atomic_load(&format->channels);
if (pull) {
// In the chain the unit hands its buffers to the RemoteIO unit as they are: float, one per channel.