Preview audio can click at decoded-buffer boundaries when playback speed or source sample rate requires interpolation. Each AudioBufferSourceNode currently sees an isolated decoded buffer, so it cannot interpolate using the next buffer's samples. Decimal timestamp subtraction can also introduce a false nonzero source offset, and start(when, offset, duration) can round a chunk's endpoint differently from the next chunk's start.
Keep the current/next decoded buffers in the existing preview iterator and supply their PCM neighborhood to Web Audio while retaining the current slice's audible duration. Compute decoded positions relative to the stream's original sample origin, rebasing on decoded sample-rate changes and preserving the exact requested timestamp for a clipped seek. Pass an absolute endpoint through the existing shared-node queue, including deferred and late nodes. Source resets do not share neighborhoods; destroying a pending read discards its result; a failed neighboring read still delivers the already-decoded current buffer before reporting the error.
This changes preview scheduling, not extractAudio or its offline resampler. It introduces no parallel queue or DSP resampler. The optional public scheduling field preserves callers that use duration-only scheduling.
Reproduction and verification
A mono 48 kHz PCM WAV containing 18,000 samples (pcm[i] = ((i * 47) % 8192 - 4096) / 32768) reproduces the issue when played through @remotion/media at 0.5×, 0.75×, and 1.25×. Compare the scheduled output with one contiguous AudioBufferSourceNode using the same decoded PCM, rate, and source interval. The defect occurs without Kino, fractional Sequences, or Premiere imports.
Standalone headless Chrome proofs exercised upstream AudioIteratorManager, MediaPlayer, Mediabunny 1.66 decoding, and the actual shared scheduler's immediate/deferred closures, compiled with production React. All six rate/queue cases now produce identical PCM to the contiguous reference. A further six preserve-pitch cases (the same rates and queue modes) compare the actual pitch iterator with a whole-source pitch transform followed by one contiguous source node; all pass with maximum error 0.000244 PCM16 LSB. The shared scheduler closures were observed outside React to control the audio clock; this is not a claim of complete live Player integration coverage.
Individual causal reversions:
Remove the neighboring PCM: all three tested speeds regain internal seam errors, up to 6,144 PCM16 LSB.
Restore timestamp subtraction: all six immediate/deferred cases fail, up to 6,144 PCM16 LSB.
Restore duration-only starts: both 1.25× cases regain errors at samples 8,192 and 14,400, up to 2,048 PCM16 LSB.
Normal-speed and nonzero frame-aligned transport anchors also pass: 30 cases at 48 kHz, plus 42 cases at 44.1 kHz spanning 0.125×–4×. Removing the previous-buffer neighborhood did not change any of those results or the six pitch cases, so this version retains only the next buffer.
Fourteen additional source-grid checks cover both sample-rate-change directions, fractional stream origins, codec-reclaim retries, and exact seek timestamps. The reported 48 kHz→44.1 kHz transition previously lost 390 samples; it now preserves the full next buffer. A seek to frame 25 at 30 fps now retains the exact requested timestamp and reuses its prepared decoder.
Additional checks cover cancellation during the next read, current-buffer delivery before the next-read error, loop source resets, EOF, and late/expired deferred sources. Expired nodes emit native ended with zero PCM, releasing the existing iterator ownership. All 48 existing audio, loop, pitch and cleanup browser tests pass (11 files). The three review-identified fixture/assertion files reproduced 11 failures before the updates and now pass all 15 cases. The nine loop-timestamp cases also pass in Node without a Web Audio polyfill. bun run build passes (77 tasks), and bun run stylecheck passes (266 tasks plus skill checks) with Bun 1.4.3.
No new agent-authored test cases are included, following this repository's PR guidance. Existing fixtures supply valid PCM metadata and account for scheduled audible slices separately from interpolation neighborhoods. The paused-buffer checks retain their original audible horizon and additionally bound allocated PCM to twice the original limit. Two existing timestamp fixture values change at floating-point precision; the duration-only scheduler fixture remains unchanged to verify omission compatibility.
Tradeoffs and scope limits
The first chunk waits for one neighboring read, which can add decode latency after a seek or at a loop boundary. Queued PCM can be up to twice the original chunk size; the existing scheduling horizon bounds it. One pending decoded source buffer is retained per iterator. This avoids retaining the full media file or introducing another queue.
Fractional source-offset behavior differs across browser versions and playback rates; this PR does not claim to resolve that browser behavior or prove every fractional trim, pitch transform, and live transport transition. The separate Web Renderer fractional Sequence-window issue is also outside this change.
Preview audio can click at decoded-buffer boundaries when playback speed or source sample rate requires interpolation. Each AudioBufferSourceNode currently sees an isolated decoded buffer, so it cannot interpolate using the next buffer's samples. Decimal timestamp subtraction can also introduce a false nonzero source offset, and start(when, offset, duration) can round a chunk's endpoint differently from the next chunk's start.
Keep the current/next decoded buffers in the existing preview iterator and supply their PCM neighborhood to Web Audio while retaining the current slice's audible duration. Compute decoded positions relative to the stream's original sample origin, rebasing on decoded sample-rate changes and preserving the exact requested timestamp for a clipped seek. Pass an absolute endpoint through the existing shared-node queue, including deferred and late nodes. Source resets do not share neighborhoods; destroying a pending read discards its result; a failed neighboring read still delivers the already-decoded current buffer before reporting the error.
This changes preview scheduling, not extractAudio or its offline resampler. It introduces no parallel queue or DSP resampler. The optional public scheduling field preserves callers that use duration-only scheduling.
Reproduction and verification
A mono 48 kHz PCM WAV containing 18,000 samples (pcm[i] = ((i * 47) % 8192 - 4096) / 32768) reproduces the issue when played through @remotion/media at 0.5×, 0.75×, and 1.25×. Compare the scheduled output with one contiguous AudioBufferSourceNode using the same decoded PCM, rate, and source interval. The defect occurs without Kino, fractional Sequences, or Premiere imports.
Standalone headless Chrome proofs exercised upstream AudioIteratorManager, MediaPlayer, Mediabunny 1.66 decoding, and the actual shared scheduler's immediate/deferred closures, compiled with production React. All six rate/queue cases now produce identical PCM to the contiguous reference. A further six preserve-pitch cases (the same rates and queue modes) compare the actual pitch iterator with a whole-source pitch transform followed by one contiguous source node; all pass with maximum error 0.000244 PCM16 LSB. The shared scheduler closures were observed outside React to control the audio clock; this is not a claim of complete live Player integration coverage.
Individual causal reversions:
Remove the neighboring PCM: all three tested speeds regain internal seam errors, up to 6,144 PCM16 LSB.
Restore timestamp subtraction: all six immediate/deferred cases fail, up to 6,144 PCM16 LSB.
Restore duration-only starts: both 1.25× cases regain errors at samples 8,192 and 14,400, up to 2,048 PCM16 LSB.
Normal-speed and nonzero frame-aligned transport anchors also pass: 30 cases at 48 kHz, plus 42 cases at 44.1 kHz spanning 0.125×–4×. Removing the previous-buffer neighborhood did not change any of those results or the six pitch cases, so this version retains only the next buffer.
Fourteen additional source-grid checks cover both sample-rate-change directions, fractional stream origins, codec-reclaim retries, and exact seek timestamps. The reported 48 kHz→44.1 kHz transition previously lost 390 samples; it now preserves the full next buffer. A seek to frame 25 at 30 fps now retains the exact requested timestamp and reuses its prepared decoder.
Additional checks cover cancellation during the next read, current-buffer delivery before the next-read error, loop source resets, EOF, and late/expired deferred sources. Expired nodes emit native ended with zero PCM, releasing the existing iterator ownership. All 48 existing audio, loop, pitch and cleanup browser tests pass (11 files). The three review-identified fixture/assertion files reproduced 11 failures before the updates and now pass all 15 cases. The nine loop-timestamp cases also pass in Node without a Web Audio polyfill. bun run build passes (77 tasks), and bun run stylecheck passes (266 tasks plus skill checks) with Bun 1.4.3.
No new agent-authored test cases are included, following this repository's PR guidance. Existing fixtures supply valid PCM metadata and account for scheduled audible slices separately from interpolation neighborhoods. The paused-buffer checks retain their original audible horizon and additionally bound allocated PCM to twice the original limit. Two existing timestamp fixture values change at floating-point precision; the duration-only scheduler fixture remains unchanged to verify omission compatibility.
Tradeoffs and scope limits
The first chunk waits for one neighboring read, which can add decode latency after a seek or at a loop boundary. Queued PCM can be up to twice the original chunk size; the existing scheduling horizon bounds it. One pending decoded source buffer is retained per iterator. This avoids retaining the full media file or introducing another queue.
Fractional source-offset behavior differs across browser versions and playback rates; this PR does not claim to resolve that browser behavior or prove every fractional trim, pitch transform, and live transport transition. The separate Web Renderer fractional Sequence-window issue is also outside this change.