/** * Types for Web Worker communication * * This file defines all message types for communication between the main thread * and the Web Worker thread. Uses discriminated unions for type safety. */ /** * Serializable audio buffer data for transferring between threads * * AudioBuffer cannot be directly cloned or transferred, so we serialize it * to its component parts which can be transferred efficiently. */ export interface SerializableAudioBuffer { /** Audio sample rate in Hz */ sampleRate: number; /** Length in samples */ length: number; /** Number of audio channels */ numberOfChannels: number; /** Channel data as Float32Arrays (can be transferred) */ channelData: Float32Array[]; } /** * Request to process audio offline with pitch shifting and time stretching */ export interface ProcessAudioRequest { type: 'process'; id: string; audioData: SerializableAudioBuffer; params: { pitch: number; speed: number; mix?: number; }; config: { workletPath?: string; wasmPath?: string; wasmBinaryPath?: string; }; } /** * Request to load and decode an audio file from a URL */ export interface LoadAudioRequest { type: 'load'; id: string; url: string; } /** * Request to decode raw audio data (ArrayBuffer) */ export interface DecodeAudioRequest { type: 'decode'; id: string; audioData: ArrayBuffer; } /** * Request to generate waveform visualization data from audio buffer */ export interface GenerateWaveformRequest { type: 'waveform'; id: string; audioData: SerializableAudioBuffer; options?: { /** Number of samples in the output waveform (default: 1000) */ samples?: number; /** Which channel to use (default: 0, or -1 for average of all channels) */ channel?: number; /** Whether to compute RMS values instead of peaks (default: false) */ useRMS?: boolean; }; } /** * Request to analyze audio buffer (frequency, spectral data, etc.) */ export interface AnalyzeAudioRequest { type: 'analyze'; id: string; audioData: SerializableAudioBuffer; options?: { /** FFT size for frequency analysis (default: 2048) */ fftSize?: number; }; } /** * Request to terminate the worker gracefully */ export interface TerminateRequest { type: 'terminate'; id: string; } /** * Discriminated union of all request message types */ export type WorkerRequest = ProcessAudioRequest | LoadAudioRequest | DecodeAudioRequest | GenerateWaveformRequest | AnalyzeAudioRequest | TerminateRequest; /** * Success response for audio processing */ export interface ProcessAudioSuccess { type: 'success'; id: string; operation: 'process'; audioData: SerializableAudioBuffer; } /** * Success response for audio loading/decoding */ export interface LoadAudioSuccess { type: 'success'; id: string; operation: 'load' | 'decode'; audioData: SerializableAudioBuffer; } /** * Success response for waveform generation */ export interface GenerateWaveformSuccess { type: 'success'; id: string; operation: 'waveform'; waveformData: Float32Array; sampleRate: number; duration: number; } /** * Success response for audio analysis */ export interface AnalyzeAudioSuccess { type: 'success'; id: string; operation: 'analyze'; frequencyData: Float32Array; /** Time domain data */ waveformData: Float32Array; } /** * Progress update during long-running operations */ export interface ProgressResponse { type: 'progress'; id: string; progress: number; message?: string; } /** * Error response */ export interface ErrorResponse { type: 'error'; id: string; message: string; stack?: string; } /** * Ready message sent when worker is initialized */ export interface ReadyResponse { type: 'ready'; } /** * Discriminated union of all response message types */ export type WorkerResponse = ProcessAudioSuccess | LoadAudioSuccess | GenerateWaveformSuccess | AnalyzeAudioSuccess | ProgressResponse | ErrorResponse | ReadyResponse; /** * Extract all success response types */ export type SuccessResponse = Extract; /** * Options for offline audio processing */ export interface OfflineProcessingOptions { /** Pitch shift in semitones (-24 to +24) */ pitch: number; /** Playback speed multiplier (0.25 to 4.0) */ speed: number; /** Wet/dry mix (0.0 to 1.0, default: 1.0) */ mix?: number; /** Path to AudioWorklet processor (default: '/bungee-processor.js') */ workletPath?: string; /** Path to WASM loader (default: '/bungee-wasm.js') */ wasmPath?: string; /** Path to WASM binary (default: '/bungee-wasm.wasm') */ wasmBinaryPath?: string; /** Callback for progress updates (0-1) */ onProgress?: (progress: number, message?: string) => void; } /** * Options for audio file loading */ export interface AudioLoadingOptions { /** Callback for progress updates during fetch */ onProgress?: (progress: number) => void; } /** * Options for waveform generation */ export interface WaveformOptions { /** Number of samples in output waveform (default: 1000) */ samples?: number; /** Which channel to use (default: 0, or -1 for average) */ channel?: number; /** Use RMS values instead of peaks (default: false) */ useRMS?: boolean; } /** * Waveform data result */ export interface WaveformData { /** Waveform sample data */ data: Float32Array; /** Audio sample rate */ sampleRate: number; /** Audio duration in seconds */ duration: number; /** Number of samples in original audio */ originalLength: number; } /** * Audio analysis result */ export interface AudioAnalysisData { /** Frequency domain data (magnitude spectrum) */ frequencyData: Float32Array; /** Time domain data (waveform) */ waveformData: Float32Array; } /** * Type guard to check if a response is a success response */ export declare function isSuccessResponse(response: WorkerResponse): response is SuccessResponse; /** * Type guard to check if a response is an error response */ export declare function isErrorResponse(response: WorkerResponse): response is ErrorResponse; /** * Type guard to check if a response is a progress response */ export declare function isProgressResponse(response: WorkerResponse): response is ProgressResponse; /** * Type guard to check if a response is a ready response */ export declare function isReadyResponse(response: WorkerResponse): response is ReadyResponse; //# sourceMappingURL=types.d.ts.map