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,17 @@
|
||||
// GENERATED from components.txt by tools/gen_components.py. Do not edit.
|
||||
#pragma once
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
typedef struct { OSType subtype; const char *toolboxType; const char *name; } SizzleComponent;
|
||||
|
||||
static const SizzleComponent kSizzleComponents[] = {
|
||||
{'sBcr', "BITCRUSHER", "Bitcrusher"},
|
||||
{'sFlt', "FILTER", "Filter"},
|
||||
{'sEqx', "EQ10", "10-Band EQ"},
|
||||
{'sDly', "DELAY", "Tape Delay"},
|
||||
{'sMxt', "MIX_TIGHTENER", "Mix Tightener"},
|
||||
{'sTpe', "TAPE_ENGINE", "Tape Engine"},
|
||||
{'sGrn', "GRANULAR", "Granular Glitch"},
|
||||
{'sAmb', "AMBIENCE", "Ambience Reverb"}
|
||||
};
|
||||
static const int kSizzleComponentCount = 8;
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.cc.tiredsysadmin.ios.sizzle</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- GENERATED from components.txt by tools/gen_components.py. Do not edit. -->
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key><string>en</string>
|
||||
<key>CFBundleDisplayName</key><string>Sizzle FX</string>
|
||||
<key>CFBundleExecutable</key><string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
|
||||
<key>CFBundleName</key><string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key><string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key><string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key><string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>AudioComponents</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Bitcrusher</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Bitcrusher</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sBcr</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Filter</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Filter</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sFlt</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle 10-Band EQ</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle 10-Band EQ</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sEqx</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Tape Delay</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Tape Delay</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sDly</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Mix Tightener</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Mix Tightener</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sMxt</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Tape Engine</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Tape Engine</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sTpe</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Granular Glitch</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Granular Glitch</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sGrn</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>description</key><string>Sizzle Ambience Reverb</string>
|
||||
<key>factoryFunction</key><string>SizzleFXViewController</string>
|
||||
<key>manufacturer</key><string>Tsys</string>
|
||||
<key>name</key><string>Tired Sysadmin: Sizzle Ambience Reverb</string>
|
||||
<key>sandboxSafe</key><true/>
|
||||
<key>subtype</key><string>sAmb</string>
|
||||
<key>tags</key><array><string>Effects</string></array>
|
||||
<key>type</key><string>aufx</string>
|
||||
<key>version</key><integer>65536</integer>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key><string>com.apple.AudioUnit-UI</string>
|
||||
<key>NSExtensionPrincipalClass</key><string>SizzleFXViewController</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,26 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// One Sizzle audio effect as an AUv3 (`aufx`): wraps a C++ `sizzle::Effect`
|
||||
/// chosen by its ToolboxType name ("DELAY", "FILTER", …). Parameters come from the
|
||||
/// generated device specs; each channel runs its own mono effect instance.
|
||||
@interface SizzleEffectAU : AUAudioUnit
|
||||
|
||||
- (nullable instancetype)initWithComponentDescription:(AudioComponentDescription)desc
|
||||
toolboxType:(const char *)toolboxType
|
||||
displayName:(NSString *)displayName
|
||||
error:(NSError **)outError;
|
||||
|
||||
/// The device's name as shown in Sizzle ("Tape Delay").
|
||||
@property (nonatomic, readonly) NSString *displayName;
|
||||
|
||||
/// Formats a parameter value the way Sizzle's editor does (units, %, choices).
|
||||
- (NSString *)stringForParameter:(AUParameter *)param value:(AUValue)value;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,405 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#import "SizzleEffectAU.h"
|
||||
#import "Components.gen.h"
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "sizzle/DeviceSpecs.gen.hpp"
|
||||
#include "sizzle/Effect.hpp"
|
||||
|
||||
using namespace sizzle;
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Everything the render thread touches, owned by the AU.
|
||||
*
|
||||
* Two ways settings reach the effect, neither of them locking:
|
||||
* - AU parameters (host automation, the UI) are written into [values] (one atomic
|
||||
* float per parameter, address = index in the spec) and bump [valuesSeq];
|
||||
* - whole settings (presets, restored state, hidden keys such as the Mix
|
||||
* Tightener's) are written by the main thread into the spare half of [mailbox]
|
||||
* and published with [mailboxIdx] / [mailboxSeq].
|
||||
* The render thread copies the published mailbox into [live], overlays the
|
||||
* parameter values, and calls Effect::update only when something changed.
|
||||
*/
|
||||
struct Kernel {
|
||||
const DeviceSpec *spec = nullptr;
|
||||
std::string type;
|
||||
std::unique_ptr<Effect> fx[2];
|
||||
int channels = 0;
|
||||
|
||||
std::atomic<float> values[Params::kMax];
|
||||
std::atomic<uint32_t> valuesSeq{1};
|
||||
|
||||
Params mailbox[2];
|
||||
std::atomic<int> mailboxIdx{0};
|
||||
std::atomic<uint32_t> mailboxSeq{1};
|
||||
|
||||
// render thread only
|
||||
Params live;
|
||||
uint32_t seenValues = 0, seenMailbox = 0;
|
||||
double tempo = 120.0;
|
||||
std::atomic<bool> bypass{false};
|
||||
std::vector<float> inBuf[2];
|
||||
AUHostMusicalContextBlock musicalContext = nil;
|
||||
|
||||
void publish(const Params &p) {
|
||||
int next = 1 - mailboxIdx.load(std::memory_order_acquire);
|
||||
mailbox[next] = p;
|
||||
mailboxIdx.store(next, std::memory_order_release);
|
||||
mailboxSeq.fetch_add(1, std::memory_order_release);
|
||||
}
|
||||
|
||||
/** Parameter i's value as Params text: a choice name or a number. */
|
||||
void overlay(Params &p) {
|
||||
for (int i = 0; i < spec->paramCount; ++i) {
|
||||
const ParamSpec &s = spec->params[i];
|
||||
float v = values[i].load(std::memory_order_relaxed);
|
||||
if (s.isEnum()) {
|
||||
int n = s.choiceCount(), idx = (int)std::lround(v);
|
||||
p.set(s.key, s.choices[idx < 0 ? 0 : (idx >= n ? n - 1 : idx)]);
|
||||
} else {
|
||||
p.set(s.key, s.isInt ? std::round(v) : v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Called at the top of each render cycle. */
|
||||
void refresh(bool tempoChanged) {
|
||||
uint32_t ms = mailboxSeq.load(std::memory_order_acquire);
|
||||
uint32_t vs = valuesSeq.load(std::memory_order_acquire);
|
||||
if (ms == seenMailbox && vs == seenValues && !tempoChanged) return;
|
||||
if (ms != seenMailbox) live = mailbox[mailboxIdx.load(std::memory_order_acquire)];
|
||||
seenMailbox = ms;
|
||||
seenValues = vs;
|
||||
overlay(live);
|
||||
for (int c = 0; c < channels; ++c) fx[c]->update(live, (float)tempo);
|
||||
}
|
||||
};
|
||||
|
||||
int choiceIndex(const ParamSpec &s, const char *name) {
|
||||
for (int i = 0; s.choices[i]; ++i) if (std::strcmp(s.choices[i], name) == 0) return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@implementation SizzleEffectAU {
|
||||
std::unique_ptr<Kernel> _k;
|
||||
AUAudioUnitBusArray *_inputs;
|
||||
AUAudioUnitBusArray *_outputs;
|
||||
AUAudioUnitBus *_inBus;
|
||||
AUAudioUnitBus *_outBus;
|
||||
AUParameterTree *_tree;
|
||||
Params _base; // main thread: the full settings (incl. hidden keys)
|
||||
NSArray<AUAudioUnitPreset *> *_factoryPresets;
|
||||
AUAudioUnitPreset *_currentPreset;
|
||||
NSString *_displayName;
|
||||
}
|
||||
|
||||
/// The standard initializer (used by AUAudioUnit registration and the Mac test):
|
||||
/// picks the device from the component's subtype in components.txt.
|
||||
- (instancetype)initWithComponentDescription:(AudioComponentDescription)desc
|
||||
options:(AudioComponentInstantiationOptions)options
|
||||
error:(NSError **)outError {
|
||||
for (int i = 0; i < kSizzleComponentCount; ++i)
|
||||
if (kSizzleComponents[i].subtype == desc.componentSubType)
|
||||
return [self initWithComponentDescription:desc toolboxType:kSizzleComponents[i].toolboxType
|
||||
displayName:@(kSizzleComponents[i].name) error:outError];
|
||||
if (outError) *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:kAudioUnitErr_InvalidElement userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (instancetype)initWithComponentDescription:(AudioComponentDescription)desc
|
||||
toolboxType:(const char *)toolboxType
|
||||
displayName:(NSString *)displayName
|
||||
error:(NSError **)outError {
|
||||
self = [super initWithComponentDescription:desc options:0 error:outError];
|
||||
if (!self) return nil;
|
||||
_displayName = displayName;
|
||||
_k = std::make_unique<Kernel>();
|
||||
_k->type = toolboxType;
|
||||
_k->spec = findDevice(toolboxType);
|
||||
if (!_k->spec) {
|
||||
if (outError) *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:kAudioUnitErr_InvalidProperty userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
AVAudioFormat *fmt = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:2];
|
||||
_inBus = [[AUAudioUnitBus alloc] initWithFormat:fmt error:outError];
|
||||
_outBus = [[AUAudioUnitBus alloc] initWithFormat:fmt error:outError];
|
||||
if (!_inBus || !_outBus) return nil;
|
||||
_inBus.maximumChannelCount = 2;
|
||||
_outBus.maximumChannelCount = 2;
|
||||
_inputs = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self busType:AUAudioUnitBusTypeInput busses:@[_inBus]];
|
||||
_outputs = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self busType:AUAudioUnitBusTypeOutput busses:@[_outBus]];
|
||||
|
||||
[self buildParameterTree];
|
||||
_base.fill(*_k->spec);
|
||||
[self pushBase];
|
||||
[self buildFactoryPresets];
|
||||
self.maximumFramesToRender = 4096;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)displayName { return _displayName; }
|
||||
|
||||
#pragma mark - parameters
|
||||
|
||||
- (void)buildParameterTree {
|
||||
const DeviceSpec *spec = _k->spec;
|
||||
NSMutableArray<AUParameter *> *params = [NSMutableArray array];
|
||||
for (int i = 0; i < spec->paramCount; ++i) {
|
||||
const ParamSpec &s = spec->params[i];
|
||||
AUParameter *p;
|
||||
AudioUnitParameterOptions flags = kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable;
|
||||
if (s.isEnum()) {
|
||||
NSMutableArray<NSString *> *names = [NSMutableArray array];
|
||||
for (int c = 0; s.choices[c]; ++c) [names addObject:@(s.choices[c])];
|
||||
p = [AUParameterTree createParameterWithIdentifier:@(s.key) name:@(s.label) address:(AUParameterAddress)i
|
||||
min:0 max:(AUValue)(names.count - 1)
|
||||
unit:kAudioUnitParameterUnit_Indexed unitName:nil
|
||||
flags:flags valueStrings:names dependentParameters:nil];
|
||||
p.value = (AUValue)s.def;
|
||||
} else {
|
||||
p = [AUParameterTree createParameterWithIdentifier:@(s.key) name:@(s.label) address:(AUParameterAddress)i
|
||||
min:s.min max:s.max
|
||||
unit:s.isInt ? kAudioUnitParameterUnit_Indexed : kAudioUnitParameterUnit_Generic
|
||||
unitName:nil flags:flags valueStrings:nil dependentParameters:nil];
|
||||
p.value = s.def;
|
||||
}
|
||||
_k->values[i].store(p.value);
|
||||
[params addObject:p];
|
||||
}
|
||||
_tree = [AUParameterTree createTreeWithChildren:params];
|
||||
|
||||
Kernel *k = _k.get();
|
||||
_tree.implementorValueObserver = ^(AUParameter *param, AUValue value) {
|
||||
if (param.address < (AUParameterAddress)k->spec->paramCount) {
|
||||
k->values[param.address].store(value, std::memory_order_relaxed);
|
||||
k->valuesSeq.fetch_add(1, std::memory_order_release);
|
||||
}
|
||||
};
|
||||
_tree.implementorValueProvider = ^AUValue(AUParameter *param) {
|
||||
return param.address < (AUParameterAddress)k->spec->paramCount ? k->values[param.address].load() : 0;
|
||||
};
|
||||
__weak SizzleEffectAU *weakSelf = self;
|
||||
_tree.implementorStringFromValueCallback = ^NSString *(AUParameter *param, const AUValue *value) {
|
||||
return [weakSelf stringForParameter:param value:value ? *value : param.value] ?: @"";
|
||||
};
|
||||
}
|
||||
|
||||
- (AUParameterTree *)parameterTree { return _tree; }
|
||||
|
||||
/// Publish [_base] to the render thread and move the AU parameters to match it.
|
||||
- (void)pushBase {
|
||||
const DeviceSpec *spec = _k->spec;
|
||||
for (int i = 0; i < spec->paramCount; ++i) {
|
||||
const ParamSpec &s = spec->params[i];
|
||||
AUValue v = s.isEnum() ? (AUValue)choiceIndex(s, _base.s(s.key, s.choices[0])) : _base.f(s.key, s.def);
|
||||
[_tree parameterWithAddress:(AUParameterAddress)i].value = v; // notifies UI + kernel
|
||||
}
|
||||
_k->publish(_base);
|
||||
}
|
||||
|
||||
/// Bring [_base] up to date with the AU parameters (they're the source of truth for
|
||||
/// the visible keys; _base also holds hidden ones).
|
||||
- (void)pullBase {
|
||||
_k->overlay(_base);
|
||||
}
|
||||
|
||||
- (NSString *)stringForParameter:(AUParameter *)param value:(AUValue)value {
|
||||
if (param.address >= (AUParameterAddress)_k->spec->paramCount) return @"";
|
||||
const ParamSpec &s = _k->spec->params[param.address];
|
||||
if (s.isEnum()) {
|
||||
int n = s.choiceCount(), i = (int)std::lround(value);
|
||||
return @(s.choices[i < 0 ? 0 : (i >= n ? n - 1 : i)]);
|
||||
}
|
||||
const char *label = s.label;
|
||||
if (strstr(label, "(dB)")) return [NSString stringWithFormat:@"%.1f dB", value];
|
||||
if (strstr(label, "(ms)")) return [NSString stringWithFormat:@"%.0f ms", value];
|
||||
if (s.isInt) return s.min < 0 ? [NSString stringWithFormat:@"%+d", (int)std::lround(value)]
|
||||
: [NSString stringWithFormat:@"%d", (int)std::lround(value)];
|
||||
if (s.min == 0 && s.max == 1) return [NSString stringWithFormat:@"%d%%", (int)std::lround(value * 100)];
|
||||
if (s.min == -1 && s.max == 1) return [NSString stringWithFormat:@"%+d%%", (int)std::lround(value * 100)];
|
||||
return [NSString stringWithFormat:@"%.2f", value];
|
||||
}
|
||||
|
||||
#pragma mark - presets and state
|
||||
|
||||
- (void)buildFactoryPresets {
|
||||
NSMutableArray *list = [NSMutableArray array];
|
||||
if (_k->type == "MIX_TIGHTENER") {
|
||||
for (int i = 0; gen::mixTightenerPresets[i]; ++i) {
|
||||
AUAudioUnitPreset *p = [AUAudioUnitPreset new];
|
||||
p.number = i;
|
||||
p.name = @(gen::mixTightenerPresets[i][0]);
|
||||
[list addObject:p];
|
||||
}
|
||||
}
|
||||
_factoryPresets = list;
|
||||
}
|
||||
|
||||
- (NSArray<AUAudioUnitPreset *> *)factoryPresets { return _factoryPresets; }
|
||||
- (BOOL)supportsUserPresets { return YES; }
|
||||
- (AUAudioUnitPreset *)currentPreset { return _currentPreset; }
|
||||
|
||||
- (void)setCurrentPreset:(AUAudioUnitPreset *)preset {
|
||||
if (preset == nil) { _currentPreset = nil; return; }
|
||||
if (preset.number >= 0) {
|
||||
if (preset.number < (NSInteger)_factoryPresets.count && _k->type == "MIX_TIGHTENER") {
|
||||
const char *const *kv = gen::mixTightenerPresets[preset.number];
|
||||
_base.fill(*_k->spec);
|
||||
for (int i = 1; kv[i] && kv[i + 1]; i += 2) _base.set(kv[i], kv[i + 1]);
|
||||
[self pushBase];
|
||||
}
|
||||
_currentPreset = preset;
|
||||
} else {
|
||||
NSError *err = nil;
|
||||
NSDictionary *state = [self presetStateFor:preset error:&err];
|
||||
if (state) self.fullState = state;
|
||||
_currentPreset = preset;
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *const kStateKey = @"sizzleValues";
|
||||
|
||||
- (NSDictionary<NSString *, id> *)fullState {
|
||||
NSMutableDictionary *state = [NSMutableDictionary dictionaryWithDictionary:[super fullState] ?: @{}];
|
||||
[self pullBase];
|
||||
NSMutableDictionary *values = [NSMutableDictionary dictionary];
|
||||
for (int i = 0; i < _base.size(); ++i) values[@(_base.keyAt(i))] = @(_base.valueAt(i));
|
||||
state[kStateKey] = values;
|
||||
state[@"sizzleType"] = @(_k->type.c_str());
|
||||
return state;
|
||||
}
|
||||
|
||||
- (void)setFullState:(NSDictionary<NSString *, id> *)fullState {
|
||||
[super setFullState:fullState];
|
||||
NSDictionary *values = fullState[kStateKey];
|
||||
if (![values isKindOfClass:[NSDictionary class]]) return;
|
||||
_base.fill(*_k->spec);
|
||||
for (NSString *key in values) {
|
||||
id v = values[key];
|
||||
if ([key isKindOfClass:[NSString class]] && [v isKindOfClass:[NSString class]])
|
||||
_base.set(key.UTF8String, ((NSString *)v).UTF8String);
|
||||
}
|
||||
[self pushBase];
|
||||
}
|
||||
|
||||
#pragma mark - busses and render
|
||||
|
||||
- (AUAudioUnitBusArray *)inputBusses { return _inputs; }
|
||||
- (AUAudioUnitBusArray *)outputBusses { return _outputs; }
|
||||
- (NSArray<NSNumber *> *)channelCapabilities { return @[@1, @1, @2, @2]; }
|
||||
- (BOOL)canProcessInPlace { return YES; }
|
||||
|
||||
- (void)setShouldBypassEffect:(BOOL)bypass {
|
||||
[super setShouldBypassEffect:bypass];
|
||||
_k->bypass.store(bypass);
|
||||
}
|
||||
|
||||
- (BOOL)allocateRenderResourcesAndReturnError:(NSError **)outError {
|
||||
if (![super allocateRenderResourcesAndReturnError:outError]) return NO;
|
||||
AVAudioChannelCount chIn = _inBus.format.channelCount, chOut = _outBus.format.channelCount;
|
||||
if (chIn != chOut || chOut < 1 || chOut > 2) {
|
||||
if (outError) *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:kAudioUnitErr_FailedInitialization userInfo:nil];
|
||||
self.renderResourcesAllocated = NO;
|
||||
return NO;
|
||||
}
|
||||
int sr = (int)std::lround(_outBus.format.sampleRate);
|
||||
Kernel *k = _k.get();
|
||||
k->channels = (int)chOut;
|
||||
for (int c = 0; c < 2; ++c) {
|
||||
k->fx[c] = c < k->channels ? Effect::create(k->type.c_str(), sr) : nullptr;
|
||||
k->inBuf[c].assign(self.maximumFramesToRender, 0.f);
|
||||
}
|
||||
if (!k->fx[0]) {
|
||||
if (outError) *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:kAudioUnitErr_FailedInitialization userInfo:nil];
|
||||
self.renderResourcesAllocated = NO;
|
||||
return NO;
|
||||
}
|
||||
k->musicalContext = self.musicalContextBlock;
|
||||
k->seenValues = k->seenMailbox = 0; // force update() on the first render
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)deallocateRenderResources {
|
||||
for (auto &f : _k->fx) f.reset();
|
||||
_k->musicalContext = nil;
|
||||
[super deallocateRenderResources];
|
||||
}
|
||||
|
||||
- (AUInternalRenderBlock)internalRenderBlock {
|
||||
Kernel *k = _k.get();
|
||||
return ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags, const AudioTimeStamp *timestamp,
|
||||
AVAudioFrameCount frameCount, NSInteger outputBusNumber,
|
||||
AudioBufferList *outputData, const AURenderEvent *events,
|
||||
AURenderPullInputBlock pullInputBlock) {
|
||||
if (frameCount > k->inBuf[0].size() || !pullInputBlock) return kAudioUnitErr_TooManyFramesToProcess;
|
||||
|
||||
// Pull the input into our own buffers.
|
||||
struct { AudioBufferList list; AudioBuffer extra; } in;
|
||||
in.list.mNumberBuffers = (UInt32)k->channels;
|
||||
for (int c = 0; c < k->channels; ++c) {
|
||||
in.list.mBuffers[c].mNumberChannels = 1;
|
||||
in.list.mBuffers[c].mDataByteSize = frameCount * sizeof(float);
|
||||
in.list.mBuffers[c].mData = k->inBuf[c].data();
|
||||
}
|
||||
AudioUnitRenderActionFlags pullFlags = 0;
|
||||
AUAudioUnitStatus err = pullInputBlock(&pullFlags, timestamp, frameCount, 0, &in.list);
|
||||
if (err != noErr) return err;
|
||||
|
||||
// Host automation arrives as render events: apply at block start.
|
||||
bool changed = false;
|
||||
for (const AURenderEvent *e = events; e; e = e->head.next) {
|
||||
if (e->head.eventType == AURenderEventParameter || e->head.eventType == AURenderEventParameterRamp) {
|
||||
AUParameterAddress a = e->parameter.parameterAddress;
|
||||
if (a < (AUParameterAddress)k->spec->paramCount) {
|
||||
k->values[a].store(e->parameter.value, std::memory_order_relaxed);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) k->valuesSeq.fetch_add(1, std::memory_order_release);
|
||||
|
||||
bool tempoChanged = false;
|
||||
if (k->musicalContext) {
|
||||
double bpm = 0;
|
||||
if (k->musicalContext(&bpm, nullptr, nullptr, nullptr, nullptr, nullptr) && bpm > 0 && bpm != k->tempo) {
|
||||
k->tempo = bpm;
|
||||
tempoChanged = true;
|
||||
}
|
||||
}
|
||||
k->refresh(tempoChanged);
|
||||
|
||||
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();
|
||||
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);
|
||||
if (bypass) {
|
||||
if (dst != src) std::memcpy(dst, src, frameCount * sizeof(float));
|
||||
continue;
|
||||
}
|
||||
Effect *fx = k->fx[c].get();
|
||||
for (AVAudioFrameCount i = 0; i < frameCount; ++i) {
|
||||
float y = fx->process(src[i]);
|
||||
dst[i] = std::isfinite(y) ? y : 0.f;
|
||||
}
|
||||
}
|
||||
(void)actionFlags; (void)outputBusNumber;
|
||||
return noErr;
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,201 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The FX extension's principal class: the factory for every effect listed in
|
||||
// components.txt (picked by subtype) and a generic editor for its parameters
|
||||
// (sliders, segmented switches for short choice lists, menus for long ones).
|
||||
// The card-style editors of the Android app come later; this keeps every
|
||||
// parameter reachable meanwhile.
|
||||
|
||||
#import <CoreAudioKit/CoreAudioKit.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "Components.gen.h"
|
||||
#import "SizzleEffectAU.h"
|
||||
|
||||
@interface SizzleFXViewController : AUViewController <AUAudioUnitFactory>
|
||||
@end
|
||||
|
||||
static UIColor *Amber(void) { return [UIColor colorWithRed:0.96 green:0.76 blue:0.29 alpha:1]; }
|
||||
static UIColor *Dim(void) { return [UIColor colorWithWhite:0.62 alpha:1]; }
|
||||
|
||||
@implementation SizzleFXViewController {
|
||||
SizzleEffectAU *_au;
|
||||
UIStackView *_stack;
|
||||
NSMutableDictionary<NSNumber *, UIControl *> *_controls;
|
||||
NSMutableDictionary<NSNumber *, UILabel *> *_valueLabels;
|
||||
AUParameterObserverToken _token;
|
||||
BOOL _built;
|
||||
}
|
||||
|
||||
#pragma mark - factory
|
||||
|
||||
- (AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
|
||||
for (int i = 0; i < kSizzleComponentCount; ++i) {
|
||||
if (kSizzleComponents[i].subtype == desc.componentSubType) {
|
||||
_au = [[SizzleEffectAU alloc] initWithComponentDescription:desc
|
||||
toolboxType:kSizzleComponents[i].toolboxType
|
||||
displayName:@(kSizzleComponents[i].name)
|
||||
error:error];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [self buildIfReady]; });
|
||||
return _au;
|
||||
}
|
||||
}
|
||||
if (error) *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:kAudioUnitErr_InvalidElement userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - view
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.preferredContentSize = CGSizeMake(520, 420);
|
||||
self.view.backgroundColor = [UIColor colorWithRed:0.07 green:0.08 blue:0.09 alpha:1];
|
||||
UIScrollView *scroll = [UIScrollView new];
|
||||
scroll.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.view addSubview:scroll];
|
||||
_stack = [UIStackView new];
|
||||
_stack.axis = UILayoutConstraintAxisVertical;
|
||||
_stack.spacing = 10;
|
||||
_stack.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[scroll addSubview:_stack];
|
||||
UILayoutGuide *g = self.view.safeAreaLayoutGuide;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[scroll.leadingAnchor constraintEqualToAnchor:g.leadingAnchor],
|
||||
[scroll.trailingAnchor constraintEqualToAnchor:g.trailingAnchor],
|
||||
[scroll.topAnchor constraintEqualToAnchor:g.topAnchor],
|
||||
[scroll.bottomAnchor constraintEqualToAnchor:g.bottomAnchor],
|
||||
[_stack.leadingAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.leadingAnchor constant:14],
|
||||
[_stack.trailingAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.trailingAnchor constant:-14],
|
||||
[_stack.topAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.topAnchor constant:12],
|
||||
[_stack.bottomAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.bottomAnchor constant:-12],
|
||||
[_stack.widthAnchor constraintEqualToAnchor:scroll.frameLayoutGuide.widthAnchor constant:-28],
|
||||
]];
|
||||
[self buildIfReady];
|
||||
}
|
||||
|
||||
- (UILabel *)label:(NSString *)text size:(CGFloat)size color:(UIColor *)color {
|
||||
UILabel *l = [UILabel new];
|
||||
l.text = text;
|
||||
l.font = [UIFont monospacedSystemFontOfSize:size weight:UIFontWeightRegular];
|
||||
l.textColor = color;
|
||||
return l;
|
||||
}
|
||||
|
||||
- (void)buildIfReady {
|
||||
if (_built || !_au || !_stack) return;
|
||||
_built = YES;
|
||||
_controls = [NSMutableDictionary dictionary];
|
||||
_valueLabels = [NSMutableDictionary dictionary];
|
||||
|
||||
[_stack addArrangedSubview:[self label:_au.displayName.uppercaseString size:15 color:Amber()]];
|
||||
|
||||
if (_au.factoryPresets.count > 0) {
|
||||
UIButton *presets = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[presets setTitle:@"PRESET ▾" forState:UIControlStateNormal];
|
||||
presets.titleLabel.font = [UIFont monospacedSystemFontOfSize:13 weight:UIFontWeightRegular];
|
||||
presets.tintColor = Amber();
|
||||
presets.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
NSMutableArray<UIAction *> *items = [NSMutableArray array];
|
||||
__weak SizzleEffectAU *au = _au;
|
||||
__weak UIButton *weakButton = presets;
|
||||
for (AUAudioUnitPreset *p in _au.factoryPresets) {
|
||||
[items addObject:[UIAction actionWithTitle:p.name image:nil identifier:nil handler:^(UIAction *a) {
|
||||
au.currentPreset = p;
|
||||
[weakButton setTitle:[NSString stringWithFormat:@"PRESET: %@ ▾", p.name] forState:UIControlStateNormal];
|
||||
}]];
|
||||
}
|
||||
presets.menu = [UIMenu menuWithChildren:items];
|
||||
presets.showsMenuAsPrimaryAction = YES;
|
||||
[_stack addArrangedSubview:presets];
|
||||
}
|
||||
|
||||
for (AUParameter *p in _au.parameterTree.allParameters) [self addRowFor:p];
|
||||
|
||||
__weak SizzleFXViewController *weakSelf = self;
|
||||
_token = [_au.parameterTree tokenByAddingParameterObserver:^(AUParameterAddress address, AUValue value) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf show:address value:value]; });
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)addRowFor:(AUParameter *)p {
|
||||
NSNumber *addr = @(p.address);
|
||||
UIStackView *head = [UIStackView new];
|
||||
head.axis = UILayoutConstraintAxisHorizontal;
|
||||
[head addArrangedSubview:[self label:p.displayName.uppercaseString size:11 color:Dim()]];
|
||||
UILabel *value = [self label:[_au stringForParameter:p value:p.value] size:11 color:UIColor.whiteColor];
|
||||
value.textAlignment = NSTextAlignmentRight;
|
||||
[head addArrangedSubview:value];
|
||||
_valueLabels[addr] = value;
|
||||
|
||||
UIControl *control;
|
||||
NSArray<NSString *> *choices = p.valueStrings;
|
||||
NSUInteger chars = [[choices componentsJoinedByString:@""] length];
|
||||
__weak SizzleFXViewController *weakSelf = self;
|
||||
if (choices.count > 0 && choices.count <= 6 && chars <= 34) {
|
||||
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:choices];
|
||||
seg.selectedSegmentIndex = (NSInteger)lroundf(p.value);
|
||||
seg.selectedSegmentTintColor = Amber();
|
||||
[seg addAction:[UIAction actionWithHandler:^(UIAction *a) {
|
||||
[weakSelf set:p value:(AUValue)seg.selectedSegmentIndex];
|
||||
}] forControlEvents:UIControlEventValueChanged];
|
||||
control = seg;
|
||||
} else if (choices.count > 0) {
|
||||
UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
b.tintColor = Amber();
|
||||
b.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
NSMutableArray<UIAction *> *items = [NSMutableArray array];
|
||||
[choices enumerateObjectsUsingBlock:^(NSString *name, NSUInteger i, BOOL *stop) {
|
||||
[items addObject:[UIAction actionWithTitle:name image:nil identifier:nil handler:^(UIAction *a) {
|
||||
[weakSelf set:p value:(AUValue)i];
|
||||
}]];
|
||||
}];
|
||||
b.menu = [UIMenu menuWithChildren:items];
|
||||
b.showsMenuAsPrimaryAction = YES;
|
||||
[b setTitle:[NSString stringWithFormat:@"%@ ▾", choices[(NSUInteger)lroundf(p.value)]] forState:UIControlStateNormal];
|
||||
control = b;
|
||||
} else {
|
||||
UISlider *s = [UISlider new];
|
||||
s.minimumValue = p.minValue;
|
||||
s.maximumValue = p.maxValue;
|
||||
s.value = p.value;
|
||||
s.minimumTrackTintColor = Amber();
|
||||
BOOL isInt = p.unit == kAudioUnitParameterUnit_Indexed;
|
||||
[s addAction:[UIAction actionWithHandler:^(UIAction *a) {
|
||||
AUValue v = isInt ? roundf(s.value) : s.value;
|
||||
[weakSelf set:p value:v];
|
||||
}] forControlEvents:UIControlEventValueChanged];
|
||||
control = s;
|
||||
}
|
||||
_controls[addr] = control;
|
||||
|
||||
UIStackView *row = [[UIStackView alloc] initWithArrangedSubviews:@[head, control]];
|
||||
row.axis = UILayoutConstraintAxisVertical;
|
||||
row.spacing = 4;
|
||||
[_stack addArrangedSubview:row];
|
||||
}
|
||||
|
||||
- (void)set:(AUParameter *)p value:(AUValue)v {
|
||||
[p setValue:v originator:_token];
|
||||
[self show:p.address value:v];
|
||||
}
|
||||
|
||||
- (void)show:(AUParameterAddress)address value:(AUValue)value {
|
||||
AUParameter *p = [_au.parameterTree parameterWithAddress:address];
|
||||
if (!p) return;
|
||||
_valueLabels[@(address)].text = [_au stringForParameter:p value:value];
|
||||
UIControl *c = _controls[@(address)];
|
||||
if ([c isKindOfClass:[UISlider class]]) {
|
||||
if (!c.isTracking) ((UISlider *)c).value = value;
|
||||
} else if ([c isKindOfClass:[UISegmentedControl class]]) {
|
||||
((UISegmentedControl *)c).selectedSegmentIndex = (NSInteger)lroundf(value);
|
||||
} else if ([c isKindOfClass:[UIButton class]] && p.valueStrings.count) {
|
||||
NSUInteger i = MIN((NSUInteger)lroundf(value), p.valueStrings.count - 1);
|
||||
[(UIButton *)c setTitle:[NSString stringWithFormat:@"%@ ▾", p.valueStrings[i]] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
if (_token && _au) [_au.parameterTree removeParameterObserver:_token];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"images" : [
|
||||
{ "filename" : "icon-1024.png", "idiom" : "universal", "platform" : "ios", "size" : "1024x1024" }
|
||||
],
|
||||
"info" : { "author" : "xcode", "version" : 1 }
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
@@ -0,0 +1 @@
|
||||
{ "info" : { "author" : "xcode", "version" : 1 } }
|
||||
@@ -0,0 +1 @@
|
||||
#import "ObjC/SPKTry.h"
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// The container app: what Sizzle installs as plugins, and an on-device check
|
||||
/// that each one loads and processes sound. The plugins themselves are used from
|
||||
/// a host (AUM, GarageBand, Loopy, …).
|
||||
struct ContentView: View {
|
||||
@StateObject private var check = PluginCheck()
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Sizzle").font(.system(.largeTitle, design: .monospaced)).foregroundColor(.orange)
|
||||
Text("AUv3 plugins for AUM, GarageBand, Loopy and other hosts.\nLook for \"Tired Sysadmin: Sizzle …\".")
|
||||
.font(.system(.footnote, design: .monospaced)).foregroundColor(.gray)
|
||||
Text(versionLine).font(.system(.caption, design: .monospaced)).foregroundColor(.gray)
|
||||
Button("Check all plugins") { Task { await check.run() } }
|
||||
.buttonStyle(.bordered).disabled(check.running)
|
||||
ScrollView {
|
||||
Text(check.lines.joined(separator: "\n"))
|
||||
.font(.system(.footnote, design: .monospaced))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.preferredColorScheme(.dark)
|
||||
.onAppear { check.listInstalled() }
|
||||
}
|
||||
|
||||
private var versionLine: String {
|
||||
let v = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?"
|
||||
let b = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "?"
|
||||
return "version \(v) (\(b)) · iOS \(ProcessInfo.processInfo.operatingSystemVersionString)"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.cc.tiredsysadmin.ios.sizzle</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// Runs `block`, turning an Objective-C exception (AVAudioEngine raises them for
|
||||
/// misuse, and Swift can't catch them, so they crash the app) into a returned
|
||||
/// description. Returns nil when the block finished normally.
|
||||
NSString *_Nullable SPKTry(NS_NOESCAPE void (^block)(void));
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#import "SPKTry.h"
|
||||
|
||||
NSString *_Nullable SPKTry(NS_NOESCAPE void (^block)(void)) {
|
||||
@try {
|
||||
block();
|
||||
return nil;
|
||||
} @catch (NSException *e) {
|
||||
return [NSString stringWithFormat:@"%@: %@", e.name, e.reason ?: @"(no reason)"];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import AVFoundation
|
||||
|
||||
/// Lists Sizzle's registered plugins and, on request, loads each one out of
|
||||
/// process (as a host would) and renders a test signal through it offline.
|
||||
/// PASS = loads, output is finite, and not silent.
|
||||
@MainActor
|
||||
final class PluginCheck: ObservableObject {
|
||||
@Published var lines: [String] = []
|
||||
@Published var running = false
|
||||
|
||||
private static let manufacturer: FourCharCode = "Tsys".utf8.reduce(0) { ($0 << 8) | FourCharCode($1) }
|
||||
|
||||
private func installed() -> [AVAudioUnitComponent] {
|
||||
let any = AudioComponentDescription(componentType: 0, componentSubType: 0,
|
||||
componentManufacturer: Self.manufacturer,
|
||||
componentFlags: 0, componentFlagsMask: 0)
|
||||
return AVAudioUnitComponentManager.shared().components(matching: any)
|
||||
.filter { $0.audioComponentDescription.componentType == kAudioUnitType_Effect }
|
||||
}
|
||||
|
||||
func listInstalled() {
|
||||
let comps = installed()
|
||||
lines = ["Registered effects: \(comps.count)"] + comps.map { " \($0.name)" }
|
||||
}
|
||||
|
||||
func run() async {
|
||||
running = true
|
||||
defer { running = false }
|
||||
let comps = installed()
|
||||
lines = ["Checking \(comps.count) effects…"]
|
||||
var ok = 0
|
||||
for c in comps {
|
||||
let result = await check(c)
|
||||
if result.hasPrefix("PASS") { ok += 1 }
|
||||
lines.append("\(result) \(c.name.replacingOccurrences(of: "Tired Sysadmin: ", with: ""))")
|
||||
}
|
||||
lines.append("\(ok)/\(comps.count) passed")
|
||||
}
|
||||
|
||||
/// 1 s at 44.1 kHz stereo: a decaying saw burst, then noise, then silence.
|
||||
private func testBuffer(format: AVAudioFormat) -> AVAudioPCMBuffer {
|
||||
let n = AVAudioFrameCount(format.sampleRate)
|
||||
let buf = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: n)!
|
||||
buf.frameLength = n
|
||||
var seed: UInt32 = 0x1234567
|
||||
for i in 0..<Int(n) {
|
||||
let t = Double(i) / format.sampleRate
|
||||
var x: Float = 0
|
||||
if t < 0.3 { x = Float(0.6 * (2 * (t * 110).truncatingRemainder(dividingBy: 1) - 1) * exp(-t * 6)) }
|
||||
else if t < 0.6 { seed = seed &* 1103515245 &+ 12345; x = Float((seed >> 8) & 0xFFFF) / 65535 * 0.6 - 0.3 }
|
||||
for ch in 0..<Int(format.channelCount) { buf.floatChannelData![ch][i] = x }
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
private func check(_ comp: AVAudioUnitComponent) async -> String {
|
||||
do {
|
||||
let unit = try await AVAudioUnit.instantiate(with: comp.audioComponentDescription, options: .loadOutOfProcess)
|
||||
let engine = AVAudioEngine()
|
||||
let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)!
|
||||
let player = AVAudioPlayerNode()
|
||||
var thrown: Error?
|
||||
let ex = SPKTry {
|
||||
do {
|
||||
try engine.enableManualRenderingMode(.offline, format: format, maximumFrameCount: 4096)
|
||||
engine.attach(player)
|
||||
engine.attach(unit)
|
||||
engine.connect(player, to: unit, format: format)
|
||||
engine.connect(unit, to: engine.mainMixerNode, format: format)
|
||||
try engine.start()
|
||||
player.scheduleBuffer(self.testBuffer(format: format), completionHandler: nil)
|
||||
player.play()
|
||||
} catch { thrown = error }
|
||||
}
|
||||
if let ex = ex { return "FAIL exception \(ex)" }
|
||||
if let e = thrown { return "FAIL \(e.localizedDescription)" }
|
||||
let out = AVAudioPCMBuffer(pcmFormat: engine.manualRenderingFormat, frameCapacity: 4096)!
|
||||
var peak: Float = 0, finite = true
|
||||
for _ in 0..<11 {
|
||||
_ = try engine.renderOffline(4096, to: out)
|
||||
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)) }
|
||||
}
|
||||
}
|
||||
engine.stop()
|
||||
if !finite { return "FAIL non-finite output" }
|
||||
return peak > 0.01 ? String(format: "PASS peak %.2f", peak) : String(format: "FAIL silent (peak %.4f)", peak)
|
||||
} catch {
|
||||
return "FAIL \(error.localizedDescription)"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct SizzleApp: App {
|
||||
var body: some Scene { WindowGroup { ContentView() } }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# The AUv3 plugins the app ships. One line each:
|
||||
# <AU type> <subtype> <ToolboxType> <display name>
|
||||
# tools/gen_components.py turns this into app/FX/Info.plist (AudioComponents) and
|
||||
# app/FX/Components.gen.h (subtype -> ToolboxType); edit here, not there.
|
||||
# Manufacturer code for all of them: Tsys. Never change a subtype once shipped:
|
||||
# hosts save projects by these codes.
|
||||
aufx sBcr BITCRUSHER Bitcrusher
|
||||
aufx sFlt FILTER Filter
|
||||
aufx sEqx EQ10 10-Band EQ
|
||||
aufx sDly DELAY Tape Delay
|
||||
aufx sMxt MIX_TIGHTENER Mix Tightener
|
||||
aufx sTpe TAPE_ENGINE Tape Engine
|
||||
aufx sGrn GRANULAR Granular Glitch
|
||||
aufx sAmb AMBIENCE Ambience Reverb
|
||||
@@ -0,0 +1,66 @@
|
||||
# XcodeGen spec for Sizzle on iOS/iPadOS (see ios/README.md). `make -C ios project`
|
||||
# generates Sizzle.xcodeproj (git-ignored). Versions are passed in by the Makefile
|
||||
# from versions.properties (ios.versionName / ios.versionCode).
|
||||
name: Sizzle
|
||||
options:
|
||||
bundleIdPrefix: cc.tiredsysadmin.ios
|
||||
deploymentTarget:
|
||||
iOS: "15.0"
|
||||
settings:
|
||||
base:
|
||||
SWIFT_VERSION: "5.0"
|
||||
TARGETED_DEVICE_FAMILY: "1,2"
|
||||
ARCHS: arm64
|
||||
DEVELOPMENT_TEAM: ""
|
||||
CLANG_CXX_LANGUAGE_STANDARD: c++17
|
||||
CLANG_ENABLE_OBJC_ARC: YES
|
||||
HEADER_SEARCH_PATHS: ["$(SRCROOT)/../core/include", "$(SRCROOT)/../core/src/fx"]
|
||||
targets:
|
||||
SizzleCore:
|
||||
type: library.static
|
||||
platform: iOS
|
||||
sources:
|
||||
- path: ../core/src
|
||||
excludes: ["**/*.md"]
|
||||
settings:
|
||||
base:
|
||||
PRODUCT_NAME: SizzleCore
|
||||
GCC_OPTIMIZATION_LEVEL: s
|
||||
SizzleFX:
|
||||
type: app-extension
|
||||
platform: iOS
|
||||
sources: [FX]
|
||||
dependencies:
|
||||
- target: SizzleCore
|
||||
- sdk: AudioToolbox.framework
|
||||
- sdk: AVFoundation.framework
|
||||
- sdk: CoreAudioKit.framework
|
||||
- sdk: UIKit.framework
|
||||
settings:
|
||||
base:
|
||||
PRODUCT_BUNDLE_IDENTIFIER: cc.tiredsysadmin.ios.sizzle.fx
|
||||
CODE_SIGN_ENTITLEMENTS: FX/FX.entitlements
|
||||
INFOPLIST_FILE: FX/Info.plist
|
||||
# force_load: the effects are found through weak placeholder makers (Registry.cpp),
|
||||
# so without it the linker keeps the placeholders and skips the real ports.
|
||||
OTHER_LDFLAGS: ["-lc++", "-force_load", "$(BUILT_PRODUCTS_DIR)/libSizzleCore.a"]
|
||||
Sizzle:
|
||||
type: application
|
||||
platform: iOS
|
||||
sources: [Host]
|
||||
dependencies:
|
||||
- target: SizzleFX
|
||||
embed: true
|
||||
codeSign: false
|
||||
settings:
|
||||
base:
|
||||
PRODUCT_BUNDLE_IDENTIFIER: cc.tiredsysadmin.ios.sizzle
|
||||
CODE_SIGN_ENTITLEMENTS: Host/Host.entitlements
|
||||
GENERATE_INFOPLIST_FILE: YES
|
||||
INFOPLIST_KEY_CFBundleDisplayName: Sizzle
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation: YES
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations: "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad: "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
|
||||
SWIFT_OBJC_BRIDGING_HEADER: Host/Bridging.h
|
||||
@@ -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