1
/***************************************************************************
2
copyright : (C) 2006 by Lukáš Lalinský
3
email : lalinsky@gmail.com
5
copyright : (C) 2002 - 2008 by Scott Wheeler
6
email : wheeler@kde.org
7
(original Vorbis implementation)
8
***************************************************************************/
10
/***************************************************************************
11
* This library is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU Lesser General Public License version *
13
* 2.1 as published by the Free Software Foundation. *
15
* This library is distributed in the hope that it will be useful, but *
16
* WITHOUT ANY WARRANTY; without even the implied warranty of *
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18
* Lesser General Public License for more details. *
20
* You should have received a copy of the GNU Lesser General Public *
21
* License along with this library; if not, write to the Free Software *
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
25
* Alternatively, this file is available under the Mozilla Public *
26
* License Version 1.1. You may obtain a copy of the License at *
27
* http://www.mozilla.org/MPL/ *
28
***************************************************************************/
33
#include <oggpageheader.h>
35
#include "speexproperties.h"
36
#include "speexfile.h"
38
using namespace TagLib;
40
class Speex::Properties::PropertiesPrivate
43
PropertiesPrivate(File *f, ReadStyle s) :
65
////////////////////////////////////////////////////////////////////////////////
67
////////////////////////////////////////////////////////////////////////////////
69
Speex::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
71
d = new PropertiesPrivate(file, style);
75
Speex::Properties::~Properties()
80
int Speex::Properties::length() const
85
int Speex::Properties::bitrate() const
87
return int(float(d->bitrate) / float(1000) + 0.5);
90
int Speex::Properties::sampleRate() const
95
int Speex::Properties::channels() const
100
int Speex::Properties::speexVersion() const
102
return d->speexVersion;
105
////////////////////////////////////////////////////////////////////////////////
107
////////////////////////////////////////////////////////////////////////////////
109
void Speex::Properties::read()
111
// Get the identification header from the Ogg implementation.
113
ByteVector data = d->file->packet(0);
117
// speex_version_id; /**< Version for Speex (for checking compatibility) */
118
d->speexVersion = data.mid(pos, 4).toUInt(false);
121
// header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
124
// rate; /**< Sampling rate used */
125
d->sampleRate = data.mid(pos, 4).toUInt(false);
128
// mode; /**< Mode used (0 for narrowband, 1 for wideband) */
129
d->mode = data.mid(pos, 4).toUInt(false);
132
// mode_bitstream_version; /**< Version ID of the bit-stream */
135
// nb_channels; /**< Number of channels encoded */
136
d->channels = data.mid(pos, 4).toUInt(false);
139
// bitrate; /**< Bit-rate used */
140
d->bitrate = data.mid(pos, 4).toUInt(false);
143
// frame_size; /**< Size of frames */
144
// unsigned int frameSize = data.mid(pos, 4).toUInt(false);
147
// vbr; /**< 1 for a VBR encoding, 0 otherwise */
148
d->vbr = data.mid(pos, 4).toUInt(false) == 1;
151
// frames_per_packet; /**< Number of frames stored per Ogg packet */
152
// unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
154
const Ogg::PageHeader *first = d->file->firstPageHeader();
155
const Ogg::PageHeader *last = d->file->lastPageHeader();
158
long long start = first->absoluteGranularPosition();
159
long long end = last->absoluteGranularPosition();
161
if(start >= 0 && end >= 0 && d->sampleRate > 0)
162
d->length = (int) ((end - start) / (long long) d->sampleRate);
164
debug("Speex::Properties::read() -- Either the PCM values for the start or "
165
"end of this file was incorrect or the sample rate is zero.");
168
debug("Speex::Properties::read() -- Could not find valid first and last Ogg pages.");