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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dcf85ba915
commit
7d8311a77f
@@ -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,
|
||||
|
||||
+14
-2
@@ -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_<n>.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 <dir>` 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`).
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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..<Int(out.format.channelCount) {
|
||||
let d = out.floatChannelData![ch]
|
||||
for i in 0..<Int(out.frameLength) { let v = d[i]; if !v.isFinite { finite = false }; peak = max(peak, abs(v)) }
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
// directly (both channels), so the wrapper adds nothing and drops nothing;
|
||||
// 2. parameters: moving every parameter through the AU's tree must change the
|
||||
// output to exactly what the core gives for those values;
|
||||
// 3. presets (Mix Tightener) and saved state (fullState round trip).
|
||||
// 3. presets (Mix Tightener) and saved state (fullState round trip);
|
||||
// 4. zero-copy input: calling the render block directly with an upstream that
|
||||
// points the input buffers at its own memory instead of filling ours. Real
|
||||
// hosts do that out of process; AVAudioEngine in-process copies, which is why
|
||||
// 0.1.0 passed here and was silent on the iPad.
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#include <cmath>
|
||||
@@ -77,14 +81,57 @@ static void renderAU(AVAudioUnit *unit, const std::vector<float> &in, std::vecto
|
||||
[engine stop];
|
||||
}
|
||||
|
||||
static std::vector<float> renderCore(const char *type, const Params &p, const std::vector<float> &in) {
|
||||
auto fx = Effect::create(type, 48000);
|
||||
static std::vector<float> renderCore(const char *type, const Params &p, const std::vector<float> &in, int sr = 48000) {
|
||||
auto fx = Effect::create(type, sr);
|
||||
fx->update(p, 120.f);
|
||||
std::vector<float> 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<float> &in, bool inPlace, std::vector<float> &L, std::vector<float> &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<float> 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<float> &a, const std::vector<float> &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<float> zin(in.begin(), in.begin() + 44032); // 86 blocks of 512
|
||||
std::vector<float> 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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 = -
|
||||
|
||||
Reference in New Issue
Block a user