/** * Utility functions for Web Worker communication and audio buffer handling */ import type { SerializableAudioBuffer } from './types'; /** * Convert an AudioBuffer to a serializable format that can be transferred * between threads efficiently using Transferable objects. * * @param audioBuffer - The AudioBuffer to serialize * @returns Serializable audio buffer with transferable Float32Arrays * * @example * ```typescript * const serializable = serializeAudioBuffer(audioBuffer); * worker.postMessage( * { audioData: serializable }, * serializable.channelData // Transfer ownership * ); * ``` */ export declare function serializeAudioBuffer(audioBuffer: AudioBuffer): SerializableAudioBuffer; /** * Convert a serializable audio buffer back to an AudioBuffer. * This function works in both main thread and worker contexts. * * @param serializable - The serializable audio buffer * @param audioContext - Optional AudioContext (required in main thread) * @returns A new AudioBuffer with the deserialized data * * @example * ```typescript * const audioBuffer = deserializeAudioBuffer(serializable, audioContext); * ``` */ export declare function deserializeAudioBuffer(serializable: SerializableAudioBuffer, audioContext?: BaseAudioContext): AudioBuffer; /** * Extract transferable objects from a serializable audio buffer. * Use this with postMessage to transfer ownership and avoid copying. * * @param serializable - The serializable audio buffer * @returns Array of transferable ArrayBuffers * * @example * ```typescript * const serializable = serializeAudioBuffer(audioBuffer); * const transferables = getTransferables(serializable); * worker.postMessage({ audioData: serializable }, transferables); * ``` */ export declare function getTransferables(serializable: SerializableAudioBuffer): ArrayBuffer[]; /** * Generate a unique ID for worker requests * * @returns A unique identifier string */ export declare function generateId(): string; /** * Create a promise that resolves after a specified timeout * * @param ms - Timeout in milliseconds * @returns Promise that resolves after the timeout */ export declare function delay(ms: number): Promise; /** * Create a promise that rejects after a specified timeout * * @param ms - Timeout in milliseconds * @param message - Error message * @returns Promise that rejects after timeout */ export declare function timeout(ms: number, message?: string): Promise; /** * Race a promise against a timeout * * @param promise - The promise to race * @param ms - Timeout in milliseconds * @param message - Optional error message for timeout * @returns Promise that resolves/rejects with the first result */ export declare function withTimeout(promise: Promise, ms: number, message?: string): Promise; /** * Downsample audio data for waveform visualization * * @param audioBuffer - The audio buffer to downsample * @param targetSamples - Number of samples in the output (default: 1000) * @param channel - Which channel to use (default: 0, -1 for average) * @param useRMS - Use RMS values instead of peaks (default: false) * @returns Downsampled waveform data * * @example * ```typescript * const waveform = downsampleAudioBuffer(audioBuffer, 1000, 0, false); * ``` */ export declare function downsampleAudioBuffer(audioBuffer: AudioBuffer, targetSamples?: number, channel?: number, useRMS?: boolean): Float32Array; /** * Validate that an audio buffer has valid parameters * * @param audioBuffer - The audio buffer to validate * @throws Error if the audio buffer is invalid */ export declare function validateAudioBuffer(audioBuffer: AudioBuffer): void; /** * Validate pitch shift parameters * * @param pitch - Pitch in semitones * @throws Error if pitch is out of range */ export declare function validatePitch(pitch: number): void; /** * Validate speed parameters * * @param speed - Speed multiplier * @throws Error if speed is out of range */ export declare function validateSpeed(speed: number): void; /** * Validate mix parameter * * @param mix - Wet/dry mix (0-1) * @throws Error if mix is out of range */ export declare function validateMix(mix: number): void; /** * Calculate the expected output length for time-stretched audio * * @param inputLength - Length of input audio in samples * @param speed - Speed multiplier * @returns Expected output length in samples */ export declare function calculateOutputLength(inputLength: number, speed: number): number; /** * Format bytes as human-readable string * * @param bytes - Number of bytes * @returns Formatted string (e.g., "1.5 MB") */ export declare function formatBytes(bytes: number): string; /** * Format duration in seconds as human-readable string * * @param seconds - Duration in seconds * @returns Formatted string (e.g., "2:30" or "1:05:30") */ export declare function formatDuration(seconds: number): string; //# sourceMappingURL=utils.d.ts.map