Repository navigation
Conversation
|
Can you split this into two commits: one with just the new test and one with the fix? Do you have a citation for this:
My reading of the docs is that the Why are we looking at a frame before the one we seeked to? That doesn't make sense to me. |
Seeking to a frame and decoding from there should give the same frames as decoding the whole file from the start. The test checks this for AAC, MP3, and Ogg Vorbis. It fails on all three, which the next commit fixes.
AAC, MP3, and Vorbis decode each frame using the frames before it. `SymphoniaDecoder::seek` sought straight to the target frame, without resetting the decoder or decoding the frames before the target, so the first frame or two after a seek came out wrong. Kira seeks where a streaming sound starts partway into its file and at every wrap of a loop region, so looping AAC and MP3 sounds had a short burst of noise at each loop point. Seek 2048 frames before the target (more than a packet of AAC or MP3), reset the decoder, and decode packets until one reaches the target. `decode` returns the frames from the target to the end of that packet first. The first frame of each packet is taken from the packet, as the first packet an Ogg Vorbis decoder decodes after a reset has no frames, though the file counts frames for it. The test compares the frames decoded after seeks to many indices with a straight decode of a short tone in AAC, MP3, and Ogg Vorbis. It fails without the change.
264ee6a to
9714599
Compare
|
I've split it in two. It's in Symphonia's docs for I tried just adding AAC, MP3, and Vorbis overlap each packet with the previous one, so the first packet you decode after a seek comes out wrong. You have to start a packet early and throw away the extra frames. Opus does the same thing (RFC 7845 section 4.6). I don't think it's a Symphonia bug. About frame 6144: |
AAC, MP3, and Vorbis need the frames before a frame to decode it.
SymphoniaDecoder::seekjumps straight to the target withformat_reader.seek: it never resets the decoder, and never decodes anything before the target. Symphonia leaves both steps to the caller, so the first frame or two after every seek come out wrong.Kira seeks whenever a streaming sound starts partway into its file, and again each time a loop region wraps. A looping AAC or MP3 sound therefore crackles briefly at every loop point. Against a straight decode of the same file, the worst sample error after a seek was about 0.16 for AAC and MP3. Ogg Vorbis goes wrong differently: the frames after a seek begin before the index that
seekreports.To reproduce, check out the first commit, which adds only the test, and run
cargo test --package kira --all-features --lib symphonia. All three new tests fail, for example:What the fix changes:
seeknow goes to 2048 frames before the target (more than one AAC packet of 1024 frames or MP3 packet of 1152), callsAudioDecoder::reset, and decodes until a packet reaches the target.decodecall.seekreturns the target, or the packet's start if that is later.pts + trim_start) rather than a running count, because Ogg Vorbis outputs nothing for the first packet after a reset even though the file counts frames for it.decodeandseekshare a new privatedecode_packet. The public API is unchanged.The test lives in
decoder/symphonia/test.rs. It decodes a 0.4 second tone in one pass, then walks backwards from the end in steps of 61 frames, seeking to each, decoding 1024 frames, and comparing them with the one-pass decode within 1e-5. Small AAC, MP3, and Ogg Vorbis versions of the tone come with it (1.7 KB, 1.2 KB, and 3.8 KB); the comment at the top of the test gives the ffmpeg command that made them. A frame decoded without its predecessors is off by 0.07 or more, far outside the tolerance. The AAC test needs theaacandisomp4features, so it runs only with--all-features; MP3 and Ogg Vorbis run with the defaults.I ran clippy with all features, and the tests in the four configurations CI uses (none,
cpal,mp3, all features), on Rust 1.86 and 1.99, then again on the current nightly after splitting the commits. There's no changelog entry, as I understand you write those at release time.This touches the same lines of
decodeas #168; I'm happy to rebase onto whichever lands first.