Redesigned toNumber/fromNumber API of ByteVector

This commit is contained in:
Tsuda Kageyu
2013-04-27 12:46:21 +09:00
parent 82e616101a
commit 362900c721
51 changed files with 802 additions and 711 deletions

View File

@ -177,19 +177,19 @@ void APE::Footer::parse(const ByteVector &data)
// Read the version number
d->version = data.mid(8, 4).toUInt32(false);
d->version = data.toUInt32LE(8);
// Read the tag size
d->tagSize = data.mid(12, 4).toUInt32(false);
d->tagSize = data.toUInt32LE(12);
// Read the item count
d->itemCount = data.mid(16, 4).toUInt32(false);
d->itemCount = data.toUInt32LE(16);
// Read the flags
std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(20, 4).toUInt32(false)));
std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt32LE(20)));
d->headerPresent = flags[31];
d->footerPresent = !flags[30];
@ -208,15 +208,15 @@ ByteVector APE::Footer::render(bool isHeader) const
// add the version number -- we always render a 2.000 tag regardless of what
// the tag originally was.
v.append(ByteVector::fromUInt32(2000, false));
v.append(ByteVector::fromUInt32LE(2000));
// add the tag size
v.append(ByteVector::fromUInt32(d->tagSize, false));
v.append(ByteVector::fromUInt32LE(d->tagSize));
// add the item count
v.append(ByteVector::fromUInt32(d->itemCount, false));
v.append(ByteVector::fromUInt32LE(d->itemCount));
// render and add the flags
@ -226,11 +226,11 @@ ByteVector APE::Footer::render(bool isHeader) const
flags[30] = false; // footer is always present
flags[29] = isHeader;
v.append(ByteVector::fromUInt32(flags.to_ulong(), false));
v.append(ByteVector::fromUInt32LE(flags.to_ulong()));
// add the reserved 64bit
v.append(ByteVector::fromUInt64(0));
v.append(ByteVector::fromUInt64BE(0));
return v;
}

View File

@ -216,8 +216,8 @@ void APE::Item::parse(const ByteVector &data)
return;
}
uint valueLength = data.mid(0, 4).toUInt32(false);
uint flags = data.mid(4, 4).toUInt32(false);
const uint valueLength = data.toUInt32LE(0);
const uint flags = data.toUInt32LE(4);
d->key = String(data.mid(8), String::UTF8);
@ -253,8 +253,8 @@ ByteVector APE::Item::render() const
else
value.append(d->value);
data.append(ByteVector::fromUInt32(value.size(), false));
data.append(ByteVector::fromUInt32(flags, false));
data.append(ByteVector::fromUInt32LE(value.size()));
data.append(ByteVector::fromUInt32LE(flags));
data.append(d->key.data(String::UTF8));
data.append(ByteVector('\0'));
data.append(value);

View File

@ -128,7 +128,7 @@ void APE::Properties::read()
ByteVector commonHeader=d->file->readBlock(6);
if(!commonHeader.startsWith("MAC "))
return;
d->version = commonHeader.mid(4).toUInt32(false);
d->version = commonHeader.toUInt16LE(4);
if(d->version >= 3980) {
analyzeCurrent();
@ -182,7 +182,7 @@ void APE::Properties::analyzeCurrent()
// Read the descriptor
d->file->seek(2, File::Current);
ByteVector descriptor = d->file->readBlock(44);
uint descriptorBytes = descriptor.mid(0,4).toUInt32(false);
uint descriptorBytes = descriptor.toUInt32LE(0);
if ((descriptorBytes - 52) > 0)
d->file->seek(descriptorBytes - 52, File::Current);
@ -191,14 +191,14 @@ void APE::Properties::analyzeCurrent()
ByteVector header = d->file->readBlock(24);
// Get the APE info
d->channels = header.mid(18, 2).toInt16(false);
d->sampleRate = header.mid(20, 4).toUInt32(false);
d->bitsPerSample = header.mid(16, 2).toInt16(false);
d->channels = header.toInt16LE(18);
d->sampleRate = header.toUInt32LE(20);
d->bitsPerSample = header.toInt16LE(16);
//d->compressionLevel =
uint totalFrames = header.mid(12, 4).toUInt32(false);
uint blocksPerFrame = header.mid(4, 4).toUInt32(false);
uint finalFrameBlocks = header.mid(8, 4).toUInt32(false);
uint totalFrames = header.toUInt32LE(12);
uint blocksPerFrame = header.toUInt32LE(4);
uint finalFrameBlocks = header.toUInt32LE(8);
d->sampleFrames = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
@ -207,13 +207,13 @@ void APE::Properties::analyzeCurrent()
void APE::Properties::analyzeOld()
{
ByteVector header = d->file->readBlock(26);
uint totalFrames = header.mid(18, 4).toUInt32(false);
uint totalFrames = header.toUInt32LE(18);
// Fail on 0 length APE files (catches non-finalized APE files)
if(totalFrames == 0)
return;
short compressionLevel = header.mid(0, 2).toInt16(false);
short compressionLevel = header.toUInt32LE(0);
uint blocksPerFrame;
if(d->version >= 3950)
blocksPerFrame = 73728 * 4;
@ -221,10 +221,10 @@ void APE::Properties::analyzeOld()
blocksPerFrame = 73728;
else
blocksPerFrame = 9216;
d->channels = header.mid(4, 2).toInt16(false);
d->sampleRate = header.mid(6, 4).toUInt32(false);
uint finalFrameBlocks = header.mid(22, 4).toUInt32(false);
uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->channels = header.toUInt16LE(4);
d->sampleRate = header.toUInt32LE(6);
const uint finalFrameBlocks = header.toUInt32LE(22);
const uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = totalBlocks / d->sampleRate;
d->bitrate = d->length > 0 ? static_cast<int>(d->streamLength * 8L / d->length / 1000) : 0;
}