OutputStreamNode class This class extends AudioWorkletNode to handle audio processing. It manages a buffer using a FrameBufferWriter instance and tracks the current frame position.

Hierarchy

  • AudioWorkletNode
    • OutputStreamNode

Properties

channelCount: number
channelCountMode: ChannelCountMode
channelInterpretation: ChannelInterpretation
context: BaseAudioContext
numberOfInputs: number
numberOfOutputs: number
onprocessorerror: null | ((this: AudioWorkletNode, ev: Event) => any)
parameters: AudioParamMap
port: MessagePort

Accessors

  • get isStart(): boolean
  • Checks if playback has started.

    Returns boolean

    A boolean indicating if playback has started.

  • get totalReadFrames(): bigint
  • Get the current frame position since the start of playback. The position is in frames and increases by 1 for each frame. It represents the total number of frames processed by the AudioWorkletProcessor.

    • AudioWorkletProcessor has read this total number of frames from the buffer. It closely indicates the playback position in frames.
    • totalReadFrames will never exceed the number of frames written to the buffer, ensuring it is always less than or equal to totalWriteFrames.
    • The difference between totalWriteFrames and totalReadFrames represents the delay in samples before playback (excluding processing beyond the AudioNode).

    Returns bigint

    The current frame position as a bigint.

  • get totalWriteFrames(): bigint
  • Get the total number of frames written to the buffer. This reflects the total frames written by the BufferWriteStrategy. Note: The method of writing to the buffer is implemented by the BufferWriteStrategy. The OutputStreamNode itself does not modify this value.

    Returns bigint

    The total number of frames written as a bigint.

Methods

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Type Parameters

    • K extends keyof AudioWorkletNodeEventMap

    Parameters

    • type: K
    • listener: ((this: AudioWorkletNode, ev: AudioWorkletNodeEventMap[K]) => any)
        • (this, ev): any
        • Parameters

          • this: AudioWorkletNode
          • ev: AudioWorkletNodeEventMap[K]

          Returns any

    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Parameters

    • type: string
    • listener: EventListenerOrEventListenerObject
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Parameters

    • destinationNode: AudioNode
    • Optionaloutput: number
    • Optionalinput: number

    Returns AudioNode

  • Parameters

    • destinationParam: AudioParam
    • Optionaloutput: number

    Returns void

  • Returns void

  • Parameters

    • output: number

    Returns void

  • Parameters

    • destinationNode: AudioNode

    Returns void

  • Parameters

    • destinationNode: AudioNode
    • output: number

    Returns void

  • Parameters

    • destinationNode: AudioNode
    • output: number
    • input: number

    Returns void

  • Parameters

    • destinationParam: AudioParam

    Returns void

  • Parameters

    • destinationParam: AudioParam
    • output: number

    Returns void

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Type Parameters

    • K extends keyof AudioWorkletNodeEventMap

    Parameters

    • type: K
    • listener: ((this: AudioWorkletNode, ev: AudioWorkletNodeEventMap[K]) => any)
        • (this, ev): any
        • Parameters

          • this: AudioWorkletNode
          • ev: AudioWorkletNodeEventMap[K]

          Returns any

    • Optionaloptions: boolean | EventListenerOptions

    Returns void

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Parameters

    • type: string
    • listener: EventListenerOrEventListenerObject
    • Optionaloptions: boolean | EventListenerOptions

    Returns void

  • Start playback. The node must be connected before starting playback using connect() method. Output samples must be written to the buffer before starting. Playback can only be started once. Once stopped, it cannot be restarted.

    Returns boolean

    A boolean indicating whether the playback started successfully.

  • Stop the node processing at a given frame position. Returns a Promise that resolves when the node has completely stopped. The node is disconnected once stopping is complete.

    Parameters

    • framePosition: bigint = ...

      The frame position at which to stop the processing, in frames. If framePosition is 0 or if the current playback frame position has already passed the specified value, the node will stop immediately.

    Returns Promise<void>

    A promise that resolves when the node has stopped.

  • Internal

    Creates an instance of OutputStreamNode.

    Parameters

    • audioContext: BaseAudioContext

      The audio context to use.

    • context: FrameBufferContext

      The context for the audio frame buffer.

    • strategy: BufferWriteStrategy

      The strategy for writing to the buffer.

    Returns Promise<OutputStreamNode>

    A promise that resolves to an instance of OutputStreamNode.