// MicVoice.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT /// A microphone voicing baked into the cabinet impulse response — the frequency signature of the /// mic in front of the speaker, layered on top of the ``CabinetVoice`` cab curve. /// /// Each voice is a compact set of ``CabIRStage`` filter stages (a presence bump, low-end and /// top-end shelving) that ``CabinetIRFactory`` appends to the cab cascade before baking, so mic /// choice costs nothing extra at render time — it is folded into the single convolution IR. These /// are **broad-strokes synthesized curves** (our own MIT content, not captures of any specific /// microphone), analogous to ``CabinetVoice``. /// /// ``off`` contributes no stages, so a cab with no mic bakes exactly the raw cab voice — the /// original, mic-less behaviour. public enum MicVoice: String, CaseIterable, Sendable { case off case dynamic case ribbon case condenser /// The voice at a selector value (an index into ``allCases``), rounded and clamped to the valid /// range. Mirrors ``CabinetVoice/voice(atSelectorValue:)`` so a huge / NaN selector never traps. /// /// - Parameter selectorValue: The live selector node value (nominally an integer index). /// - Returns: The corresponding voice, clamped to `allCases`. public static func voice(atSelectorValue selectorValue: Double) -> MicVoice { let all: [MicVoice] = allCases guard selectorValue.isFinite else { return all[0] } let bounded: Double = Swift.min(Swift.max(selectorValue, 0.0), Double(all.count - 1)) let index: Int = Int(bounded.rounded()) return all[index] } /// Human-readable name for pickers. public var displayName: String { switch self { case .off: return "No Mic" case .dynamic: return "Dynamic" case .ribbon: return "Ribbon" case .condenser: return "Condenser" } } /// The mic's filter stages, appended to the cab cascade before baking. Empty for ``off``. /// /// Broad-strokes voicings: the **dynamic** (moving-coil, close-mic staple) adds an upper-mid /// presence bump with a tightened low end and rolled-off extreme top; the **ribbon** is dark and /// smooth (warm low-mid, steep top rolloff, no presence spike); the **condenser** is the most /// extended and airy (gentle top-end lift, light presence sheen). var stages: [CabIRStage] { switch self { case .off: return [] case .dynamic: return [ CabIRStage.lowShelf(120.0, gainDb: -2.0), CabIRStage.peaking(5500.0, q: 1.0, gainDb: 4.0), CabIRStage.highShelf(9000.0, gainDb: -3.0), ] case .ribbon: return [ CabIRStage.lowShelf(200.0, gainDb: 2.5), CabIRStage.peaking(2500.0, q: 0.8, gainDb: -1.5), CabIRStage.highShelf(6500.0, gainDb: -7.0), ] case .condenser: return [ CabIRStage.peaking(8000.0, q: 1.0, gainDb: 1.5), CabIRStage.highShelf(11000.0, gainDb: 3.0), ] } } }