// RoomReverbPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Room reverb pedal: the GVerb FDN room/hall algorithm, folded to mono. /// /// Signal chain (inside `effect(_:)`): /// ``` /// dry → GVerb.Audio(dryLevel: 0, roomSize:, reverbTime:, damping:, tailLevel:) → stereo (2 ch) /// → SumChannels.Audio(mul: 0.5) → mono (fold) /// ``` /// /// `GVerb` runs with `dryLevel: 0` (pure wet); the base `Pedal` handles the wet/dry blend via its /// own `mix` parameter. The native-stereo output is summed to mono with a ×0.5 gain. /// /// ## Parameters /// /// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: /// /// - Parameters: /// - size: Room size in metres, in [1, 100]. Larger = bigger space. Defaults to `30`. /// - decay: Reverb time (T60) in seconds, in [0.2, 12]. Defaults to `3`. /// - damp: High-frequency damping in [0, 1]. Higher = darker tail. Defaults to `0.5`. /// - tail: Late-reverb level in [0, 1] — how present the room tail sits. Defaults to `0.6`. public final class RoomReverbPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Parametric room and hall reverb — dial the space in metres and its decay time." } // MARK: - Parameters /// Room size in metres, in [1, 100]. Larger = bigger space. @UIParam public var size: Double = 30.0 /// Reverb time (T60) in seconds, in [0.2, 12]. @UIParam public var decay: Double = 3.0 /// High-frequency damping in [0, 1]. Higher = darker tail. @UIParam public var damp: Double = 0.5 /// Late-reverb level in [0, 1] — how present the room tail sits. @UIParam public var tail: Double = 0.6 // MARK: - Constants /// GVerb dry level. `0` = pure wet; the base `Pedal` handles dry/wet blending. private let gverbDryLevel: Double = 0.0 /// Gain applied to the summed stereo→mono fold, compensating for channel doubling. private let stereoSumGain: Double = 0.5 /// Default wet/dry blend — a partial mix so the dry signal stays up front. private static let defaultMix: Double = 0.3 // MARK: - Ranges private let sizeRange: ClosedRange = 1.0 ... 100.0 private let decayRange: ClosedRange = 0.2 ... 12.0 private let normalizedRange: ClosedRange = 0.0 ... 1.0 // MARK: - UI knobs public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Size", node: $size, range: sizeRange), PedalKnob(label: "Decay", node: $decay, range: decayRange), PedalKnob(label: "Damp", node: $damp, range: normalizedRange), PedalKnob(label: "Tail", node: $tail, range: normalizedRange), ] } // MARK: - Init /// Creates a room reverb 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: "Room Reverb", inputBus: inputBus, outputBus: outputBus, initialMix: RoomReverbPedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { // GVerb produces a 2-channel stereo output. let stereoRoom: GVerb.Audio = GVerb.Audio( source: dry, roomSize: $size, reverbTime: $decay, damping: $damp, tailLevel: $tail, dryLevel: gverbDryLevel, sampleRate: sampleRate ) // Sum stereo → mono with ×0.5 to avoid level doubling. return SumChannels.Audio( input: stereoRoom, mul: stereoSumGain ) } }