Examples
Audio Mixing
Generate a melody with real-time waveform visualization using mixAudio
Use mixAudio to generate audio samples in JavaScript and mux them into the video. This example synthesizes the first phrase of Ode to Joy and visualizes the waveform in real time.
Notes
mixAudiocallback runs once per frame and returns aFloat32Arrayof audio samples. The library muxes them into the video's audio track. No microphone permissions needed.- Phase accumulators (stored in a ref) keep the oscillator phases continuous across frames. Two oscillators run per note: the fundamental and a sub-octave at 30% amplitude for warmth.
- Per-sample envelope ramps amplitude smoothly over 3 frames at each note boundary, creating clear note separation without clicks.
- Spectrum-style bars show a gaussian peak centered at the current note's frequency. As the melody plays, the peak slides across the bars. Exponential smoothing creates a trailing glow effect.
mixAudio and audioFile cannot be combined. Use mixAudio for procedurally generated audio (synths, sound effects, tone generators). Use audioFile for pre-recorded audio files.