mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-28 03:59:26 -06:00
Problem: playback decoded and mixed every ~10 ms device buffer inside the cpal callback (AAC decode, effects, opening a clip's file at a cut, rayon, locks). On a loaded Mac any stall missed the device deadline: static and dropouts, different on every play. Solution: play_ahead mixes on its own thread into a lock-free ring kept 200 ms ahead; the callback only copies. An underrun plays silence, is counted, and the mixer skips the same span so sound stays locked to the picture. Any device width plays the channels it shares with the mix. perf.stats reports playback.audio (callbacks, underruns, missingFrames, minLeadMs). The program mix moved to playback_mix so bench_audio can play a real project through a simulated 48 kHz device and count dropouts. Context: on a real 22-sequence project, load average 38-58, 15 s per cut: mixing in the callback overran 8-170 times, mixing ahead 0 (ring never below 149 ms). The web build keeps mixing in its callback (no threads). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>