Files
sizzletracker-android/ios/app/Host/PluginCheck.swift
T
ReactorcoremeltdownandClaude Opus 5.5 dcf85ba915 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>
2026-11-14 20:47:06 +01:00

97 lines
4.4 KiB
Swift

// 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)"
}
}
}