mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
WAV: Move property parsing code to Properties.
Make use of 'fact' chunk to get the number of total samples.
This commit is contained in:
parent
ed25204d75
commit
9c8e36d3be
@ -191,10 +191,7 @@ bool RIFF::WAV::File::hasInfoTag() const
|
||||
|
||||
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]) {
|
||||
@ -218,26 +215,6 @@ void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle properties
|
||||
}
|
||||
}
|
||||
}
|
||||
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])
|
||||
@ -246,8 +223,8 @@ void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle properties
|
||||
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)
|
||||
|
@ -179,6 +179,8 @@ namespace TagLib {
|
||||
*/
|
||||
uint findInfoTagChunk();
|
||||
|
||||
friend class Properties;
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
|
@ -23,12 +23,9 @@
|
||||
* 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;
|
||||
|
||||
@ -64,18 +61,18 @@ RIFF::WAV::Properties::Properties(const ByteVector & /*data*/, ReadStyle style)
|
||||
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()
|
||||
@ -137,14 +134,50 @@ int RIFF::WAV::Properties::format() const
|
||||
// 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);
|
||||
|
@ -67,12 +67,9 @@ namespace TagLib {
|
||||
|
||||
/*!
|
||||
* 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.
|
||||
@ -144,7 +141,7 @@ namespace TagLib {
|
||||
* 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;
|
||||
|
||||
@ -152,7 +149,7 @@ namespace TagLib {
|
||||
Properties(const Properties &);
|
||||
Properties &operator=(const Properties &);
|
||||
|
||||
void read(const ByteVector &data, uint streamLength, uint totalSamples);
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
|
Loading…
Reference in New Issue
Block a user