From 7b3f279294737a18a6c4d760cd0f90484ba887ad Mon Sep 17 00:00:00 2001 From: "Stephen F. Booth" Date: Mon, 30 Jan 2012 22:31:15 -0500 Subject: [PATCH 1/8] Correctly handle non-integral bit depths --- taglib/riff/wav/wavproperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index c8b7fd6b..f0453968 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -125,5 +125,5 @@ void RIFF::WAV::Properties::read(const ByteVector &data) d->length = byteRate > 0 ? d->streamLength / byteRate : 0; if(d->channels > 0 && d->sampleWidth > 0) - d->sampleFrames = d->streamLength / (d->channels * (d->sampleWidth / 8)); + d->sampleFrames = d->streamLength / (d->channels * ((d->sampleWidth + 7) / 8)); } From 06424598bbfb45e20099e7faca1954911d214c90 Mon Sep 17 00:00:00 2001 From: Birunthan Mohnathas Date: Thu, 2 Feb 2012 15:03:41 +0200 Subject: [PATCH 2/8] Fixed memory leak. --- taglib/mpeg/id3v1/id3v1tag.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index 4a1d69b2..dea197bb 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -51,7 +51,8 @@ public: static const StringHandler *stringHandler; }; -const ID3v1::StringHandler *ID3v1::Tag::TagPrivate::stringHandler = new StringHandler; +static const StringHandler defaultStringHandler; +const ID3v1::StringHandler *ID3v1::Tag::TagPrivate::stringHandler = &defaultStringHandler; //////////////////////////////////////////////////////////////////////////////// // StringHandler implementation @@ -189,7 +190,6 @@ void ID3v1::Tag::setTrack(uint i) void ID3v1::Tag::setStringHandler(const StringHandler *handler) { - delete TagPrivate::stringHandler; TagPrivate::stringHandler = handler; } From 1f2248d24b479c55908cd14b75dbc9b62147c037 Mon Sep 17 00:00:00 2001 From: Birunthan Mohnathas Date: Thu, 2 Feb 2012 17:50:58 +0200 Subject: [PATCH 3/8] Additional change to previous fix. --- taglib/mpeg/id3v1/id3v1tag.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index dea197bb..3da68821 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -190,6 +190,9 @@ void ID3v1::Tag::setTrack(uint i) void ID3v1::Tag::setStringHandler(const StringHandler *handler) { + if (TagPrivate::stringHandler != &defaultStringHandler) + delete TagPrivate::stringHandler; + TagPrivate::stringHandler = handler; } From 9564956a7fd5e10270d483a74cc7b508a492254a Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Thu, 2 Feb 2012 18:12:37 +0200 Subject: [PATCH 4/8] Removed space. --- taglib/mpeg/id3v1/id3v1tag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index 3da68821..1457c81b 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -190,7 +190,7 @@ void ID3v1::Tag::setTrack(uint i) void ID3v1::Tag::setStringHandler(const StringHandler *handler) { - if (TagPrivate::stringHandler != &defaultStringHandler) + if(TagPrivate::stringHandler != &defaultStringHandler) delete TagPrivate::stringHandler; TagPrivate::stringHandler = handler; From dc628204c06acf826ce522e6eab578bdd589edf8 Mon Sep 17 00:00:00 2001 From: "Stephen F. Booth" Date: Sat, 4 Feb 2012 08:30:34 -0500 Subject: [PATCH 5/8] Added sampleFrames() for TTA files --- taglib/trueaudio/trueaudioproperties.cpp | 13 ++++++++++--- taglib/trueaudio/trueaudioproperties.h | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index 5b1bf12d..bae386aa 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -48,7 +48,8 @@ public: bitrate(0), sampleRate(0), channels(0), - bitsPerSample(0) {} + bitsPerSample(0), + sampleFrames(0) {} ByteVector data; long streamLength; @@ -59,6 +60,7 @@ public: int sampleRate; int channels; int bitsPerSample; + uint sampleFrames; }; //////////////////////////////////////////////////////////////////////////////// @@ -101,6 +103,11 @@ int TrueAudio::Properties::channels() const return d->channels; } +uint TrueAudio::Properties::sampleFrames() const +{ + return d->sampleFrames; +} + int TrueAudio::Properties::ttaVersion() const { return d->version; @@ -129,8 +136,8 @@ void TrueAudio::Properties::read() d->sampleRate = d->data.mid(pos, 4).toUInt(false); pos += 4; - unsigned long samples = d->data.mid(pos, 4).toUInt(false); - d->length = samples / d->sampleRate; + d->sampleFrames = d->data.mid(pos, 4).toUInt(false); + d->length = d->sampleFrames / d->sampleRate; d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; } diff --git a/taglib/trueaudio/trueaudioproperties.h b/taglib/trueaudio/trueaudioproperties.h index f66fd2e9..126b6788 100644 --- a/taglib/trueaudio/trueaudioproperties.h +++ b/taglib/trueaudio/trueaudioproperties.h @@ -73,6 +73,11 @@ namespace TagLib { */ int bitsPerSample() const; + /*! + * Returns the total number of sample frames + */ + uint sampleFrames() const; + /*! * Returns the major version number. */ From fa662a23dbd33493d77b2fecfcaa436d9280ba3f Mon Sep 17 00:00:00 2001 From: "Stephen F. Booth" Date: Sat, 4 Feb 2012 08:39:45 -0500 Subject: [PATCH 6/8] Check if the header is TTA1 before parsing --- taglib/trueaudio/trueaudioproperties.cpp | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index bae386aa..1e4e87d3 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -125,19 +125,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; - d->sampleFrames = d->data.mid(pos, 4).toUInt(false); - d->length = d->sampleFrames / 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; + d->sampleFrames = d->data.mid(pos, 4).toUInt(false); + d->length = d->sampleFrames / d->sampleRate; + + d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0; + } } From 51675f3399e0ea8701686e3992a46a625303c112 Mon Sep 17 00:00:00 2001 From: "Stephen F. Booth" Date: Sat, 4 Feb 2012 11:34:40 -0500 Subject: [PATCH 7/8] Added sampleFrames to FLACProperties --- taglib/flac/flacproperties.cpp | 21 ++++++++++++++++----- taglib/flac/flacproperties.h | 5 +++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/taglib/flac/flacproperties.cpp b/taglib/flac/flacproperties.cpp index d36d26ec..8bdc5d8d 100644 --- a/taglib/flac/flacproperties.cpp +++ b/taglib/flac/flacproperties.cpp @@ -42,7 +42,8 @@ public: bitrate(0), sampleRate(0), sampleWidth(0), - channels(0) {} + channels(0), + sampleFrames(0) {} ByteVector data; long streamLength; @@ -52,6 +53,7 @@ public: int sampleRate; int sampleWidth; int channels; + unsigned long long sampleFrames; ByteVector signature; }; @@ -101,6 +103,11 @@ int FLAC::Properties::channels() const return d->channels; } +unsigned long long FLAC::Properties::sampleFrames() const +{ + return d->sampleFrames; +} + ByteVector FLAC::Properties::signature() const { return d->signature; @@ -132,6 +139,8 @@ void FLAC::Properties::read() pos += 3; uint flags = d->data.mid(pos, 4).toUInt(true); + pos += 4; + d->sampleRate = flags >> 12; d->channels = ((flags >> 9) & 7) + 1; d->sampleWidth = ((flags >> 4) & 31) + 1; @@ -139,12 +148,14 @@ void FLAC::Properties::read() // The last 4 bits are the most significant 4 bits for the 36 bit // stream length in samples. (Audio files measured in days) - uint highLength =d->sampleRate > 0 ? (((flags & 0xf) << 28) / d->sampleRate) << 4 : 0; + unsigned long long hi = flags & 0xf; + unsigned long long lo = d->data.mid(pos, 4).toUInt(true); pos += 4; - d->length = d->sampleRate > 0 ? - (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength : 0; - pos += 4; + d->sampleFrames = (hi << 32) | lo; + + if(d->sampleRate > 0) + d->length = int(d->sampleFrames / d->sampleRate); // Uncompressed bitrate: diff --git a/taglib/flac/flacproperties.h b/taglib/flac/flacproperties.h index a8a02e7c..c1458981 100644 --- a/taglib/flac/flacproperties.h +++ b/taglib/flac/flacproperties.h @@ -77,6 +77,11 @@ namespace TagLib { */ int sampleWidth() const; + /*! + * Return the number of sample frames + */ + unsigned long long sampleFrames() const; + /*! * Returns the MD5 signature of the uncompressed audio stream as read * from the stream info header header. From cdfb447042cb0676a19b476db18df5d363e2d688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Sat, 4 Feb 2012 21:22:52 +0100 Subject: [PATCH 8/8] Add explicitly declared default constructor to StringHandler --- taglib/mpeg/id3v1/id3v1tag.cpp | 4 ++++ taglib/mpeg/id3v1/id3v1tag.h | 1 + 2 files changed, 5 insertions(+) diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index 1457c81b..94d533ae 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -58,6 +58,10 @@ const ID3v1::StringHandler *ID3v1::Tag::TagPrivate::stringHandler = &defaultStri // StringHandler implementation //////////////////////////////////////////////////////////////////////////////// +StringHandler::StringHandler() +{ +} + String ID3v1::StringHandler::parse(const ByteVector &data) const { return String(data, String::Latin1).stripWhiteSpace(); diff --git a/taglib/mpeg/id3v1/id3v1tag.h b/taglib/mpeg/id3v1/id3v1tag.h index fad485e5..a90ac531 100644 --- a/taglib/mpeg/id3v1/id3v1tag.h +++ b/taglib/mpeg/id3v1/id3v1tag.h @@ -62,6 +62,7 @@ namespace TagLib { TAGLIB_IGNORE_MISSING_DESTRUCTOR public: // BIC: Add virtual destructor. + StringHandler(); /*! * Decode a string from \a data. The default implementation assumes that