aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorThierry Crozat2015-04-05 20:29:07 +0100
committerThierry Crozat2015-04-05 21:17:06 +0100
commit5c7cc826f082a10fef1cd44766f2226bb66b9b2f (patch)
tree6bd33a5421a098b577d1290d8e5e0970d2209b3f /audio
parentd9168c8fae304c0984b59d142dfc66e04b9fab36 (diff)
downloadscummvm-rg350-5c7cc826f082a10fef1cd44766f2226bb66b9b2f.tar.gz
scummvm-rg350-5c7cc826f082a10fef1cd44766f2226bb66b9b2f.tar.bz2
scummvm-rg350-5c7cc826f082a10fef1cd44766f2226bb66b9b2f.zip
AUDIO: Skip ID3 tag at start of mp3 files
This fixes bug #6834 MP3: ScummVM doesn't skip ID3 tag at beginning of file.
Diffstat (limited to 'audio')
-rw-r--r--audio/decoders/mp3.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/audio/decoders/mp3.cpp b/audio/decoders/mp3.cpp
index c1b3faaeb1..feb531f5ae 100644
--- a/audio/decoders/mp3.cpp
+++ b/audio/decoders/mp3.cpp
@@ -246,6 +246,23 @@ void MP3Stream::initStream() {
_inStream->seek(0, SEEK_SET);
_curTime = mad_timer_zero;
_posInFrame = 0;
+
+ // Skip ID3 TAG if any
+ // ID3v1 (beginning with with 'TAG') is located at the end of files. So we can ignore those.
+ // ID3v2 can be located at the start of files and begins with a 10 bytes header, the first 3 bytes being 'ID3'.
+ // The tag size is coded on the last 4 bytes of the 10 bytes header as a 32 bit synchsafe integer.
+ // See http://id3.org/id3v2.4.0-structure for details.
+ char data[10];
+ _inStream->read(data, 10);
+ if (data[0] == 'I' && data[1] == 'D' && data[2] == '3') {
+ uint32 size = data[9] + 128 * (data[8] + 128 * (data[7] + 128 * data[6]));
+ // This size does not include an optional 10 bytes footer. Check if it is present.
+ if (data[5] & 0x10)
+ size += 10;
+ debug("Skipping ID3 TAG (%d bytes)", size + 10);
+ _inStream->seek(size, SEEK_CUR);
+ } else
+ _inStream->seek(0, SEEK_SET);
// Update state
_state = MP3_STATE_READY;