retrieve_audio_to decodes whole codec frames but copies only the part inside the requested chunk; the tail of the frame crossing the chunk end (up to 1023 samples for AAC) was consumed by the decoder and lost, so the next chunk started with a hole. On the playback grid (1920 samples at 25fps/48kHz) the hole cycles 128..896 samples and hits 7 of 8 chunk starts -- the heavy stutter/noise heard during playback. Keep the overflow (decode and resampler-flush tails) in a per-session carry buffer and serve it at the start of the next contiguous chunk; clear it on seek, format change and chunk failure. Also make seek() actually drop the cached resampler as its comment claimed. Verified sample-exact: chunked decode of a 440Hz tone now matches a one-shot decode bit for bit, and chunked renders of real media line up with the ffmpeg CLI reference at correlation 1.0 / drift 0. Adds a regression test (playback_sized_chunks_match_oneshot_sample_exact) with a new tone fixture -- demo.mp4's audio is -90dB digital silence and cannot expose the holes -- plus a render_audio_wav example used to diagnose chunk-boundary artifacts offline.
128 KiB
128 KiB