UNPKG

saltfish

Version:

An interactive video-guided tour system for web applications

113 lines 4.14 kB
/** * Manager class for handling real-time audio visualization using Web Audio API * Analyzes frequency data from video/audio elements to create soundbar effects */ export declare class AudioVisualizationManager { private audioContext; private analyser; private sourceVideo1; private sourceVideo2; private activeSource; private videoElement1; private videoElement2; private dataArray; private animationId; private isInitialized; private useFallbackMode; private isPaused; private readonly fftSize; private readonly barCount; private readonly smoothingTimeConstant; private fallbackTime; private zeroDataFrameCount; private readonly maxZeroFramesBeforeFallback; /** * Initializes the Web Audio API context and connects to the video element * Handles dual video element system by creating sources for both elements * @param videoElement - The video/audio element to analyze */ initialize(videoElement: HTMLVideoElement): void; /** * Switches active source and connects it to the analyser * Disconnects previous source to avoid audio doubling */ private switchToSource; /** * Gets frequency data for visualization bars * Maps lower frequencies to left bars (bass) and higher frequencies to right bars (treble) * Falls back to animated visualization if Web Audio API fails or CORS blocks analysis * Returns flat bars when paused * @returns Array of normalized bar heights (0-1) for each bar */ getBarHeights(): number[]; /** * Generates fallback bar heights when Web Audio API is unavailable * Returns all zeros (no animation) for audio-only content * Mirrors the first 50% to match real audio visualization * @returns Array of normalized bar heights (0-1) all at zero */ private getFallbackBarHeights; /** * Returns flat bar heights for paused state * All bars at minimal height for visual presence * @returns Array of normalized bar heights (0-1) all at minimal value */ private getFlatBarHeights; /** * Gets the average amplitude across all frequencies * Used for dynamic color intensity * Falls back to zero if Web Audio API fails * @returns Normalized amplitude value (0-1) */ getAverageAmplitude(): number; /** * Starts the animation loop for continuous visualization updates * @param callback - Function called on each animation frame with bar heights and amplitude */ startVisualization(callback: (barHeights: number[], amplitude: number) => void): void; /** * Stops the visualization animation loop */ stopVisualization(): void; /** * Pauses the visualization - bars will stay at minimal height * Animation loop continues but returns flat bars */ pause(): void; /** * Resumes the visualization - bars will react to audio again */ resume(): void; /** * Resumes the AudioContext if it's suspended * Safe to call multiple times - will only resume if needed * MUST be called after user interaction for audio to work */ resumeAudioContext(): void; /** * Resets fallback mode to attempt real-time audio analysis again * Call this when unmuting or when conditions change that might allow audio analysis */ resetFallbackMode(): void; /** * Checks if visualization is currently initialized */ getIsInitialized(): boolean; /** * Resets video element references for playlist restart * Keeps AudioContext and analyser intact but clears video element tracking * This allows new video elements to be assigned when playlist restarts */ reset(): void; /** * Cleans up Web Audio resources * Important to call this to prevent memory leaks * WARNING: Only call this when truly destroying - not when switching video elements! */ cleanup(): void; /** * Destroys the manager and releases all resources */ destroy(): void; } //# sourceMappingURL=AudioVisualizationManager.d.ts.map