From: Stephen F. Booth Date: Sat, 4 Feb 2012 13:39:45 +0000 (-0500) Subject: Check if the header is TTA1 before parsing X-Git-Tag: v1.7.1~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23c86cf27d625d25318a1897029922302c9d21a8;p=taglib Check if the header is TTA1 before parsing --- diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index 5b1bf12d..3cab855b 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -118,19 +118,26 @@ void TrueAudio::Properties::read() int pos = 3; d->version = d->data[pos] - '0'; - pos += 1 + 2; + pos += 1; - d->channels = d->data.mid(pos, 2).toShort(false); - pos += 2; + // According to http://en.true-audio.com/TTA_Lossless_Audio_Codec_-_Format_Description + // TTA2 headers are in development, and have a different format + if(1 == d->version) { + // Skip the audio format + pos += 2; - d->bitsPerSample = d->data.mid(pos, 2).toShort(false); - pos += 2; + d->channels = d->data.mid(pos, 2).toShort(false); + pos += 2; - d->sampleRate = d->data.mid(pos, 4).toUInt(false); - pos += 4; + d->bitsPerSample = d->data.mid(pos, 2).toShort(false); + pos += 2; - unsigned long samples = d->data.mid(pos, 4).toUInt(false); - d->length = samples / d->sampleRate; + d->sampleRate = d->data.mid(pos, 4).toUInt(false); + pos += 4; - d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + uint sampleFrames = d->data.mid(pos, 4).toUInt(false); + d->length = d->sampleRate > 0 ? sampleFrames / d->sampleRate : 0; + + d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + } }