feat(pedals): component Amp pedal (S2) on Lyrebird 1.7

Bump Lyrebird dependency to 1.7.0 and add a full white-box amp built on its new
amp-modeling core.

AmpPedal chain: preamp TriodeStage(drive: gain) → ToneStack(bass/mid/treble,
model) → gentle power-amp TriodeStage → speaker-cabinet ConvolutionReverb. The
tone-stack model (Fender/Marshall/Vox) and cabinet voice are each built per
option and picked live with Select, so both round-trip through the rig save
format. Fully wet (Level is master; Mix hidden).

Controls: Gain, Bass, Mid, Treble knobs + Amp / Cab selectors. Registered in
PedalRegistry / PedalType / PedalCategory (.gain) / palette / enclosure color;
Help acknowledgments cite the Yeh & Smith tone-stack model.

Tests: builds/non-silent/finite; gain, tone, amp-model, and cab all change the
output; controls exposed; amp/cab selections round-trip through PedalState;
registry resolves "Amp". Full suite 494.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 20:06:28 -07:00
parent 77df1675cb
commit fe31eb6d7d
10 changed files with 287 additions and 6 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
{
"originHash" : "9365abc9e3bf41483a03dca1c6be0421a5ca41bff1a9db33c8ddc62b2de04ef1",
"originHash" : "7d48b3cb04ded2905154feb906405cef4e190bcef981bdf1cacf3b92271d0960",
"pins" : [
{
"identity" : "linenoise-swift",
@@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
"state" : {
"revision" : "d6875da2cb6628c4274454dd55a632dd76212759",
"version" : "1.6.4"
"revision" : "3e33f09e0719dad95750de7c2b604ae97a826584",
"version" : "1.7.0"
}
},
{
+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.6.4"),
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.7.0"),
],
targets: [
// The core target depends on LyrebirdUI as well as the synthesis core:
+1
View File
@@ -44,6 +44,7 @@ public struct PedalType: RawRepresentable, Hashable, Sendable {
public extension PedalType {
// Drive & dynamics
static let amp = PedalType("Amp")
static let overdrive = PedalType("Overdrive")
static let distortion = PedalType("Distortion")
static let fuzz = PedalType("Fuzz")
@@ -0,0 +1,168 @@
// AmpPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// A full component-style guitar amp: preamp tube stage → tone stack → power-amp tube stage →
/// speaker cabinet, all white-box (no neural capture).
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → TriodeStage(drive: gain) (preamp)
/// → ToneStack(bass, mid, treble, model) (tone stack — Fender/Marshall/Vox, live-selectable)
/// → TriodeStage(power-amp drive) (power-amp warmth)
/// → ConvolutionReverb(cab IR) (speaker cabinet — live-selectable voice)
/// → mono out
/// ```
///
/// The tone-stack model and cabinet voice are each built once per option at `build()` and picked
/// live with a `Select` (so both round-trip through the rig save format). The amp is fully wet;
/// `Level` is the master volume. Built on Lyrebird 1.7's `TriodeStage` / `ToneStack` plus
/// ShoeGaze's synthesized cabinet IRs.
///
/// > Note: `Select` evaluates *all* its inputs every block (SC parity — keeps state in sync), so
/// > every tone-stack model **and** every cabinet convolver runs continuously, not just the
/// > selected one. That is a few extra IIRs plus one partitioned-FFT convolver per unselected
/// > cabinet voice — a real (but bounded) CPU cost that scales with the number of voices. The
/// > cabinet IRs are synthesized at `build()` for the injected `sampleRate`; a live engine
/// > sample-rate change takes effect on the next rebuild.
///
/// ## Parameters
///
/// Inherits `bypass` and `level` (master) from `Pedal`, plus:
///
/// - `gain`: Preamp drive. Range `[1, 30]`.
/// - `bass` / `mid` / `treble`: Tone-stack controls in `[0, 1]`.
/// - `amp`: Tone-stack model (Fender / Marshall / Vox).
/// - `cab`: Speaker-cabinet voice.
public final class AmpPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Full tube amp — preamp, tone stack, power amp, and speaker cabinet in one."
}
/// The amp is fully wet (it replaces the dry signal); hide the Mix control.
public override var showsMixControl: Bool { false }
// MARK: - Parameters
/// Preamp drive into the first tube stage. Range [1, 30].
@UIParam public var gain: Double = 6.0
/// Tone-stack bass control in [0, 1].
@UIParam public var bass: Double = 0.5
/// Tone-stack mid control in [0, 1].
@UIParam public var mid: Double = 0.5
/// Tone-stack treble control in [0, 1].
@UIParam public var treble: Double = 0.6
/// Selected tone-stack model as an index into `ToneStackModel.allCases`.
@UIParam public var amp: Double = 0.0
/// Selected cabinet voice as an index into `CabinetVoice.allCases`.
@UIParam public var cab: Double = 0.0
// MARK: - Constants
private static let defaultMix: Double = 1.0
/// Preamp grid bias — a little asymmetry for even-harmonic warmth.
private let preampBias: Double = 0.2
/// Fixed power-amp stage drive and bias (gentler than the preamp).
private let powerAmpDrive: Double = 1.5
private let powerAmpBias: Double = 0.0
/// Fully-wet convolution; the base class provides bypass and master level.
private let cabinetMix: Double = 1.0
/// Gain knob range.
private let gainRange: ClosedRange<Double> = 1.0 ... 30.0
private let toneRange: ClosedRange<Double> = 0.0 ... 1.0
private static let ampStops: [PedalSelectorKnob.Stop] = ToneStackModel.allCases
.enumerated()
.map { (index: Int, model: ToneStackModel) in
PedalSelectorKnob.Stop(title: model.displayName, value: Double(index))
}
private static let cabStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
.enumerated()
.map { (index: Int, voice: CabinetVoice) in
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
}
// MARK: - Init
/// Creates an 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: "Amp",
inputBus: inputBus,
outputBus: outputBus,
initialMix: AmpPedal.defaultMix
)
}
// MARK: - UI
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Gain", node: $gain, range: gainRange),
PedalKnob(label: "Bass", node: $bass, range: toneRange),
PedalKnob(label: "Mid", node: $mid, range: toneRange),
PedalKnob(label: "Treble", node: $treble, range: toneRange),
]
}
public override var effectSelectors: [PedalSelectorKnob] {
[
PedalSelectorKnob(label: "Amp", node: $amp, stops: AmpPedal.ampStops),
PedalSelectorKnob(label: "Cab", node: $cab, stops: AmpPedal.cabStops),
]
}
// MARK: - Effect
/// Preamp → tone stack (model-selected) → power amp → cabinet (voice-selected).
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: The amped, cab-convolved mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
let sr: Double = sampleRate
// Preamp tube stage.
let preamp: TriodeStage = TriodeStage(input: dry, drive: $gain, bias: preampBias, oversample: 4)
// Tone stack — one per model, picked live.
let toneStacks: [any ValidGeneratorInput] = ToneStackModel.allCases.map { (model: ToneStackModel) in
ToneStack(input: preamp, bass: $bass, mid: $mid, treble: $treble, model: model)
}
let toned: Select.Audio = Select.Audio(which: $amp, inputs: toneStacks)
// Power-amp tube stage (fixed, gentle).
let powerAmp: TriodeStage = TriodeStage(input: toned, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2)
// Speaker cabinet — one convolver per voice, picked live.
let cabinets: [any ValidGeneratorInput] = CabinetVoice.allCases.map { (voice: CabinetVoice) in
ConvolutionReverb.Audio(
input: powerAmp,
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
mix: cabinetMix
)
}
return Select.Audio(which: $cab, inputs: cabinets)
}
}
@@ -31,6 +31,7 @@ public enum PedalRegistry {
/// `ShoeGaze.loadRig(from:)` updates `inputBus`/`outputBus` when adding the pedal
/// to a board via `board.add(_:)`.
public static let builtIn: [String: @MainActor () -> Pedal] = [
"Amp": { AmpPedal() },
"Overdrive": { OverdrivePedal() },
"Distortion": { DistortionPedal() },
"Delay": { DelayPedal() },
@@ -178,6 +178,9 @@ public struct HelpView: View {
+ "built-in speaker impulse responses.",
"The Cabinet pedal's built-in cab voicings are original impulse responses generated in "
+ "code — not captures of any third-party hardware or IR pack.",
"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.",
]
)
}
@@ -42,7 +42,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
}
private static let mapping: [String: PedalCategory] = [
"Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
"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] = [
"Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
"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",
@@ -16,6 +16,7 @@ import LyrebirdShoeGaze
/// here in the UI target. Unrecognised names fall through to `.gray`.
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 "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,107 @@
// AmpPedalTests.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("AmpPedal")
struct AmpPedalTests {
private let sampleRate: Double = 48000.0
private func render(configure: (AmpPedal) -> Void = { _ in }) throws -> [Float] {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.2, 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: AmpPedal = AmpPedal(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 = 4096, window: Int = 4096) -> 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 buildsAndProducesNonSilentFiniteOutput() throws {
let samples: [Float] = try render()
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "AmpPedal produced silence")
#expect(samples.allSatisfy { $0.isFinite }, "AmpPedal produced non-finite output")
}
@Test func gainChangesOutput() throws {
let clean: [Float] = try render { $0.gain = 2.0 }
let hot: [Float] = try render { $0.gain = 25.0 }
#expect(hasNonSilentOutput(clean) && hasNonSilentOutput(hot))
#expect(windowedSSD(clean, hot) > 0, "gain had no effect")
}
@Test func toneControlsChangeOutput() throws {
let dark: [Float] = try render { $0.treble = 0.0; $0.bass = 1.0 }
let bright: [Float] = try render { $0.treble = 1.0; $0.bass = 0.0 }
#expect(windowedSSD(dark, bright) > 0, "tone controls had no effect")
}
@Test func midChangesOutput() throws {
let scooped: [Float] = try render { $0.mid = 0.0 }
let full: [Float] = try render { $0.mid = 1.0 }
#expect(windowedSSD(scooped, full) > 0, "mid control had no effect")
}
@Test func ampModelChangesOutput() throws {
let fender: [Float] = try render { $0.amp = 0.0 }
let vox: [Float] = try render { $0.amp = 2.0 }
#expect(windowedSSD(fender, vox) > 0, "amp model had no effect")
}
@Test func cabChangesOutput() throws {
let cabA: [Float] = try render { $0.cab = 0.0 }
let cabB: [Float] = try render { $0.cab = 2.0 }
#expect(windowedSSD(cabA, cabB) > 0, "cab selection had no effect")
}
@Test func exposesControls() throws {
let pedal: AmpPedal = AmpPedal()
#expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble"])
#expect(pedal.effectSelectors.map { $0.label } == ["Amp", "Cab"])
}
@Test func selectionsRoundTripThroughState() throws {
let pedal: AmpPedal = AmpPedal()
pedal.amp = 1.0
pedal.cab = 2.0
let restored: AmpPedal = AmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.amp == 1.0 && restored.cab == 2.0, "amp/cab selection did not round-trip")
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "Amp")
#expect(pedal is AmpPedal)
}
}