EZ Web Audio / BaseEffect
Abstract Class: BaseEffect
Defined in: packages/core/src/effects/base-effect.ts:46
Abstract base class for audio effects that provides shared wet/dry mixing, bypass, and parameter ramping functionality.
Subclasses must:
- Call
super(audioContext)in their constructor - Wire their effect chain:
this.inputNode -> [effect nodes] -> this.wetGain - Implement
getAudioParam()to map parameter names to AudioParams
BaseEffect handles:
- Wet/dry mixing via equal-power crossfade
- Bypass (routes signal fully dry)
rampTo()for smooth parameter transitions
Example
class MyEffect extends BaseEffect {
private readonly myNode: GainNode
constructor(audioContext: AudioContext) {
super(audioContext)
this.myNode = audioContext.createGain()
this.inputNode.connect(this.myNode)
this.myNode.connect(this.wetGain)
}
protected getAudioParam(name: string): AudioParam | null {
if (name === 'gain') return this.myNode.gain
return null
}
}Extends
TypedEventEmitter<BaseEffectEventMap>
Extended by
Implements
Constructors
Constructor
new BaseEffect(
audioContext):BaseEffect
Defined in: packages/core/src/effects/base-effect.ts:62
Parameters
audioContext
AudioContext
Returns
BaseEffect
Overrides
Accessors
bypass
Get Signature
get bypass():
boolean
Defined in: packages/core/src/effects/base-effect.ts:95
When true, signal bypasses the effect entirely (100% dry).
Returns
boolean
Set Signature
set bypass(
v):void
Defined in: packages/core/src/effects/base-effect.ts:99
When true, effect is bypassed (passthrough)
Parameters
v
boolean
Returns
void
When true, effect is bypassed (passthrough)
Implementation of
input
Get Signature
get input():
AudioNode
Defined in: packages/core/src/effects/base-effect.ts:83
The input AudioNode (receives signal from chain)
Returns
AudioNode
The input AudioNode that receives signal from the chain
Implementation of
mix
Get Signature
get mix():
number
Defined in: packages/core/src/effects/base-effect.ts:108
Wet/dry mix: 0 = fully dry (no effect), 1 = fully wet (all through effect). Uses equal-power crossfade for natural mixing.
Returns
number
Set Signature
set mix(
v):void
Defined in: packages/core/src/effects/base-effect.ts:112
Wet/dry mix: 0 = fully dry (no effect), 1 = fully wet (full effect)
Parameters
v
number
Returns
void
Wet/dry mix: 0 = fully dry (no effect), 1 = fully wet (full effect)
Implementation of
output
Get Signature
get output():
AudioNode
Defined in: packages/core/src/effects/base-effect.ts:88
The output AudioNode (sends signal to next in chain)
Returns
AudioNode
The output AudioNode that sends signal to the next in chain
Implementation of
Methods
_clearListeners()
protected_clearListeners():void
Defined in: packages/core/src/events/typed-event-emitter.ts:192
Remove every listener registered through this emitter (via addEventListener(), on(), or once()), regardless of how many or what event type they're bound to.
Native EventTarget has no removeAllListeners(). This works around that by aborting a shared AbortSignal threaded through every addEventListener() call this class makes, then swapping in a fresh AbortController so the instance can keep accepting new listeners afterward (e.g. if it's reused before being garbage collected).
Subclasses call this from their dispose() alongside neutering dispatchEvent — the neuter stops future emits, this stops stale listener closures from being retained/invoked at all.
Returns
void
Inherited from
TypedEventEmitter._clearListeners
addEventListener()
Call Signature
addEventListener<
K>(type,listener,options?):void
Defined in: packages/core/src/events/typed-event-emitter.ts:44
Add a typed event listener for known event types. Overloaded to provide type safety for known event types while remaining compatible with the native EventTarget API.
Type Parameters
K
K extends "dispose"
Parameters
type
K
The event type (key of TMap)
listener
(event) => void
Typed event handler
options?
Standard addEventListener options
boolean | AddEventListenerOptions
Returns
void
Inherited from
TypedEventEmitter.addEventListener
Call Signature
addEventListener(
type,listener,options?):void
Defined in: packages/core/src/events/typed-event-emitter.ts:49
Add a typed event listener for known event types. Overloaded to provide type safety for known event types while remaining compatible with the native EventTarget API.
Parameters
type
string
The event type (key of TMap)
listener
Typed event handler
EventListenerOrEventListenerObject | null
options?
Standard addEventListener options
boolean | AddEventListenerOptions
Returns
void
Inherited from
TypedEventEmitter.addEventListener
dispose()
dispose():
void
Defined in: packages/core/src/effects/base-effect.ts:272
Disconnect all internal audio nodes and emit a 'dispose' event.
Subclass disposal contract: Subclasses that create additional audio nodes (e.g., BiquadFilterNode, DynamicsCompressorNode, WaveShaperNode) MUST override dispose() to disconnect those nodes before calling super.dispose().
Returns
void
Example
public override dispose(): void {
try { this.myNode.disconnect() } catch { /* already disconnected */ }
super.dispose()
}Idempotent — safe to call multiple times.
Implementation of
emit()
protectedemit<K>(type,detail):void
Defined in: packages/core/src/events/typed-event-emitter.ts:95
Emit a typed event with the given detail.
Creates a CustomEvent with the provided detail and dispatches it on this target. Subclasses call this internally to fire lifecycle events.
Type Parameters
K
K extends "dispose"
Parameters
type
K
The event type to emit (key of TMap)
detail
BaseEffectEventMap[K]["detail"]
The event detail object (typed by TMap)
Returns
void
Inherited from
getAudioContext()
getAudioContext():
AudioContext
Defined in: packages/core/src/effects/base-effect.ts:121
Get the AudioContext used by this effect. Useful for external tools (e.g., LFO) that need the context.
Returns
AudioContext
getAudioParam()
abstractprotectedgetAudioParam(name):AudioParam|null
Defined in: packages/core/src/effects/base-effect.ts:308
Map a parameter name to its underlying AudioParam. Subclasses implement this to expose their effect-specific parameters.
Parameters
name
string
The parameter name
Returns
AudioParam | null
The AudioParam, or null if not recognized
getParam()
getParam(
name):AudioParam|null
Defined in: packages/core/src/effects/base-effect.ts:134
Get a named AudioParam from this effect for external modulation.
Delegates to the subclass's getAudioParam() implementation. Returns null if the parameter name is not recognized.
Parameters
name
string
The parameter name (e.g., 'frequency', 'time', 'feedback')
Returns
AudioParam | null
The AudioParam, or null if not recognized
getUnrampableParams()
protectedgetUnrampableParams(): readonlystring[]
Defined in: packages/core/src/effects/base-effect.ts:243
Names of documented effect properties that are NOT backed by a single AudioParam (e.g. WaveShaper curve swaps, multi-node comb/allpass networks) and therefore cannot be smoothly ramped via rampTo(). rampTo() warns instead of silently no-op-ing when called with one of these names, so callers don't mistake "no-op" for "it worked."
Default: none. Subclasses override where applicable.
Returns
readonly string[]
off()
off<
K>(type,listener):this
Defined in: packages/core/src/events/typed-event-emitter.ts:167
Unsubscribe from an event.
Note: Due to native EventTarget limitations, you must provide the same listener function reference that was used when subscribing.
Type Parameters
K
K extends "dispose"
Parameters
type
K
The event type to unsubscribe from
listener
(event) => void
The event handler function to remove
Returns
this
this for chaining
Example
const handler = (e) => console.log(e.detail)
emitter.on('play', handler)
// later...
emitter.off('play', handler)Inherited from
on()
on<
K>(type,listener):this
Defined in: packages/core/src/events/typed-event-emitter.ts:116
Subscribe to one or more events. Supports chaining.
Type Parameters
K
K extends "dispose"
Parameters
type
The event type(s) to subscribe to (key or array of keys of TMap)
K | K[]
listener
(event) => void
The event handler function
Returns
this
this for chaining
Example
emitter.on('play', handlePlay).on('stop', handleStop)
emitter.on(['play', 'stop'], handleBoth)Inherited from
once()
once<
K>(type,listener):this
Defined in: packages/core/src/events/typed-event-emitter.ts:141
Subscribe to an event once. Handler is removed after first invocation.
Type Parameters
K
K extends "dispose"
Parameters
type
K
The event type to subscribe to
listener
(event) => void
The event handler function
Returns
this
this for chaining
Example
emitter.once('end', () => console.log('Finished'))Inherited from
onParamRamped()
protectedonParamRamped(_param,value):number
Defined in: packages/core/src/effects/base-effect.ts:230
Hook invoked by rampTo() for every recognized non-'mix' parameter, immediately before the value is written to the AudioParam.
Subclasses that expose shadow-state getters (any param whose setter uses smoothParamSet/clamping instead of a raw AudioParam) MUST override this to:
- Apply the exact same validation/clamping their public setter uses
- Store the clamped value in the shadow field so the getter stays honest
- Return the clamped value
rampTo() writes the value this hook returns to the AudioParam — so the ramped path can never write (or report via the getter) a value the synchronous setter would have rejected/clamped. Default: identity passthrough (no shadow state to keep in sync).
Parameters
_param
string
The parameter name being ramped
value
number
The raw, caller-supplied target value
Returns
number
The value actually written to the AudioParam (and getter)
rampTo()
rampTo(
param,value,duration):void
Defined in: packages/core/src/effects/base-effect.ts:164
Smoothly ramp a parameter to a target value over a duration.
Uses AudioParam.setTargetAtTime for glitch-free transitions. If the parameter name is not recognized, this is a no-op (a console.warn is emitted if the name is a real, documented effect property that just isn't backed by a single AudioParam — see getUnrampableParams).
Single write path: every ramped write is funneled through onParamRamped, the same hook subclasses use to keep their shadow getters honest. This guarantees effect.someParam reflects the ramp target immediately after calling rampTo(), and that the exact same validation/clamping a synchronous property-set would apply is also applied to ramped writes — the AudioParam and the getter can never diverge from each other.
Parameters
param
string
Parameter name (e.g., 'frequency', 'time', 'feedback')
value
number
Target value
duration
number
Ramp duration in seconds
Returns
void
Example
delay.rampTo('time', 0.5, 2) // Ramp delay time to 0.5s over 2 seconds
filter.rampTo('frequency', 800, 1) // Ramp cutoff to 800Hz over 1 secondremoveEventListener()
Call Signature
removeEventListener<
K>(type,listener,options?):void
Defined in: packages/core/src/events/typed-event-emitter.ts:70
Remove a typed event listener for known event types. Overloaded to provide type safety for known event types while remaining compatible with the native EventTarget API.
Type Parameters
K
K extends "dispose"
Parameters
type
K
The event type (key of TMap)
listener
(event) => void
Typed event handler to remove
options?
Standard removeEventListener options
boolean | EventListenerOptions
Returns
void
Inherited from
TypedEventEmitter.removeEventListener
Call Signature
removeEventListener(
type,listener,options?):void
Defined in: packages/core/src/events/typed-event-emitter.ts:75
Remove a typed event listener for known event types. Overloaded to provide type safety for known event types while remaining compatible with the native EventTarget API.
Parameters
type
string
The event type (key of TMap)
listener
Typed event handler to remove
EventListenerOrEventListenerObject | null
options?
Standard removeEventListener options
boolean | EventListenerOptions
Returns
void