mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Changing the API to something more flexible (And needed for Ogg/FLAC)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@301824 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
9fe8b9ea34
commit
4f1f6adf59
@ -256,7 +256,7 @@ void FLAC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle
|
||||
d->tag = new FLAC::Tag(new Ogg::XiphComment);
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(this, propertiesStyle);
|
||||
d->properties = new Properties(streamInfoData(), streamLength(), propertiesStyle);
|
||||
}
|
||||
|
||||
ByteVector FLAC::File::streamInfoData()
|
||||
|
@ -97,12 +97,6 @@ namespace TagLib {
|
||||
*/
|
||||
void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
|
||||
|
||||
/*!
|
||||
* Returns the block of data used by FLAC::Properties for parsing the
|
||||
* stream properties.
|
||||
*/
|
||||
ByteVector streamInfoData();
|
||||
|
||||
/*!
|
||||
* Returns the length of the audio-stream, used by FLAC::Properties for
|
||||
* calculating the bitrate.
|
||||
@ -117,6 +111,7 @@ namespace TagLib {
|
||||
void scan();
|
||||
long findID3v2();
|
||||
long findID3v1();
|
||||
ByteVector streamInfoData();
|
||||
ByteVector xiphCommentData();
|
||||
|
||||
class FilePrivate;
|
||||
|
@ -30,8 +30,9 @@ using namespace TagLib;
|
||||
class FLAC::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(File *f, ReadStyle s) :
|
||||
file(f),
|
||||
PropertiesPrivate(ByteVector d, long st, ReadStyle s) :
|
||||
data(d),
|
||||
streamLength(st),
|
||||
style(s),
|
||||
length(0),
|
||||
bitrate(0),
|
||||
@ -39,7 +40,8 @@ public:
|
||||
sampleWidth(0),
|
||||
channels(0) {}
|
||||
|
||||
File *file;
|
||||
ByteVector data;
|
||||
long streamLength;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int bitrate;
|
||||
@ -52,9 +54,9 @@ public:
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FLAC::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
|
||||
FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style)
|
||||
{
|
||||
d = new PropertiesPrivate(file, style);
|
||||
d = new PropertiesPrivate(data, streamLength, style);
|
||||
read();
|
||||
}
|
||||
|
||||
@ -94,10 +96,6 @@ int FLAC::Properties::channels() const
|
||||
|
||||
void FLAC::Properties::read()
|
||||
{
|
||||
// Get the identification header.
|
||||
|
||||
ByteVector data = d->file->streamInfoData();
|
||||
|
||||
int pos = 0;
|
||||
|
||||
// Minimum block size (in samples)
|
||||
@ -112,7 +110,7 @@ void FLAC::Properties::read()
|
||||
// Maximum frame size (in bytes)
|
||||
pos += 3;
|
||||
|
||||
uint flags = data.mid(pos, 4).toUInt(true);
|
||||
uint flags = d->data.mid(pos, 4).toUInt(true);
|
||||
d->sampleRate = flags >> 12;
|
||||
d->channels = ((flags >> 9) & 7) + 1;
|
||||
d->sampleWidth = ((flags >> 4) & 31) + 1;
|
||||
@ -123,16 +121,18 @@ void FLAC::Properties::read()
|
||||
uint highlength = (((flags & 0xf) << 28) / d->sampleRate) << 4;
|
||||
pos += 4;
|
||||
|
||||
d->length = (data.mid(pos, 4).toUInt(true)) / d->sampleRate + highlength;
|
||||
d->length = (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highlength;
|
||||
pos += 4;
|
||||
|
||||
// Uncompressed bitrate:
|
||||
|
||||
// d->bitrate = ((d->sampleRate * d->channels) / 1000) * d->sampleWidth;
|
||||
//d->bitrate = ((d->sampleRate * d->channels) / 1000) * d->sampleWidth;
|
||||
|
||||
// Real bitrate:
|
||||
|
||||
d->bitrate = ((d->file->streamLength()*8L) / d->length)/1000;
|
||||
|
||||
if (d->length)
|
||||
d->bitrate = ((d->streamLength*8L) / d->length)/1000;
|
||||
else
|
||||
d->bitrate = 0;
|
||||
|
||||
}
|
||||
|
@ -42,9 +42,10 @@ namespace TagLib {
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of FLAC::Properties with the data read from the
|
||||
* FLAC::File \a file.
|
||||
* ByteVector \a data.
|
||||
* BIC: API changed since last stable release
|
||||
*/
|
||||
Properties(File *file, ReadStyle style = Average);
|
||||
Properties(ByteVector data, long streamLength, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this FLAC::Properties instance.
|
||||
|
Loading…
Reference in New Issue
Block a user