void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
{
- ByteVector formatData;
- uint streamLength = 0;
- uint totalSamples = 0;
- 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[ID3v2Index]) {
}
}
}
- else if(readProperties) {
- if(name == "fmt ") {
- if(formatData.isEmpty())
- formatData = chunkData(i);
- else
- debug("RIFF::WAV::File::read() - Duplicate 'fmt ' chunk found.");
- }
- else if(name == "data") {
- if(streamLength == 0)
- streamLength = chunkDataSize(i) + chunkPadding(i);
- else
- debug("RIFF::WAV::File::read() - Duplicate 'data' chunk found.");
- }
- else if(name == "fact") {
- if(totalSamples == 0)
- totalSamples = chunkData(i).toUInt(0, false);
- else
- debug("RIFF::WAV::File::read() - Duplicate 'fact' chunk found.");
- }
- }
}
if(!d->tag[ID3v2Index])
if(!d->tag[InfoIndex])
d->tag.set(InfoIndex, new RIFF::Info::Tag);
- if(!formatData.isEmpty())
- d->properties = new Properties(formatData, streamLength, totalSamples, propertiesStyle);
+ if(readProperties)
+ d->properties = new Properties(this, propertiesStyle);
}
void RIFF::WAV::File::strip(TagTypes tags)
* http://www.mozilla.org/MPL/ *
***************************************************************************/
-#include "wavproperties.h"
-
-#include <tstring.h>
#include <tdebug.h>
-#include <cmath>
-#include <math.h>
+#include "wavfile.h"
+#include "wavproperties.h"
using namespace TagLib;
debug("RIFF::WAV::Properties::Properties() -- This constructor is no longer used.");
}
-RIFF::WAV::Properties::Properties(const ByteVector &data, uint streamLength, ReadStyle style) :
+RIFF::WAV::Properties::Properties(const ByteVector & /*data*/, uint /*streamLength*/, ReadStyle style) :
AudioProperties(style),
d(new PropertiesPrivate())
{
debug("RIFF::WAV::Properties::Properties() -- This constructor is no longer used.");
}
-TagLib::RIFF::WAV::Properties::Properties(const ByteVector &data, uint streamLength, uint totalSamples, ReadStyle style) :
+TagLib::RIFF::WAV::Properties::Properties(File *file, ReadStyle style) :
AudioProperties(style),
d(new PropertiesPrivate())
{
- read(data, streamLength, totalSamples);
+ read(file);
}
RIFF::WAV::Properties::~Properties()
// private members
////////////////////////////////////////////////////////////////////////////////
-void RIFF::WAV::Properties::read(const ByteVector &data, uint streamLength, uint totalSamples)
+void RIFF::WAV::Properties::read(File *file)
{
+ ByteVector data;
+ uint streamLength = 0;
+ uint totalSamples = 0;
+
+ for(uint i = 0; i < file->chunkCount(); ++i) {
+ const ByteVector name = file->chunkName(i);
+ if(name == "fmt ") {
+ if(data.isEmpty())
+ data = file->chunkData(i);
+ else
+ debug("RIFF::WAV::Properties::read() - Duplicate 'fmt ' chunk found.");
+ }
+ else if(name == "data") {
+ if(streamLength == 0)
+ streamLength = file->chunkDataSize(i) + file->chunkPadding(i);
+ else
+ debug("RIFF::WAV::Properties::read() - Duplicate 'data' chunk found.");
+ }
+ else if(name == "fact") {
+ if(totalSamples == 0)
+ totalSamples = file->chunkData(i).toUInt(0, false);
+ else
+ debug("RIFF::WAV::Properties::read() - Duplicate 'fact' chunk found.");
+ }
+ }
+
if(data.size() < 16) {
- debug("RIFF::WAV::Properties::read() - \"fmt \" chunk is too short for WAV.");
+ debug("RIFF::WAV::Properties::read() - 'fmt ' chunk not found or too short.");
+ return;
+ }
+
+ if(streamLength == 0) {
+ debug("RIFF::WAV::Properties::read() - 'data' chunk not found.");
+ return;
+ }
+
+ d->format = data.toShort(0, false);
+ if(d->format != 1 && totalSamples == 0) {
+ debug("RIFF::WAV::Properties::read() - Non-PCM format, but 'fact' chunk not found.");
return;
}
- d->format = data.toShort(0, false);
d->channels = data.toShort(2, false);
d->sampleRate = data.toUInt(4, false);
d->bitsPerSample = data.toShort(14, false);
/*!
* Create an instance of WAV::Properties with the data read from the
- * ByteVector \a data and the length calculated using \a streamLength
- * and \a totalSamples.
- *
- * \note totalSamples can be zero if the file doesn't have a 'fact' chunk.
+ * WAV::File \a file.
*/
- Properties(const ByteVector &data, uint streamLength, uint totalSamples, ReadStyle style);
+ Properties(File *file, ReadStyle style);
/*!
* Destroys this WAV::Properties instance.
* Returns the format ID of the file.
* 0 for unknown, 1 for PCM, 2 for ADPCM, 3 for 32/64-bit IEEE754, and so forth.
*
- * \note For further information, refer to \a mmreg.h in Windows Media SDK.
+ * \note For further information, refer to RFC 2361.
*/
int format() const;
Properties(const Properties &);
Properties &operator=(const Properties &);
- void read(const ByteVector &data, uint streamLength, uint totalSamples);
+ void read(File *file);
class PropertiesPrivate;
PropertiesPrivate *d;