feat(pedals): Neural Amp pedal (S3) + PedalState resource path; Lyrebird 1.7.1

Bump Lyrebird to 1.7.1 (ProteusModelImporter) and add a neural amp-capture pedal.

- NeuralAmpPedal: loads a GuitarML Proteus/NeuralPi model (via ProteusModelImporter)
  and runs it with LSTMAmp on the gain-trimmed input; passes through clean when no
  model is loaded. Model files are user-supplied, not bundled (GuitarML = GPL-3.0).
- PedalState gains an optional `resourcePath` (backward-compatible, decodeIfPresent)
  and Pedal a matching `resourcePath` property, wired through captureState/applyState
  — so the loaded model file persists across rig save/load. The neural pedal reads it
  at build() (applied on rebuild). This foundation also unblocks a future
  custom-cabinet-IR path.
- Registered in PedalRegistry / PedalType / PedalCategory (.gain) / palette /
  enclosure color; Help acknowledges the GuitarML model format.

Tests: no-model passthrough; loaded model transforms output & differs from
passthrough; gain affects modeled output; resourcePath round-trips through
PedalState; gain knob exposed; registry resolves "Neural Amp". Full suite 501.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 20:39:18 -07:00
parent fe31eb6d7d
commit 40fa590196
13 changed files with 271 additions and 8 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
{
"originHash" : "7d48b3cb04ded2905154feb906405cef4e190bcef981bdf1cacf3b92271d0960",
"originHash" : "bc2a61a4b15bd882ede79ecb295b7878eca7ce7b55f4832eaf9bd7e7f557dd4f",
"pins" : [
{
"identity" : "linenoise-swift",
@@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
"state" : {
"revision" : "3e33f09e0719dad95750de7c2b604ae97a826584",
"version" : "1.7.0"
"revision" : "ea0aa84ca796d9a21667e4b5a7d76a1ac2c280b6",
"version" : "1.7.1"
}
},
{
+1 -1
View File
@@ -24,7 +24,7 @@ let package = Package(
.library(name: "LyrebirdShoeGazeUI", targets: ["LyrebirdShoeGazeUI"]),
],
dependencies: [
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.7.0"),
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.7.1"),
],
targets: [
// The core target depends on LyrebirdUI as well as the synthesis core:
+5
View File
@@ -53,6 +53,11 @@ open class Pedal: SynthesizerBase {
/// Output gain as a linear multiplier. `1.0` = unity gain.
@UIParam public var level: Double = 1.0
/// Optional path to an external resource this pedal references (e.g. a neural-amp model file).
/// Not a `@UIParam` — it's a `String`, applied at `build()`, and persisted separately in
/// ``PedalState/resourcePath``. Default `nil`. Pedals that don't use an external file ignore it.
public var resourcePath: String?
// MARK: - Sample rate
/// Engine sample rate, injected by `PedalBoard.add(_:)` before the pedal is added
+1
View File
@@ -45,6 +45,7 @@ public extension PedalType {
// Drive & dynamics
static let amp = PedalType("Amp")
static let neuralAmp = PedalType("Neural Amp")
static let overdrive = PedalType("Overdrive")
static let distortion = PedalType("Distortion")
static let fuzz = PedalType("Fuzz")
@@ -0,0 +1,120 @@
// NeuralAmpPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
import LyrebirdSynth
import LyrebirdUI
/// Neural amp/pedal capture player: runs a GuitarML Proteus / NeuralPi LSTM model on the input.
///
/// Load a model with ``loadModel(path:)`` (or set ``Pedal/resourcePath``); the file path is
/// persisted in the rig, so a saved rig reloads the same capture. With no model loaded the pedal
/// passes the signal through clean.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → × gain → LSTMAmp(model) → mono out (model loaded)
/// dry → mono out (no model)
/// ```
///
/// The model is read and built at `build()` (off the RT thread); changing it takes effect on the
/// next rebuild. Fully wet when a model is loaded; `Level` is the master.
///
/// > Model files are **user-supplied and not bundled** — GuitarML models are GPL-3.0. Download a
/// > capture (e.g. from the GuitarML Tone Library or Tone3000) and point the pedal at it.
///
/// ## Parameters
///
/// Inherits `bypass` and `level` (master) from `Pedal`, plus:
/// - `gain`: Input drive into the model (linear). Range `[0.25, 4]`.
public final class NeuralAmpPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Plays a neural amp/pedal capture (GuitarML Proteus / NeuralPi model)."
}
/// Fully wet when a model is loaded; hide the Mix control.
public override var showsMixControl: Bool { false }
// MARK: - Parameters
/// Input drive into the model (linear multiplier). Range [0.25, 4].
@UIParam public var gain: Double = 1.0
// MARK: - Constants
private static let defaultMix: Double = 1.0
private let gainRange: ClosedRange<Double> = 0.25 ... 4.0
/// Caches the parsed model per path so a stereo-region build (which calls `effect(_:)` once
/// per channel) reads and decodes the file only once. Keyed on the path so a model change
/// re-parses. Touched only at `build()` on the main thread.
private var loadedModel: (path: String, model: NeuralAmpModel)?
// MARK: - Init
/// Creates a neural amp pedal.
///
/// - Parameters:
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
public init(
inputBus: Int = 0,
outputBus: Int = 0
) {
super.init(
name: "Neural Amp",
inputBus: inputBus,
outputBus: outputBus,
initialMix: NeuralAmpPedal.defaultMix
)
}
/// Points the pedal at a Proteus/NeuralPi model file. Takes effect on the next rebuild.
///
/// - Parameter path: Filesystem path to the model `.json`.
public func loadModel(path: String) {
resourcePath = path
}
// MARK: - UI
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Gain", node: $gain, range: gainRange),
]
}
// MARK: - Effect
/// Runs the loaded model on the (gain-trimmed) input; passes through clean if no model is set
/// or the file can't be read/parsed.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: The model output, or the dry signal when no model is loaded.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
guard let path: String = resourcePath, let model: NeuralAmpModel = resolveModel(path: path) else {
return dry
}
let driven: any ValidGeneratorInput = dry * $gain
return LSTMAmp(input: driven, model: model)
}
/// Loads (and caches) the model at `path`, or returns `nil` if the file is missing/unparsable.
private func resolveModel(path: String) -> NeuralAmpModel? {
if let cached: (path: String, model: NeuralAmpModel) = loadedModel, cached.path == path {
return cached.model
}
guard let data: Data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let model: NeuralAmpModel = try? ProteusModelImporter.model(fromProteusJSON: data)
else {
return nil
}
loadedModel = (path, model)
return model
}
}
@@ -28,7 +28,8 @@ extension Pedal {
sliderValues: sliderValues,
selectorValues: selectorValues,
bypass: bypass,
tempoSync: tempoSync.isEmpty ? nil : tempoSync
tempoSync: tempoSync.isEmpty ? nil : tempoSync,
resourcePath: resourcePath
)
}
@@ -66,5 +67,6 @@ extension Pedal {
// tempo by `ShoeGaze` after the rebuild, so no clock is required here.
tempoSync = state.tempoSync ?? [:]
tempoSyncRevision.bump()
resourcePath = state.resourcePath
}
}
@@ -32,6 +32,7 @@ public enum PedalRegistry {
/// to a board via `board.add(_:)`.
public static let builtIn: [String: @MainActor () -> Pedal] = [
"Amp": { AmpPedal() },
"Neural Amp": { NeuralAmpPedal() },
"Overdrive": { OverdrivePedal() },
"Distortion": { DistortionPedal() },
"Delay": { DelayPedal() },
@@ -50,6 +50,10 @@ public struct PedalState: Codable, Equatable {
/// decode to "all parameters free".
public let tempoSync: [String: TempoSync]?
/// Optional path to an external resource the pedal references (e.g. a neural-amp model file).
/// `nil` for pedals that use no external file, and for presets saved before this existed.
public let resourcePath: String?
/// Creates a pedal state snapshot.
///
/// - Parameters:
@@ -60,6 +64,8 @@ public struct PedalState: Codable, Equatable {
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
/// - tempoSync: Tempo-sync state per syncable parameter, or `nil` for none. Defaults to `nil`.
/// - resourcePath: Path to an external resource the pedal references (e.g. a neural-amp
/// model file), or `nil`. Defaults to `nil`.
public init(
id: UUID = UUID(),
type: String,
@@ -68,7 +74,8 @@ public struct PedalState: Codable, Equatable {
sliderValues: [Double] = [],
selectorValues: [Double] = [],
bypass: Double,
tempoSync: [String: TempoSync]? = nil
tempoSync: [String: TempoSync]? = nil,
resourcePath: String? = nil
) {
self.id = id
self.type = type
@@ -78,6 +85,7 @@ public struct PedalState: Codable, Equatable {
self.selectorValues = selectorValues
self.bypass = bypass
self.tempoSync = tempoSync
self.resourcePath = resourcePath
}
private enum CodingKeys: String, CodingKey {
@@ -89,6 +97,7 @@ public struct PedalState: Codable, Equatable {
case selectorValues
case bypass
case tempoSync
case resourcePath
}
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
@@ -103,5 +112,6 @@ public struct PedalState: Codable, Equatable {
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
self.bypass = try container.decode(Double.self, forKey: .bypass)
self.tempoSync = try container.decodeIfPresent([String: TempoSync].self, forKey: .tempoSync)
self.resourcePath = try container.decodeIfPresent(String.self, forKey: .resourcePath)
}
}
@@ -181,6 +181,9 @@ public struct HelpView: View {
"The Amp pedal's tone stack follows the Yeh & Smith analysis of the Fender/Marshall/Vox "
+ "tone-stack circuit (\"Discretization of the '59 Fender Bassman Tone Stack\", DAFx-06); "
+ "its models are original code, not captures of specific hardware.",
"The Neural Amp pedal loads GuitarML Proteus / NeuralPi capture models (the open LSTM "
+ "format from github.com/GuitarML). You supply the model file; none are bundled, and "
+ "those models are licensed by their respective authors.",
]
)
}
@@ -42,7 +42,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
}
private static let mapping: [String: PedalCategory] = [
"Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
"Amp": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
"Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics,
"Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter,
"Cabinet": .filter,
@@ -54,7 +54,7 @@ public struct PedalPaletteView: View {
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
private static let preferredOrder: [String] = [
"Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
"Amp", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
"Volume",
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
"Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
@@ -17,6 +17,7 @@ import LyrebirdShoeGaze
private func enclosureColor(for displayName: String) -> Color {
switch displayName {
case "Amp": return Color(red: 0.18, green: 0.17, blue: 0.20) // amp-head charcoal
case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
case "Delay": return Color(red: 0.10, green: 0.55, blue: 0.55) // teal
@@ -0,0 +1,120 @@
// NeuralAmpPedalTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
@MainActor
@Suite("NeuralAmpPedal")
struct NeuralAmpPedalTests {
private let sampleRate: Double = 48000.0
/// Writes a small, deterministic Proteus/NeuralPi-format model JSON to a temp file and returns
/// its path. Weights are arbitrary-but-fixed (a real capture is not needed to exercise the
/// load → import → LSTMAmp path).
private func writeTempModel(hidden h: Int) throws -> String {
let gated: Int = 4 * h
let weightIH: [[Double]] = (0..<gated).map { [0.1 * sin(Double($0) + 1.0)] }
let weightHH: [[Double]] = (0..<gated).map { r in (0..<h).map { 0.05 * cos(Double(r * h + $0) + 1.0) } }
let biasIH: [Double] = (0..<gated).map { 0.01 * Double($0) }
let biasHH: [Double] = [Double](repeating: 0.0, count: gated)
let linWeight: [[Double]] = [(0..<h).map { 0.3 * sin(Double($0) + 0.5) }]
let object: [String: Any] = [
"model_data": [
"unit_type": "LSTM", "input_size": 1, "hidden_size": h,
"num_layers": 1, "output_size": 1, "skip": 1,
],
"state_dict": [
"rec.weight_ih_l0": weightIH,
"rec.weight_hh_l0": weightHH,
"rec.bias_ih_l0": biasIH,
"rec.bias_hh_l0": biasHH,
"lin.weight": linWeight,
"lin.bias": [0.05],
],
]
let data: Data = try JSONSerialization.data(withJSONObject: object)
let url: URL = FileManager.default.temporaryDirectory
.appendingPathComponent("neuralamp-test-\(h)-\(UUID().uuidString).json")
try data.write(to: url)
return url.path
}
private func render(configure: (NeuralAmpPedal) -> Void = { _ in }) throws -> [Float] {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.15, sampleRate: sampleRate, numAudioBuses: 64)
defer { try? FileManager.default.removeItem(at: url) }
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer {
engine.busAllocator.releaseAudioBus(srcBus)
engine.busAllocator.releaseAudioBus(dstBus)
}
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
let pedal: NeuralAmpPedal = NeuralAmpPedal(inputBus: srcBus.index, outputBus: dstBus.index)
pedal.sampleRate = sampleRate
configure(pedal)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(source)
try engine.add(pedal, position: NodePosition.after(source))
try engine.add(master, position: NodePosition.after(pedal))
try engine.start()
return readStereoCAF(url: url, sampleRate: sampleRate)
}
private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 2048, window: Int = 2048) -> Double {
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
let d: Double = Double(pair.0 - pair.1); return acc + d * d
}
}
@Test func noModelPassesThroughNonSilent() throws {
let out: [Float] = try render()
#expect(hasNonSilentOutput(out), "no-model passthrough was silent")
#expect(out.allSatisfy { $0.isFinite })
}
@Test func loadedModelTransformsAndDiffersFromPassthrough() throws {
let path: String = try writeTempModel(hidden: 8)
defer { try? FileManager.default.removeItem(atPath: path) }
let passthrough: [Float] = try render()
let modeled: [Float] = try render { $0.resourcePath = path }
#expect(hasNonSilentOutput(modeled), "modeled output was silent")
#expect(modeled.allSatisfy { $0.isFinite })
#expect(windowedSSD(passthrough, modeled) > 0, "loaded model did not change the output")
}
@Test func gainChangesModeledOutput() throws {
let path: String = try writeTempModel(hidden: 8)
defer { try? FileManager.default.removeItem(atPath: path) }
let low: [Float] = try render { $0.resourcePath = path; $0.gain = 0.5 }
let high: [Float] = try render { $0.resourcePath = path; $0.gain = 3.0 }
#expect(windowedSSD(low, high) > 0, "gain had no effect on modeled output")
}
@Test func resourcePathRoundTripsThroughState() throws {
let pedal: NeuralAmpPedal = NeuralAmpPedal()
pedal.resourcePath = "/some/model.json"
let restored: NeuralAmpPedal = NeuralAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.resourcePath == "/some/model.json", "resourcePath did not round-trip")
}
@Test func exposesGainKnob() throws {
let pedal: NeuralAmpPedal = NeuralAmpPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Gain"])
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "Neural Amp")
#expect(pedal is NeuralAmpPedal)
}
}