Added sampleFrames to FLACProperties

This commit is contained in:
Stephen F. Booth 2012-02-04 11:34:40 -05:00
parent fa662a23db
commit 51675f3399
2 changed files with 21 additions and 5 deletions

View File

@ -42,7 +42,8 @@ public:
bitrate(0),
sampleRate(0),
sampleWidth(0),
channels(0) {}
channels(0),
sampleFrames(0) {}
ByteVector data;
long streamLength;
@ -52,6 +53,7 @@ public:
int sampleRate;
int sampleWidth;
int channels;
unsigned long long sampleFrames;
ByteVector signature;
};
@ -101,6 +103,11 @@ int FLAC::Properties::channels() const
return d->channels;
}
unsigned long long FLAC::Properties::sampleFrames() const
{
return d->sampleFrames;
}
ByteVector FLAC::Properties::signature() const
{
return d->signature;
@ -132,6 +139,8 @@ void FLAC::Properties::read()
pos += 3;
uint flags = d->data.mid(pos, 4).toUInt(true);
pos += 4;
d->sampleRate = flags >> 12;
d->channels = ((flags >> 9) & 7) + 1;
d->sampleWidth = ((flags >> 4) & 31) + 1;
@ -139,12 +148,14 @@ void FLAC::Properties::read()
// The last 4 bits are the most significant 4 bits for the 36 bit
// stream length in samples. (Audio files measured in days)
uint highLength =d->sampleRate > 0 ? (((flags & 0xf) << 28) / d->sampleRate) << 4 : 0;
unsigned long long hi = flags & 0xf;
unsigned long long lo = d->data.mid(pos, 4).toUInt(true);
pos += 4;
d->length = d->sampleRate > 0 ?
(d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength : 0;
pos += 4;
d->sampleFrames = (hi << 32) | lo;
if(d->sampleRate > 0)
d->length = int(d->sampleFrames / d->sampleRate);
// Uncompressed bitrate:

View File

@ -77,6 +77,11 @@ namespace TagLib {
*/
int sampleWidth() const;
/*!
* Return the number of sample frames
*/
unsigned long long sampleFrames() const;
/*!
* Returns the MD5 signature of the uncompressed audio stream as read
* from the stream info header header.