@ain1084/audio-frame-buffer - v0.2.1
    Preparing search index...

    Class FrameBufferWriter

    FrameBufferWriter class This class writes audio frame data to a shared Float32Array buffer. The buffer usage is tracked using a Uint32Array.

    Index
    • Creates an instance of FrameBufferWriter.

      Parameters

      • context: FrameBufferContext

        The context object containing:

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

      Returns FrameBufferWriter

    • get availableFrames(): number

      Get the number of available frames in the buffer. This represents the number of frames that can be written before the buffer is full.

      Returns number

      The number of available frames in the buffer.

    • get totalFrames(): bigint

      Get the total number of frames written to the buffer.

      Returns bigint

      The total number of frames written.

    • Writes audio frame data into the buffer using the provided callback. This method handles one or more writable 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 writable segment of the ring buffer. It receives:

        1. segment: An FrameBufferSegment instance representing the writable 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 wrote. 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 written, and enumeration will stop.

      Returns number

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

      RangeError - If the processFrameSegment callback returns a written length greater than the available space 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.