From d21ff8be54c548fee530b468a2335625e875feaa Mon Sep 17 00:00:00 2001 From: Nick Shaforostoff Date: Wed, 23 Feb 2011 08:58:17 +0000 Subject: [PATCH 1/5] divide by 1000 instead of 1024 when calculating riff bitrate to get standard 1411 kbps bitrate on AudioCD wavs CCMAIL:taglib-devel@kde.org git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1222375 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/riff/aiff/aiffproperties.cpp | 2 +- taglib/riff/wav/wavproperties.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/riff/aiff/aiffproperties.cpp b/taglib/riff/aiff/aiffproperties.cpp index 9da5b1d8..77c3d277 100644 --- a/taglib/riff/aiff/aiffproperties.cpp +++ b/taglib/riff/aiff/aiffproperties.cpp @@ -148,6 +148,6 @@ void RIFF::AIFF::Properties::read(const ByteVector &data) d->sampleWidth = data.mid(6, 2).toShort(); double sampleRate = ConvertFromIeeeExtended(reinterpret_cast(data.mid(8, 10).data())); d->sampleRate = sampleRate; - d->bitrate = (sampleRate * d->sampleWidth * d->channels) / 1024.0; + d->bitrate = (sampleRate * d->sampleWidth * d->channels) / 1000.0; d->length = sampleFrames / d->sampleRate; } diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index 07971a06..37216860 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -114,7 +114,7 @@ void RIFF::WAV::Properties::read(const ByteVector &data) d->sampleWidth = data.mid(14, 2).toShort(false); uint byteRate = data.mid(8, 4).toUInt(false); - d->bitrate = byteRate * 8 / 1024; + d->bitrate = byteRate * 8 / 1000; d->length = byteRate > 0 ? d->streamLength / byteRate : 0; } From 272719e666651e789c049c0749d89fbce7491e7d Mon Sep 17 00:00:00 2001 From: Nick Shaforostoff Date: Wed, 23 Feb 2011 09:16:25 +0000 Subject: [PATCH 2/5] a formal change: convert rifffile.cpp to use vector of structs instead of several vectors of simple types git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1222376 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/riff/rifffile.cpp | 79 ++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 5fa8e212..2910b5cc 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -32,6 +32,14 @@ using namespace TagLib; +struct Chunk +{ + ByteVector name; + uint offset; + uint size; + char padding; +}; + class RIFF::File::FilePrivate { public: @@ -46,10 +54,7 @@ public: uint size; ByteVector format; - std::vector chunkNames; - std::vector chunkOffsets; - std::vector chunkSizes; - std::vector chunkPadding; + std::vector chunks; }; //////////////////////////////////////////////////////////////////////////////// @@ -81,22 +86,22 @@ TagLib::uint RIFF::File::riffSize() const TagLib::uint RIFF::File::chunkCount() const { - return d->chunkNames.size(); + return d->chunks.size(); } TagLib::uint RIFF::File::chunkDataSize(uint i) const { - return d->chunkSizes[i]; + return d->chunks[i].size; } TagLib::uint RIFF::File::chunkOffset(uint i) const { - return d->chunkOffsets[i]; + return d->chunks[i].offset; } TagLib::uint RIFF::File::chunkPadding(uint i) const { - return d->chunkPadding[i]; + return d->chunks[i].padding; } ByteVector RIFF::File::chunkName(uint i) const @@ -104,7 +109,7 @@ ByteVector RIFF::File::chunkName(uint i) const if(i >= chunkCount()) return ByteVector::null; - return d->chunkNames[i]; + return d->chunks[i].name; } ByteVector RIFF::File::chunkData(uint i) @@ -117,39 +122,39 @@ ByteVector RIFF::File::chunkData(uint i) long begin = 12 + 8; for(uint it = 0; it < i; it++) - begin += 8 + d->chunkSizes[it] + d->chunkPadding[it]; + begin += 8 + d->chunks[it].size + d->chunks[it].padding; seek(begin); - return readBlock(d->chunkSizes[i]); + return readBlock(d->chunks[i].size); } void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data) { - if(d->chunkNames.size() == 0) { + if(d->chunks.size() == 0) { debug("RIFF::File::setChunkData - No valid chunks found."); return; } - for(uint i = 0; i < d->chunkNames.size(); i++) { - if(d->chunkNames[i] == name) { + for(uint i = 0; i < d->chunks.size(); i++) { + if(d->chunks[i].name == name) { // First we update the global size - d->size += ((data.size() + 1) & ~1) - (d->chunkSizes[i] + d->chunkPadding[i]); + d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding); insert(ByteVector::fromUInt(d->size, d->endianness == BigEndian), 4, 4); // Now update the specific chunk - writeChunk(name, data, d->chunkOffsets[i] - 8, d->chunkSizes[i] + d->chunkPadding[i] + 8); + writeChunk(name, data, d->chunks[i].offset - 8, d->chunks[i].size + d->chunks[i].padding + 8); - d->chunkSizes[i] = data.size(); - d->chunkPadding[i] = (data.size() & 0x01) ? 1 : 0; + d->chunks[i].size = data.size(); + d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0; // Now update the internal offsets - for(i++; i < d->chunkNames.size(); i++) - d->chunkOffsets[i] = d->chunkOffsets[i-1] + 8 + d->chunkSizes[i-1] + d->chunkPadding[i-1]; + for(i++; i < d->chunks.size(); i++) + d->chunks[i].offset = d->chunks[i-1].offset + 8 + d->chunks[i-1].size + d->chunks[i-1].padding; return; } @@ -157,8 +162,8 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data) // Couldn't find an existing chunk, so let's create a new one. - uint i = d->chunkNames.size() - 1; - ulong offset = d->chunkOffsets[i] + d->chunkSizes[i]; + uint i = d->chunks.size() - 1; + ulong offset = d->chunks[i].offset + d->chunks[i].size; // First we update the global size @@ -172,13 +177,17 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data) // And update our internal structure if (offset & 1) { - d->chunkPadding[i] = 1; + d->chunks[i].padding = 1; offset++; } - d->chunkNames.push_back(name); - d->chunkSizes.push_back(data.size()); - d->chunkOffsets.push_back(offset + 8); - d->chunkPadding.push_back((data.size() & 0x01) ? 1 : 0); + + Chunk chunk; + chunk.name = name; + chunk.size = data.size(); + chunk.offset = offset + 8; + chunk.padding = (data.size() & 0x01) ? 1 : 0; + + d->chunks.push_back(chunk); } //////////////////////////////////////////////////////////////////////////////// @@ -203,15 +212,15 @@ void RIFF::File::read() break; } - d->chunkNames.push_back(chunkName); - d->chunkSizes.push_back(chunkSize); + Chunk chunk; + chunk.name = readBlock(4); + chunk.size = readBlock(4).toUInt(bigEndian); + chunk.offset = tell(); - d->chunkOffsets.push_back(tell()); - - seek(chunkSize, Current); + seek(chunk.size, Current); // check padding - char paddingSize = 0; + chunk.padding = 0; long uPosNotPadded = tell(); if((uPosNotPadded & 0x01) != 0) { ByteVector iByte = readBlock(1); @@ -220,10 +229,10 @@ void RIFF::File::read() seek(uPosNotPadded, Beginning); } else { - paddingSize = 1; + chunk.padding = 1; } } - d->chunkPadding.push_back(paddingSize); + d->chunks.push_back(chunk); } } From 7cc1ce1c362998ccb76a161e94c2cecd3d739a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Fri, 25 Feb 2011 19:42:49 +0000 Subject: [PATCH 3/5] Fix the patch from r1222376 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1222752 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/riff/rifffile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 2910b5cc..46581e51 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -213,8 +213,8 @@ void RIFF::File::read() } Chunk chunk; - chunk.name = readBlock(4); - chunk.size = readBlock(4).toUInt(bigEndian); + chunk.name = chunkName; + chunk.size = chunkSize; chunk.offset = tell(); seek(chunk.size, Current); From 10fff6d79760996c28a6b1ecd905cdcedb0e95f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Fri, 25 Feb 2011 19:43:25 +0000 Subject: [PATCH 4/5] Update the AIFF test git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1222753 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- tests/test_aiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_aiff.cpp b/tests/test_aiff.cpp index 54f93702..df1c5ac1 100644 --- a/tests/test_aiff.cpp +++ b/tests/test_aiff.cpp @@ -23,7 +23,7 @@ public: string filename = copy.fileName(); RIFF::AIFF::File *f = new RIFF::AIFF::File(filename.c_str()); - CPPUNIT_ASSERT_EQUAL(689, f->audioProperties()->bitrate()); + CPPUNIT_ASSERT_EQUAL(705, f->audioProperties()->bitrate()); } }; From eee860f9c63f9b5a6162d32a89e9dc9c98c24398 Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Wed, 2 Mar 2011 03:05:28 +0000 Subject: [PATCH 5/5] Fix build when the 'uint' typedef is already defined. Using uint in those structs gave me the following error: /home/rakuco/kde4/src/kdesupport/taglib/taglib/riff/rifffile.cpp:38: error: reference to 'uint' is ambiguous /usr/include/sys/types.h:56: error: candidates are: typedef unsigned int uint Is it really necessary to have those typedefs in taglib.h? It'd be nice to at least check if they are not being redefined. CCMAIL: lalinsky@gmail.com git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1223282 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- taglib/riff/rifffile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 46581e51..8d23bcd6 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -35,8 +35,8 @@ using namespace TagLib; struct Chunk { ByteVector name; - uint offset; - uint size; + TagLib::uint offset; + TagLib::uint size; char padding; }; @@ -51,7 +51,7 @@ public: } Endianness endianness; ByteVector type; - uint size; + TagLib::uint size; ByteVector format; std::vector chunks;