Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35ae16040a | |||
| f67a5370ff |
@@ -18,7 +18,10 @@ import LyrebirdUI
|
|||||||
///
|
///
|
||||||
/// Signal path (inside `effect(_:)`):
|
/// Signal path (inside `effect(_:)`):
|
||||||
/// ```
|
/// ```
|
||||||
/// dry → ConvolutionReverb(ir: selectedVoice) → mono out
|
/// dry → ConvolutionReverb(ir: cab voice + mic voice) (one IR — mic colour baked in)
|
||||||
|
/// → RBJHighShelf (Position) → RBJLowShelf (Proximity) (live mic-placement shelves)
|
||||||
|
/// → LookAheadLimiter(±1) (transparent peak safety)
|
||||||
|
/// → mono out
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// The wet/dry mix and bypass are handled by the `Pedal` base class.
|
/// The wet/dry mix and bypass are handled by the `Pedal` base class.
|
||||||
@@ -32,6 +35,9 @@ import LyrebirdUI
|
|||||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
///
|
///
|
||||||
/// - `cabinet`: Selects the built-in cabinet voicing (stepped selector over ``CabinetVoice``).
|
/// - `cabinet`: Selects the built-in cabinet voicing (stepped selector over ``CabinetVoice``).
|
||||||
|
/// - `mic`: Selects the microphone voicing baked into the IR (stepped selector over ``MicVoice``).
|
||||||
|
/// - `position` / `proximity`: Live mic-placement shelves in the advanced pop-over (on-axis ↔ edge,
|
||||||
|
/// distant ↔ close).
|
||||||
public final class CabinetPedal: Pedal {
|
public final class CabinetPedal: Pedal {
|
||||||
|
|
||||||
/// One-line description shown in the picker and info panel.
|
/// One-line description shown in the picker and info panel.
|
||||||
@@ -48,6 +54,14 @@ public final class CabinetPedal: Pedal {
|
|||||||
/// Selected microphone voicing as an index into ``MicVoice/allCases`` (`0` = No Mic). Baked into
|
/// 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`.
|
/// the same IR as the cab voice, so it costs nothing extra at render time. `rebuildsOnChange`.
|
||||||
@UIParam public var mic: Double = 0.0
|
@UIParam public var mic: Double = 0.0
|
||||||
|
/// Mic **Position** on the speaker in `[0, 1]`: `0` = on-axis (bright, centred on the dust cap),
|
||||||
|
/// `1` = cone edge / off-axis (progressively darker). A live high-shelf cut, so it is a smooth
|
||||||
|
/// knob (no rebake); `0` is a bit-exact 0 dB identity. Surfaced in the advanced pop-over.
|
||||||
|
@UIParam public var position: Double = 0.0
|
||||||
|
/// Mic **Proximity** in `[0, 1]`: `0` = distant (flat lows), `1` = close-mic'd (proximity-effect
|
||||||
|
/// low-end boost). A live low-shelf boost, so it is a smooth knob (no rebake); `0` is a bit-exact
|
||||||
|
/// 0 dB identity. Surfaced in the advanced pop-over.
|
||||||
|
@UIParam public var proximity: Double = 0.0
|
||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
@@ -67,6 +81,19 @@ public final class CabinetPedal: Pedal {
|
|||||||
/// Limiter gain-release time constant — slow enough not to modulate sustained low frequencies.
|
/// Limiter gain-release time constant — slow enough not to modulate sustained low frequencies.
|
||||||
private let limiterReleaseSeconds: Double = 0.050
|
private let limiterReleaseSeconds: Double = 0.050
|
||||||
|
|
||||||
|
/// Mic-position high-shelf corner (Hz) and its maximum cut (dB) at the cone edge (`position = 1`).
|
||||||
|
/// Moving off-axis toward the cone rolls the top off; on-axis (`0`) is a 0 dB identity.
|
||||||
|
private let positionShelfFreqHz: Double = 3500.0
|
||||||
|
private let positionMaxCutDb: Double = 9.0
|
||||||
|
/// Mic-proximity low-shelf corner (Hz) and its maximum boost (dB) up close (`proximity = 1`) —
|
||||||
|
/// the proximity-effect bass lift; distant (`0`) is a 0 dB identity.
|
||||||
|
private let proximityShelfFreqHz: Double = 150.0
|
||||||
|
private let proximityMaxBoostDb: Double = 6.0
|
||||||
|
/// Shelf slope for the position / proximity live shelves (gentle, like the amp shelves).
|
||||||
|
private let placementShelfSlope: Double = 0.7
|
||||||
|
/// `[0, 1]` range for the Position / Proximity pop-over knobs.
|
||||||
|
private static let placementRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
/// 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()
|
||||||
@@ -111,6 +138,16 @@ public final class CabinetPedal: Pedal {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mic-placement deep-cut controls, tucked behind the pedal card's advanced pop-over: **Position**
|
||||||
|
/// (on-axis ↔ cone edge) and **Proximity** (distance / bass lift). Live shelves (not baked), so
|
||||||
|
/// they are smooth knobs; neither is a topology control. Persisted positionally in `advancedValues`.
|
||||||
|
public override var advancedKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Position", node: $position, range: CabinetPedal.placementRange),
|
||||||
|
PedalKnob(label: "Proximity", node: $proximity, range: CabinetPedal.placementRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Effect
|
// MARK: - Effect
|
||||||
|
|
||||||
/// Convolves the dry signal against the single selected cabinet + mic IR, then soft-limits.
|
/// Convolves the dry signal against the single selected cabinet + mic IR, then soft-limits.
|
||||||
@@ -142,12 +179,32 @@ public final class CabinetPedal: Pedal {
|
|||||||
ir: CabinetIRFactory.makeIR(voice: voice, mic: micVoice, sampleRate: sr),
|
ir: CabinetIRFactory.makeIR(voice: voice, mic: micVoice, sampleRate: sr),
|
||||||
mix: convolutionMix
|
mix: convolutionMix
|
||||||
)
|
)
|
||||||
|
let placed: any ValidGeneratorInput = applyPlacement(convolved)
|
||||||
return LookAheadLimiter(
|
return LookAheadLimiter(
|
||||||
in: convolved,
|
in: placed,
|
||||||
maxAmplitude: outputCeiling,
|
maxAmplitude: outputCeiling,
|
||||||
lookAheadTime: limiterLookAheadSeconds,
|
lookAheadTime: limiterLookAheadSeconds,
|
||||||
releaseTime: limiterReleaseSeconds,
|
releaseTime: limiterReleaseSeconds,
|
||||||
sampleRate: sr
|
sampleRate: sr
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Applies the live mic-placement shelves to the convolved signal: a **Position** high-shelf that
|
||||||
|
/// rolls the top off as the mic moves off-axis toward the cone edge, then a **Proximity**
|
||||||
|
/// low-shelf that lifts the low end as the mic moves closer. Both map their knob `[0, 1]` to a
|
||||||
|
/// shelf gain in dB with `0` → `0` dB, so at the default (`0, 0`) each shelf is a bit-exact
|
||||||
|
/// identity and the cabinet sounds exactly as it did before placement existed.
|
||||||
|
///
|
||||||
|
/// - Parameter signal: The cab-convolved signal.
|
||||||
|
/// - Returns: The placement-shaped signal.
|
||||||
|
private func applyPlacement(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let positionCutDb: LinLin.Audio = LinLin.Audio(
|
||||||
|
$position, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: -positionMaxCutDb)
|
||||||
|
let positioned: RBJHighShelf.Audio = RBJHighShelf.Audio(
|
||||||
|
input: signal, freq: positionShelfFreqHz, gain: positionCutDb, slope: placementShelfSlope)
|
||||||
|
let proximityBoostDb: LinLin.Audio = LinLin.Audio(
|
||||||
|
$proximity, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: proximityMaxBoostDb)
|
||||||
|
return RBJLowShelf.Audio(
|
||||||
|
input: positioned, freq: proximityShelfFreqHz, gain: proximityBoostDb, slope: placementShelfSlope)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,62 @@ struct CabinetPedalTests {
|
|||||||
#expect(restored.cabinet == 2.0 && restored.mic == 3.0, "cab/mic selection did not round-trip")
|
#expect(restored.cabinet == 2.0 && restored.mic == 3.0, "cab/mic selection did not round-trip")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func positionChangesOutput() throws {
|
||||||
|
// Position sweeps a live high-shelf cut (on-axis → cone edge), so it must change the output.
|
||||||
|
let onAxis: [Float] = try render { $0.position = 0.0 }
|
||||||
|
let edge: [Float] = try render { $0.position = 1.0 }
|
||||||
|
let skip: Int = 4096, window: Int = 4096
|
||||||
|
#expect(onAxis.count >= skip + window && edge.count >= skip + window, "render too short")
|
||||||
|
guard onAxis.count >= skip + window, edge.count >= skip + window else { return }
|
||||||
|
let ssd: Double = zip(onAxis[skip..<(skip + window)], edge[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 Position had no effect on output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func proximityChangesOutput() throws {
|
||||||
|
// Proximity sweeps a live low-shelf boost (distant → close), so it must change the output.
|
||||||
|
let distant: [Float] = try render { $0.proximity = 0.0 }
|
||||||
|
let close: [Float] = try render { $0.proximity = 1.0 }
|
||||||
|
let skip: Int = 4096, window: Int = 4096
|
||||||
|
#expect(distant.count >= skip + window && close.count >= skip + window, "render too short")
|
||||||
|
guard distant.count >= skip + window, close.count >= skip + window else { return }
|
||||||
|
let ssd: Double = zip(distant[skip..<(skip + window)], close[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 Proximity had no effect on output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func explicitDefaultPlacementMatchesImplicit() throws {
|
||||||
|
// A default-consistency guard: the shipped defaults are position = 0 / proximity = 0, so
|
||||||
|
// setting them explicitly must reproduce the default render exactly. (That those defaults are
|
||||||
|
// a *no-op* on the tone follows from the RBJ shelves collapsing to unity at 0 dB — a Lyrebird
|
||||||
|
// property; this test pins that the defaults are those values and the render is deterministic.)
|
||||||
|
let byDefault: [Float] = try render()
|
||||||
|
let explicit: [Float] = try render { $0.position = 0.0; $0.proximity = 0.0 }
|
||||||
|
let skip: Int = 4096, window: Int = 4096
|
||||||
|
#expect(byDefault.count >= skip + window && explicit.count >= skip + window, "render too short")
|
||||||
|
guard byDefault.count >= skip + window, explicit.count >= skip + window else { return }
|
||||||
|
let ssd: Double = zip(byDefault[skip..<(skip + window)], explicit[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||||
|
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||||
|
}
|
||||||
|
#expect(ssd == 0, "explicit default placement did not match the default render")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func advancedKnobsExposePlacement() throws {
|
||||||
|
let pedal: CabinetPedal = CabinetPedal()
|
||||||
|
#expect(pedal.advancedKnobs.map { $0.label } == ["Position", "Proximity"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func placementRoundTripsThroughState() throws {
|
||||||
|
let pedal: CabinetPedal = CabinetPedal()
|
||||||
|
pedal.position = 0.7
|
||||||
|
pedal.proximity = 0.4
|
||||||
|
let restored: CabinetPedal = CabinetPedal()
|
||||||
|
restored.applyState(pedal.captureState())
|
||||||
|
#expect(restored.position == 0.7 && restored.proximity == 0.4, "placement did not round-trip")
|
||||||
|
}
|
||||||
|
|
||||||
@Test func outputStaysWithinCeiling() throws {
|
@Test func outputStaysWithinCeiling() throws {
|
||||||
// The tanh soft-limit + Clip(±1) bound the output so a decoupled amp → cabinet chain can't
|
// 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.
|
// clip the DAC. No render may exceed ±1.
|
||||||
@@ -104,6 +160,11 @@ struct CabinetPedalTests {
|
|||||||
#expect(peak <= 1.0 + ceilingEpsilon, "cab=\(cab) mic=\(micValue) peak \(peak) exceeds ±1")
|
#expect(peak <= 1.0 + ceilingEpsilon, "cab=\(cab) mic=\(micValue) peak \(peak) exceeds ±1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Placement extremes (max proximity bass lift) must still be caught by the limiter.
|
||||||
|
let placed: [Float] = try render { $0.position = 1.0; $0.proximity = 1.0 }
|
||||||
|
#expect(placed.allSatisfy { $0.isFinite })
|
||||||
|
let placedPeak: Double = placed.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||||
|
#expect(placedPeak <= 1.0 + ceilingEpsilon, "placement extremes peak \(placedPeak) exceeds ±1")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func cabinetSelectorRebuildsOnChange() throws {
|
@Test func cabinetSelectorRebuildsOnChange() throws {
|
||||||
|
|||||||
Reference in New Issue
Block a user