1 /***************************************************************************
2 copyright : (C) 2006 by Lukáš Lalinský
3 email : lalinsky@gmail.com
5 copyright : (C) 2004 by Allan Sandfeld Jensen
6 email : kde@carewolf.org
7 (original MPC 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 ***************************************************************************/
34 #include "wavpackproperties.h"
35 #include "wavpackfile.h"
37 using namespace TagLib;
39 class WavPack::Properties::PropertiesPrivate
42 PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
64 ////////////////////////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////////////////////////
68 WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
70 d = new PropertiesPrivate(data, streamLength, style);
74 WavPack::Properties::~Properties()
79 int WavPack::Properties::length() const
84 int WavPack::Properties::bitrate() const
89 int WavPack::Properties::sampleRate() const
94 int WavPack::Properties::channels() const
99 int WavPack::Properties::version() const
104 int WavPack::Properties::bitsPerSample() const
106 return d->bitsPerSample;
109 ////////////////////////////////////////////////////////////////////////////////
111 ////////////////////////////////////////////////////////////////////////////////
113 static const unsigned int sample_rates[] = { 6000, 8000, 9600, 11025, 12000,
114 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
116 #define BYTES_STORED 3
120 #define SHIFT_MASK (0x1fL << SHIFT_LSB)
123 #define SRATE_MASK (0xfL << SRATE_LSB)
125 void WavPack::Properties::read()
127 if(!d->data.startsWith("wvpk"))
130 d->version = d->data.mid(8, 2).toShort(false);
132 unsigned int flags = d->data.mid(24, 4).toUInt(false);
133 d->bitsPerSample = ((flags & BYTES_STORED) + 1) * 8 -
134 ((flags & SHIFT_MASK) >> SHIFT_LSB);
135 d->sampleRate = sample_rates[(flags & SRATE_MASK) >> SRATE_LSB];
136 d->channels = (flags & MONO_FLAG) ? 1 : 2;
138 unsigned int samples = d->data.mid(12, 4).toUInt(false);
139 d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
141 d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;