diff options
| author | Tom Kirchner <git@halffull.org> | 2025-01-11 22:04:49 -0800 |
|---|---|---|
| committer | Tom Kirchner <git@halffull.org> | 2025-01-11 22:10:34 -0800 |
| commit | f8199bbd6d7b8bc64d8f58dc5638af8bc36cc73f (patch) | |
| tree | bebee08d1185349ffa3e1a6a2d46ffee2b2aa128 | |
| parent | 35f124637943976450150b96bdd0359bf26287f7 (diff) | |
| download | tangara-fw-f8199bbd6d7b8bc64d8f58dc5638af8bc36cc73f.tar.gz | |
Handle optional frames field in bytes offset of MP3 header
| -rw-r--r-- | src/codecs/mad.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index a0184487..e6e641f5 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -367,20 +367,26 @@ auto MadMp3Decoder::GetMp3Info(const mad_header& header) uint32_t flags = ((uint32_t)flags_raw[0] << 24) + ((uint32_t)flags_raw[1] << 16) + ((uint32_t)flags_raw[2] << 8) + ((uint32_t)flags_raw[3]); + auto toc_offset = 8; + auto bytes_offset = 8; + if (flags & 1) { + // Frames field is present + toc_offset += 4; + bytes_offset += 4; + } + if (flags & 2) { + // Bytes field is present + toc_offset += 4; + } if (flags & 4) { // TOC flag is set - auto toc_offset = 8; - if (flags & 1) { - toc_offset += 4; - } if (flags & 2) { // Bytes field - unsigned char const* bytes_raw = stream_->this_frame + xing_offset + 12; + unsigned char const* bytes_raw = stream_->this_frame + xing_offset + bytes_offset; uint32_t num_bytes = ((uint32_t)bytes_raw[0] << 24) + ((uint32_t)bytes_raw[1] << 16) + ((uint32_t)bytes_raw[2] << 8) + ((uint32_t)bytes_raw[3]); bytes.emplace(num_bytes); - toc_offset += 4; } // Read the table of contents in toc.emplace((stream_->this_frame + xing_offset + toc_offset), 100); |
