/** * Web Audio API integration module * Handles AudioContext, buffer processing, and stream management */ import { PitchWorklet } from './worklet'; export interface AudioProcessorOptions { sampleRate?: number; frameSize?: number; hopSize?: number; useWorklet?: boolean; workletPath?: string; } /** * Manages Web Audio API context and audio processing */ export declare class AudioProcessor { private context; private analyser; private source; private worklet; private readonly options; constructor(options?: AudioProcessorOptions); /** * Initialize AudioContext (must be called after user gesture in browsers) */ initialize(): Promise; /** * Get the current AudioContext */ getContext(): AudioContext; /** * Extract audio frames from an AudioBuffer */ extractFrames(buffer: AudioBuffer): Float32Array[]; /** * Resample audio buffer to target sample rate if needed */ resampleBuffer(buffer: AudioBuffer, targetSampleRate: number): Promise; /** * Create an AnalyserNode for real-time frequency analysis */ createAnalyser(): AnalyserNode; /** * Connect a MediaStream to the audio processor */ connectStream(stream: MediaStream): Promise; /** * Process audio from MediaStream in real-time */ processStream(stream: MediaStream): AsyncGenerator; /** * Load audio from URL */ loadFromUrl(url: string): Promise; /** * Load audio from File */ loadFromFile(file: File): Promise; /** * Convert mono channel data to AudioBuffer */ createBufferFromChannelData(channelData: Float32Array): AudioBuffer; /** * Get current sample rate */ getSampleRate(): number; /** * Get the worklet instance (if enabled) */ getWorklet(): PitchWorklet | null; /** * Clean up resources */ dispose(): void; /** * Check if processor is initialized */ isInitialized(): boolean; } /** * Utility: Mix stereo to mono */ export declare function mixToMono(leftChannel: Float32Array, rightChannel: Float32Array): Float32Array; /** * Utility: Calculate RMS (Root Mean Square) of audio signal */ export declare function calculateRMS(samples: Float32Array): number; /** * Utility: Normalize audio to [-1, 1] range */ export declare function normalizeAudio(samples: Float32Array): Float32Array; /** * Utility: Apply pre-emphasis filter (boosts high frequencies) */ export declare function applyPreEmphasis(samples: Float32Array, coefficient?: number): Float32Array;