FrameBufferReader class This class reads audio frame data from a shared Float32Array buffer and processes it. The buffer usage is tracked using a Uint32Array.

Constructors

Accessors

Methods

Constructors

  • Creates an instance of FrameBufferReader.

    Parameters

    • context: FrameBufferContext

      The context object containing:

      • sampleBuffer: The shared buffer to read audio data frames from.
      • samplesPerFrame: The number of samples per frame.
      • usedFramesInBuffer: A Uint32Array tracking the usage of frames in the buffer.
      • totalReadFrames: A BigUint64Array tracking the total frames read from the buffer.

    Returns FrameBufferReader

Accessors

  • get availableFrames(): number
  • Get the number of available frames in the buffer.

    Returns number

    The number of available frames in the buffer.

  • get totalFrames(): bigint
  • Get the total number of frames read from the buffer.

    Returns bigint

    The total number of frames read.

Methods

  • Reads audio frame data from the buffer using the provided callback. This method handles one or more readable segments within the ring buffer and invokes the callback for each segment.

    Parameters

    • processFrameSegment: ((segment: FrameBufferSegment, offset: number) => number)

      The callback function invoked for each readable segment of the ring buffer. It receives:

      1. segment: An FrameBufferSegment instance representing the readable segment of the buffer.
      2. offset: The cumulative number of frames processed so far, used as the starting index for the current segment relative to the entire data.

      The callback must return the number of frames it successfully read. If the callback returns a smaller number of frames than are available in the current segment, only the returned number of frames will be considered read, and enumeration will stop.

        • (segment, offset): number
        • Parameters

          Returns number

    Returns number

    The total number of frames processed across all segments. Note: The return value is in frames, not in samples.

    RangeError - If the processFrameSegment callback returns a processed length greater than the available frames in the current segment.

    The buffer is an array of samples, but it is always provided in frame-sized segments. Each frame consists of multiple samples (e.g., for stereo, a frame contains a sample for the left channel and one for the right channel). You must access and process the buffer in frame-sized chunks, based on the structure of the frames.