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;
39 using namespace TagLib::Ogg;
41 class Speex::Properties::PropertiesPrivate
44 PropertiesPrivate(File *f, ReadStyle s) :
66 ////////////////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////////////////
70 Speex::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
72 d = new PropertiesPrivate(file, style);
76 Speex::Properties::~Properties()
81 int Speex::Properties::length() const
86 int Speex::Properties::bitrate() const
88 return int(float(d->bitrate) / float(1000) + 0.5);
91 int Speex::Properties::sampleRate() const
96 int Speex::Properties::channels() const
101 int Speex::Properties::speexVersion() const
103 return d->speexVersion;
106 ////////////////////////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////////////////////////
110 void Speex::Properties::read()
112 // Get the identification header from the Ogg implementation.
114 ByteVector data = d->file->packet(0);
118 // speex_version_id; /**< Version for Speex (for checking compatibility) */
119 d->speexVersion = data.mid(pos, 4).toUInt(false);
122 // header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
125 // rate; /**< Sampling rate used */
126 d->sampleRate = data.mid(pos, 4).toUInt(false);
129 // mode; /**< Mode used (0 for narrowband, 1 for wideband) */
130 d->mode = data.mid(pos, 4).toUInt(false);
133 // mode_bitstream_version; /**< Version ID of the bit-stream */
136 // nb_channels; /**< Number of channels encoded */
137 d->channels = data.mid(pos, 4).toUInt(false);
140 // bitrate; /**< Bit-rate used */
141 d->bitrate = data.mid(pos, 4).toUInt(false);
144 // frame_size; /**< Size of frames */
145 // unsigned int frameSize = data.mid(pos, 4).toUInt(false);
148 // vbr; /**< 1 for a VBR encoding, 0 otherwise */
149 d->vbr = data.mid(pos, 4).toUInt(false) == 1;
152 // frames_per_packet; /**< Number of frames stored per Ogg packet */
153 // unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
155 const Ogg::PageHeader *first = d->file->firstPageHeader();
156 const Ogg::PageHeader *last = d->file->lastPageHeader();
159 long long start = first->absoluteGranularPosition();
160 long long end = last->absoluteGranularPosition();
162 if(start >= 0 && end >= 0 && d->sampleRate > 0)
163 d->length = (int) ((end - start) / (long long) d->sampleRate);
165 debug("Speex::Properties::read() -- Either the PCM values for the start or "
166 "end of this file was incorrect or the sample rate is zero.");
169 debug("Speex::Properties::read() -- Could not find valid first and last Ogg pages.");