feat(amp): Bias X (push-pull balance) in the advanced pop-over
Phase 13. Add a shared power-amp Bias X control modelling push-pull tube balance. powerAmpStage(_:) runs two TriodeStage halves biased at powerAmpBiasInput ± (biasX·biasXMaxSpread) and averages them: at biasX = 0 both halves share the base bias, so the average is bit-identical to the prior single stage (default, no re-voicing); turning it up spreads the operating points, shifting the even/odd harmonic mix. Deliberately a character control on the single-ended power model, not a full push-pull topology rebuild — it reduces to the exact shipped tone at biasX = 0 (monotonic imbalance amount, default 0). Appended to advancedKnobs (Sag, Bias, Bias X) — append-only so Phase-11 presets (2 advancedValues) still load with Bias X defaulting. Tests: Bias X changes waveshape (RMS-normalized, not level), stays within ±1, is exposed in the pop-over, round-trips through state; neutral Sag/Bias/Bias X is bit-exact identity. 650 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,10 @@ import LyrebirdUI
|
||||
/// → TriodeStage(drive: gain) (preamp)
|
||||
/// → ToneStack(bass, mid, treble, model) (fixed per amp)
|
||||
/// → onboardEffects(_:) (subclass hook — e.g. reverb + tremolo; default identity)
|
||||
/// → TriodeStage(power-amp drive) (power-amp warmth)
|
||||
/// → powerAmpStage(_:) (power amp — two TriodeStage halves blended by
|
||||
/// Bias X; single-stage tone at biasX = 0)
|
||||
/// → shapeVoice(_:) (subclass signature filter)
|
||||
/// → applySag(_:) (shared power-supply Sag droop; identity at sag = 0)
|
||||
/// → ConvolutionReverb(cab IR) (speaker cabinet — voice-selectable, or None for a
|
||||
/// separate cab block; rebuild on change)
|
||||
/// → TriodeStage(bias: 0) → Clip(±1) (output soft-limit + hard safety ceiling — always on)
|
||||
@@ -57,6 +59,11 @@ open class AmpVoicePedal: Pedal {
|
||||
/// hotter (warmer, more even harmonics). Surfaced in the advanced pop-over. See
|
||||
/// ``powerAmpBiasInput``.
|
||||
@UIParam public var bias: Double = 0.5
|
||||
/// Power-amp **Bias X** (push-pull balance) in `[0, 1]`, default `0` = balanced. `0` reproduces
|
||||
/// the shipped single-stage tone exactly; turning it up spreads the two power-amp half-stages'
|
||||
/// operating points, shifting the even/odd harmonic mix as an imbalanced push-pull pair would.
|
||||
/// Surfaced in the advanced pop-over. See ``powerAmpStage(_:)``.
|
||||
@UIParam public var biasX: Double = 0.0
|
||||
|
||||
// MARK: - Subclass configuration
|
||||
|
||||
@@ -169,6 +176,34 @@ open class AmpVoicePedal: Pedal {
|
||||
LinLin.Audio($bias, inLo: 0.0, inHi: 1.0, outLo: coldPowerAmpBias, outHi: hotPowerAmpBias)
|
||||
}
|
||||
|
||||
/// The power-amp stage, modelling push-pull tube **balance** via ``biasX``: two `TriodeStage`
|
||||
/// halves biased at `powerAmpBiasInput ± (biasX · biasXMaxSpread)`, averaged. At `biasX = 0` both
|
||||
/// halves share the base bias, so the average is bit-identical to a single stage (the shipped
|
||||
/// behaviour); turning `biasX` up spreads their operating points, shifting the even/odd harmonic
|
||||
/// mix the way an imbalanced push-pull pair would.
|
||||
///
|
||||
/// > Note: this is a character control layered on the single-ended power-stage model, not a full
|
||||
/// > push-pull topology rebuild — it deliberately reduces to the exact prior tone at `biasX = 0`.
|
||||
///
|
||||
/// - Parameter signal: The post-`onboardEffects` signal into the power amp.
|
||||
/// - Returns: The blended power-amp output.
|
||||
func powerAmpStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let imbalance: any ValidGeneratorInput = $biasX * biasXMaxSpread
|
||||
let hotHalf: TriodeStage = TriodeStage(
|
||||
input: signal,
|
||||
drive: powerAmpDriveInput,
|
||||
bias: powerAmpBiasInput + imbalance,
|
||||
oversample: powerAmpOversample
|
||||
)
|
||||
let coldHalf: TriodeStage = TriodeStage(
|
||||
input: signal,
|
||||
drive: powerAmpDriveInput,
|
||||
bias: powerAmpBiasInput - imbalance,
|
||||
oversample: powerAmpOversample
|
||||
)
|
||||
return (hotHalf + coldHalf) * powerAmpHalfBlend
|
||||
}
|
||||
|
||||
/// Applies power-supply **Sag**: an `AmplitudeFollower` on `signal` reduces gain as it gets loud
|
||||
/// (droop) and recovers slowly (bloom). `Sag` scales the depth; at `sag = 0` the droop is `0` and
|
||||
/// the gain is a constant `1.0` (an identity multiply), so a sag-less amp is unchanged.
|
||||
@@ -208,6 +243,12 @@ open class AmpVoicePedal: Pedal {
|
||||
/// drastically re-voicing the amp.
|
||||
private let coldPowerAmpBias: Double = -0.25
|
||||
private let hotPowerAmpBias: Double = 0.25
|
||||
/// Maximum push-pull bias imbalance at `biasX = 1` — the offset applied oppositely to the two
|
||||
/// power-amp half-stages. Modest so the control colours the harmonics without destabilising the amp.
|
||||
private let biasXMaxSpread: Double = 0.35
|
||||
/// Equal-weight blend of the two power-amp half-stages. `0.5·(hot + cold)` averages them, so at
|
||||
/// `biasX = 0` (identical halves) the result is bit-identical to a single stage.
|
||||
private let powerAmpHalfBlend: Double = 0.5
|
||||
/// Sag envelope-follower attack — moderately fast (the supply starts drooping under load).
|
||||
private let sagAttackSeconds: Double = 0.02
|
||||
/// Sag envelope-follower release — slow, so the sag lingers and blooms back (supply recovery).
|
||||
@@ -296,12 +337,14 @@ open class AmpVoicePedal: Pedal {
|
||||
}
|
||||
|
||||
/// Power-amp deep-cut controls, tucked behind the pedal card's advanced pop-over: **Sag**
|
||||
/// (power-supply droop/bloom) and **Bias** (power-amp grid-bias operating point). Neither is a
|
||||
/// topology control — both are live nodes that round-trip through the rig save format.
|
||||
/// (power-supply droop/bloom), **Bias** (power-amp grid-bias operating point), and **Bias X**
|
||||
/// (push-pull balance). None is a topology control — all are live nodes that round-trip through
|
||||
/// the rig save format. Order is append-only (persisted positionally in `advancedValues`).
|
||||
public override var advancedKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Sag", node: $sag, range: signatureRange),
|
||||
PedalKnob(label: "Bias", node: $bias, range: toneRange),
|
||||
PedalKnob(label: "Bias X", node: $biasX, range: signatureRange),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -336,8 +379,7 @@ open class AmpVoicePedal: Pedal {
|
||||
let toned: ToneStack = ToneStack(
|
||||
input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel)
|
||||
let processed: any ValidGeneratorInput = onboardEffects(toned)
|
||||
let powerAmp: TriodeStage = TriodeStage(
|
||||
input: processed, drive: powerAmpDriveInput, bias: powerAmpBiasInput, oversample: powerAmpOversample)
|
||||
let powerAmp: any ValidGeneratorInput = powerAmpStage(processed)
|
||||
return applySag(shapeVoice(powerAmp))
|
||||
}
|
||||
|
||||
|
||||
@@ -229,24 +229,49 @@ struct AmpVoicePedalTests {
|
||||
}
|
||||
|
||||
@Test func neutralBiasAndZeroSagAreIdentityDefault() throws {
|
||||
// The shipped defaults are sag = 0 and bias = 0.5 (neutral). Setting them explicitly to those
|
||||
// values must be bit-for-bit identical to leaving them at their defaults — proof the new
|
||||
// controls don't perturb any existing amp's voice at their neutral position.
|
||||
// The shipped defaults are sag = 0, bias = 0.5, biasX = 0 (all neutral). Setting them
|
||||
// explicitly to those values must be bit-for-bit identical to leaving them at their defaults
|
||||
// — proof the pop-over controls don't perturb any existing amp's voice at their neutral point.
|
||||
for voice in voices {
|
||||
let byDefault: [Float] = try render(voice.make)
|
||||
let explicit: [Float] = try render(voice.make) { $0.sag = 0.0; $0.bias = 0.5 }
|
||||
#expect(windowedSSD(byDefault, explicit) == 0, "\(voice.name) neutral Sag/Bias is not identity")
|
||||
let explicit: [Float] = try render(voice.make) { $0.sag = 0.0; $0.bias = 0.5; $0.biasX = 0.0 }
|
||||
#expect(windowedSSD(byDefault, explicit) == 0, "\(voice.name) neutral Sag/Bias/Bias X is not identity")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func advancedKnobsExposeSagAndBias() throws {
|
||||
@Test func biasXChangesWaveshape() throws {
|
||||
// Bias X spreads the two power-amp half-stages' operating points → changes the even/odd
|
||||
// harmonic mix (a waveshape change), not merely the level. RMS-normalize so a pure level
|
||||
// difference collapses.
|
||||
for voice in voices {
|
||||
let balanced: [Float] = try render(voice.make) { $0.gain = 22.0; $0.biasX = 0.0 }
|
||||
let imbalanced: [Float] = try render(voice.make) { $0.gain = 22.0; $0.biasX = 1.0 }
|
||||
#expect(hasNonSilentOutput(balanced) && hasNonSilentOutput(imbalanced))
|
||||
#expect(rmsNormalizedSSD(balanced, imbalanced) > 1.0e-4,
|
||||
"\(voice.name) Bias X changed level but not waveshape")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func biasXStaysWithinCeiling() throws {
|
||||
let ceilingEpsilon: Double = 1.0e-4
|
||||
for voice in voices {
|
||||
let hot: [Float] = try render(voice.make) { (pedal: AmpVoicePedal) in
|
||||
pedal.gain = 30.0; pedal.bass = 1.0; pedal.treble = 1.0; pedal.biasX = 1.0
|
||||
}
|
||||
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||
#expect(peak <= 1.0 + ceilingEpsilon, "\(voice.name) Bias X peak \(peak) exceeds ±1")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func advancedKnobsExposeSagBiasAndBiasX() throws {
|
||||
for voice in voices {
|
||||
let pedal: AmpVoicePedal = voice.make()
|
||||
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias"], "\(voice.name) advanced knobs")
|
||||
// Sag/Bias are pop-over-only — they must NOT also appear on the pedal face.
|
||||
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias", "Bias X"],
|
||||
"\(voice.name) advanced knobs")
|
||||
// These are pop-over-only — they must NOT also appear on the pedal face.
|
||||
let faceLabels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(!faceLabels.contains("Sag") && !faceLabels.contains("Bias"),
|
||||
"\(voice.name) leaked Sag/Bias onto the pedal face")
|
||||
#expect(!faceLabels.contains("Sag") && !faceLabels.contains("Bias") && !faceLabels.contains("Bias X"),
|
||||
"\(voice.name) leaked an advanced knob onto the pedal face")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,9 +279,11 @@ struct AmpVoicePedalTests {
|
||||
let pedal: CaliforniaAmpPedal = CaliforniaAmpPedal()
|
||||
pedal.sag = 0.7
|
||||
pedal.bias = 0.2
|
||||
pedal.biasX = 0.6
|
||||
let restored: CaliforniaAmpPedal = CaliforniaAmpPedal()
|
||||
restored.applyState(pedal.captureState())
|
||||
#expect(restored.sag == 0.7 && restored.bias == 0.2, "Sag/Bias did not round-trip through state")
|
||||
#expect(restored.sag == 0.7 && restored.bias == 0.2 && restored.biasX == 0.6,
|
||||
"Sag/Bias/Bias X did not round-trip through state")
|
||||
}
|
||||
|
||||
// MARK: - Cabinet decoupling
|
||||
|
||||
@@ -101,7 +101,7 @@ struct ModernHighGainAmpPedalTests {
|
||||
// Sag now lives in the shared advanced pop-over (with Bias), not on the pedal face.
|
||||
#expect(pedal.effectKnobs.map { $0.label }
|
||||
== ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive"])
|
||||
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias"])
|
||||
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias", "Bias X"])
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Channel", "Tight"])
|
||||
#expect(pedal.widthUnits == 4)
|
||||
#expect(pedal.toneStackModel == .mesa)
|
||||
@@ -140,7 +140,8 @@ struct ModernHighGainAmpPedalTests {
|
||||
// Gain…Drive, then Mix (0.8), Level (0.9) — the old Sag (0.7) is gone from knobValues.
|
||||
#expect(restored.knobValues == [10.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 15.0, 0.8, 0.9],
|
||||
"legacy Sag shifted Mix/Level: \(restored.knobValues)")
|
||||
// Sag lifted into advanced slot 0; Bias had no legacy value → default 0.5.
|
||||
#expect(restored.advancedValues == [0.7, 0.5], "Sag/Bias advanced values wrong: \(restored.advancedValues)")
|
||||
// Sag lifted into advanced slot 0; Bias (0.5) and Bias X (0.0) had no legacy value → defaults.
|
||||
#expect(restored.advancedValues == [0.7, 0.5, 0.0],
|
||||
"Sag/Bias/Bias X advanced values wrong: \(restored.advancedValues)")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user