Move property parsing code to Properties.
void RIFF::AIFF::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
{
- ByteVector formatData;
- for(uint i = 0; i < chunkCount(); i++) {
+ for(uint i = 0; i < chunkCount(); ++i) {
const ByteVector name = chunkName(i);
if(name == "ID3 " || name == "id3 ") {
if(!d->tag) {
- d->tagChunkID = name;
d->tag = new ID3v2::Tag(this, chunkOffset(i));
+ d->tagChunkID = name;
d->hasID3v2 = true;
}
else {
debug("RIFF::AIFF::File::read() - Duplicate ID3v2 tag found.");
}
}
- else if(readProperties) {
- if(name == "COMM") {
- if(formatData.isEmpty()) {
- formatData = chunkData(i);
- }
- else {
- debug("RIFF::AIFF::File::read() - Duplicate 'COMM' chunk found.");
- }
- }
- else if(name == "SSND") {
- if(streamLength == 0) {
- streamLength = chunkDataSize(i) + chunkPadding(i);
- }
- else {
- debug("RIFF::AIFF::File::read() - Duplicate 'SSND' chunk found.");
- }
- }
- }
}
if(!d->tag)
- d->tag = new ID3v2::Tag;
+ d->tag = new ID3v2::Tag();
- if(!formatData.isEmpty())
- d->properties = new Properties(formatData, propertiesStyle);
+ if(readProperties)
+ d->properties = new Properties(this, propertiesStyle);
}
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
+ friend class Properties;
+
class FilePrivate;
FilePrivate *d;
};
#include <tstring.h>
#include <tdebug.h>
+#include "aifffile.h"
#include "aiffproperties.h"
using namespace TagLib;
// public members
////////////////////////////////////////////////////////////////////////////////
-RIFF::AIFF::Properties::Properties(const ByteVector &data, ReadStyle style) :
+RIFF::AIFF::Properties::Properties(const ByteVector & /*data*/, ReadStyle style) :
AudioProperties(style),
d(new PropertiesPrivate())
{
- read(data);
+ debug("RIFF::AIFF::Properties::Properties() - This constructor is no longer used.");
+}
+
+RIFF::AIFF::Properties::Properties(File *file, ReadStyle style) :
+ AudioProperties(style),
+ d(new PropertiesPrivate())
+{
+ read(file);
}
RIFF::AIFF::Properties::~Properties()
{
return d->compressionName;
}
+
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
-void RIFF::AIFF::Properties::read(const ByteVector &data)
-{
+void RIFF::AIFF::Properties::read(File *file)
+{
+ ByteVector data;
+ uint streamLength = 0;
+ for(uint i = 0; i < file->chunkCount(); i++) {
+ const ByteVector name = file->chunkName(i);
+ if(name == "COMM") {
+ if(data.isEmpty())
+ data = file->chunkData(i);
+ else
+ debug("RIFF::AIFF::Properties::read() - Duplicate 'COMM' chunk found.");
+ }
+ else if(name == "SSND") {
+ if(streamLength == 0)
+ streamLength = file->chunkDataSize(i) + file->chunkPadding(i);
+ else
+ debug("RIFF::AIFF::Properties::read() - Duplicate 'SSND' chunk found.");
+ }
+ }
+
if(data.size() < 18) {
- debug("RIFF::AIFF::Properties::read() - \"COMM\" chunk is too short for AIFF.");
+ debug("RIFF::AIFF::Properties::read() - 'COMM' chunk not found or too short.");
+ return;
+ }
+
+ if(streamLength == 0) {
+ debug("RIFF::AIFF::Properties::read() - 'SSND' chunk not found.");
return;
}
d->bitsPerSample = data.toShort(6U);
const long double sampleRate = data.toFloat80BE(8);
- if(sampleRate >= 1.0) {
+ if(sampleRate >= 1.0)
d->sampleRate = static_cast<int>(sampleRate + 0.5);
- d->bitrate = static_cast<int>(sampleRate * d->bitsPerSample * d->channels / 1000.0 + 0.5);
- d->length = static_cast<int>(d->sampleFrames * 1000.0 / sampleRate + 0.5);
+
+ if(d->sampleFrames > 0 && d->sampleRate > 0) {
+ const double length = d->sampleFrames * 1000.0 / d->sampleRate;
+ d->length = static_cast<int>(length + 0.5);
+ d->bitrate = static_cast<int>(streamLength * 8.0 / length + 0.5);
}
if(data.size() >= 23) {
/*!
* Create an instance of AIFF::Properties with the data read from the
* ByteVector \a data.
+ *
+ * \deprecated
*/
Properties(const ByteVector &data, ReadStyle style);
+ /*!
+ * Create an instance of AIFF::Properties with the data read from the
+ * AIFF::File \a file.
+ */
+ Properties(File *file, ReadStyle style);
+
/*!
* Destroys this AIFF::Properties instance.
*/
Properties(const Properties &);
Properties &operator=(const Properties &);
- void read(const ByteVector &data);
+ void read(File *file);
class PropertiesPrivate;
PropertiesPrivate *d;
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(37, f.audioProperties()->lengthInMilliseconds());
- CPPUNIT_ASSERT_EQUAL(706, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(355, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());