iOS: TrollStore AUv3 spike (host app + sine AUv3 + App Group self-test)
Separate tree under ios/ with its own Makefile: XcodeGen project, unsigned device build ad-hoc signed with entitlements and packed as an .ipa. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0c09c3a0f3
commit
77d6e459b2
@@ -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.sizzlespike</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import CoreAudioKit
|
||||
import UIKit
|
||||
|
||||
/// The extension's principal class: the AU factory and its (minimal) view.
|
||||
public final class AudioUnitViewController: AUViewController, AUAudioUnitFactory {
|
||||
private var audioUnit: AUAudioUnit?
|
||||
|
||||
public func createAudioUnit(with componentDescription: AudioComponentDescription) throws -> AUAudioUnit {
|
||||
let au = try SpikeAudioUnit(componentDescription: componentDescription, options: [])
|
||||
audioUnit = au
|
||||
return au
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
preferredContentSize = CGSize(width: 400, height: 220)
|
||||
view.backgroundColor = UIColor(red: 0.08, green: 0.09, blue: 0.10, alpha: 1)
|
||||
let label = UILabel()
|
||||
label.numberOfLines = 0
|
||||
label.font = .monospacedSystemFont(ofSize: 12, weight: .regular)
|
||||
label.textColor = UIColor(red: 0.96, green: 0.76, blue: 0.29, alpha: 1)
|
||||
label.text = "Sizzle Spike Sine (AUv3)\nPlay notes from the host.\n\n" + Spike.probeGroup(as: "au-view")
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(label)
|
||||
NSLayoutConstraint.activate([
|
||||
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 12),
|
||||
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -12),
|
||||
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 12),
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Sizzle Spike AU</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 Spike Sine</string>
|
||||
<key>factoryFunction</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).AudioUnitViewController</string>
|
||||
<key>manufacturer</key>
|
||||
<string>Tsys</string>
|
||||
<key>name</key>
|
||||
<string>Tired Sysadmin: Sizzle Spike Sine</string>
|
||||
<key>sandboxSafe</key>
|
||||
<true/>
|
||||
<key>subtype</key>
|
||||
<string>sSpk</string>
|
||||
<key>tags</key>
|
||||
<array>
|
||||
<string>Synthesizer</string>
|
||||
</array>
|
||||
<key>type</key>
|
||||
<string>aumu</string>
|
||||
<key>version</key>
|
||||
<integer>65536</integer>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.AudioUnit-UI</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).AudioUnitViewController</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import AudioToolbox
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
|
||||
/// State the render block touches. Allocated before rendering starts; the render
|
||||
/// block only reads and writes these fields (no allocation, no locks).
|
||||
final class SineKernel {
|
||||
var sampleRate: Double = 44_100
|
||||
var phase: Double = 0
|
||||
var freq: Double = 440
|
||||
var env: Float = 0
|
||||
var gate = false
|
||||
var gain: Float = 0.3
|
||||
/// Our own output memory for hosts that pass buffers with nil mData.
|
||||
var scratch = UnsafeMutablePointer<Float>.allocate(capacity: 2 * 4096)
|
||||
deinit { scratch.deallocate() }
|
||||
}
|
||||
|
||||
/// The spike's instrument: one sine voice, MIDI note on/off, one Gain parameter.
|
||||
public final class SpikeAudioUnit: AUAudioUnit {
|
||||
private let kernel = SineKernel()
|
||||
private var outBus: AUAudioUnitBus!
|
||||
private var busses: AUAudioUnitBusArray!
|
||||
private var tree: AUParameterTree!
|
||||
|
||||
public override init(componentDescription: AudioComponentDescription,
|
||||
options: AudioComponentInstantiationOptions = []) throws {
|
||||
try super.init(componentDescription: componentDescription, options: options)
|
||||
let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)!
|
||||
outBus = try AUAudioUnitBus(format: format)
|
||||
outBus.maximumChannelCount = 2
|
||||
busses = AUAudioUnitBusArray(audioUnit: self, busType: .output, busses: [outBus])
|
||||
|
||||
let gain = AUParameterTree.createParameter(
|
||||
withIdentifier: "gain", name: "Gain", address: 0, min: 0, max: 1,
|
||||
unit: .linearGain, unitName: nil, flags: [.flag_IsReadable, .flag_IsWritable],
|
||||
valueStrings: nil, dependentParameters: nil)
|
||||
tree = AUParameterTree.createTree(withChildren: [gain])
|
||||
let k = kernel
|
||||
tree.implementorValueObserver = { p, v in if p.address == 0 { k.gain = v } }
|
||||
tree.implementorValueProvider = { p in p.address == 0 ? k.gain : 0 }
|
||||
maximumFramesToRender = 4096
|
||||
|
||||
// Prove the extension side can write the App Group too.
|
||||
_ = Spike.probeGroup(as: "au")
|
||||
}
|
||||
|
||||
public override var outputBusses: AUAudioUnitBusArray { busses }
|
||||
public override var parameterTree: AUParameterTree? { get { tree } set { } }
|
||||
|
||||
public override func allocateRenderResources() throws {
|
||||
try super.allocateRenderResources()
|
||||
kernel.sampleRate = outBus.format.sampleRate
|
||||
if maximumFramesToRender > 4096 {
|
||||
kernel.scratch.deallocate()
|
||||
kernel.scratch = .allocate(capacity: 2 * Int(maximumFramesToRender))
|
||||
}
|
||||
}
|
||||
|
||||
public override var internalRenderBlock: AUInternalRenderBlock {
|
||||
let k = kernel
|
||||
return { _, _, frameCount, _, outputData, eventList, _ in
|
||||
// MIDI (applied at the start of the block; good enough for a spike)
|
||||
var ev = eventList
|
||||
while let e = ev {
|
||||
if e.pointee.head.eventType == .MIDI {
|
||||
let m = e.pointee.MIDI
|
||||
let status = m.data.0 & 0xF0, note = m.data.1, vel = m.data.2
|
||||
if status == 0x90 && vel > 0 {
|
||||
k.freq = 440 * pow(2, (Double(note) - 69) / 12); k.gate = true
|
||||
} else if status == 0x80 || status == 0x90 {
|
||||
k.gate = false
|
||||
}
|
||||
}
|
||||
ev = UnsafePointer(e.pointee.head.next)
|
||||
}
|
||||
let abl = UnsafeMutableAudioBufferListPointer(outputData)
|
||||
for j in 0..<abl.count where abl[j].mData == nil {
|
||||
abl[j].mData = UnsafeMutableRawPointer(k.scratch + j * Int(frameCount))
|
||||
abl[j].mDataByteSize = frameCount * 4
|
||||
}
|
||||
let inc = 2 * Double.pi * k.freq / k.sampleRate
|
||||
for i in 0..<Int(frameCount) {
|
||||
k.env += ((k.gate ? 1 : 0) - k.env) * 0.002
|
||||
let s = Float(sin(k.phase)) * k.env * k.gain
|
||||
k.phase += inc
|
||||
if k.phase > 2 * Double.pi { k.phase -= 2 * Double.pi }
|
||||
for j in 0..<abl.count { abl[j].mData!.assumingMemoryBound(to: Float.self)[i] = s }
|
||||
}
|
||||
return noErr
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.sizzlespike</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@StateObject private var test = SelfTest()
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Sizzle AUv3 spike").font(.system(.title2, design: .monospaced)).foregroundColor(.orange)
|
||||
Text("In AUM / GarageBand / Loopy look for\n\"Tired Sysadmin: Sizzle Spike Sine\" (instrument).")
|
||||
.font(.system(.footnote, design: .monospaced)).foregroundColor(.gray)
|
||||
HStack {
|
||||
Button("Run self-test") { Task { await test.run() } }
|
||||
Button("Play tone (1 s)") { Task { await test.playTone() } }
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
ScrollView {
|
||||
Text(test.lines.joined(separator: "\n"))
|
||||
.font(.system(.footnote, design: .monospaced))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.preferredColorScheme(.dark)
|
||||
.task { await test.run() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import AVFoundation
|
||||
import os
|
||||
|
||||
/// Answers the spike's questions on the device itself:
|
||||
/// 1. did iOS register the extension's Audio Unit (what hosts will list)?
|
||||
/// 2. does it load out of process and render sound?
|
||||
/// 3. can the app and the extension share files through the App Group?
|
||||
@MainActor
|
||||
final class SelfTest: ObservableObject {
|
||||
@Published var lines: [String] = []
|
||||
private let log = Logger(subsystem: "cc.tiredsysadmin.ios.sizzlespike", category: "selftest")
|
||||
private var liveEngine: AVAudioEngine?
|
||||
|
||||
private func say(_ s: String) {
|
||||
lines.append(s)
|
||||
log.notice("\(s, privacy: .public)")
|
||||
}
|
||||
|
||||
func run() async {
|
||||
lines = []
|
||||
let os = ProcessInfo.processInfo.operatingSystemVersionString
|
||||
say("iOS \(os)")
|
||||
|
||||
// 1. Registration
|
||||
let all = AVAudioUnitComponentManager.shared().components(matching: Spike.desc)
|
||||
say("[1] Registered components matching Tsys/sSpk: \(all.count) \(all.isEmpty ? "FAIL" : "PASS")")
|
||||
for c in all { say(" \(c.name) v\(c.versionString), type \(c.typeName)") }
|
||||
|
||||
// 3a. App Group from the app side (before the AU writes)
|
||||
say("[3] " + Spike.probeGroup(as: "app"))
|
||||
|
||||
// 2. Load out of process, render 1 s offline (silent), measure the peak
|
||||
do {
|
||||
let unit = try await AVAudioUnit.instantiate(with: Spike.desc, options: .loadOutOfProcess)
|
||||
say("[2] Instantiated \"\(unit.auAudioUnit.audioUnitName ?? "?")\" out of process: PASS")
|
||||
let engine = AVAudioEngine()
|
||||
let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)!
|
||||
try engine.enableManualRenderingMode(.offline, format: format, maximumFrameCount: 4096)
|
||||
engine.attach(unit)
|
||||
engine.connect(unit, to: engine.mainMixerNode, format: format)
|
||||
try engine.start()
|
||||
(unit as? AVAudioUnitMIDIInstrument)?.startNote(69, withVelocity: 100, onChannel: 0)
|
||||
let buf = AVAudioPCMBuffer(pcmFormat: engine.manualRenderingFormat, frameCapacity: 4096)!
|
||||
var peak: Float = 0
|
||||
for _ in 0..<11 {
|
||||
_ = try engine.renderOffline(4096, to: buf)
|
||||
let ch = buf.floatChannelData![0]
|
||||
for i in 0..<Int(buf.frameLength) { peak = max(peak, abs(ch[i])) }
|
||||
}
|
||||
engine.stop()
|
||||
say(String(format: "[2] Rendered 1 s offline, peak %.3f: %@", peak, peak > 0.05 ? "PASS" : "FAIL"))
|
||||
} catch {
|
||||
say("[2] FAIL: \(error.localizedDescription) (\((error as NSError).code))")
|
||||
}
|
||||
|
||||
// 3b. The AU wrote au.txt when it was created; read it back from the app side
|
||||
say("[3] after AU load: " + Spike.probeGroup(as: "app"))
|
||||
}
|
||||
|
||||
/// Audible check through the speaker, using the same out-of-process AU.
|
||||
func playTone() async {
|
||||
do {
|
||||
try AVAudioSession.sharedInstance().setCategory(.playback)
|
||||
try AVAudioSession.sharedInstance().setActive(true)
|
||||
let unit = try await AVAudioUnit.instantiate(with: Spike.desc, options: .loadOutOfProcess)
|
||||
let engine = AVAudioEngine()
|
||||
engine.attach(unit)
|
||||
engine.connect(unit, to: engine.mainMixerNode, format: nil)
|
||||
try engine.start()
|
||||
liveEngine = engine
|
||||
let inst = unit as? AVAudioUnitMIDIInstrument
|
||||
inst?.startNote(69, withVelocity: 100, onChannel: 0)
|
||||
try await Task.sleep(nanoseconds: 1_000_000_000)
|
||||
inst?.stopNote(69, onChannel: 0)
|
||||
try await Task.sleep(nanoseconds: 300_000_000)
|
||||
engine.stop()
|
||||
liveEngine = nil
|
||||
say("Played A4 for 1 s")
|
||||
} catch {
|
||||
say("Play FAIL: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct SpikeApp: App {
|
||||
var body: some Scene { WindowGroup { ContentView() } }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import AudioToolbox
|
||||
import Foundation
|
||||
|
||||
/// What the app and the extension agree on: the App Group and the AU's identity.
|
||||
enum Spike {
|
||||
static let group = "group.cc.tiredsysadmin.ios.sizzlespike"
|
||||
|
||||
/// 'aumu' / 'sSpk' / 'Tsys' — must match AU/Info.plist.
|
||||
static let desc = AudioComponentDescription(
|
||||
componentType: kAudioUnitType_MusicDevice,
|
||||
componentSubType: fourCC("sSpk"),
|
||||
componentManufacturer: fourCC("Tsys"),
|
||||
componentFlags: 0, componentFlagsMask: 0)
|
||||
|
||||
static func fourCC(_ s: String) -> FourCharCode {
|
||||
s.utf8.reduce(0) { ($0 << 8) | FourCharCode($1) }
|
||||
}
|
||||
|
||||
/// Writes `<who>.txt` into the App Group container and reports every file in it,
|
||||
/// so each side shows what the other one wrote.
|
||||
static func probeGroup(as who: String) -> String {
|
||||
guard let dir = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group) else {
|
||||
return "App Group \(group): NOT AVAILABLE (entitlement missing or not honoured)"
|
||||
}
|
||||
let stamp = ISO8601DateFormatter().string(from: Date())
|
||||
let wrote = (try? "\(who) was here at \(stamp)\n".write(to: dir.appendingPathComponent("\(who).txt"),
|
||||
atomically: true, encoding: .utf8)) != nil
|
||||
var out = "App Group OK, \(who) write \(wrote ? "OK" : "FAILED")"
|
||||
let files = (try? FileManager.default.contentsOfDirectory(atPath: dir.path).sorted()) ?? []
|
||||
for f in files where f.hasSuffix(".txt") {
|
||||
let text = (try? String(contentsOf: dir.appendingPathComponent(f), encoding: .utf8)) ?? "?"
|
||||
out += "\n \(f): \(text.trimmingCharacters(in: .whitespacesAndNewlines))"
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# XcodeGen spec for the TrollStore AUv3 spike (see ios/README.md).
|
||||
# `make -C ios project` turns this into SizzleSpike.xcodeproj; never edit the
|
||||
# generated project by hand.
|
||||
name: SizzleSpike
|
||||
options:
|
||||
bundleIdPrefix: cc.tiredsysadmin.ios
|
||||
deploymentTarget:
|
||||
iOS: "15.0"
|
||||
settings:
|
||||
base:
|
||||
MARKETING_VERSION: "0.1.0"
|
||||
CURRENT_PROJECT_VERSION: "1"
|
||||
SWIFT_VERSION: "5.0"
|
||||
TARGETED_DEVICE_FAMILY: "1,2"
|
||||
ARCHS: arm64
|
||||
DEVELOPMENT_TEAM: ""
|
||||
targets:
|
||||
SizzleSpike:
|
||||
type: application
|
||||
platform: iOS
|
||||
sources: [App, Shared]
|
||||
dependencies:
|
||||
- target: SizzleSpikeAU
|
||||
embed: true
|
||||
codeSign: false
|
||||
settings:
|
||||
base:
|
||||
PRODUCT_BUNDLE_IDENTIFIER: cc.tiredsysadmin.ios.sizzlespike
|
||||
CODE_SIGN_ENTITLEMENTS: App/App.entitlements
|
||||
GENERATE_INFOPLIST_FILE: YES
|
||||
INFOPLIST_KEY_CFBundleDisplayName: Sizzle Spike
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation: YES
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations: "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad: "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"
|
||||
INFOPLIST_KEY_UIBackgroundModes: audio
|
||||
SizzleSpikeAU:
|
||||
type: app-extension
|
||||
platform: iOS
|
||||
sources: [AU, Shared]
|
||||
settings:
|
||||
base:
|
||||
PRODUCT_BUNDLE_IDENTIFIER: cc.tiredsysadmin.ios.sizzlespike.au
|
||||
CODE_SIGN_ENTITLEMENTS: AU/AU.entitlements
|
||||
INFOPLIST_FILE: AU/Info.plist
|
||||
Reference in New Issue
Block a user