Repository navigation
Description
What happens
fl::Mp3Decoder decodes MP3 frames with a raw mp3dec_decode_frame_r loop over the byte stream. That loop does not understand container metadata, so for a LAME- or Xing-encoded file it:
- decodes the VBR tag frame as audio. The Xing/LAME header occupies a real, valid MPEG frame at the start of the stream. It contains no music; decoding it yields a frame of noise-adjacent output.
- does not apply the encoder delay/padding the LAME header specifies, so the first ~576–1152 samples of genuine encoder priming are emitted rather than trimmed.
Practically: playing a LAME-encoded MP3 through FastLED starts with a short burst of garbage before the music. Most MP3s in the wild are LAME-encoded.
Evidence
ci/codec_conformance/run.py carries this as its single explicit exception:
EXCEPTED l3-nonstandard-sin1k0db_lame_vbrtag: 2.85 dB
2.85 dB against a reference that assumes gapless trimming, where every other Layer III vector scores above 100 dB.
It is not an arithmetic defect. The upstream float build scores identically — 2.85 dB — so this is not something the fixed-point port introduced. Frame-shifting the comparison does not rescue it either (best alignment reaches 30.15 dB at a 3-frame skip, still far below the floor), which is consistent with a leading garbage frame plus an untrimmed delay rather than a simple constant offset.
Where the missing logic lives
Upstream minimp3 handles this in minimp3_ex.h — mp3dec_ex_open / mp3dec_load parse the ID3/APE tags, read the Xing/LAME header, and apply delay/padding for gapless playback. FastLED vendors only minimp3.h and calls the raw frame API, deliberately, because minimp3_ex.h brings a stdio/file layer that does not belong on an MCU.
So the fix is to implement the small part of that we actually need against the byte stream we already have, not to vendor minimp3_ex.h.
Related: tags are not skipped either
The same conformance run shows four vectors decoding zero frames:
l3-nonstandard-id3v1l3-nonstandard-id3v2l3-nonstandard-apetagl3-nonstandard-id3v1-apetag
These are the tag-handling conformance cases. A file whose leading bytes are an ID3v2 tag is not decoded at all by the raw loop. That is arguably more serious than the delay problem, since ID3v2 tags are near-universal in real files — worth confirming against a real tagged MP3 before sizing the work, as the sync-word scan may recover on many real files where it fails on these deliberately-shaped ones.
Acceptance criteria
- Skip a leading ID3v2 tag (
ID3magic, syncsafe size) and a leading APE tag before the first sync-word search. - Detect the Xing/Info/VBRI header in the first frame and not emit it as audio.
- Apply the LAME header's encoder delay and padding so playback starts at the first real sample.
-
l3-nonstandard-sin1k0db_lame_vbrtagclears the 60 dB ISO floor and moves out ofKNOWN_EXCEPTIONSinci/codec_conformance/run.py. - The four tag vectors above decode a non-zero number of frames.
- Memory ledger unchanged: this is parsing over the existing stream buffer, and must not add per-frame allocation.
Found while auditing whether the MP3 decoder is actually verified against a gold reference (#4127). The conformance suite added there is what makes this measurable.
Refs #4127
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Sep 1, 2026
Correction and quantification
I filed this with two claims. Having measured both: one is confirmed and now has exact numbers, the other is wrong and I am withdrawing it.
Confirmed: the Xing tag frame and encoder delay are emitted as audio
A sample-level offset scan against the reference pins it exactly:
108.18 dB is right in line with every other Layer III vector. So the decode is correct; it is simply offset. And the offset decomposes precisely:
2257 x 2 channels = 4514 interleaved samples, which is the measured best offset to the sample. That is as clean a confirmation as this kind of thing gets: skip the tag frame and honour the delay, and the vector passes at 108 dB instead of 2.85.
Withdrawn: ID3v2/APE tags do not break real files
I wrote that a file whose leading bytes are an ID3v2 tag "is not decoded at all", and flagged it as possibly more serious than the delay. I hedged that it needed confirming against a real tagged MP3 before sizing. I have now confirmed it, and it is not true.
Taking a real multi-frame file (
l3-hecommon, 30 frames) and attaching tags:Byte-identical output. The sync-word scan walks past leading tags without help.
(The ID3v1 trailer case is a small bonus: it suppresses the spurious 30th frame, so the decoded length matches the reference exactly.)
Why the four tag vectors decode zero frames is unrelated to tags. They are single-frame files of 274-2048 bytes, and minimp3 will not decode a lone frame without lookahead to validate it. Upstream's float build produces zero frames on all four as well, so it is neither a regression nor specific to the fixed-point port. Whether a one-frame stream should decode is a separate question, and a much smaller one than "tags break playback" — which is what I incorrectly implied.
Revised scope
l3-nonstandard-sin1k0db_lame_vbrtagclears the ISO floor and leavesKNOWN_EXCEPTIONSinci/codec_conformance/run.py.Dropped from scope: ID3v2/APE skipping (unnecessary -- the sync scan already handles it) and the four single-frame tag vectors (upstream behaviour, not tag-related).
fix(mp3): skip the VBR tag frame and encoder priming (#4129)
fix(mp3): clear VBR state between streams, and bound the length excep…
fix(mp3): stop clamping dequantised samples to 1.0 (FastLED#4127) (Fa…