Compare commits
2 Commits
9588d77137
...
48dce06f5a
| Author | SHA1 | Date | |
|---|---|---|---|
| 48dce06f5a | |||
| b9a63eeaf5 |
@@ -85,6 +85,19 @@ open class AmpVoicePedal: Pedal {
|
|||||||
signal
|
signal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drive into the power-amp `TriodeStage`. Defaults to the fixed power-amp drive; a
|
||||||
|
/// master-volume amp overrides this to return a live `Master` knob mapped to a drive range, so
|
||||||
|
/// turning Master up pushes the power-amp stage into saturation — the real master-volume
|
||||||
|
/// behaviour — rather than merely attenuating the finished output the way `level` does. Non-
|
||||||
|
/// master amps leave it at the fixed value and are unaffected.
|
||||||
|
open var powerAmpDriveInput: any ValidGeneratorInput { powerAmpDrive }
|
||||||
|
|
||||||
|
/// Oversampling factor for the power-amp stage — `2` or `4`. Amps that drive the power amp hard
|
||||||
|
/// (a `Master` control) override to `4` for more anti-alias headroom, since higher drive
|
||||||
|
/// generates more high-order harmonics. Defaults to `2` (ample for the lightly-driven fixed
|
||||||
|
/// power stage of the non-master amps).
|
||||||
|
open var powerAmpOversample: Int { 2 }
|
||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
private static let defaultMix: Double = 1.0
|
private static let defaultMix: Double = 1.0
|
||||||
@@ -201,7 +214,7 @@ open class AmpVoicePedal: Pedal {
|
|||||||
input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel)
|
input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel)
|
||||||
let processed: any ValidGeneratorInput = onboardEffects(toned)
|
let processed: any ValidGeneratorInput = onboardEffects(toned)
|
||||||
let powerAmp: TriodeStage = TriodeStage(
|
let powerAmp: TriodeStage = TriodeStage(
|
||||||
input: processed, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2)
|
input: processed, drive: powerAmpDriveInput, bias: powerAmpBias, oversample: powerAmpOversample)
|
||||||
return shapeVoice(powerAmp)
|
return shapeVoice(powerAmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,26 +7,49 @@
|
|||||||
import LyrebirdSynth
|
import LyrebirdSynth
|
||||||
import LyrebirdUI
|
import LyrebirdUI
|
||||||
|
|
||||||
/// British-voiced amp (mid-forward crunch) with a **Presence** upper-high lift control.
|
/// British-voiced amp (mid-forward crunch) with a **Presence** lift and a **Master** volume.
|
||||||
///
|
///
|
||||||
/// A ``AmpVoicePedal`` fixed to the British tone stack, defaulting to a higher gain for crunch.
|
/// A ``AmpVoicePedal`` fixed to the British tone stack, defaulting to a higher gain for crunch. The
|
||||||
|
/// Master control drives the power-amp stage (via ``AmpVoicePedal/powerAmpDriveInput``), so raising
|
||||||
|
/// it adds power-amp saturation — turn `Gain` up for preamp grind and use `Master` to set how hard
|
||||||
|
/// that hits the power amp, the classic master-volume interplay.
|
||||||
public final class BritishAmpPedal: AmpVoicePedal {
|
public final class BritishAmpPedal: AmpVoicePedal {
|
||||||
|
|
||||||
/// Presence amount in [0, 1] → 0…`presenceMaxGainDb` of lift above `presenceFreqHz`.
|
/// Presence amount in [0, 1] → 0…`presenceMaxGainDb` of lift above `presenceFreqHz`.
|
||||||
@UIParam public var presence: Double = 0.4
|
@UIParam public var presence: Double = 0.4
|
||||||
|
/// Master volume in [0, 1] → power-amp drive in [`masterMinDrive`, `masterMaxDrive`]. The
|
||||||
|
/// default maps to ≈1.5 drive — the amp's prior fixed power-amp drive — so the out-of-box tone
|
||||||
|
/// is unchanged; turn it up for power-amp saturation.
|
||||||
|
@UIParam public var master: Double = 0.22
|
||||||
|
|
||||||
private let presenceFreqHz: Double = 4500.0
|
private let presenceFreqHz: Double = 4500.0
|
||||||
private let presenceMaxGainDb: Double = 8.0
|
private let presenceMaxGainDb: Double = 8.0
|
||||||
private let shelfSlope: Double = 0.7
|
private let shelfSlope: Double = 0.7
|
||||||
|
/// Power-amp drive at `master = 0` — barely driven (cleanest power stage).
|
||||||
|
private let masterMinDrive: Double = 0.5
|
||||||
|
/// Power-amp drive at `master = 1` — hard into power-amp saturation.
|
||||||
|
private let masterMaxDrive: Double = 5.0
|
||||||
|
|
||||||
public override var toneStackModel: ToneStackModel { .marshall }
|
public override var toneStackModel: ToneStackModel { .marshall }
|
||||||
public override var summaryText: String {
|
public override var summaryText: String {
|
||||||
"British crunch — forward mids and bite, with a Presence lift."
|
"British crunch — forward mids and bite, with Presence and a Master volume."
|
||||||
}
|
}
|
||||||
public override var signatureKnobs: [PedalKnob] {
|
public override var signatureKnobs: [PedalKnob] {
|
||||||
[PedalKnob(label: "Presence", node: $presence, range: signatureRange)]
|
[
|
||||||
|
PedalKnob(label: "Presence", node: $presence, range: signatureRange),
|
||||||
|
PedalKnob(label: "Master", node: $master, range: signatureRange),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Master drives the power-amp stage: `[0, 1]` → `[masterMinDrive, masterMaxDrive]`.
|
||||||
|
public override var powerAmpDriveInput: any ValidGeneratorInput {
|
||||||
|
LinLin.Audio($master, inLo: 0.0, inHi: 1.0, outLo: masterMinDrive, outHi: masterMaxDrive)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 4× oversampling on the power-amp stage — Master can drive it well past the fixed value used
|
||||||
|
/// by the non-master amps, so the extra anti-alias headroom keeps the added harmonics clean.
|
||||||
|
public override var powerAmpOversample: Int { 4 }
|
||||||
|
|
||||||
/// Creates a British amp.
|
/// Creates a British amp.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
|
|||||||
@@ -49,6 +49,25 @@ struct AmpVoicePedalTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sum-of-squared-differences after RMS-normalizing each window, so a pure level difference
|
||||||
|
/// collapses to ~0 and only a genuine waveshape (saturation) change registers.
|
||||||
|
private func rmsNormalizedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double {
|
||||||
|
guard a.count >= skip + window, b.count >= skip + window else { return 0.0 }
|
||||||
|
let aw: ArraySlice<Float> = a[skip..<(skip + window)]
|
||||||
|
let bw: ArraySlice<Float> = b[skip..<(skip + window)]
|
||||||
|
func rms(_ x: ArraySlice<Float>) -> Double {
|
||||||
|
let sumSq: Double = x.reduce(0.0) { $0 + Double($1) * Double($1) }
|
||||||
|
return (sumSq / Double(x.count)).squareRoot()
|
||||||
|
}
|
||||||
|
let ra: Double = rms(aw)
|
||||||
|
let rb: Double = rms(bw)
|
||||||
|
guard ra > 0.0, rb > 0.0 else { return 0.0 }
|
||||||
|
return zip(aw, bw).reduce(0.0) { acc, pair in
|
||||||
|
let d: Double = Double(pair.0) / ra - Double(pair.1) / rb
|
||||||
|
return acc + d * d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The three concrete voices under test, keyed by their display name / registry key.
|
/// The three concrete voices under test, keyed by their display name / registry key.
|
||||||
private let voices: [(name: String, make: () -> AmpVoicePedal)] = [
|
private let voices: [(name: String, make: () -> AmpVoicePedal)] = [
|
||||||
("California", { CaliforniaAmpPedal() }),
|
("California", { CaliforniaAmpPedal() }),
|
||||||
@@ -127,6 +146,37 @@ struct AmpVoicePedalTests {
|
|||||||
#expect(windowedSSD(flat, lifted) > 0, "British Presence had no effect")
|
#expect(windowedSSD(flat, lifted) > 0, "British Presence had no effect")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func britishMasterDrivesPowerAmp() throws {
|
||||||
|
// Master drives the power-amp stage into saturation — so it must change the *waveshape*, not
|
||||||
|
// just the level (which is what `level` would do). RMS-normalize each window before diffing:
|
||||||
|
// a pure level change collapses to ~0, so a clearly-positive normalized SSD proves genuine
|
||||||
|
// power-amp saturation.
|
||||||
|
let low: [Float] = try render({ BritishAmpPedal() }) { $0.gain = 12.0; $0.master = 0.1 }
|
||||||
|
let high: [Float] = try render({ BritishAmpPedal() }) { $0.gain = 12.0; $0.master = 1.0 }
|
||||||
|
#expect(hasNonSilentOutput(low) && hasNonSilentOutput(high))
|
||||||
|
#expect(rmsNormalizedSSD(low, high) > 1.0e-3, "Master changed level but not tone (no power-amp saturation)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func britishStaysWithinCeilingAtMaxMaster() throws {
|
||||||
|
let ceilingEpsilon: Double = 1.0e-4
|
||||||
|
let hot: [Float] = try render({ BritishAmpPedal() }) { (pedal: BritishAmpPedal) in
|
||||||
|
pedal.gain = 30.0
|
||||||
|
pedal.bass = 1.0
|
||||||
|
pedal.treble = 1.0
|
||||||
|
pedal.master = 1.0
|
||||||
|
}
|
||||||
|
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
|
||||||
|
#expect(peak <= 1.0 + ceilingEpsilon, "British peak \(peak) exceeds the ±1 ceiling at max Master")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func britishMasterRoundTripsThroughState() throws {
|
||||||
|
let pedal: BritishAmpPedal = BritishAmpPedal()
|
||||||
|
pedal.master = 0.8
|
||||||
|
let restored: BritishAmpPedal = BritishAmpPedal()
|
||||||
|
restored.applyState(pedal.captureState())
|
||||||
|
#expect(restored.master == 0.8, "Master did not round-trip")
|
||||||
|
}
|
||||||
|
|
||||||
@Test func chimeCutChangesOutput() throws {
|
@Test func chimeCutChangesOutput() throws {
|
||||||
let open: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 0.0 }
|
let open: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 0.0 }
|
||||||
let dark: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 1.0 }
|
let dark: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 1.0 }
|
||||||
@@ -137,7 +187,7 @@ struct AmpVoicePedalTests {
|
|||||||
|
|
||||||
@Test func exposesControls() throws {
|
@Test func exposesControls() throws {
|
||||||
#expect(CaliforniaAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Bright"])
|
#expect(CaliforniaAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Bright"])
|
||||||
#expect(BritishAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Presence"])
|
#expect(BritishAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Presence", "Master"])
|
||||||
#expect(ChimeAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"])
|
#expect(ChimeAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"])
|
||||||
for voice in voices {
|
for voice in voices {
|
||||||
let pedal: AmpVoicePedal = voice.make()
|
let pedal: AmpVoicePedal = voice.make()
|
||||||
|
|||||||
Reference in New Issue
Block a user