// 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..> 8) & 0xFFFF) / 65535 * 0.6 - 0.3 } for ch in 0.. 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.. 0.01 ? String(format: "PASS peak %.2f", peak) : String(format: "FAIL silent (peak %.4f)", peak) } catch { return "FAIL \(error.localizedDescription)" } } }