// 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 × OscSin(frequency) → 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 = 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 { let carrier: OscSin.Audio = OscSin.Audio(freq: $frequency) return dry * carrier } }