feat(amp): shared power-amp Sag + Bias in an advanced pop-over
Phase 11. Promote Sag from Modern High-Gain to a shared AmpVoicePedal capability and add a Bias control, both surfaced in a new pedal-card pop-over rather than on the amp face. - AmpVoicePedal gains `sag` [0,1] (AmplitudeFollower gain-droop, clamped [0.15,1] to prevent phase inversion) and `bias` [0,1] mapped to the power-amp TriodeStage grid bias ([-0.25,0.25], neutral 0.5 → 0.0 so existing voices are unchanged at defaults). Both applied in preCabinetCore; new `applySag(_:)` + `powerAmpBiasInput` helpers. - Modern High-Gain drops its bespoke sag (now inherited); keeps sag=0.3 default. Sag moves off its face into the pop-over. - Pedal gains an `advancedKnobs` surface; PedalView draws a gear button (top-right) presenting them in a popover, reusing the existing pattern. - Advanced knobs round-trip through PedalState (new `advancedValues`, backward-compatible decode) and are MIDI-CC-mappable (appended last). De-branding (review nits): "Vox" removed from the Chime family's user-visible summaries + docs; "Fullerton Princeton" renamed to display "Fullerton Ivy League". Palette horizontal picker second row now shows Routing before the Amp Model group. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -183,6 +183,82 @@ struct AmpVoicePedalTests {
|
||||
#expect(windowedSSD(open, dark) > 0, "Chime Cut had no effect")
|
||||
}
|
||||
|
||||
// MARK: - Power-amp Sag / Bias (shared)
|
||||
|
||||
@Test func sagChangesOutput() throws {
|
||||
for voice in voices {
|
||||
let stiff: [Float] = try render(voice.make) { $0.gain = 20.0; $0.sag = 0.0 }
|
||||
let saggy: [Float] = try render(voice.make) { $0.gain = 20.0; $0.sag = 1.0 }
|
||||
#expect(windowedSSD(stiff, saggy) > 0, "\(voice.name) Sag had no effect")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func sagStaysWithinCeilingWithoutPhaseInversion() throws {
|
||||
// Sag is a gain droop; it must attenuate loud content, never phase-invert it. The envelope
|
||||
// tracks a post-power-amp signal that can exceed 1, so the droop gain is clamped positive.
|
||||
// Assert the sagged output correlates positively with the stiff one (not an inverted copy)
|
||||
// and never breaches the ±1 ceiling.
|
||||
let ceilingEpsilon: Double = 1.0e-4
|
||||
for voice in voices {
|
||||
let cfg: (AmpVoicePedal) -> Void = { (p: AmpVoicePedal) in
|
||||
p.gain = 25.0; p.bass = 1.0; p.treble = 1.0
|
||||
}
|
||||
let stiff: [Float] = try render(voice.make) { cfg($0); $0.sag = 0.0 }
|
||||
let saggy: [Float] = try render(voice.make) { cfg($0); $0.sag = 1.0 }
|
||||
let peak: Double = saggy.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||
#expect(peak <= 1.0 + ceilingEpsilon, "\(voice.name) sagged peak \(peak) exceeds ±1")
|
||||
let skip: Int = 4096, window: Int = 4096
|
||||
guard stiff.count >= skip + window, saggy.count >= skip + window else {
|
||||
Issue.record("\(voice.name) render too short"); continue
|
||||
}
|
||||
let dotProduct: Double = zip(stiff[skip..<(skip + window)], saggy[skip..<(skip + window)])
|
||||
.reduce(0.0) { acc, pair in acc + Double(pair.0) * Double(pair.1) }
|
||||
#expect(dotProduct > 0, "\(voice.name) Sag phase-inverted the signal (dot \(dotProduct) < 0)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func biasChangesWaveshape() throws {
|
||||
// Bias shifts the power-amp tanh operating point → 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 cold: [Float] = try render(voice.make) { $0.gain = 22.0; $0.bias = 0.0 }
|
||||
let hot: [Float] = try render(voice.make) { $0.gain = 22.0; $0.bias = 1.0 }
|
||||
#expect(hasNonSilentOutput(cold) && hasNonSilentOutput(hot))
|
||||
#expect(rmsNormalizedSSD(cold, hot) > 1.0e-4, "\(voice.name) Bias changed level but not waveshape")
|
||||
}
|
||||
}
|
||||
|
||||
@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.
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func advancedKnobsExposeSagAndBias() 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.
|
||||
let faceLabels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(!faceLabels.contains("Sag") && !faceLabels.contains("Bias"),
|
||||
"\(voice.name) leaked Sag/Bias onto the pedal face")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func sagBiasRoundTripThroughState() throws {
|
||||
let pedal: CaliforniaAmpPedal = CaliforniaAmpPedal()
|
||||
pedal.sag = 0.7
|
||||
pedal.bias = 0.2
|
||||
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")
|
||||
}
|
||||
|
||||
// MARK: - Chrome / config
|
||||
|
||||
@Test func exposesControls() throws {
|
||||
|
||||
Reference in New Issue
Block a user