mirror of
https://github.com/taglib/taglib.git
synced 2025-11-17 07:02:53 -05:00
Redesigned toNumber/fromNumber API of ByteVector
This commit is contained in:
@ -119,7 +119,7 @@ bool Ogg::FLAC::File::save()
|
||||
|
||||
// Put the size in the first 32 bit (I assume no more than 24 bit are used)
|
||||
|
||||
ByteVector v = ByteVector::fromUInt32(d->xiphCommentData.size());
|
||||
ByteVector v = ByteVector::fromUInt32BE(d->xiphCommentData.size());
|
||||
|
||||
// Set the type of the metadata-block to be a Xiph / Vorbis comment
|
||||
|
||||
@ -241,7 +241,7 @@ void Ogg::FLAC::File::scan()
|
||||
|
||||
char blockType = header[0] & 0x7f;
|
||||
bool lastBlock = (header[0] & 0x80) != 0;
|
||||
uint length = header.mid(1, 3).toUInt32();
|
||||
uint length = header.toUInt24BE(1);
|
||||
overhead += length;
|
||||
|
||||
// Sanity: First block should be the stream_info metadata
|
||||
@ -264,7 +264,7 @@ void Ogg::FLAC::File::scan()
|
||||
header = metadataHeader.mid(0, 4);
|
||||
blockType = header[0] & 0x7f;
|
||||
lastBlock = (header[0] & 0x80) != 0;
|
||||
length = header.mid(1, 3).toUInt32();
|
||||
length = header.toUInt24BE(1);
|
||||
overhead += length;
|
||||
|
||||
if(blockType == 1) {
|
||||
|
||||
@ -188,7 +188,7 @@ ByteVector Ogg::Page::render() const
|
||||
// the entire page with the 4 bytes reserved for the checksum zeroed and then
|
||||
// inserted in bytes 22-25 of the page header.
|
||||
|
||||
ByteVector checksum = ByteVector::fromUInt32(data.checksum(), false);
|
||||
ByteVector checksum = ByteVector::fromUInt32LE(data.checksum());
|
||||
for(int i = 0; i < 4; i++)
|
||||
data[i + 22] = checksum[i];
|
||||
|
||||
|
||||
@ -203,15 +203,15 @@ ByteVector Ogg::PageHeader::render() const
|
||||
|
||||
// absolute granular position
|
||||
|
||||
data.append(ByteVector::fromUInt64(d->absoluteGranularPosition, false));
|
||||
data.append(ByteVector::fromUInt64LE(d->absoluteGranularPosition));
|
||||
|
||||
// stream serial number
|
||||
|
||||
data.append(ByteVector::fromUInt32(d->streamSerialNumber, false));
|
||||
data.append(ByteVector::fromUInt32LE(d->streamSerialNumber));
|
||||
|
||||
// page sequence number
|
||||
|
||||
data.append(ByteVector::fromUInt32(d->pageSequenceNumber, false));
|
||||
data.append(ByteVector::fromUInt32LE(d->pageSequenceNumber));
|
||||
|
||||
// checksum -- this is left empty and should be filled in by the Ogg::Page
|
||||
// class
|
||||
@ -255,9 +255,9 @@ void Ogg::PageHeader::read()
|
||||
d->firstPageOfStream = flags.test(1);
|
||||
d->lastPageOfStream = flags.test(2);
|
||||
|
||||
d->absoluteGranularPosition = data.mid(6, 8).toInt64(false);
|
||||
d->streamSerialNumber = data.mid(14, 4).toUInt32(false);
|
||||
d->pageSequenceNumber = data.mid(18, 4).toUInt32(false);
|
||||
d->absoluteGranularPosition = data.toInt64LE(6);
|
||||
d->streamSerialNumber = data.toUInt32LE(14);
|
||||
d->pageSequenceNumber = data.toUInt32LE(18);
|
||||
|
||||
// Byte number 27 is the number of page segments, which is the only variable
|
||||
// length portion of the page header. After reading the number of page
|
||||
|
||||
@ -129,11 +129,11 @@ void Opus::Properties::read()
|
||||
pos += 1;
|
||||
|
||||
// *Pre-skip* (16 bits, unsigned, little endian)
|
||||
ushort preSkip = data.mid(pos, 2).toUInt16(false);
|
||||
ushort preSkip = data.toUInt16LE(pos);
|
||||
pos += 2;
|
||||
|
||||
// *Input Sample Rate* (32 bits, unsigned, little endian)
|
||||
d->inputSampleRate = data.mid(pos, 4).toUInt32(false);
|
||||
d->inputSampleRate = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// *Output Gain* (16 bits, signed, little endian)
|
||||
|
||||
@ -113,32 +113,32 @@ void Speex::Properties::read()
|
||||
|
||||
ByteVector data = d->file->packet(0);
|
||||
|
||||
int pos = 28;
|
||||
size_t pos = 28;
|
||||
|
||||
// speex_version_id; /**< Version for Speex (for checking compatibility) */
|
||||
d->speexVersion = data.mid(pos, 4).toUInt32(false);
|
||||
d->speexVersion = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
|
||||
pos += 4;
|
||||
|
||||
// rate; /**< Sampling rate used */
|
||||
d->sampleRate = data.mid(pos, 4).toUInt32(false);
|
||||
d->sampleRate = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// mode; /**< Mode used (0 for narrowband, 1 for wideband) */
|
||||
d->mode = data.mid(pos, 4).toUInt32(false);
|
||||
d->mode = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// mode_bitstream_version; /**< Version ID of the bit-stream */
|
||||
pos += 4;
|
||||
|
||||
// nb_channels; /**< Number of channels encoded */
|
||||
d->channels = data.mid(pos, 4).toUInt32(false);
|
||||
d->channels = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// bitrate; /**< Bit-rate used */
|
||||
d->bitrate = data.mid(pos, 4).toUInt32(false);
|
||||
d->bitrate = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
// frame_size; /**< Size of frames */
|
||||
@ -146,7 +146,7 @@ void Speex::Properties::read()
|
||||
pos += 4;
|
||||
|
||||
// vbr; /**< 1 for a VBR encoding, 0 otherwise */
|
||||
d->vbr = data.mid(pos, 4).toUInt32(false) == 1;
|
||||
d->vbr = data.toUInt32LE(pos) == 1;
|
||||
pos += 4;
|
||||
|
||||
// frames_per_packet; /**< Number of frames stored per Ogg packet */
|
||||
|
||||
@ -151,22 +151,22 @@ void Ogg::Vorbis::Properties::read()
|
||||
|
||||
pos += 7;
|
||||
|
||||
d->vorbisVersion = data.mid(pos, 4).toUInt32(false);
|
||||
d->vorbisVersion = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
d->channels = uchar(data[pos]);
|
||||
pos += 1;
|
||||
|
||||
d->sampleRate = data.mid(pos, 4).toUInt32(false);
|
||||
d->sampleRate = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateMaximum = data.mid(pos, 4).toUInt32(false);
|
||||
d->bitrateMaximum = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateNominal = data.mid(pos, 4).toUInt32(false);
|
||||
d->bitrateNominal = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateMinimum = data.mid(pos, 4).toUInt32(false);
|
||||
d->bitrateMinimum = data.toUInt32LE(pos);
|
||||
|
||||
// TODO: Later this should be only the "fast" mode.
|
||||
d->bitrate = d->bitrateNominal;
|
||||
|
||||
@ -286,12 +286,12 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
|
||||
|
||||
ByteVector vendorData = d->vendorID.data(String::UTF8);
|
||||
|
||||
data.append(ByteVector::fromUInt32(vendorData.size(), false));
|
||||
data.append(ByteVector::fromUInt32LE(vendorData.size()));
|
||||
data.append(vendorData);
|
||||
|
||||
// Add the number of fields.
|
||||
|
||||
data.append(ByteVector::fromUInt32(fieldCount(), false));
|
||||
data.append(ByteVector::fromUInt32LE(fieldCount()));
|
||||
|
||||
// Iterate over the the field lists. Our iterator returns a
|
||||
// std::pair<String, StringList> where the first String is the field name and
|
||||
@ -311,7 +311,7 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
|
||||
fieldData.append('=');
|
||||
fieldData.append((*valuesIt).data(String::UTF8));
|
||||
|
||||
data.append(ByteVector::fromUInt32(fieldData.size(), false));
|
||||
data.append(ByteVector::fromUInt32LE(fieldData.size()));
|
||||
data.append(fieldData);
|
||||
}
|
||||
}
|
||||
@ -344,9 +344,9 @@ void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
// The first thing in the comment data is the vendor ID length, followed by a
|
||||
// UTF8 string with the vendor ID.
|
||||
|
||||
uint pos = 0;
|
||||
size_t pos = 0;
|
||||
|
||||
uint vendorLength = data.mid(0, 4).toUInt32(false);
|
||||
const uint vendorLength = data.toUInt32LE(0);
|
||||
pos += 4;
|
||||
|
||||
d->vendorID = String(data.mid(pos, vendorLength), String::UTF8);
|
||||
@ -354,7 +354,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
|
||||
// Next the number of fields in the comment vector.
|
||||
|
||||
uint commentFields = data.mid(pos, 4).toUInt32(false);
|
||||
uint commentFields = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
if(commentFields > (data.size() - 8) / 4) {
|
||||
@ -366,7 +366,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
// Each comment field is in the format "KEY=value" in a UTF8 string and has
|
||||
// 4 bytes before the text starts that gives the length.
|
||||
|
||||
uint commentLength = data.mid(pos, 4).toUInt32(false);
|
||||
uint commentLength = data.toUInt32LE(pos);
|
||||
pos += 4;
|
||||
|
||||
String comment = String(data.mid(pos, commentLength), String::UTF8);
|
||||
|
||||
Reference in New Issue
Block a user