/** * Configuration options for BungeePitchShift * * @example * ```typescript * const config: BungeePitchShiftConfig = { * workletPath: '/audio/bungee-processor.js', * wasmPath: '/wasm/bungee-wasm.js', * wasmBinaryPath: '/wasm/bungee-wasm.wasm', * initialPitch: 0, * initialSpeed: 1.0, * initialMix: 1.0 * }; * ``` */ export interface BungeePitchShiftConfig { /** * Path to the AudioWorklet processor file * * **Recommended:** Use the bundled processor (`/bungee-processor-bundled.js`) which includes * the WASM glue code and embedded binary in a single self-contained file. * * This file contains the AudioWorkletProcessor implementation that runs * in the audio processing thread. * * @default '/bungee-processor-bundled.js' * * @example * ```typescript * // Recommended: Use bundled processor (self-contained) * workletPath: '/bungee-processor-bundled.js' * * // Or specify custom path * workletPath: '/audio-worklets/bungee-processor-bundled.js' * ``` */ workletPath?: string; /** * Path or URL to the WASM loader JS file * * @deprecated This option is no longer needed when using the bundled processor. * The WASM module is already embedded in `bungee-processor-bundled.js` via * Emscripten's SINGLE_FILE=1 option. This field is kept for backward compatibility * but is ignored. * * @default '/bungee-wasm.js' */ wasmPath?: string; /** * Path or URL to the WASM binary file * * @deprecated This option is no longer needed when using the bundled processor. * The WASM binary is already embedded in `bungee-processor-bundled.js` via * Emscripten's SINGLE_FILE=1 option. This field is kept for backward compatibility * but is ignored. * * When using the bundled processor, only `workletPath` is required. * * @default '/bungee-wasm.wasm' */ wasmBinaryPath?: string; /** * Initial pitch shift in semitones * * Positive values shift pitch up, negative values shift down. * Typical range is -12 to +12 semitones (one octave). * * @default 0 * @minimum -24 * @maximum 24 * * @example * ```typescript * initialPitch: 7 // Perfect fifth up * initialPitch: -12 // One octave down * ``` */ initialPitch?: number; /** * Initial playback speed multiplier * * Values > 1.0 speed up playback, values < 1.0 slow it down. * Typical range is 0.5 (half speed) to 2.0 (double speed). * * @default 1.0 * @minimum 0.25 * @maximum 4.0 * * @example * ```typescript * initialSpeed: 1.5 // 50% faster * initialSpeed: 0.75 // 25% slower * ``` */ initialSpeed?: number; /** * Initial wet/dry mix ratio * * Controls the balance between processed (wet) and original (dry) signal. * - 0.0 = 100% dry (bypass, original signal only) * - 1.0 = 100% wet (fully processed signal only) * - 0.5 = 50/50 mix of dry and wet * * @default 1.0 * @minimum 0.0 * @maximum 1.0 * * @example * ```typescript * initialMix: 1.0 // Fully processed * initialMix: 0.5 // Equal mix * ``` */ initialMix?: number; } /** * Current parameters of the pitch shifter * * These represent the real-time state of the pitch shifting algorithm. * All parameters can be updated during playback without audio discontinuities. * * @example * ```typescript * const params: PitchShiftParams = { * pitchSemitones: 5, * speed: 1.2, * mix: 0.8 * }; * ``` */ export interface PitchShiftParams { /** * Pitch shift in semitones * * Positive values shift pitch up, negative values shift down. * Typical range is -12 to +12 semitones (one octave). * * @minimum -24 * @maximum 24 * * @example * ```typescript * pitchSemitones: 12 // One octave up * pitchSemitones: -7 // Perfect fifth down * ``` */ pitchSemitones: number; /** * Playback speed multiplier * * Independent of pitch shift. Values > 1.0 speed up playback, * values < 1.0 slow it down. * * @minimum 0.25 * @maximum 4.0 * * @example * ```typescript * speed: 2.0 // Double speed * speed: 0.5 // Half speed * ``` */ speed: number; /** * Wet/dry mix ratio * * Controls the balance between processed and original signal. * * @minimum 0.0 * @maximum 1.0 * * @example * ```typescript * mix: 1.0 // 100% wet (fully processed) * mix: 0.0 // 100% dry (bypass) * ``` */ mix: number; } /** * Information about the Bungee processor * * This information is provided by the Bungee WASM library and includes * version details and processing characteristics. * * @example * ```typescript * const info: BungeeInfo = { * version: "1.2.0", * edition: "wasm", * latency: 2048 * }; * ``` */ export interface BungeeInfo { /** * Bungee library version string * * @example "1.2.0" */ version?: string; /** * Bungee edition identifier * * Typically "wasm" for the WebAssembly build. * * @example "wasm" */ edition?: string; /** * Processing latency in samples * * This represents the algorithmic delay introduced by the pitch shifting * process. Actual perceived latency also depends on the audio context's * buffer size. * * @example 2048 */ latency?: number; } /** * Event emitted when the processor is initialized */ export interface InitializedEvent { /** Event type discriminator */ type: 'initialized'; /** Bungee library information */ info: BungeeInfo; } /** * Event emitted when processor info is received */ export interface InfoEvent { /** Event type discriminator */ type: 'info'; /** Bungee library information */ info: BungeeInfo; } /** * Event emitted when an error occurs */ export interface ErrorEvent { /** Event type discriminator */ type: 'error'; /** Error message description */ message: string; } /** * Discriminated union of all event types emitted by BungeePitchShift * * Use the `type` property to discriminate between event types in your * event listener callbacks. * * @example * ```typescript * pitchShift.addEventListener((event) => { * switch (event.type) { * case 'initialized': * console.log('Version:', event.info.version); * break; * case 'info': * console.log('Latency:', event.info.latency); * break; * case 'error': * console.error('Error:', event.message); * break; * } * }); * ``` */ export type BungeePitchShiftEvent = InitializedEvent | InfoEvent | ErrorEvent; /** * Event listener callback function * * Receives events from BungeePitchShift and should handle them appropriately. * * @param event - The event object with discriminated type * * @example * ```typescript * const listener: EventListener = (event) => { * if (event.type === 'error') { * alert(`Pitch shift error: ${event.message}`); * } * }; * * pitchShift.addEventListener(listener); * ``` */ export type EventListener = (event: BungeePitchShiftEvent) => void; /** * Extract a specific event type from the BungeePitchShiftEvent union * * @example * ```typescript * type InitEvent = ExtractEvent<'initialized'>; * // Result: { type: 'initialized'; info: BungeeInfo } * ``` */ export type ExtractEvent = Extract; /** * Type guard to check if an event is an InitializedEvent * * @param event - The event to check * @returns True if the event is an InitializedEvent * * @example * ```typescript * if (isInitializedEvent(event)) { * console.log('Version:', event.info.version); * } * ``` */ export declare function isInitializedEvent(event: BungeePitchShiftEvent): event is InitializedEvent; /** * Type guard to check if an event is an InfoEvent * * @param event - The event to check * @returns True if the event is an InfoEvent * * @example * ```typescript * if (isInfoEvent(event)) { * console.log('Latency:', event.info.latency); * } * ``` */ export declare function isInfoEvent(event: BungeePitchShiftEvent): event is InfoEvent; /** * Type guard to check if an event is an ErrorEvent * * @param event - The event to check * @returns True if the event is an ErrorEvent * * @example * ```typescript * if (isErrorEvent(event)) { * console.error('Error:', event.message); * } * ``` */ export declare function isErrorEvent(event: BungeePitchShiftEvent): event is ErrorEvent; /** * Interface describing the public API of BungeePitchShift * * This standalone interface can be used for: * - Typing function parameters that accept pitch shifter instances * - Creating mock implementations for testing * - Documentation and IDE autocomplete * - Duck typing scenarios * * @example * Using in function parameters: * ```typescript * function applyPitchEffect( * pitchShift: IBungeePitchShift, * semitones: number * ): void { * pitchShift.setPitch(semitones); * pitchShift.setMix(1.0); * } * ``` * * @example * Creating a mock for testing: * ```typescript * class MockPitchShift implements IBungeePitchShift { * node: AudioWorkletNode = {} as AudioWorkletNode; * initialized = true; * params = { pitchSemitones: 0, speed: 1.0, mix: 1.0 }; * info = { version: "1.0.0" }; * * setPitch(semitones: number): void { * this.params.pitchSemitones = semitones; * } * // ... implement other methods * } * ``` */ export interface IBungeePitchShift { /** * The AudioWorkletNode for connecting to the audio graph * * Connect audio sources to this node's input, and connect this node's * output to your destination or other effects. * * @example * ```typescript * sourceNode.connect(pitchShift.node); * pitchShift.node.connect(audioContext.destination); * ``` */ readonly node: AudioWorkletNode; /** * Whether the pitch shifter is fully initialized and ready to use * * @example * ```typescript * if (pitchShift.initialized) { * pitchShift.setPitch(5); * } * ``` */ readonly initialized: boolean; /** * Current parameter values * * Returns a readonly copy of the current pitch, speed, and mix values. * * @example * ```typescript * const { pitchSemitones, speed, mix } = pitchShift.params; * console.log(`Current pitch: ${pitchSemitones} semitones`); * ``` */ readonly params: Readonly; /** * Bungee library information * * Contains version, edition, and latency information from the WASM module. * * @example * ```typescript * console.log(`Bungee v${pitchShift.info.version}`); * console.log(`Latency: ${pitchShift.info.latency} samples`); * ``` */ readonly info: Readonly; /** * Set pitch shift in semitones * * @param semitones - Pitch shift amount (-24 to +24 range supported) * * @example * ```typescript * pitchShift.setPitch(12); // One octave up * pitchShift.setPitch(-5); // Perfect fourth down * pitchShift.setPitch(0); // No pitch shift * ``` */ setPitch(semitones: number): void; /** * Set playback speed multiplier * * @param speed - Speed multiplier (0.25 to 4.0 range supported) * * @example * ```typescript * pitchShift.setSpeed(2.0); // Double speed * pitchShift.setSpeed(0.5); // Half speed * pitchShift.setSpeed(1.0); // Normal speed * ``` */ setSpeed(speed: number): void; /** * Set wet/dry mix ratio * * @param mix - Mix amount (0.0 = dry, 1.0 = wet) * * @example * ```typescript * pitchShift.setMix(1.0); // 100% wet (fully processed) * pitchShift.setMix(0.5); // 50/50 blend * pitchShift.setMix(0.0); // 100% dry (bypass) * ``` */ setMix(mix: number): void; /** * Reset the internal processing state * * Useful when seeking in audio playback to clear the internal buffers * and avoid artifacts from the previous audio content. * * @example * ```typescript * // When seeking to a new position: * audioSource.stop(); * pitchShift.reset(); * audioSource = createNewSource(); * audioSource.start(); * ``` */ reset(): void; /** * Connect the pitch shifter to another audio node * * @param destination - Audio node to connect to * * @example * ```typescript * pitchShift.connect(audioContext.destination); * pitchShift.connect(reverbNode); * ``` */ connect(destination: AudioNode): void; /** * Disconnect from all or a specific audio node * * @param destination - Optional specific node to disconnect from * * @example * ```typescript * pitchShift.disconnect(); // Disconnect from all * pitchShift.disconnect(reverbNode); // Disconnect from specific node * ``` */ disconnect(destination?: AudioNode): void; /** * Add an event listener for pitch shifter events * * @param listener - Callback function to handle events * * @example * ```typescript * pitchShift.addEventListener((event) => { * if (event.type === 'initialized') { * console.log('Ready!', event.info); * } else if (event.type === 'error') { * console.error('Error:', event.message); * } * }); * ``` */ addEventListener(listener: EventListener): void; /** * Remove a previously added event listener * * @param listener - Callback function to remove * * @example * ```typescript * const listener = (event) => console.log(event); * pitchShift.addEventListener(listener); * // Later... * pitchShift.removeEventListener(listener); * ``` */ removeEventListener(listener: EventListener): void; /** * Dispose and clean up all resources * * Call this when you're done using the pitch shifter to free up resources. * After calling dispose(), the instance should not be used again. * * @example * ```typescript * pitchShift.disconnect(); * pitchShift.dispose(); * pitchShift = null; * ``` */ dispose(): void; } //# sourceMappingURL=types.d.ts.map