UNPKG

ez-web-audio

Version:

Making the Web Audio API super EZ since 2024.

66 lines 2.29 kB
import { Effect } from './index'; /** * GainEffect - A thin wrapper around GainNode that implements the Effect interface. * * For a single-node effect like GainEffect: * - `input` and `output` both point to the same GainNode * - `bypass` sets gain to 1.0 (passthrough), stores/restores the previous value * - `mix` controls how much of the effect is applied (0=passthrough, 1=full effect) * - `value` is the gain amount applied when not bypassed * * @example * ```typescript * const gain = createGainEffect(audioContext, 0.5) * gain.value = 0.8 // Set gain to 80% * gain.bypass = true // Passthrough (gain becomes 1.0) * gain.bypass = false // Restore to 0.8 * ``` */ export declare class GainEffect implements Effect { private readonly gainNode; private _bypass; private _mix; private _value; constructor(audioContext: AudioContext, initialValue?: number); /** The input AudioNode (same as output for single-node effect) */ get input(): AudioNode; /** The output AudioNode (same as input for single-node effect) */ get output(): AudioNode; /** The gain value (0.0 to any positive number) */ get value(): number; set value(v: number); /** * When true, gain becomes 1.0 (passthrough). * When false, restores the previous gain value. */ get bypass(): boolean; set bypass(v: boolean); /** * Wet/dry mix: 0 = passthrough (gain of 1.0), 1 = full effect. * Mix interpolates between 1.0 and the set value. */ get mix(): number; set mix(v: number); /** * Apply the effective gain based on mix level. * effectiveGain = 1 + (value - 1) * mix * When mix = 0: effectiveGain = 1 (passthrough) * When mix = 1: effectiveGain = value (full effect) */ private applyEffectiveGain; } /** * Factory function to create a GainEffect. * * @param audioContext - The AudioContext to use * @param initialValue - Initial gain value (default: 1.0) * @returns A new GainEffect instance * * @example * ```typescript * const gain = createGainEffect(audioContext) * gain.value = 0.5 // 50% volume * ``` */ export declare function createGainEffect(audioContext: AudioContext, initialValue?: number): GainEffect; //# sourceMappingURL=gain-effect.d.ts.map