ez-web-audio
Version:
Making the Web Audio API super EZ since 2024.
41 lines • 1.76 kB
TypeScript
import { Track } from '../track';
/**
* Generates an equal-power crossfade curve using cosine/sine functions.
* Equal-power curves maintain constant power during crossfading: cos²(x) + sin²(x) = 1
*
* @param direction - 'in' for fade-in (0→1 sin curve), 'out' for fade-out (1→0 cos curve)
* @param length - Number of samples in the curve (typically 256)
* @returns Float32Array containing the curve values
*
* @example
* ```typescript
* const fadeIn = generateEqualPowerCurve('in', 256) // 0→1
* const fadeOut = generateEqualPowerCurve('out', 256) // 1→0
* ```
*/
export declare function generateEqualPowerCurve(direction: 'in' | 'out', length: number): Float32Array;
/**
* Smoothly crossfades from one Track to another using equal-power curves.
* This creates a DJ-style transition without volume dips at the midpoint.
*
* Behavior:
* - Source track (fromTrack): fades out from current gain to 0
* - Destination track (toTrack): fades in from current gain (or 0) to 1
* - Source track automatically stops and resets gain to 1.0 after fade completes
* - If destination is already playing, continues from current position
* - If destination is not playing, starts it at gain 0 then fades in
*
* @param fromTrack - Track to fade out (will be stopped after fade)
* @param toTrack - Track to fade in
* @param duration - Crossfade duration in seconds
* @returns Promise that resolves when crossfade completes
*
* @example
* ```typescript
* // Crossfade from track1 to track2 over 2 seconds
* await crossfade(track1, track2, 2)
* // track1 is now stopped, track2 is playing
* ```
*/
export declare function crossfade(fromTrack: Track, toTrack: Track, duration: number): Promise<void>;
//# sourceMappingURL=crossfade.d.ts.map