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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user