iOS 0.1.0: the eight audio effects as AUv3 plugins on a C++ core
C++ ports of the Kotlin effects, checked against audio the Kotlin code renders (25 scenarios, IosGoldenExport); an Objective-C++ AUv3 wrapper checked on the Mac against the core (parameters, presets, saved state); a container app that checks each plugin on the device. Built as a TrollStore .ipa. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c9ad186de1
commit
dcf85ba915
@@ -0,0 +1,159 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Mac-side check of the AUv3 wrapper (SizzleEffectAU), run by `make -C ios au-test`.
|
||||
// AUAudioUnit exists on macOS too, so every effect in components.txt is registered
|
||||
// in-process and driven through AVAudioEngine (offline), like a host would:
|
||||
// 1. audio: the reference input through the AU must equal the C++ core run
|
||||
// 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).
|
||||
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#import "Components.gen.h"
|
||||
#import "SizzleEffectAU.h"
|
||||
#include "sizzle/DeviceSpecs.gen.hpp"
|
||||
#include "sizzle/Effect.hpp"
|
||||
|
||||
using namespace sizzle;
|
||||
|
||||
static int failures = 0;
|
||||
static void check(bool ok, const char *what, const char *name) {
|
||||
std::printf("%s %-18s %s\n", ok ? "PASS" : "FAIL", name, what);
|
||||
if (!ok) ++failures;
|
||||
}
|
||||
|
||||
static std::vector<float> readF32(const char *path) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
std::vector<char> b((std::istreambuf_iterator<char>(f)), {});
|
||||
std::vector<float> v(b.size() / 4);
|
||||
memcpy(v.data(), b.data(), v.size() * 4);
|
||||
return v;
|
||||
}
|
||||
|
||||
static AVAudioUnit *instantiate(AudioComponentDescription d) {
|
||||
__block AVAudioUnit *unit = nil;
|
||||
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
|
||||
[AVAudioUnit instantiateWithComponentDescription:d options:0 completionHandler:^(AVAudioUnit *u, NSError *e) {
|
||||
unit = u;
|
||||
if (e) std::printf("instantiate error: %s\n", e.localizedDescription.UTF8String);
|
||||
dispatch_semaphore_signal(sem);
|
||||
}];
|
||||
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
|
||||
return unit;
|
||||
}
|
||||
|
||||
/// Render [in] (mono, both channels) through [unit]; returns the left and right outputs.
|
||||
static void renderAU(AVAudioUnit *unit, const std::vector<float> &in, std::vector<float> &L, std::vector<float> &R) {
|
||||
AVAudioEngine *engine = [AVAudioEngine new];
|
||||
AVAudioFormat *fmt = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:48000 channels:2];
|
||||
NSError *err = nil;
|
||||
[engine enableManualRenderingMode:AVAudioEngineManualRenderingModeOffline format:fmt maximumFrameCount:1024 error:&err];
|
||||
AVAudioPlayerNode *player = [AVAudioPlayerNode new];
|
||||
[engine attachNode:player];
|
||||
[engine attachNode:unit];
|
||||
[engine connect:player to:unit format:fmt];
|
||||
[engine connect:unit to:engine.mainMixerNode format:fmt];
|
||||
[engine startAndReturnError:&err];
|
||||
AVAudioPCMBuffer *src = [[AVAudioPCMBuffer alloc] initWithPCMFormat:fmt frameCapacity:(AVAudioFrameCount)in.size()];
|
||||
src.frameLength = (AVAudioFrameCount)in.size();
|
||||
memcpy(src.floatChannelData[0], in.data(), in.size() * 4);
|
||||
memcpy(src.floatChannelData[1], in.data(), in.size() * 4);
|
||||
[player scheduleBuffer:src completionHandler:nil];
|
||||
[player play];
|
||||
AVAudioPCMBuffer *out = [[AVAudioPCMBuffer alloc] initWithPCMFormat:engine.manualRenderingFormat frameCapacity:1024];
|
||||
L.clear(); R.clear();
|
||||
while (L.size() < in.size()) {
|
||||
[engine renderOffline:1024 toBuffer:out error:&err];
|
||||
L.insert(L.end(), out.floatChannelData[0], out.floatChannelData[0] + out.frameLength);
|
||||
R.insert(R.end(), out.floatChannelData[1], out.floatChannelData[1] + out.frameLength);
|
||||
}
|
||||
L.resize(in.size()); R.resize(in.size());
|
||||
[engine stop];
|
||||
}
|
||||
|
||||
static std::vector<float> renderCore(const char *type, const Params &p, const std::vector<float> &in) {
|
||||
auto fx = Effect::create(type, 48000);
|
||||
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;
|
||||
}
|
||||
|
||||
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]));
|
||||
return m;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@autoreleasepool {
|
||||
if (argc < 2) { std::fprintf(stderr, "usage: au_test <golden/input.f32>\n"); return 2; }
|
||||
std::vector<float> in = readF32(argv[1]);
|
||||
in.resize(48000); // 1 s is plenty
|
||||
for (int c = 0; c < kSizzleComponentCount; ++c) {
|
||||
const SizzleComponent &sc = kSizzleComponents[c];
|
||||
AudioComponentDescription d = {kAudioUnitType_Effect, sc.subtype, 'Tsys', 0, 0};
|
||||
[AUAudioUnit registerSubclass:SizzleEffectAU.class asComponentDescription:d name:@(sc.name) version:1];
|
||||
AVAudioUnit *unit = instantiate(d);
|
||||
if (!unit) { check(false, "instantiate", sc.name); continue; }
|
||||
const DeviceSpec *spec = findDevice(sc.toolboxType);
|
||||
|
||||
// 1. defaults
|
||||
Params p; p.fill(*spec);
|
||||
std::vector<float> L, R, want = renderCore(sc.toolboxType, p, in);
|
||||
renderAU(unit, in, L, R);
|
||||
char msg[160];
|
||||
double dl = maxDiff(L, want), dr = maxDiff(R, want);
|
||||
snprintf(msg, sizeof msg, "defaults: AU == core (L %.2g, R %.2g)", dl, dr);
|
||||
check(dl < 1e-6 && dr < 1e-6, msg, sc.name);
|
||||
|
||||
// 2. move every parameter to 70% (enums: last choice) through the AU tree
|
||||
AUAudioUnit *au = unit.AUAudioUnit;
|
||||
for (int i = 0; i < spec->paramCount; ++i) {
|
||||
const ParamSpec &s = spec->params[i];
|
||||
AUParameter *param = [au.parameterTree parameterWithAddress:(AUParameterAddress)i];
|
||||
AUValue v = s.isEnum() ? (AUValue)(s.choiceCount() - 1) : s.min + 0.7f * (s.max - s.min);
|
||||
if (s.isInt) v = std::round(v);
|
||||
param.value = v;
|
||||
if (s.isEnum()) p.set(s.key, s.choices[s.choiceCount() - 1]); else p.set(s.key, v);
|
||||
}
|
||||
want = renderCore(sc.toolboxType, p, in);
|
||||
renderAU(unit, in, L, R);
|
||||
dl = maxDiff(L, want);
|
||||
snprintf(msg, sizeof msg, "parameters at 70%%: AU == core (%.2g)", dl);
|
||||
check(dl < 1e-6, msg, sc.name);
|
||||
|
||||
// 3a. factory presets
|
||||
if (au.factoryPresets.count > 0) {
|
||||
au.currentPreset = au.factoryPresets[1];
|
||||
Params pp; pp.fill(*spec);
|
||||
const char *const *kv = gen::mixTightenerPresets[1];
|
||||
for (int i = 1; kv[i] && kv[i + 1]; i += 2) pp.set(kv[i], kv[i + 1]);
|
||||
want = renderCore(sc.toolboxType, pp, in);
|
||||
renderAU(unit, in, L, R);
|
||||
dl = maxDiff(L, want);
|
||||
snprintf(msg, sizeof msg, "factory preset \"%s\": AU == core (%.2g)", kv[0], dl);
|
||||
check(dl < 1e-6, msg, sc.name);
|
||||
}
|
||||
|
||||
// 3b. fullState round trip into a fresh instance
|
||||
NSDictionary *state = au.fullState;
|
||||
AVAudioUnit *other = instantiate(d);
|
||||
other.AUAudioUnit.fullState = state;
|
||||
std::vector<float> L2, R2;
|
||||
renderAU(unit, in, L, R);
|
||||
renderAU(other, in, L2, R2);
|
||||
dl = maxDiff(L, L2);
|
||||
snprintf(msg, sizeof msg, "fullState round trip renders the same (%.2g)", dl);
|
||||
check(dl < 1e-6, msg, sc.name);
|
||||
}
|
||||
std::printf("\n%s (%d failures)\n", failures ? "FAILED" : "all passed", failures);
|
||||
}
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user