feat(reverb): add FreezVerb — filter-from-the-current-moment into a stereo room

A spectral reverb ported from the composer's FilterFromCurrentMoment process.
Press Capture and the spectrum playing at that instant is locked in as a fixed
filter; everything you play afterwards is masked through that frozen spectral
shape and poured into a large reverb. The name plays on the FreeVerb tank at
its core.

- A side-chain SpectralChain (analyze-only) of the dry drives a SpectralCrossMap
  (maxMagnitude, mode 1.0) as a `.dual` stage on a main chain over the dry. While
  live the mask tracks the input; the Capture footswitch sets crossMap.freeze, so
  the captured moment becomes a fixed formant filter on the ongoing signal.
- The masked result feeds a GVerb room (fixed 120 m, as in the original), with a
  Time knob (T60, tempo-syncable) and a Damp knob shaping the tail.
- Mono in, stereo out (channelKind .widener): the reverb is summed to mono and
  placed across the field by a Pan knob (Pan2), replacing the original's
  ambisonic encoding. The time-stretched random-pointer source is dropped — the
  filter is captured straight off the live input by the footswitch.
- `captured` is transport state (a Capture button indicator) and is not
  serialized into presets.

Wired at all four points (+ README catalog). 818 tests pass;
lyrebird_external_review clean (no blocking findings).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 19:55:07 -08:00
parent 843ae5b5f6
commit 0873bbd82e
6 changed files with 558 additions and 2 deletions
+1
View File
@@ -124,6 +124,7 @@ public extension PedalType {
static let reverseReverb = PedalType("Reverse Reverb")
static let granularReverb = PedalType("Granular Reverb")
static let freezeReverb = PedalType("Freeze Reverb")
static let freezVerb = PedalType("FreezVerb")
// Pitch & octave
static let octaveSplitter = PedalType("Octave Splitter")
@@ -0,0 +1,244 @@
// FreezVerbPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// A spectral *filter-from-the-current-moment* reverb — press **Capture** and the spectrum playing
/// at that instant is locked in as a fixed filter, and everything you play afterwards is poured
/// through that frozen spectral shape into a big reverb.
///
/// Where ``FreezeReverbPedal`` holds a snapshot as a *sounding* pad, this holds a snapshot as a
/// *filter*. A `SpectralCrossMap` masks the live spectrum bin-by-bin against a template taken from a
/// side-chain analysis of the input: while live, the template tracks what you play; press Capture and
/// the template freezes, so the captured moment becomes a fixed formant mask on your ongoing signal.
/// The masked result feeds a large `GVerb` room (fixed 120 m) for a cavernous tail, and a **Pan**
/// knob places the stereo wash anywhere across the field.
///
/// Ported from the composer's `FilterFromCurrentMoment` process: the original drew its filter from a
/// random pointer into a time-stretched buffer and spatialised with ambisonics; here the filter is
/// captured straight off the live input by the footswitch, and the output is plain stereo via the
/// Pan knob.
///
/// ## Knobs
/// - `time`: Reverb tail length (GVerb T60) in seconds. Range `[0.5, 12.0]`.
/// - `damp`: High-frequency damping of the tail. Range `[0, 1]`: `0` = bright, `1` = dark.
/// - `pan`: Stereo position of the wash. Range `[-1, +1]`: `-1` = hard left, `+1` = hard right.
///
/// ## Transport
/// - `Capture`: latching footswitch — press to lock the current-moment spectrum as the filter, press
/// again to return to live tracking.
public final class FreezVerbPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Capture a moment's spectrum as a filter and pour your playing through it into a vast room."
}
/// Mono in, stereo out: the reverb wash is panned across the field by the ``pan`` knob.
public override var channelKind: PedalChannelKind { .widener }
// MARK: - Parameters
/// Reverb tail length (GVerb T60) in seconds. Range `[0.5, 12.0]`.
@UIParam public var time: Double = 6.0
/// High-frequency damping of the tail. Range `[0, 1]`: `0` = bright, `1` = dark.
@UIParam public var damp: Double = 0.5
/// Stereo position of the wash. Range `[-1, +1]`: `-1` = hard left, `+1` = hard right.
@UIParam public var pan: Double = 0.0
// MARK: - Internal live state (read by the audio graph)
/// `1` while the filter is locked to a captured moment, else `0`. Drives the Capture footswitch
/// LED. Transport state — not a preset control, so neither captured nor restored.
@UIParam public var captured: Double = 0.0
// MARK: - Constants
/// FFT frame size for the spectral cross-map. Matches the composer's original process — large
/// enough for a finely-resolved formant filter at the cost of latency on the wet path (the dry
/// path is never delayed).
private static let fftSize: Int = 4096
/// Samples between FFT hops (75% overlap at `fftSize` 4096).
private static let hopSize: Int = 1024
/// GVerb room size in metres — fixed, as in the original process. Large, for a cavernous tail.
private let roomSize: Double = 120.0
/// Cross-map blend: `1.0` = full spectral bandpass mask (loud template bins pass, quiet bins are
/// attenuated). Matches the original process.
private let crossMapMode: Double = 1.0
/// GVerb dry level — kept at `0` so the wet path is pure reverb; the base `mix` provides the
/// dry/wet blend.
private let verbDryLevel: Double = 0.0
/// Gain folding GVerb's two decorrelated channels to mono before the pan — a conservative trim
/// (the channels are not identical) that leaves output headroom.
private let stereoSumGain: Double = 0.5
// MARK: - Ranges
private let timeRange: ClosedRange<Double> = 0.5 ... 12.0
private let dampRange: ClosedRange<Double> = 0.0 ... 1.0
private let panRange: ClosedRange<Double> = -1.0 ... 1.0
// MARK: - Live generator references (rebuilt each `wideEffect(_:)`)
/// The spectral cross-map the Capture footswitch locks. Recreated on every rebuild so the button
/// always acts on the current instance.
private var crossMap: SpectralCrossMap?
/// Mirror of the locked state, so a toggle knows which way to go and the LED survives a rebuild.
private var isCaptured: Bool = false
// MARK: - Knobs
public override var tempoSyncableParams: [TempoSyncableParam] {
[
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
]
}
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Time", node: $time, range: timeRange),
PedalKnob(label: "Damp", node: $damp, range: dampRange),
PedalKnob(label: "Pan", node: $pan, range: panRange),
]
}
// MARK: - Transport
public override var effectTransportButtons: [PedalButton] {
[
PedalButton(
label: "Capture",
indicator: $captured,
dynamicLabel: { [weak self] in (self?.isCaptured ?? false) ? "Live" : "Capture" }
) { [weak self] in self?.toggleCapture() }
]
}
/// `true` while a moment's spectrum is locked as the filter. Exposed for UI / tests.
public var holding: Bool { isCaptured }
/// Lock the current-moment spectrum as the filter, or return to live tracking. Latched by the
/// Capture footswitch. Before the graph is built `crossMap` is nil and only the latch/LED state
/// moves; `resetForRebuild()` then clears it on the next build so the two never drift apart.
public func toggleCapture() {
if isCaptured {
crossMap?.freeze = false
isCaptured = false
captured = 0.0
} else {
crossMap?.freeze = true
isCaptured = true
captured = 1.0
}
}
// MARK: - Init
/// Creates a filter-from-the-current-moment FreezVerb.
///
/// - 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: "FreezVerb",
inputBus: inputBus,
outputBus: outputBus,
initialMix: 0.4
)
}
// MARK: - Effect
public override func wideEffect(
_ dry: any ValidGeneratorInput
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
// `wideEffect()` re-runs on every add/rebuild. Start from a clean, live-tracking state so the
// button never holds a reference to a discarded cross-map.
resetForRebuild()
// Side-chain: a continuous analysis of the live input. While the cross-map is live it captures
// its filter template from this each hop; once the footswitch sets `freeze`, the last template
// is held and this side-chain is ignored — the captured moment becomes the fixed filter.
let sideChain: SpectralChain.Audio = SpectralChain.Audio(
input: dry,
fftSize: FreezVerbPedal.fftSize,
hopSize: FreezVerbPedal.hopSize,
analyzeOnly: true
)
let map: SpectralCrossMap = SpectralCrossMap(
fftSize: FreezVerbPedal.fftSize,
normalization: .maxMagnitude
)
map.mode = crossMapMode
crossMap = map
// Main chain: the live input masked by the (tracking or captured) template.
let masked: SpectralChain.Audio = SpectralChain.Audio(
input: dry,
fftSize: FreezVerbPedal.fftSize,
hopSize: FreezVerbPedal.hopSize,
stages: [.dual(map, sideChain: sideChain)]
)
// A large room for a cavernous tail; `time` sets the T60, `damp` the brightness.
let reverb: GVerb.Audio = GVerb.Audio(
source: masked,
roomSize: roomSize,
reverbTime: $time,
damping: $damp,
dryLevel: verbDryLevel,
sampleRate: sampleRate
)
// GVerb is natively stereo (two decorrelated channels); fold to mono, then pan the wash across
// the field with the Pan knob.
let monoWet: SumChannels.Audio = SumChannels.Audio(input: reverb, mul: stereoSumGain)
let panned: Pan2 = Pan2(input: monoWet, pan: $pan)
return (panned.left, panned.right)
}
// MARK: - Lifecycle
/// Returns to live tracking when the engine stops.
public override func engineDidStop() {
releaseHold()
}
/// Returns to live tracking before this instance is discarded on a rig teardown.
public override func rigWillTeardown() {
releaseHold()
}
// MARK: - Helpers
/// Unlocks any captured filter and returns to live tracking.
private func releaseHold() {
crossMap?.freeze = false
isCaptured = false
captured = 0.0
}
/// Clears the live generator reference and the locked state so a graph rebuild starts fresh.
/// Called at the top of ``wideEffect(_:)``.
private func resetForRebuild() {
crossMap = nil
isCaptured = false
captured = 0.0
}
}
@@ -92,6 +92,7 @@ public enum PedalRegistry {
"Reverse Reverb": { ReverseReverbPedal() },
"Granular Reverb": { GranularReverbPedal() },
"Freeze Reverb": { FreezeReverbPedal() },
"FreezVerb": { FreezVerbPedal() },
"Limiter": { LimiterPedal() },
"Cabinet": { CabinetPedal() },
"Noise Gate": { NoiseGatePedal() },
@@ -60,7 +60,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
"Reverse Delay": .delay, "DL4": .delay,
"Reverb": .reverb, "Shimmer Reverb": .reverb,
"Plate Reverb": .reverb, "Room Reverb": .reverb, "Spring Reverb": .reverb,
"Reverse Reverb": .reverb, "Granular Reverb": .reverb, "Freeze Reverb": .reverb,
"Reverse Reverb": .reverb, "Granular Reverb": .reverb, "Freeze Reverb": .reverb, "FreezVerb": .reverb,
"Diffuser": .texture, "Bitcrusher": .texture, "Granulator": .texture, "Auto Granulator": .texture,
"Karplus Resonator": .texture, "Tape Looper": .texture,
]