Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/MagnaVibratoAmpPedal.swift
T
josh f9ddd6b160 feat(amp): Gain/Drive become a 1–11 dial with a musical taper
Every amp's Gain (and the boutique/drive-channel Drive) is now a 1–11 dial —
yes, it goes to eleven — instead of the raw 1–30 tube-drive number.

- New AmpVoicePedal.taperedDrive(_:) maps the 1–11 dial to the 1–30 tube drive
  through an exponential LinExp taper, so 1 is nearly clean, 11 is full
  saturation, and the useful grind spreads across the dial (fine at the bottom,
  steep at the top) rather than bunching near the low end.
- Wired into the base preampStage and every override that feeds a drive:
  Boutique / Fullerton Drive / Jazz Clean / British Dual (Drive channel),
  Anaheim (SS preamp), British Master (cascaded stage).
- gainRange / driveRange → 1...11; every amp's default gain/drive reconverted
  from drive-space to the equivalent dial value (dial = 1 + 10·ln(drive)/ln(30)),
  so each amp's shipped voicing is preserved.
- No preset migration (nothing shipped — per product owner); all knob work
  stays within ShoeGaze (no core Lyrebird change).
- Tests updated to the 1–11 scale; added range + exponential-taper assertions.

671 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-04 10:42:35 -07:00

89 lines
3.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MagnaVibratoAmpPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// American clean combo with **true pitch vibrato** — the Magnatone voice: a genuine
/// frequency-modulation warble (a swept delay line), not the amplitude-modulation "vibrato" other
/// amps label as such.
///
/// A ``AmpVoicePedal`` (`.fender`) whose onboard effect is a delay line whose read position is swept
/// by an LFO — modulating pitch. `Depth` scales the sweep, `Speed` its rate, and a Vibrato
/// footswitch bypasses it (a fixed short delay, no warble).
public final class MagnaVibratoAmpPedal: AmpVoicePedal {
/// Vibrato LFO rate in Hz. Range [0.5, 12].
@UIParam public var speed: Double = 5.0
/// Vibrato depth in [0, 1] → 0…±`maxSweepSeconds` of delay-time sweep around the base delay
/// (the LFO is bipolar, so the delay swings both above and below `baseDelaySeconds`).
@UIParam public var depth: Double = 0.3
/// Vibrato footswitch: `1` = engaged, `0` = bypassed (`Speed`/`Depth` preserved).
@UIParam public var vibratoEnabled: Double = 1.0
/// Base delay time (the centre the LFO sweeps around), in seconds.
private let baseDelaySeconds: Double = 0.005
/// Maximum ± sweep at full depth, in seconds.
private let maxSweepSeconds: Double = 0.002
/// Delay-line capacity — must exceed base + max sweep.
private let maxDelaySeconds: Double = 0.010
private let speedRange: ClosedRange<Double> = 0.5 ... 12.0
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
public override var toneStackModel: ToneStackModel { .fender }
public override var summaryText: String {
"American clean combo with true pitch vibrato (a swept delay, not tremolo)."
}
public override var signatureKnobs: [PedalKnob] {
[
PedalKnob(label: "Speed", node: $speed, range: speedRange),
PedalKnob(label: "Depth", node: $depth, range: depthRange),
]
}
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Vibrato",
node: $vibratoEnabled,
options: [
PedalSwitch.Option(title: "Off", value: switchOffValue),
PedalSwitch.Option(title: "On", value: switchOnValue),
]
),
]
}
/// Wider card for the vibrato knobs plus the Vibrato switch.
public override var widthUnits: Int { 3 }
/// Creates a Magna Vibrato amp.
///
/// - 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: "Magna Vibrato", inputBus: inputBus, outputBus: outputBus)
gain = 5.08 // clean platform for the vibrato
cab = 0.0 // American 1×12
}
/// True pitch vibrato: a delay line whose delay time is swept by a sine LFO. The footswitch
/// gates the sweep to zero (a fixed base delay, no warble) while keeping Speed/Depth.
public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let sweepSeconds: any ValidGeneratorInput = ($depth * $vibratoEnabled) * maxSweepSeconds
let delayTime: OscSin.Audio = OscSin.Audio(
freq: $speed, mul: sweepSeconds, add: baseDelaySeconds)
return DelayLine(
input: signal,
maxDelay: maxDelaySeconds,
delay: delayTime,
sampleRate: sampleRate,
interpolation: .linear
)
}
}