Added reading of WAV audio length

BUG:116033


git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1148614 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský
2010-07-11 09:47:58 +00:00
parent 49631a3013
commit 1d10bde500
9 changed files with 48 additions and 11 deletions

View File

@ -79,6 +79,11 @@ TagLib::uint RIFF::File::chunkCount() const
return d->chunkNames.size();
}
TagLib::uint RIFF::File::chunkDataSize(uint i) const
{
return d->chunkSizes[i];
}
TagLib::uint RIFF::File::chunkOffset(uint i) const
{
return d->chunkOffsets[i];

View File

@ -67,6 +67,11 @@ namespace TagLib {
*/
uint chunkOffset(uint i) const;
/*!
* \return The size of the chunk data.
*/
uint chunkDataSize(uint i) const;
/*!
* \return The name of the specified chunk, for instance, "COMM" or "ID3 "
*/

View File

@ -96,13 +96,20 @@ bool RIFF::WAV::File::save()
void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
{
ByteVector formatData;
uint streamLength = 0;
for(uint i = 0; i < chunkCount(); i++) {
if(chunkName(i) == "ID3 ")
d->tag = new ID3v2::Tag(this, chunkOffset(i));
else if(chunkName(i) == "fmt " && readProperties)
d->properties = new Properties(chunkData(i), propertiesStyle);
formatData = chunkData(i);
else if(chunkName(i) == "data" && readProperties)
streamLength = chunkDataSize(i);
}
if(!formatData.isEmpty())
d->properties = new Properties(formatData, streamLength, propertiesStyle);
if(!d->tag)
d->tag = new ID3v2::Tag;
}

View File

@ -35,12 +35,13 @@ using namespace TagLib;
class RIFF::WAV::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
PropertiesPrivate(uint streamLength = 0) :
format(0),
length(0),
bitrate(0),
sampleRate(0),
channels(0)
channels(0),
streamLength(streamLength)
{
}
@ -50,6 +51,7 @@ public:
int bitrate;
int sampleRate;
int channels;
uint streamLength;
};
////////////////////////////////////////////////////////////////////////////////
@ -58,7 +60,13 @@ public:
RIFF::WAV::Properties::Properties(const ByteVector &data, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate;
d = new PropertiesPrivate();
read(data);
}
RIFF::WAV::Properties::Properties(const ByteVector &data, uint streamLength, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate(streamLength);
read(data);
}
@ -93,12 +101,12 @@ int RIFF::WAV::Properties::channels() const
void RIFF::WAV::Properties::read(const ByteVector &data)
{
d->format = data.mid(0, 2).toShort(false);
d->channels = data.mid(2, 2).toShort(false);
d->format = data.mid(0, 2).toShort(false);
d->channels = data.mid(2, 2).toShort(false);
d->sampleRate = data.mid(4, 4).toUInt(false);
d->bitrate = data.mid(8, 4).toUInt(false) * 8 / 1024;
// short bitsPerSample = data.mid(10, 2).toShort();
// d->bitrate = (sampleRate * sampleSize * d->channels) / 1024.0;
// d->length = sampleFrames / d->sampleRate;
uint byteRate = data.mid(8, 4).toUInt(false);
d->bitrate = byteRate * 8 / 1024;
d->length = byteRate > 0 ? d->streamLength / byteRate : 0;
}

View File

@ -26,6 +26,7 @@
#ifndef TAGLIB_WAVPROPERTIES_H
#define TAGLIB_WAVPROPERTIES_H
#include "taglib.h"
#include "audioproperties.h"
namespace TagLib {
@ -54,6 +55,12 @@ namespace TagLib {
*/
Properties(const ByteVector &data, ReadStyle style);
/*!
* Create an instance of WAV::Properties with the data read from the
* ByteVector \a data and the length calculated using \a streamLength.
*/
Properties(const ByteVector &data, uint streamLength, ReadStyle style);
/*!
* Destroys this WAV::Properties instance.
*/