From 7d8311a77fd157faa8431e7905d397f9e4f5e4cd Mon Sep 17 00:00:00 2001 From: Reactorcoremeltdown Date: Sat, 14 Nov 2026 21:07:05 +0100 Subject: [PATCH] iOS 0.1.1: effects read the input where the host puts it (were silent out of process) Out of process the pulled input arrives by pointer, not in the buffers the plugin offered. au_test now drives the render block with such an upstream; it fails on 0.1.0 and passes now. Co-Authored-By: Claude Opus 5.5 --- ios/CHANGELOG.md | 8 ++++ ios/README.md | 16 +++++++- ios/app/FX/SizzleEffectAU.mm | 7 +++- ios/app/Host/PluginCheck.swift | 3 +- ios/app/tests/au_test.mm | 67 ++++++++++++++++++++++++++++++++-- versions.properties | 4 +- 6 files changed, 95 insertions(+), 10 deletions(-) diff --git a/ios/CHANGELOG.md b/ios/CHANGELOG.md index 9b9a2b6..8c39d91 100644 --- a/ios/CHANGELOG.md +++ b/ios/CHANGELOG.md @@ -3,6 +3,14 @@ Sizzle for iOS/iPadOS (`cc.tiredsysadmin.ios.sizzle`). One entry per version in `../versions.properties` (`ios.versionName` / `ios.versionCode`). +## 0.1.1 (build 2) + +- Fix: the effects were silent in real hosts (and 0/8 in the app's check). When a + plugin runs out of process, iOS hands it the input in its own buffers instead + of filling the plugin's; the plugin kept reading its own, empty ones. It now + reads the input wherever the host puts it. +- The app's check reports a failed render as such instead of "silent". + ## 0.1.0 (build 1) - First build: Sizzle's eight audio effects as AUv3 plugins (Bitcrusher, Filter, diff --git a/ios/README.md b/ios/README.md index a66c8c0..3f14401 100644 --- a/ios/README.md +++ b/ios/README.md @@ -54,7 +54,16 @@ below 0.5), so it only tests the dry path; add a scenario with heads on. macOS): every effect is registered in-process and driven through AVAudioEngine. The output must equal the core's at defaults and after moving every parameter through the AU, a Mix Tightener factory preset must equal the core with that -preset, and `fullState` must restore into a fresh instance. All pass bit-exact. +preset, and `fullState` must restore into a fresh instance. It also calls the +render block directly with an upstream that points the input buffers at its own +memory instead of filling the plugin's, with and without host output buffers. +All pass bit-exact. + +That last check exists because AVAudioEngine in-process copies the input into the +plugin's buffers, but out of process (every real host on iOS) the input arrives +by pointer. 0.1.0 read its own buffers and was silent on the iPad while every Mac +test passed. Render code must read the input from the pulled AudioBufferList, +never from the buffers it offered. ## The plugins (0.1.0: the eight audio effects) @@ -114,7 +123,10 @@ have been every plugin failing to start. ### Test on the iPad 1. Install the newest `cc.tiredsysadmin.ios.sizzle_.ipa` with TrollStore. -2. Open **Sizzle**, tap **Check all plugins**: 8/8 should pass. +2. Open **Sizzle**, tap **Check all plugins**: 8/8 should pass. With the iPad on + USB, `idevicesyslog` (`brew install libimobiledevice`) shows the plugin + process as `SizzleFX` and the host side as `Sizzle(AudioToolboxCore)`; + `idevicecrashreport -k -e ` copies crash reports without deleting them. 3. In AUM, add an audio track or a synth, then an effect slot: the plugins are listed as "Tired Sysadmin: Sizzle …". Try the editor, a Mix Tightener preset, and saving and reopening an AUM session (restores `fullState`). diff --git a/ios/app/FX/SizzleEffectAU.mm b/ios/app/FX/SizzleEffectAU.mm index 8bbfd10..853c8f0 100644 --- a/ios/app/FX/SizzleEffectAU.mm +++ b/ios/app/FX/SizzleEffectAU.mm @@ -346,7 +346,9 @@ static NSString *const kStateKey = @"sizzleValues"; AURenderPullInputBlock pullInputBlock) { if (frameCount > k->inBuf[0].size() || !pullInputBlock) return kAudioUnitErr_TooManyFramesToProcess; - // Pull the input into our own buffers. + // Pull the input, offering our own buffers. The upstream may instead point + // mData at its own memory (it does out of process, i.e. in every real host), + // so the samples are wherever in.list points afterwards, not necessarily inBuf. struct { AudioBufferList list; AudioBuffer extra; } in; in.list.mNumberBuffers = (UInt32)k->channels; for (int c = 0; c < k->channels; ++c) { @@ -383,7 +385,8 @@ static NSString *const kStateKey = @"sizzleValues"; bool bypass = k->bypass.load(std::memory_order_relaxed); for (int c = 0; c < k->channels && c < (int)outputData->mNumberBuffers; ++c) { - float *src = k->inBuf[c].data(); + float *src = (float *)in.list.mBuffers[c].mData; + if (!src) return kAudioUnitErr_NoConnection; if (!outputData->mBuffers[c].mData) outputData->mBuffers[c].mData = src; // in place float *dst = (float *)outputData->mBuffers[c].mData; outputData->mBuffers[c].mDataByteSize = frameCount * sizeof(float); diff --git a/ios/app/Host/PluginCheck.swift b/ios/app/Host/PluginCheck.swift index a1c217c..7df1781 100644 --- a/ios/app/Host/PluginCheck.swift +++ b/ios/app/Host/PluginCheck.swift @@ -80,7 +80,8 @@ final class PluginCheck: ObservableObject { let out = AVAudioPCMBuffer(pcmFormat: engine.manualRenderingFormat, frameCapacity: 4096)! var peak: Float = 0, finite = true for _ in 0..<11 { - _ = try engine.renderOffline(4096, to: out) + let status = try engine.renderOffline(4096, to: out) + if status != .success { engine.stop(); return "FAIL render status \(status.rawValue)" } for ch in 0.. #include @@ -77,14 +81,57 @@ static void renderAU(AVAudioUnit *unit, const std::vector &in, std::vecto [engine stop]; } -static std::vector renderCore(const char *type, const Params &p, const std::vector &in) { - auto fx = Effect::create(type, 48000); +static std::vector renderCore(const char *type, const Params &p, const std::vector &in, int sr = 48000) { + auto fx = Effect::create(type, sr); fx->update(p, 120.f); std::vector y(in.size()); for (size_t i = 0; i < in.size(); ++i) { float v = fx->process(in[i]); y[i] = std::isfinite(v) ? v : 0.f; } return y; } +/// Render [in] through the AU's render block at 44.1 kHz in 512-frame blocks. The +/// upstream hands over its own buffers (mData replaced, ours untouched); with +/// [inPlace] the output buffers are null too, as hosts may pass them. +static void renderZeroCopy(AUAudioUnit *au, const std::vector &in, bool inPlace, std::vector &L, std::vector &R) { + au.maximumFramesToRender = 4096; + NSError *err = nil; + if (![au allocateRenderResourcesAndReturnError:&err]) { std::printf("allocate: %s\n", err.localizedDescription.UTF8String); return; } + AURenderBlock render = au.renderBlock; + const AVAudioFrameCount n = 512; + std::vector upL(n), upR(n), outL(n), outR(n); + L.clear(); R.clear(); + for (size_t pos = 0; pos + n <= in.size(); pos += n) { + memcpy(upL.data(), &in[pos], n * 4); + memcpy(upR.data(), &in[pos], n * 4); + float *upL0 = upL.data(), *upR0 = upR.data(); + AURenderPullInputBlock pull = ^AUAudioUnitStatus(AudioUnitRenderActionFlags *f, const AudioTimeStamp *t, + AUAudioFrameCount frames, NSInteger bus, AudioBufferList *data) { + for (UInt32 c = 0; c < data->mNumberBuffers; ++c) { + data->mBuffers[c].mData = c ? upR0 : upL0; + data->mBuffers[c].mDataByteSize = frames * 4; + } + return noErr; + }; + struct { AudioBufferList list; AudioBuffer extra; } out; + out.list.mNumberBuffers = 2; + for (int c = 0; c < 2; ++c) { + out.list.mBuffers[c].mNumberChannels = 1; + out.list.mBuffers[c].mDataByteSize = n * 4; + out.list.mBuffers[c].mData = inPlace ? nullptr : (c ? outR.data() : outL.data()); + } + AudioTimeStamp ts = {}; + ts.mSampleTime = (Float64)pos; + ts.mFlags = kAudioTimeStampSampleTimeValid; + AudioUnitRenderActionFlags flags = 0; + AUAudioUnitStatus st = render(&flags, &ts, n, 0, &out.list, pull); + if (st != noErr) { std::printf("render status %d\n", (int)st); break; } + const float *l = (const float *)out.list.mBuffers[0].mData, *r = (const float *)out.list.mBuffers[1].mData; + L.insert(L.end(), l, l + n); + R.insert(R.end(), r, r + n); + } + [au deallocateRenderResources]; +} + static double maxDiff(const std::vector &a, const std::vector &b) { double m = 0; for (size_t i = 0; i < a.size() && i < b.size(); ++i) m = std::max(m, std::fabs((double)a[i] - b[i])); @@ -152,6 +199,20 @@ int main(int argc, char **argv) { dl = maxDiff(L, L2); snprintf(msg, sizeof msg, "fullState round trip renders the same (%.2g)", dl); check(dl < 1e-6, msg, sc.name); + + // 4. zero-copy input, with and without host output buffers + for (int inPlace = 0; inPlace < 2; ++inPlace) { + AVAudioUnit *fresh = instantiate(d); + Params dp; dp.fill(*spec); + std::vector zin(in.begin(), in.begin() + 44032); // 86 blocks of 512 + std::vector zw = renderCore(sc.toolboxType, dp, zin, 44100), zL, zR; + renderZeroCopy(fresh.AUAudioUnit, zin, inPlace, zL, zR); + double zl = zL.size() == zin.size() ? maxDiff(zL, zw) : 1e9; + double zr = zR.size() == zin.size() ? maxDiff(zR, zw) : 1e9; + snprintf(msg, sizeof msg, "zero-copy input%s: AU == core (L %.2g, R %.2g)", + inPlace ? ", in-place output" : "", zl, zr); + check(zl < 1e-6 && zr < 1e-6, msg, sc.name); + } } std::printf("\n%s (%d failures)\n", failures ? "FAILED" : "all passed", failures); } diff --git a/versions.properties b/versions.properties index 6c1d70b..9e906d5 100644 --- a/versions.properties +++ b/versions.properties @@ -17,8 +17,8 @@ android.versionCode = 70 # iOS/iPadOS (cc.tiredsysadmin.ios.sizzle): the AUv3 plugin app in ios/app; the # Makefile there passes these to Xcode and names the .ipa by versionCode. (The # TrollStore spike in ios/spike keeps its own version in its project.yml.) -ios.versionName = 0.1.0 -ios.versionCode = 1 +ios.versionName = 0.1.1 +ios.versionCode = 2 macos.versionName = - linux.versionName = - bsd.versionName = -