8983e8829e
Anti-aliasing (Tier 1): every hard nonlinearity ran at the engine rate, so the harmonics it generated folded back as inharmonic aliasing — worst on loud/bright input at high drive. Add two oversampled RT generators built on Lyrebird's halfband up/down-samplers and move the drive pedals onto them: - OversampledSaturator (+ SaturationCurve) — tanh / normalised soft-clip / tanh+hard-clip curves at 2× or 4×. DistortionPedal now does its tanh→gain→hard clip at 4× (clip before the tone low-pass), with a final hard clip after the low-pass to re-establish the strict output bound; FuzzPedal (tanh) and OverdrivePedal (soft-clip) at 2×. - OversampledRingModulator — input × sine carrier at 2×, carrier synthesized at the oversampled rate so the sum sideband can't alias. Phase wraps both directions (safe for negative carrier frequencies) and a sampleRate guard prevents NaN latching. RingModulatorPedal uses it. Dynamics (Tier 2): SustainerPedal gains an opt-in Safety switch (off by default) that inserts a brick-wall LookAheadLimiter after its compressor to catch the transient overshoot a low-threshold/high-makeup setting can push past full scale. Tests: generator-level alias-reduction proofs (Goertzel alias/fundamental ratio vs a naive base-rate baseline) for both oversampled generators, hard-clip/soft bounds, negative-carrier stability, distortion output-bound at high drive, and Sustainer safety switch exposure + peak-capping. Full suite 478 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
86 lines
2.6 KiB
Swift
86 lines
2.6 KiB
Swift
// RingModulatorPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Ring modulator pedal.
|
||
///
|
||
/// Multiplies the input by a tunable sine carrier, producing sum-and-difference sidebands —
|
||
/// metallic, bell-like, and robotic tones. Below ~30 Hz the carrier reads as tremolo-style
|
||
/// amplitude modulation; in the audio range it becomes classic ring modulation.
|
||
///
|
||
/// Signal path (inside `effect(_:)`):
|
||
/// ```
|
||
/// dry → OversampledRingModulator(freq: frequency, oversample: 2) → wet
|
||
/// ```
|
||
///
|
||
/// The wet/dry blend and bypass are handled by the `Pedal` base class.
|
||
///
|
||
/// ## Parameters
|
||
///
|
||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||
///
|
||
/// - Parameters:
|
||
/// - frequency: Carrier frequency in Hz. Range `[20, 2000]`. Defaults to `220.0`.
|
||
public final class RingModulatorPedal: Pedal {
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Carrier frequency in Hz. Range [20, 2000].
|
||
@UIParam public var frequency: Double = 220.0
|
||
|
||
// MARK: - Constants
|
||
|
||
/// Default wet/dry blend — ring mod is harsh, so keep the dry signal present.
|
||
private static let defaultMix: Double = 0.5
|
||
|
||
// MARK: - UI knobs
|
||
|
||
private let frequencyRange: ClosedRange<Double> = 20.0 ... 2000.0
|
||
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Frequency", node: $frequency, range: frequencyRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a ring modulator pedal.
|
||
///
|
||
/// - Parameters:
|
||
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
||
public init(
|
||
inputBus: Int = 0,
|
||
outputBus: Int = 0
|
||
) {
|
||
super.init(
|
||
name: "Ring Modulator",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: RingModulatorPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
public override var summary: String {
|
||
"Multiplies your signal by a tunable carrier for metallic, bell-like, and robotic tones."
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
/// Multiplies the dry signal by the sine carrier.
|
||
///
|
||
/// - Parameter dry: Dry mono input signal.
|
||
/// - Returns: The ring-modulated wet signal.
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
// Oversampled multiply: the sum sideband (f_in + f_carrier) can exceed Nyquist and
|
||
// fold back as an inharmonic alias, so do the product at 2× and filter on the way down.
|
||
return OversampledRingModulator(dry, freq: $frequency, oversample: 2)
|
||
}
|
||
}
|