Files
sizzletracker-android/ios/app/Host/PluginCheck.swift
T
ReactorcoremeltdownandClaude Opus 5.5 7d8311a77f iOS 0.1.1: effects read the input where the host puts it (were silent out of process)
Out of process the pulled input arrives by pointer, not in the buffers the
plugin offered. au_test now drives the render block with such an upstream;
it fails on 0.1.0 and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 21:07:05 +01:00

98 lines
4.5 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 {
let status = try engine.renderOffline(4096, to: out)
if status != .success { engine.stop(); return "FAIL render status \(status.rawValue)" }
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)"
}
}
}