mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Meh, why not go ahead and expose this. Add a method to get the samples per frame.
FEATURE:130755 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@769207 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
72316ef1e7
commit
b87c8f042b
@ -46,7 +46,8 @@ public:
|
||||
channelMode(Stereo),
|
||||
isCopyrighted(false),
|
||||
isOriginal(false),
|
||||
frameLength(0) {}
|
||||
frameLength(0),
|
||||
samplesPerFrame(0) {}
|
||||
|
||||
bool isValid;
|
||||
Version version;
|
||||
@ -59,6 +60,7 @@ public:
|
||||
bool isCopyrighted;
|
||||
bool isOriginal;
|
||||
int frameLength;
|
||||
int samplesPerFrame;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -137,6 +139,11 @@ int MPEG::Header::frameLength() const
|
||||
return d->frameLength;
|
||||
}
|
||||
|
||||
int MPEG::Header::samplesPerFrame() const
|
||||
{
|
||||
return d->samplesPerFrame;
|
||||
}
|
||||
|
||||
MPEG::Header &MPEG::Header::operator=(const Header &h)
|
||||
{
|
||||
if(&h == this)
|
||||
@ -252,6 +259,17 @@ void MPEG::Header::parse(const ByteVector &data)
|
||||
else
|
||||
d->frameLength = 72000 * d->bitrate / d->sampleRate + int(d->isPadded);
|
||||
|
||||
// Samples per frame
|
||||
|
||||
static const int samplesPerFrame[3][2] = {
|
||||
// MPEG1, 2/2.5
|
||||
{ 384, 384 }, // Layer I
|
||||
{ 1152, 1152 }, // Layer II
|
||||
{ 1152, 576 } // Layer III
|
||||
};
|
||||
|
||||
d->samplesPerFrame = samplesPerFrame[layerIndex][versionIndex];
|
||||
|
||||
// Now that we're done parsing, set this to be a valid frame.
|
||||
|
||||
d->isValid = true;
|
||||
|
@ -144,6 +144,11 @@ namespace TagLib {
|
||||
*/
|
||||
int frameLength() const;
|
||||
|
||||
/*!
|
||||
* Returns the number of frames per sample.
|
||||
*/
|
||||
int samplesPerFrame() const;
|
||||
|
||||
/*!
|
||||
* Makes a shallow copy of the header.
|
||||
*/
|
||||
|
@ -215,17 +215,9 @@ void MPEG::Properties::read()
|
||||
firstHeader.sampleRate() > 0 &&
|
||||
d->xingHeader->totalFrames() > 0)
|
||||
{
|
||||
static const int blockSize[2][4] = {
|
||||
// Version 1
|
||||
{ 0, 384, 1152, 1152 },
|
||||
// Version 2 or 2.5
|
||||
{ 0, 384, 1152, 576 }
|
||||
};
|
||||
|
||||
int versionIndex = firstHeader.version() == Header::Version1 ? 0 : 1;
|
||||
double timePerFrame =
|
||||
double(blockSize[versionIndex][firstHeader.layer()]) /
|
||||
firstHeader.sampleRate();
|
||||
double(firstHeader.samplesPerFrame()) / firstHeader.sampleRate();
|
||||
|
||||
d->length = int(timePerFrame * d->xingHeader->totalFrames());
|
||||
d->bitrate = d->length > 0 ? d->xingHeader->totalSize() * 8 / d->length / 1000 : 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user