Added sampleFrames() to audio properties

This commit is contained in:
Stephen F. Booth 2012-04-06 18:30:13 -04:00
parent 2297a6d531
commit 69ac59f5f0
6 changed files with 51 additions and 11 deletions

View File

@ -46,6 +46,7 @@ public:
channels(0),
version(0),
bitsPerSample(0),
sampleFrames(0),
file(file),
streamLength(streamLength) {}
@ -55,6 +56,7 @@ public:
int channels;
int version;
int bitsPerSample;
uint sampleFrames;
File *file;
long streamLength;
};
@ -104,6 +106,11 @@ int APE::Properties::bitsPerSample() const
return d->bitsPerSample;
}
uint APE::Properties::sampleFrames() const
{
return d->sampleFrames;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
@ -192,8 +199,8 @@ void APE::Properties::analyzeCurrent()
uint totalFrames = header.mid(12, 4).toUInt(false);
uint blocksPerFrame = header.mid(4, 4).toUInt(false);
uint finalFrameBlocks = header.mid(8, 4).toUInt(false);
uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = d->sampleRate > 0 ? totalBlocks / d->sampleRate : 0;
d->sampleFrames = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
}

View File

@ -71,6 +71,7 @@ namespace TagLib {
* Returns number of bits per sample.
*/
int bitsPerSample() const;
uint sampleFrames() const;
/*!
* Returns APE version.

View File

@ -43,7 +43,9 @@ public:
length(0),
bitrate(0),
sampleRate(0),
channels(0) {}
channels(0),
totalFrames(0),
sampleFrames(0) {}
ByteVector data;
long streamLength;
@ -53,6 +55,8 @@ public:
int bitrate;
int sampleRate;
int channels;
uint totalFrames;
uint sampleFrames;
};
////////////////////////////////////////////////////////////////////////////////
@ -95,6 +99,16 @@ int MPC::Properties::mpcVersion() const
return d->version;
}
uint MPC::Properties::totalFrames() const
{
return d->totalFrames;
}
uint MPC::Properties::sampleFrames() const
{
return d->sampleFrames;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
@ -108,14 +122,21 @@ void MPC::Properties::read()
d->version = d->data[3] & 15;
unsigned int frames;
if(d->version >= 7) {
frames = d->data.mid(4, 4).toUInt(false);
d->totalFrames = d->data.mid(4, 4).toUInt(false);
std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(d->data.mid(8, 4).toUInt(false)));
d->sampleRate = sftable[flags[17] * 2 + flags[16]];
d->channels = 2;
uint gapless = d->data.mid(5, 4).toUInt(false);
bool trueGapless = (gapless >> 31) & 0x0001;
if(trueGapless) {
uint lastFrameSamples = (gapless >> 20) & 0x07FF;
d->sampleFrames = d->totalFrames * 1152 - lastFrameSamples;
}
else
d->sampleFrames = d->totalFrames * 1152 - 576;
}
else {
uint headerData = d->data.mid(0, 4).toUInt(false);
@ -126,14 +147,14 @@ void MPC::Properties::read()
d->channels = 2;
if(d->version >= 5)
frames = d->data.mid(4, 4).toUInt(false);
d->totalFrames = d->data.mid(4, 4).toUInt(false);
else
frames = d->data.mid(6, 2).toUInt(false);
d->totalFrames = d->data.mid(6, 2).toUInt(false);
d->sampleFrames = d->totalFrames * 1152 - 576;
}
uint samples = frames * 1152 - 576;
d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
d->length = d->sampleRate > 0 ? (d->sampleFrames + (d->sampleRate / 2)) / d->sampleRate : 0;
if(!d->bitrate)
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;

View File

@ -69,6 +69,8 @@ namespace TagLib {
* Returns the version of the bitstream (SV4-SV7)
*/
int mpcVersion() const;
uint totalFrames() const;
uint sampleFrames() const;
private:
Properties(const Properties &);

View File

@ -48,6 +48,7 @@ public:
channels(0),
version(0),
bitsPerSample(0),
sampleFrames(0),
file(0) {}
ByteVector data;
@ -59,6 +60,7 @@ public:
int channels;
int version;
int bitsPerSample;
uint sampleFrames;
File *file;
};
@ -115,6 +117,11 @@ int WavPack::Properties::bitsPerSample() const
return d->bitsPerSample;
}
uint WavPack::Properties::sampleFrames() const
{
return d->sampleFrames;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
@ -161,6 +168,7 @@ void WavPack::Properties::read()
}
}
d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
d->sampleFrames = samples;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
}

View File

@ -82,6 +82,7 @@ namespace TagLib {
* Returns number of bits per sample.
*/
int bitsPerSample() const;
uint sampleFrames() const;
/*!
* Returns WavPack version.