mirror of
https://github.com/taglib/taglib.git
synced 2025-07-27 09:24:25 -04:00
Refactored AudioProperties classes in some ways
This commit is contained in:
@ -29,7 +29,6 @@
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "opusproperties.h"
|
||||
@ -41,16 +40,12 @@ using namespace TagLib::Ogg;
|
||||
class Opus::AudioProperties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(File *f, ReadStyle s) :
|
||||
file(f),
|
||||
style(s),
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
inputSampleRate(0),
|
||||
channels(0),
|
||||
opusVersion(0) {}
|
||||
|
||||
File *file;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int inputSampleRate;
|
||||
int channels;
|
||||
@ -61,11 +56,10 @@ public:
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Opus::AudioProperties::AudioProperties(File *file, ReadStyle style)
|
||||
: TagLib::AudioProperties(style)
|
||||
Opus::AudioProperties::AudioProperties(File *file, ReadStyle style) :
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
d = new PropertiesPrivate(file, style);
|
||||
read();
|
||||
read(file);
|
||||
}
|
||||
|
||||
Opus::AudioProperties::~AudioProperties()
|
||||
@ -110,16 +104,16 @@ int Opus::AudioProperties::opusVersion() const
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Opus::AudioProperties::read()
|
||||
void Opus::AudioProperties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
// http://tools.ietf.org/html/draft-terriberry-oggopus-01#section-5.1
|
||||
|
||||
ByteVector data = d->file->packet(0);
|
||||
const ByteVector data = file->packet(0);
|
||||
|
||||
// *Magic Signature*
|
||||
uint pos = 8;
|
||||
size_t pos = 8;
|
||||
|
||||
// *Version* (8 bits, unsigned)
|
||||
d->opusVersion = uchar(data.at(pos));
|
||||
@ -143,12 +137,12 @@ void Opus::AudioProperties::read()
|
||||
// *Channel Mapping Family* (8 bits, unsigned)
|
||||
pos += 1;
|
||||
|
||||
const Ogg::PageHeader *first = d->file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = d->file->lastPageHeader();
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
long long start = first->absoluteGranularPosition();
|
||||
long long end = last->absoluteGranularPosition();
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0)
|
||||
d->length = (int) ((end - start - preSkip) / 48000);
|
||||
|
@ -51,7 +51,7 @@ namespace TagLib {
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Opus::AudioProperties with the data read from
|
||||
* Creates an instance of Opus::AudioProperties with the data read from
|
||||
* the Opus::File \a file.
|
||||
*/
|
||||
AudioProperties(File *file, ReadStyle style = Average);
|
||||
@ -81,10 +81,7 @@ namespace TagLib {
|
||||
int opusVersion() const;
|
||||
|
||||
private:
|
||||
AudioProperties(const AudioProperties &);
|
||||
AudioProperties &operator=(const AudioProperties &);
|
||||
|
||||
void read();
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "speexproperties.h"
|
||||
@ -41,9 +40,7 @@ using namespace TagLib::Ogg;
|
||||
class Speex::AudioProperties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(File *f, ReadStyle s) :
|
||||
file(f),
|
||||
style(s),
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
bitrate(0),
|
||||
sampleRate(0),
|
||||
@ -52,8 +49,6 @@ public:
|
||||
vbr(false),
|
||||
mode(0) {}
|
||||
|
||||
File *file;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int bitrate;
|
||||
int sampleRate;
|
||||
@ -67,11 +62,10 @@ public:
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Speex::AudioProperties::AudioProperties(File *file, ReadStyle style)
|
||||
: TagLib::AudioProperties(style)
|
||||
Speex::AudioProperties::AudioProperties(File *file, ReadStyle style) :
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
d = new PropertiesPrivate(file, style);
|
||||
read();
|
||||
read(file);
|
||||
}
|
||||
|
||||
Speex::AudioProperties::~AudioProperties()
|
||||
@ -108,11 +102,11 @@ int Speex::AudioProperties::speexVersion() const
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Speex::AudioProperties::read()
|
||||
void Speex::AudioProperties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
ByteVector data = d->file->packet(0);
|
||||
const ByteVector data = file->packet(0);
|
||||
|
||||
size_t pos = 28;
|
||||
|
||||
@ -153,12 +147,12 @@ void Speex::AudioProperties::read()
|
||||
// frames_per_packet; /**< Number of frames stored per Ogg packet */
|
||||
// unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
|
||||
|
||||
const Ogg::PageHeader *first = d->file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = d->file->lastPageHeader();
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
long long start = first->absoluteGranularPosition();
|
||||
long long end = last->absoluteGranularPosition();
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0 && d->sampleRate > 0)
|
||||
d->length = (int) ((end - start) / (long long) d->sampleRate);
|
||||
|
@ -51,7 +51,7 @@ namespace TagLib {
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Speex::AudioProperties with the data read from
|
||||
* Creates an instance of Speex::AudioProperties with the data read from
|
||||
* the Speex::File \a file.
|
||||
*/
|
||||
AudioProperties(File *file, ReadStyle style = Average);
|
||||
@ -74,10 +74,7 @@ namespace TagLib {
|
||||
int speexVersion() const;
|
||||
|
||||
private:
|
||||
AudioProperties(const AudioProperties &);
|
||||
AudioProperties &operator=(const AudioProperties &);
|
||||
|
||||
void read();
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
|
@ -36,9 +36,7 @@ using namespace TagLib;
|
||||
class Ogg::Vorbis::AudioProperties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(File *f, ReadStyle s) :
|
||||
file(f),
|
||||
style(s),
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
bitrate(0),
|
||||
sampleRate(0),
|
||||
@ -48,8 +46,6 @@ public:
|
||||
bitrateNominal(0),
|
||||
bitrateMinimum(0) {}
|
||||
|
||||
File *file;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int bitrate;
|
||||
int sampleRate;
|
||||
@ -65,18 +61,17 @@ namespace TagLib {
|
||||
* Vorbis headers can be found with one type ID byte and the string "vorbis" in
|
||||
* an Ogg stream. 0x01 indicates the setup header.
|
||||
*/
|
||||
static const char vorbisSetupHeaderID[] = { 0x01, 'v', 'o', 'r', 'b', 'i', 's', 0 };
|
||||
const char vorbisSetupHeaderID[] = { 0x01, 'v', 'o', 'r', 'b', 'i', 's', 0 };
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::Vorbis::AudioProperties::AudioProperties(File *file, ReadStyle style)
|
||||
: TagLib::AudioProperties(style)
|
||||
Ogg::Vorbis::AudioProperties::AudioProperties(File *file, ReadStyle style) :
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
d = new PropertiesPrivate(file, style);
|
||||
read();
|
||||
read(file);
|
||||
}
|
||||
|
||||
Ogg::Vorbis::AudioProperties::~AudioProperties()
|
||||
@ -137,13 +132,13 @@ String Ogg::Vorbis::AudioProperties::toString() const
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ogg::Vorbis::AudioProperties::read()
|
||||
void Ogg::Vorbis::AudioProperties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
ByteVector data = d->file->packet(0);
|
||||
const ByteVector data = file->packet(0);
|
||||
|
||||
uint pos = 0;
|
||||
size_t pos = 0;
|
||||
|
||||
if(data.mid(pos, 7) != vorbisSetupHeaderID) {
|
||||
debug("Ogg::Vorbis::Properties::read() -- invalid Ogg::Vorbis identification header");
|
||||
@ -175,12 +170,12 @@ void Ogg::Vorbis::AudioProperties::read()
|
||||
// Find the length of the file. See http://wiki.xiph.org/Ogg::VorbisStreamLength/
|
||||
// for my notes on the topic.
|
||||
|
||||
const Ogg::PageHeader *first = d->file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = d->file->lastPageHeader();
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
long long start = first->absoluteGranularPosition();
|
||||
long long end = last->absoluteGranularPosition();
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0 && d->sampleRate > 0)
|
||||
d->length = (int)((end - start) / (long long) d->sampleRate);
|
||||
|
@ -48,7 +48,7 @@ namespace TagLib {
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Vorbis::Properties with the data read from the
|
||||
* Creates an instance of Vorbis::Properties with the data read from the
|
||||
* Vorbis::File \a file.
|
||||
*/
|
||||
AudioProperties(File *file, ReadStyle style = Average);
|
||||
@ -74,26 +74,29 @@ namespace TagLib {
|
||||
/*!
|
||||
* Returns the maximum bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*
|
||||
* \note The value is in bits per second unlike bitrate().
|
||||
*/
|
||||
int bitrateMaximum() const;
|
||||
|
||||
/*!
|
||||
* Returns the nominal bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*
|
||||
* \note The value is in bits per second unlike bitrate().
|
||||
*/
|
||||
int bitrateNominal() const;
|
||||
|
||||
/*!
|
||||
* Returns the minimum bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*
|
||||
* \note The value is in bits per second unlike bitrate().
|
||||
*/
|
||||
int bitrateMinimum() const;
|
||||
|
||||
private:
|
||||
AudioProperties(const AudioProperties &);
|
||||
AudioProperties &operator=(const AudioProperties &);
|
||||
|
||||
void read();
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
|
Reference in New Issue
Block a user