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

feat: Karaoke runs on any iPhone with iOS 18 that has enough free memory when the model loads

My-Name-Is-Jeff37abd95adfff
diff --git a/docs/tweaks.md b/docs/tweaks.md
index aae75954..d6dc4fdb 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -249,7 +249,8 @@ Shared:
Update available), and deleted as its download ends or at a launch that finds both
(SGSingRemoveOldModel, which logs the space freed), Sing moving to the new one at its next load;
loaded only while Spotify
- is active (SGSingLoader.m), a CPU copy first and warmed, then on Automatic, where the iPhone has a
+ is active (SGSingLoader.m), on any iPhone with iOS 18, a CPU copy first and warmed, only with 1 GB left to the
+ process (no floor on the iPhone's memory: both copies warm add 0.1 GB of footprint), then on Automatic, where the iPhone has a
Neural Engine, a Neural Engine copy of the same model beside it, which takes every window once it is
in, in the background too, each load with a deadline and kept a minute after the mic goes off; the
Neural Engine copy loads only with 0.5 GB left to the process, its first load after every install
diff --git a/tweak/Sources/Shared/Sing/SGSingLoader.m b/tweak/Sources/Shared/Sing/SGSingLoader.m
index 1f615e3d..a7fedab5 100644
--- a/tweak/Sources/Shared/Sing/SGSingLoader.m
+++ b/tweak/Sources/Shared/Sing/SGSingLoader.m
@@ -12,6 +12,10 @@ double SGSingLoaderCPUDeadline = 120, SGSingLoaderNeuralDeadline = 600, SGSingLo
// A CPU copy loads beside an abandoned load still out (or again after a memory warning) only with this much left: a
// second copy took 1.07-1.15 GB more of the process's footprint on an M4.
static const unsigned long long kCopyRoom = 1600ull * 1000 * 1000;
+// The first CPU copy loads only with this much left, in place of a floor on the iPhone's memory. On an iPhone 15 Pro both
+// copies warm added 0.1 GB of footprint (0.20 to 0.30 GB); the weights are mapped from disk and counted only as resident.
+// 1 GB leaves the Neural Engine copy its 0.5 GB after the CPU's.
+static const unsigned long long kFirstRoom = 1000ull * 1000 * 1000;
// The Neural Engine copy loads beside the CPU's only with this much left. On an iPhone 15 Pro it added 0.06-0.1 GB of
// footprint (resident 1.06 to 1.13 GB); 0.5 GB is that five times over, for its first compile, which was not measured
// apart, and for Spotify's own memory to grow without iOS closing it for a copy Sing can do without.
@@ -181,9 +185,11 @@ BOOL SGSingLoaderPrepareNeural(NSURL *url, void (^done)(BOOL loaded)) {
}
static void startCPU(void) {
- if (sg_outstanding && !roomFor(kCopyRoom)) {
+ if (!roomFor(sg_outstanding ? kCopyRoom : kFirstRoom)) {
sg_state = SGSingLoaderFailed;
- sg_error = [NSString stringWithFormat:@"A load abandoned earlier still holds memory, and %@. Close Spotify and open it again to load the voice model.", memoryText()];
+ sg_error = sg_outstanding
+ ? [NSString stringWithFormat:@"A load abandoned earlier still holds memory, and %@. Close Spotify and open it again to load the voice model.", memoryText()]
+ : [NSString stringWithFormat:@"iOS leaves Spotify too little memory for the voice model: %@, and it needs %.1f GB. Closing Spotify and opening it again can free some.", memoryText(), kFirstRoom / 1e9];
SGLog(@"sing: no new load: %@", sg_error);
changed();
return;
diff --git a/tweak/Sources/Shared/Sing/SGSingModel.m b/tweak/Sources/Shared/Sing/SGSingModel.m
index c90f1c6f..1d195e7c 100644
--- a/tweak/Sources/Shared/Sing/SGSingModel.m
+++ b/tweak/Sources/Shared/Sing/SGSingModel.m
@@ -521,11 +521,3 @@ BOOL SGSingOSSupported(void) {
if (@available(iOS 18.0, *)) return YES;
return NO;
}
-
-// The model is 209 MB of weights, held while Sing is on beside Spotify's own memory (about 1.07 GB resident with its
-// CPU copy warm on an iPhone 15 Pro): an iPhone with less than 6 GB (which report a little under 6) would have Spotify
-// closed under it.
-// ponytail: a memory floor stands in for a list of phones; measure on a 6 GB phone and a 4 GB one to place it.
-BOOL SGSingDeviceSupported(void) {
- return NSProcessInfo.processInfo.physicalMemory >= 5ull * 1000 * 1000 * 1000;
-}
diff --git a/tweak/Sources/Shared/Sing/Sing.h b/tweak/Sources/Shared/Sing/Sing.h
index 4efbb97e..a67cf97e 100644
--- a/tweak/Sources/Shared/Sing/Sing.h
+++ b/tweak/Sources/Shared/Sing/Sing.h
@@ -151,6 +151,5 @@ NSString *SGSingModelInUseSizeText(void);
// is in, logging the space freed; from any thread, at launch and as the download ends.
void SGSingRemoveOldModel(void);
NSArray<NSString *> *SGSingComputeUnitNames(void);
-// Whether this OS can load the model (iOS 18) and this iPhone was built to run it.
+// Whether this OS can load the model (iOS 18). Memory is checked as the model loads (SGSingLoader.m).
BOOL SGSingOSSupported(void);
-BOOL SGSingDeviceSupported(void);
diff --git a/tweak/Sources/Shared/Sing/Sing.x b/tweak/Sources/Shared/Sing/Sing.x
index 5cb17593..b2fa134b 100644
--- a/tweak/Sources/Shared/Sing/Sing.x
+++ b/tweak/Sources/Shared/Sing/Sing.x
@@ -355,7 +355,7 @@ static void updateSpatial(void) {
}
BOOL SGSingSpatialAvailable(void) {
- return SGSingOSSupported() && SGSingDeviceSupported() && SGHeadGesturesAvailable();
+ return SGSingOSSupported() && SGHeadGesturesAvailable();
}
BOOL SGSingSpatial(void) {
@@ -513,13 +513,12 @@ void SGSetSingIgnoresHeat(BOOL ignores) {
NSString *SGSingMissing(void) {
if (!SGSingOSSupported()) return [NSString stringWithFormat:@"Karaoke needs iOS 18, the first its voice model runs on. This iPhone has iOS %@.", UIDevice.currentDevice.systemVersion];
- if (!SGSingDeviceSupported()) return @"Karaoke needs an iPhone with 6 GB of memory or more, which the voice model was built for. This one has less.";
if (SGSingModelCurrentState() != SGSingModelReady) return [NSString stringWithFormat:@"Karaoke needs its voice model, which is downloaded from Mod Settings > Karaoke (%@).", SGSingModelSizeText()];
return nil;
}
SGSingState SGSingCurrentState(void) {
- if (!SGSingOSSupported() || !SGSingDeviceSupported()) return SGSingStateUnavailable;
+ if (!SGSingOSSupported()) return SGSingStateUnavailable;
SGSingModelState model = SGSingModelCurrentState();
if (model == SGSingModelDownloading) return SGSingStateDownloading;
if (model != SGSingModelReady) return SGSingStateNoModel;
diff --git a/tweak/Sources/Shared/Sing/SingSettings.m b/tweak/Sources/Shared/Sing/SingSettings.m
index 4c94e071..0efe7197 100644
--- a/tweak/Sources/Shared/Sing/SingSettings.m
+++ b/tweak/Sources/Shared/Sing/SingSettings.m
@@ -9,6 +9,14 @@
#import "Settings/SGModPage.h"
#import "Settings/SGPageStyle.h"
#import "Sing.h"
+#import <sys/utsname.h>
+
+// Chips before the A14 (the iPhone XS, XR, 11 and SE 2: iPhone11,x and iPhone12,x) are untested and may not keep up.
+static BOOL untestedChip(void) {
+ struct utsname name;
+ int major = 0;
+ return uname(&name) == 0 && sscanf(name.machine, "iPhone%d,", &major) == 1 && major < 13;
+}
UIView *SGSingCardView(void); // SGSingCard.m
@@ -46,7 +54,7 @@ static SGSingModelState rowState(void) {
}
static NSString *modelValue(void) {
- if (!SGSingOSSupported() || !SGSingDeviceSupported()) return @"Unavailable";
+ if (!SGSingOSSupported()) return @"Unavailable";
BOOL update = SGSingModelUpdateAvailable();
switch (rowState()) {
case SGSingModelDownloading:
@@ -65,7 +73,7 @@ static NSString *modelValue(void) {
}
static void modelTapped(UITableViewController *page) {
- if (!SGSingOSSupported() || !SGSingDeviceSupported()) {
+ if (!SGSingOSSupported()) {
tell(@"Voice model", SGSingMissing());
return;
}
@@ -76,6 +84,7 @@ static void modelTapped(UITableViewController *page) {
SGSingModelError() ? [NSString stringWithFormat:@"The last try failed: %@\n\n", SGSingModelError()] : @"",
update ? @"The new voice model runs on the Neural Engine, faster and cooler, and Karaoke keeps the one it has until it is in. " : @"",
SGSingModelSizeText()];
+ if (untestedChip()) message = [message stringByAppendingString:@"\n\nKaraoke is tested on the iPhone 15 Pro. On iPhones older than the iPhone 12 it may not keep up."];
NSString *title = SGSingModelPausedBytes() ? (update ? @"Carry on with the update?" : @"Carry on with the download?")
: (update ? @"Download the update?" : @"Download the voice model?");
ask(title, message, @"Download", NO, ^{ SGSingDownloadModel(); });