audio-processor.js

Overview

The audio-processor.js file defines an AudioProcessor class that extends the AudioWorkletProcessor interface provided by the Web Audio API. Its primary function is to capture audio input data, optionally resample it to a target sample rate (defaulting to 22,000 Hz), and send the processed audio data to the main thread for further handling. This processing occurs in the audio rendering thread, enabling low-latency and efficient audio data manipulation.

Classes and Methods

Class: AudioProcessor

Extends: AudioWorkletProcessor

This class is a specialized audio processor designed to resample incoming audio streams from the browser's native sample rate to a target sample rate and communicate the processed audio data back to the main thread.

Constructor: constructor()

Method: process(inputs, outputs, parameters)

Method: resample(audioData)

Registration

Important Implementation Details

Interaction with Other System Components

Structure Diagram

classDiagram
class AudioProcessor {
-targetSampleRate: number
-originalSampleRate: number
-resampleRatio: number
+constructor()
+process(inputs, outputs, parameters): boolean
+resample(audioData): Float32Array
}
AudioProcessor ..|> AudioWorkletProcessor

This diagram shows the AudioProcessor class extending AudioWorkletProcessor and its key methods and properties related to audio resampling and processing.