Compare commits
3 Commits
a2fcd59e1b
...
96ab2a0586
| Author | SHA1 | Date | |
|---|---|---|---|
| 96ab2a0586 | |||
| 99649c2d89 | |||
| 7f1856e8e5 |
@@ -0,0 +1,43 @@
|
|||||||
|
// CabIRStage.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// One filter stage in an off-RT cabinet-IR cascade, as a kind plus parameters.
|
||||||
|
///
|
||||||
|
/// Consumed by ``CabinetIRFactory`` when it bakes an impulse response: the cab voice contributes a
|
||||||
|
/// fixed cascade, and a ``MicVoice`` contributes extra stages (presence bump, top-end/low-end
|
||||||
|
/// shelving) appended to it. `q` is used by high-pass / low-pass / peaking stages; `gainDb` by
|
||||||
|
/// peaking and the shelves; shelves use a fixed slope set by the factory.
|
||||||
|
struct CabIRStage {
|
||||||
|
|
||||||
|
/// The biquad kind this stage bakes into.
|
||||||
|
enum Kind {
|
||||||
|
case highPass
|
||||||
|
case lowPass
|
||||||
|
case peaking
|
||||||
|
case lowShelf
|
||||||
|
case highShelf
|
||||||
|
}
|
||||||
|
|
||||||
|
let kind: Kind
|
||||||
|
let freq: Double
|
||||||
|
let q: Double
|
||||||
|
let gainDb: Double
|
||||||
|
|
||||||
|
/// A resonant peak/dip at `freq`.
|
||||||
|
static func peaking(_ freq: Double, q: Double, gainDb: Double) -> CabIRStage {
|
||||||
|
CabIRStage(kind: .peaking, freq: freq, q: q, gainDb: gainDb)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A low-frequency shelf at `freq` (slope fixed by the factory).
|
||||||
|
static func lowShelf(_ freq: Double, gainDb: Double) -> CabIRStage {
|
||||||
|
CabIRStage(kind: .lowShelf, freq: freq, q: 0.0, gainDb: gainDb)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A high-frequency shelf at `freq` (slope fixed by the factory).
|
||||||
|
static func highShelf(_ freq: Double, gainDb: Double) -> CabIRStage {
|
||||||
|
CabIRStage(kind: .highShelf, freq: freq, q: 0.0, gainDb: gainDb)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,8 @@ import Darwin
|
|||||||
/// Fraction of the sample rate above which a filter centre frequency is clamped, so the RBJ
|
/// Fraction of the sample rate above which a filter centre frequency is clamped, so the RBJ
|
||||||
/// coefficients stay well-behaved below Nyquist even at low sample rates.
|
/// coefficients stay well-behaved below Nyquist even at low sample rates.
|
||||||
private let cabinetBiquadNyquistFraction: Double = 0.49
|
private let cabinetBiquadNyquistFraction: Double = 0.49
|
||||||
/// RBJ-cookbook divisor converting a peaking-filter gain in dB to its `A` amplitude term.
|
/// RBJ-cookbook divisor converting a filter gain in dB to its `A` amplitude term (peaking + shelves).
|
||||||
private let cabinetPeakingGainDivisor: Double = 40.0
|
private let cabinetDbToAmplitudeDivisor: Double = 40.0
|
||||||
|
|
||||||
/// Synthesizes a short cabinet impulse response for a ``CabinetVoice`` by running a unit
|
/// Synthesizes a short cabinet impulse response for a ``CabinetVoice`` by running a unit
|
||||||
/// impulse through a cascade of RBJ biquads (high-pass → two-stage low-pass → low-mid body
|
/// impulse through a cascade of RBJ biquads (high-pass → two-stage low-pass → low-mid body
|
||||||
@@ -37,16 +37,24 @@ public enum CabinetIRFactory {
|
|||||||
private static let breakupQ: Double = 2.0
|
private static let breakupQ: Double = 2.0
|
||||||
/// Q for the mid interference notch (narrow, so it dips without gutting the midrange).
|
/// Q for the mid interference notch (narrow, so it dips without gutting the midrange).
|
||||||
private static let notchQ: Double = 2.5
|
private static let notchQ: Double = 2.5
|
||||||
|
/// Fixed shelf slope for the ``MicVoice`` low-/high-shelf stages (gentle, like the amp shelves).
|
||||||
|
private static let micShelfSlope: Double = 0.7
|
||||||
|
|
||||||
/// Builds the impulse response for `voice` at `sampleRate`.
|
/// Builds the impulse response for `voice` (optionally mic'd by `mic`) at `sampleRate`.
|
||||||
|
///
|
||||||
|
/// The cab voice's fixed cascade is baked first; any ``MicVoice`` stages are appended before the
|
||||||
|
/// impulse is run, so the mic colour is folded into the same single IR (no extra render-time
|
||||||
|
/// cost). ``MicVoice/off`` appends nothing, so the result is byte-for-byte the raw cab voice.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - voice: The cabinet voicing to synthesize.
|
/// - voice: The cabinet voicing to synthesize.
|
||||||
|
/// - mic: The microphone voicing layered on top. Defaults to ``MicVoice/off`` (no mic).
|
||||||
/// - sampleRate: Engine sample rate in Hz.
|
/// - sampleRate: Engine sample rate in Hz.
|
||||||
/// - frames: IR length in frames. Defaults to ``defaultFrames``.
|
/// - frames: IR length in frames. Defaults to ``defaultFrames``.
|
||||||
/// - Returns: A mono `LyrebirdBuffer` holding the normalized IR, tagged with `sampleRate`.
|
/// - Returns: A mono `LyrebirdBuffer` holding the normalized IR, tagged with `sampleRate`.
|
||||||
public static func makeIR(
|
public static func makeIR(
|
||||||
voice: CabinetVoice,
|
voice: CabinetVoice,
|
||||||
|
mic: MicVoice = .off,
|
||||||
sampleRate: Double,
|
sampleRate: Double,
|
||||||
frames: Int = CabinetIRFactory.defaultFrames
|
frames: Int = CabinetIRFactory.defaultFrames
|
||||||
) -> LyrebirdBuffer {
|
) -> LyrebirdBuffer {
|
||||||
@@ -60,6 +68,25 @@ public enum CabinetIRFactory {
|
|||||||
OfflineBiquad.peaking(freq: voice.notchHz, q: notchQ, gainDb: voice.notchGainDb, sampleRate: sampleRate),
|
OfflineBiquad.peaking(freq: voice.notchHz, q: notchQ, gainDb: voice.notchGainDb, sampleRate: sampleRate),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Append the mic voicing's stages (none for `.off`) so its colour bakes into the same IR.
|
||||||
|
for stage: CabIRStage in mic.stages {
|
||||||
|
switch stage.kind {
|
||||||
|
case .highPass:
|
||||||
|
chain.append(OfflineBiquad.highPass(freq: stage.freq, q: stage.q, sampleRate: sampleRate))
|
||||||
|
case .lowPass:
|
||||||
|
chain.append(OfflineBiquad.lowPass(freq: stage.freq, q: stage.q, sampleRate: sampleRate))
|
||||||
|
case .peaking:
|
||||||
|
chain.append(OfflineBiquad.peaking(
|
||||||
|
freq: stage.freq, q: stage.q, gainDb: stage.gainDb, sampleRate: sampleRate))
|
||||||
|
case .lowShelf:
|
||||||
|
chain.append(OfflineBiquad.lowShelf(
|
||||||
|
freq: stage.freq, gainDb: stage.gainDb, slope: micShelfSlope, sampleRate: sampleRate))
|
||||||
|
case .highShelf:
|
||||||
|
chain.append(OfflineBiquad.highShelf(
|
||||||
|
freq: stage.freq, gainDb: stage.gainDb, slope: micShelfSlope, sampleRate: sampleRate))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ir: [Double] = [Double](repeating: 0.0, count: frames)
|
var ir: [Double] = [Double](repeating: 0.0, count: frames)
|
||||||
for n: Int in 0..<frames {
|
for n: Int in 0..<frames {
|
||||||
var sample: Double = n == 0 ? 1.0 : 0.0
|
var sample: Double = n == 0 ? 1.0 : 0.0
|
||||||
@@ -149,7 +176,7 @@ private struct OfflineBiquad {
|
|||||||
|
|
||||||
static func peaking(freq: Double, q: Double, gainDb: Double, sampleRate: Double) -> OfflineBiquad {
|
static func peaking(freq: Double, q: Double, gainDb: Double, sampleRate: Double) -> OfflineBiquad {
|
||||||
let f: Double = clampedFreq(freq, sampleRate: sampleRate)
|
let f: Double = clampedFreq(freq, sampleRate: sampleRate)
|
||||||
let amplitude: Double = pow(10.0, gainDb / cabinetPeakingGainDivisor)
|
let amplitude: Double = pow(10.0, gainDb / cabinetDbToAmplitudeDivisor)
|
||||||
let w0: Double = 2.0 * Double.pi * f / sampleRate
|
let w0: Double = 2.0 * Double.pi * f / sampleRate
|
||||||
let cosW0: Double = cos(w0)
|
let cosW0: Double = cos(w0)
|
||||||
let alpha: Double = sin(w0) / (2.0 * q)
|
let alpha: Double = sin(w0) / (2.0 * q)
|
||||||
@@ -161,4 +188,44 @@ private struct OfflineBiquad {
|
|||||||
let a2: Double = 1.0 - alpha / amplitude
|
let a2: Double = 1.0 - alpha / amplitude
|
||||||
return OfflineBiquad(b0: b0 / a0, b1: b1 / a0, b2: b2 / a0, a1: a1 / a0, a2: a2 / a0)
|
return OfflineBiquad(b0: b0 / a0, b1: b1 / a0, b2: b2 / a0, a1: a1 / a0, a2: a2 / a0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// RBJ low-shelf. `slope` is the cookbook `S` (1.0 = steepest without overshoot).
|
||||||
|
static func lowShelf(freq: Double, gainDb: Double, slope: Double, sampleRate: Double) -> OfflineBiquad {
|
||||||
|
let f: Double = clampedFreq(freq, sampleRate: sampleRate)
|
||||||
|
let amplitude: Double = pow(10.0, gainDb / cabinetDbToAmplitudeDivisor)
|
||||||
|
let w0: Double = 2.0 * Double.pi * f / sampleRate
|
||||||
|
let cosW0: Double = cos(w0)
|
||||||
|
let sinW0: Double = sin(w0)
|
||||||
|
let alpha: Double = sinW0 / 2.0 * sqrt((amplitude + 1.0 / amplitude) * (1.0 / slope - 1.0) + 2.0)
|
||||||
|
let twoSqrtAAlpha: Double = 2.0 * sqrt(amplitude) * alpha
|
||||||
|
let ap1: Double = amplitude + 1.0
|
||||||
|
let am1: Double = amplitude - 1.0
|
||||||
|
let b0: Double = amplitude * (ap1 - am1 * cosW0 + twoSqrtAAlpha)
|
||||||
|
let b1: Double = 2.0 * amplitude * (am1 - ap1 * cosW0)
|
||||||
|
let b2: Double = amplitude * (ap1 - am1 * cosW0 - twoSqrtAAlpha)
|
||||||
|
let a0: Double = ap1 + am1 * cosW0 + twoSqrtAAlpha
|
||||||
|
let a1: Double = -2.0 * (am1 + ap1 * cosW0)
|
||||||
|
let a2: Double = ap1 + am1 * cosW0 - twoSqrtAAlpha
|
||||||
|
return OfflineBiquad(b0: b0 / a0, b1: b1 / a0, b2: b2 / a0, a1: a1 / a0, a2: a2 / a0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// RBJ high-shelf. `slope` is the cookbook `S` (1.0 = steepest without overshoot).
|
||||||
|
static func highShelf(freq: Double, gainDb: Double, slope: Double, sampleRate: Double) -> OfflineBiquad {
|
||||||
|
let f: Double = clampedFreq(freq, sampleRate: sampleRate)
|
||||||
|
let amplitude: Double = pow(10.0, gainDb / cabinetDbToAmplitudeDivisor)
|
||||||
|
let w0: Double = 2.0 * Double.pi * f / sampleRate
|
||||||
|
let cosW0: Double = cos(w0)
|
||||||
|
let sinW0: Double = sin(w0)
|
||||||
|
let alpha: Double = sinW0 / 2.0 * sqrt((amplitude + 1.0 / amplitude) * (1.0 / slope - 1.0) + 2.0)
|
||||||
|
let twoSqrtAAlpha: Double = 2.0 * sqrt(amplitude) * alpha
|
||||||
|
let ap1: Double = amplitude + 1.0
|
||||||
|
let am1: Double = amplitude - 1.0
|
||||||
|
let b0: Double = amplitude * (ap1 + am1 * cosW0 + twoSqrtAAlpha)
|
||||||
|
let b1: Double = -2.0 * amplitude * (am1 + ap1 * cosW0)
|
||||||
|
let b2: Double = amplitude * (ap1 + am1 * cosW0 - twoSqrtAAlpha)
|
||||||
|
let a0: Double = ap1 - am1 * cosW0 + twoSqrtAAlpha
|
||||||
|
let a1: Double = 2.0 * (am1 - ap1 * cosW0)
|
||||||
|
let a2: Double = ap1 - am1 * cosW0 - twoSqrtAAlpha
|
||||||
|
return OfflineBiquad(b0: b0 / a0, b1: b1 / a0, b2: b2 / a0, a1: a1 / a0, a2: a2 / a0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
// MicVoice.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// A microphone voicing baked into the cabinet impulse response — the frequency signature of the
|
||||||
|
/// mic in front of the speaker, layered on top of the ``CabinetVoice`` cab curve.
|
||||||
|
///
|
||||||
|
/// Each voice is a compact set of ``CabIRStage`` filter stages (a presence bump, low-end and
|
||||||
|
/// top-end shelving) that ``CabinetIRFactory`` appends to the cab cascade before baking, so mic
|
||||||
|
/// choice costs nothing extra at render time — it is folded into the single convolution IR. These
|
||||||
|
/// are **broad-strokes synthesized curves** (our own MIT content, not captures of any specific
|
||||||
|
/// microphone), analogous to ``CabinetVoice``.
|
||||||
|
///
|
||||||
|
/// ``off`` contributes no stages, so a cab with no mic bakes exactly the raw cab voice — the
|
||||||
|
/// original, mic-less behaviour.
|
||||||
|
public enum MicVoice: String, CaseIterable, Sendable {
|
||||||
|
case off
|
||||||
|
case dynamic
|
||||||
|
case ribbon
|
||||||
|
case condenser
|
||||||
|
|
||||||
|
/// The voice at a selector value (an index into ``allCases``), rounded and clamped to the valid
|
||||||
|
/// range. Mirrors ``CabinetVoice/voice(atSelectorValue:)`` so a huge / NaN selector never traps.
|
||||||
|
///
|
||||||
|
/// - Parameter selectorValue: The live selector node value (nominally an integer index).
|
||||||
|
/// - Returns: The corresponding voice, clamped to `allCases`.
|
||||||
|
public static func voice(atSelectorValue selectorValue: Double) -> MicVoice {
|
||||||
|
let all: [MicVoice] = allCases
|
||||||
|
guard selectorValue.isFinite else { return all[0] }
|
||||||
|
let bounded: Double = Swift.min(Swift.max(selectorValue, 0.0), Double(all.count - 1))
|
||||||
|
let index: Int = Int(bounded.rounded())
|
||||||
|
return all[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Human-readable name for pickers.
|
||||||
|
public var displayName: String {
|
||||||
|
switch self {
|
||||||
|
case .off: return "No Mic"
|
||||||
|
case .dynamic: return "Dynamic"
|
||||||
|
case .ribbon: return "Ribbon"
|
||||||
|
case .condenser: return "Condenser"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The mic's filter stages, appended to the cab cascade before baking. Empty for ``off``.
|
||||||
|
///
|
||||||
|
/// Broad-strokes voicings: the **dynamic** (moving-coil, close-mic staple) adds an upper-mid
|
||||||
|
/// presence bump with a tightened low end and rolled-off extreme top; the **ribbon** is dark and
|
||||||
|
/// smooth (warm low-mid, steep top rolloff, no presence spike); the **condenser** is the most
|
||||||
|
/// extended and airy (gentle top-end lift, light presence sheen).
|
||||||
|
var stages: [CabIRStage] {
|
||||||
|
switch self {
|
||||||
|
case .off:
|
||||||
|
return []
|
||||||
|
case .dynamic:
|
||||||
|
return [
|
||||||
|
CabIRStage.lowShelf(120.0, gainDb: -2.0),
|
||||||
|
CabIRStage.peaking(5500.0, q: 1.0, gainDb: 4.0),
|
||||||
|
CabIRStage.highShelf(9000.0, gainDb: -3.0),
|
||||||
|
]
|
||||||
|
case .ribbon:
|
||||||
|
return [
|
||||||
|
CabIRStage.lowShelf(200.0, gainDb: 2.5),
|
||||||
|
CabIRStage.peaking(2500.0, q: 0.8, gainDb: -1.5),
|
||||||
|
CabIRStage.highShelf(6500.0, gainDb: -7.0),
|
||||||
|
]
|
||||||
|
case .condenser:
|
||||||
|
return [
|
||||||
|
CabIRStage.peaking(8000.0, q: 1.0, gainDb: 1.5),
|
||||||
|
CabIRStage.highShelf(11000.0, gainDb: 3.0),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@ public final class CabinetPedal: Pedal {
|
|||||||
/// stops via the ``cabinet`` selector; read at board-build time by `effect(_:)`, which
|
/// stops via the ``cabinet`` selector; read at board-build time by `effect(_:)`, which
|
||||||
/// instantiates only that voice's convolver (the selector is `rebuildsOnChange`).
|
/// instantiates only that voice's convolver (the selector is `rebuildsOnChange`).
|
||||||
@UIParam public var cabinet: Double = 0.0
|
@UIParam public var cabinet: Double = 0.0
|
||||||
|
/// Selected microphone voicing as an index into ``MicVoice/allCases`` (`0` = No Mic). Baked into
|
||||||
|
/// the same IR as the cab voice, so it costs nothing extra at render time. `rebuildsOnChange`.
|
||||||
|
@UIParam public var mic: Double = 0.0
|
||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
@@ -54,6 +57,16 @@ public final class CabinetPedal: Pedal {
|
|||||||
/// Convolution is taken fully wet here; the `Pedal` base class provides the user wet/dry mix.
|
/// Convolution is taken fully wet here; the `Pedal` base class provides the user wet/dry mix.
|
||||||
private let convolutionMix: Double = 1.0
|
private let convolutionMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Output peak ceiling. A true look-ahead limiter holds `|output| ≤` this, taming the peaks a
|
||||||
|
/// speaker convolution can push past ±1 (an analog cab can't digital-clip) while leaving signals
|
||||||
|
/// below the ceiling **untouched** — no always-on saturation of clean, below-ceiling material.
|
||||||
|
private let outputCeiling: Double = 1.0
|
||||||
|
/// Limiter look-ahead / output delay. Short (2 ms) so the added latency is negligible in-line
|
||||||
|
/// while still catching the brief convolution-overshoot transients.
|
||||||
|
private let limiterLookAheadSeconds: Double = 0.002
|
||||||
|
/// Limiter gain-release time constant — slow enough not to modulate sustained low frequencies.
|
||||||
|
private let limiterReleaseSeconds: Double = 0.050
|
||||||
|
|
||||||
/// Selector stops, one per ``CabinetVoice`` in `allCases` order (value == index).
|
/// Selector stops, one per ``CabinetVoice`` in `allCases` order (value == index).
|
||||||
private static let voiceStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
|
private static let voiceStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases
|
||||||
.enumerated()
|
.enumerated()
|
||||||
@@ -61,6 +74,13 @@ public final class CabinetPedal: Pedal {
|
|||||||
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Selector stops, one per ``MicVoice`` in `allCases` order (value == index).
|
||||||
|
private static let micStops: [PedalSelectorKnob.Stop] = MicVoice.allCases
|
||||||
|
.enumerated()
|
||||||
|
.map { (index: Int, mic: MicVoice) in
|
||||||
|
PedalSelectorKnob.Stop(title: mic.displayName, value: Double(index))
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
/// Creates a cabinet pedal.
|
/// Creates a cabinet pedal.
|
||||||
@@ -86,28 +106,48 @@ public final class CabinetPedal: Pedal {
|
|||||||
[
|
[
|
||||||
PedalSelectorKnob(
|
PedalSelectorKnob(
|
||||||
label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops, rebuildsOnChange: true),
|
label: "Cab", node: $cabinet, stops: CabinetPedal.voiceStops, rebuildsOnChange: true),
|
||||||
|
PedalSelectorKnob(
|
||||||
|
label: "Mic", node: $mic, stops: CabinetPedal.micStops, rebuildsOnChange: true),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Effect
|
// MARK: - Effect
|
||||||
|
|
||||||
/// Convolves the dry signal against the single selected cabinet IR.
|
/// Convolves the dry signal against the single selected cabinet + mic IR, then soft-limits.
|
||||||
///
|
///
|
||||||
/// Only the voice named by the live `cabinet` selector is instantiated, so exactly one
|
/// Only the voice/mic named by the live selectors is baked, so exactly one partitioned-FFT
|
||||||
/// partitioned-FFT convolver runs. Changing the selector triggers a board rebuild (the selector
|
/// convolver runs; the mic colour is folded into that same IR at no extra render cost. Changing
|
||||||
/// is `rebuildsOnChange`), which re-enters `effect(_:)` with the new voice — so switching cabs
|
/// either selector triggers a board rebuild (both are `rebuildsOnChange`). Synthesizing the short
|
||||||
/// costs a brief rebuild rather than running every voice at once. Synthesizing the short IR
|
/// IR happens off the RT thread in `build()`.
|
||||||
/// happens off the RT thread in `build()`.
|
///
|
||||||
|
/// The closing `LookAheadLimiter` is a transparent peak limiter on the **wet** convolution
|
||||||
|
/// output: a speaker cab is analog and can't digital-clip, and the convolution can push peaks
|
||||||
|
/// past ±1. Unlike a `tanh` saturator, a look-ahead limiter leaves signals **below** the ceiling
|
||||||
|
/// bit-for-bit untouched (no coloration of clean, below-ceiling material) and only pulls gain
|
||||||
|
/// down for the brief peaks that would exceed ±1. It adds a short (2 ms) output delay. At the
|
||||||
|
/// default fully-wet `mix` this bounds the pedal output to ±1 (e.g. a decoupled amp → cabinet
|
||||||
|
/// chain); a partial `mix` re-introduces the dry signal via the base class's equal-power
|
||||||
|
/// crossfade, so at intermediate settings final level is the board's output-stage concern. The
|
||||||
|
/// 2 ms wet delay is uniform at the default fully-wet mix; at a partial mix it sits against the
|
||||||
|
/// undelayed dry path, so a slight comb is expected there (a cab is normally run fully wet).
|
||||||
///
|
///
|
||||||
/// - Parameter dry: Dry mono input signal.
|
/// - Parameter dry: Dry mono input signal.
|
||||||
/// - Returns: The cabinet-convolved mono output.
|
/// - Returns: The cabinet-convolved, mic-voiced, peak-limited mono output.
|
||||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
let sr: Double = sampleRate
|
let sr: Double = sampleRate
|
||||||
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cabinet)
|
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cabinet)
|
||||||
return ConvolutionReverb.Audio(
|
let micVoice: MicVoice = MicVoice.voice(atSelectorValue: mic)
|
||||||
|
let convolved: ConvolutionReverb.Audio = ConvolutionReverb.Audio(
|
||||||
input: dry,
|
input: dry,
|
||||||
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
|
ir: CabinetIRFactory.makeIR(voice: voice, mic: micVoice, sampleRate: sr),
|
||||||
mix: convolutionMix
|
mix: convolutionMix
|
||||||
)
|
)
|
||||||
|
return LookAheadLimiter(
|
||||||
|
in: convolved,
|
||||||
|
maxAmplitude: outputCeiling,
|
||||||
|
lookAheadTime: limiterLookAheadSeconds,
|
||||||
|
releaseTime: limiterReleaseSeconds,
|
||||||
|
sampleRate: sr
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,8 +176,9 @@ public struct HelpView: View {
|
|||||||
"Filter design follows the RBJ Audio EQ Cookbook by Robert Bristow-Johnson — the "
|
"Filter design follows the RBJ Audio EQ Cookbook by Robert Bristow-Johnson — the "
|
||||||
+ "standard biquad coefficient formulas, used to synthesize the Cabinet pedal's "
|
+ "standard biquad coefficient formulas, used to synthesize the Cabinet pedal's "
|
||||||
+ "built-in speaker impulse responses.",
|
+ "built-in speaker impulse responses.",
|
||||||
"The Cabinet pedal's built-in cab voicings are original impulse responses generated in "
|
"The Cabinet pedal's built-in cab and microphone voicings are original impulse "
|
||||||
+ "code — not captures of any third-party hardware or IR pack.",
|
+ "responses generated in code — not captures of any third-party speaker, "
|
||||||
|
+ "microphone, or IR pack.",
|
||||||
"The tube-amp voice pedals' tone stacks "
|
"The tube-amp voice pedals' tone stacks "
|
||||||
+ "follow the Yeh & Smith analysis of the classic passive tone-stack circuit (\"Discretization "
|
+ "follow the Yeh & Smith analysis of the classic passive tone-stack circuit (\"Discretization "
|
||||||
+ "of the '59 Fender Bassman Tone Stack\", DAFx-06); their models are original code, not "
|
+ "of the '59 Fender Bassman Tone Stack\", DAFx-06); their models are original code, not "
|
||||||
|
|||||||
@@ -110,4 +110,57 @@ struct CabinetIRFactoryTests {
|
|||||||
let names: [String] = CabinetVoice.allCases.map { $0.displayName }
|
let names: [String] = CabinetVoice.allCases.map { $0.displayName }
|
||||||
#expect(Set(names).count == names.count, "duplicate cabinet display names")
|
#expect(Set(names).count == names.count, "duplicate cabinet display names")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Mic voicing
|
||||||
|
|
||||||
|
/// Ratio of the IR's magnitude at `hz` to a mid-band reference (800 Hz). Peak-normalization
|
||||||
|
/// scales the whole IR, so it cancels in this ratio — letting a mic's *relative* boost/cut at a
|
||||||
|
/// frequency be compared across IRs regardless of their independent normalization.
|
||||||
|
private func tiltRatio(_ ir: LyrebirdBuffer, hz: Double) -> Double {
|
||||||
|
let reference: Double = responseMagnitude(ir, hz: 800.0)
|
||||||
|
guard reference > 0.0 else { return 0.0 }
|
||||||
|
return responseMagnitude(ir, hz: hz) / reference
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func noMicMatchesRawCabIR() {
|
||||||
|
// MicVoice.off must append no stages, so the IR is byte-identical to the mic-less default —
|
||||||
|
// the backward-compatible path for cabs saved before mic voicing existed.
|
||||||
|
for voice: CabinetVoice in CabinetVoice.allCases {
|
||||||
|
let raw: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: voice, sampleRate: sampleRate)
|
||||||
|
let offMic: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: voice, mic: .off, sampleRate: sampleRate)
|
||||||
|
#expect(raw.count == offMic.count)
|
||||||
|
var identical: Bool = true
|
||||||
|
for i: Int in 0..<raw.count where raw[i, 0] != offMic[i, 0] { identical = false; break }
|
||||||
|
#expect(identical, "\(voice) No-Mic IR differs from the raw cab IR")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func dynamicMicLiftsPresence() {
|
||||||
|
// The dynamic mic adds a presence bump at ~5.5 kHz → a higher 5.5 kHz-to-mid tilt than no mic.
|
||||||
|
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, mic: .off, sampleRate: sampleRate)
|
||||||
|
let dynamic: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .americanCombo, mic: .dynamic, sampleRate: sampleRate)
|
||||||
|
#expect(tiltRatio(dynamic, hz: 5500.0) > tiltRatio(off, hz: 5500.0),
|
||||||
|
"dynamic mic did not lift the presence region")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func ribbonMicDarkensTop() {
|
||||||
|
// The ribbon mic rolls the top off (−7 dB shelf @ 6.5 kHz) → a lower 8 kHz-to-mid tilt.
|
||||||
|
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .off, sampleRate: sampleRate)
|
||||||
|
let ribbon: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .ribbon, sampleRate: sampleRate)
|
||||||
|
#expect(tiltRatio(ribbon, hz: 8000.0) < tiltRatio(off, hz: 8000.0),
|
||||||
|
"ribbon mic did not darken the top end")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func condenserMicAddsAir() {
|
||||||
|
// The condenser mic lifts the extreme top (+3 dB shelf @ 11 kHz) → a higher 10 kHz-to-mid tilt.
|
||||||
|
let off: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .off, sampleRate: sampleRate)
|
||||||
|
let condenser: LyrebirdBuffer = CabinetIRFactory.makeIR(voice: .fullRange, mic: .condenser, sampleRate: sampleRate)
|
||||||
|
#expect(tiltRatio(condenser, hz: 10000.0) > tiltRatio(off, hz: 10000.0),
|
||||||
|
"condenser mic did not add top-end air")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func micNamesAreUnique() {
|
||||||
|
let names: [String] = MicVoice.allCases.map { $0.displayName }
|
||||||
|
#expect(Set(names).count == names.count, "duplicate mic display names")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,13 +59,51 @@ struct CabinetPedalTests {
|
|||||||
#expect(ssd > 0, "cabinet selection had no effect on output")
|
#expect(ssd > 0, "cabinet selection had no effect on output")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func exposesCabinetSelector() throws {
|
@Test func exposesCabinetAndMicSelectors() throws {
|
||||||
let pedal: CabinetPedal = CabinetPedal()
|
let pedal: CabinetPedal = CabinetPedal()
|
||||||
let labels: [String] = pedal.effectSelectors.map { $0.label }
|
let labels: [String] = pedal.effectSelectors.map { $0.label }
|
||||||
#expect(labels == ["Cab"])
|
#expect(labels == ["Cab", "Mic"])
|
||||||
// One stop per voice, in allCases order.
|
// One Cab stop per voice, one Mic stop per mic voice, both in allCases order.
|
||||||
let stops: [String] = pedal.effectSelectors.first?.stops.map { $0.title } ?? []
|
let cabStops: [String] = pedal.effectSelectors.first { $0.label == "Cab" }?.stops.map { $0.title } ?? []
|
||||||
#expect(stops == CabinetVoice.allCases.map { $0.displayName })
|
#expect(cabStops == CabinetVoice.allCases.map { $0.displayName })
|
||||||
|
let micStops: [String] = pedal.effectSelectors.first { $0.label == "Mic" }?.stops.map { $0.title } ?? []
|
||||||
|
#expect(micStops == MicVoice.allCases.map { $0.displayName })
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func micSelectionChangesOutput() throws {
|
||||||
|
// Mic 0 = No Mic, mic 1 = Dynamic — different baked IRs, different output.
|
||||||
|
let noMic: [Float] = try render { $0.mic = 0.0 }
|
||||||
|
let dynamic: [Float] = try render { $0.mic = 1.0 }
|
||||||
|
#expect(hasNonSilentOutput(noMic) && hasNonSilentOutput(dynamic))
|
||||||
|
let skip: Int = 4096, window: Int = 4096
|
||||||
|
guard noMic.count >= skip + window, dynamic.count >= skip + window else { return }
|
||||||
|
let ssd: Double = zip(noMic[skip..<(skip + window)], dynamic[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||||
|
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||||
|
}
|
||||||
|
#expect(ssd > 0, "mic selection had no effect on output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func micSelectionRoundTripsThroughState() throws {
|
||||||
|
let pedal: CabinetPedal = CabinetPedal()
|
||||||
|
pedal.cabinet = 2.0
|
||||||
|
pedal.mic = 3.0
|
||||||
|
let restored: CabinetPedal = CabinetPedal()
|
||||||
|
restored.applyState(pedal.captureState())
|
||||||
|
#expect(restored.cabinet == 2.0 && restored.mic == 3.0, "cab/mic selection did not round-trip")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func outputStaysWithinCeiling() throws {
|
||||||
|
// The tanh soft-limit + Clip(±1) bound the output so a decoupled amp → cabinet chain can't
|
||||||
|
// clip the DAC. No render may exceed ±1.
|
||||||
|
let ceilingEpsilon: Double = 1.0e-4
|
||||||
|
for cab: Double in [0.0, 2.0, 6.0] {
|
||||||
|
for micValue: Double in [0.0, 1.0, 2.0, 3.0] {
|
||||||
|
let out: [Float] = try render { $0.cabinet = cab; $0.mic = micValue }
|
||||||
|
#expect(out.allSatisfy { $0.isFinite })
|
||||||
|
let peak: Double = out.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||||
|
#expect(peak <= 1.0 + ceilingEpsilon, "cab=\(cab) mic=\(micValue) peak \(peak) exceeds ±1")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func cabinetSelectorRebuildsOnChange() throws {
|
@Test func cabinetSelectorRebuildsOnChange() throws {
|
||||||
|
|||||||
Reference in New Issue
Block a user