wav64/opus: support partial (non-frame-aligned) loops#915
Open
meeq wants to merge 1 commit into
Open
Conversation
Looping Opus playback with a loop point that is not on a frame boundary
(an "intro'd" loop that should not replay its intro) hit two issues that
together made it crash on the first wrap:
1. waveform_opus_read() asserted loop_len == len when the decode overshot
the waveform tail, so only full loops were handled. The trim it guards
(samplebuffer_undo of the overshoot) is valid for partial loops too --
the mixer continues the loop via a separate seeking read at loop_start.
Relax the assert to the real invariant: overshoot < frame_size.
2. The seeking read drops intra_skip leading samples via OPUS_memmove (RSP),
which required an 8-byte-aligned RDRAM destination. The mixer's sample
buffer does not guarantee that alignment for a large (buffer-spanning)
loop, so the destination could be 4-byte aligned and the move hit the
0x8509 RSP assert. Generalize OPUS_memmove: when src and dst share a
common even non-zero offset, read-modify-write the destination's aligned
window (preserving the original head bytes), then hand any remaining
aligned chunks to the existing loop. Handles a move of any length; the
aligned (offset 0) path is unchanged. Preconditions are asserted under
RSPQ_DEBUG and are strictly weaker than the previous full-alignment ones,
so existing callers are unaffected (the decoder's internal int32 move is
always 8-byte aligned).
Validated with a standalone harness across all four cases:
{aligned, unaligned} x {single-chunk, multi-chunk}.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Looping Opus playback with a loop point that is not on a frame boundary hit two issues that together made it crash on the first wrap:
waveform_opus_read() asserted loop_len == len when the decode overshot the waveform tail, so only full loops were handled. The trim it guards (samplebuffer_undo of the overshoot) is valid for partial loops too -- the mixer continues the loop via a separate seeking read at loop_start. Relax the assert to the real invariant: overshoot < frame_size.
The seeking read drops intra_skip leading samples via OPUS_memmove (RSP), which required an 8-byte-aligned RDRAM destination. The mixer's sample buffer does not guarantee that alignment for a large (buffer-spanning) loop, so the destination could be 4-byte aligned and the move hit the RSP assert.
Proposed solution
Generalize OPUS_memmove: when src and dst share a common even non-zero offset, read-modify-write the destination's aligned window (preserving the original head bytes), then hand any remaining aligned chunks to the existing loop. Handles a move of any length; the aligned (offset 0) path is unchanged. Preconditions are asserted under RSPQ_DEBUG and are strictly weaker than the previous full-alignment ones, so existing callers are unaffected (the decoder's internal int32 move is always 8-byte aligned).