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., 51 Franklin Street, Fifth Floor, Boston, *
24
***************************************************************************/
32
#include "wvproperties.h"
35
using namespace TagLib;
37
class WavPack::Properties::PropertiesPrivate
40
PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
62
////////////////////////////////////////////////////////////////////////////////
64
////////////////////////////////////////////////////////////////////////////////
66
WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
68
d = new PropertiesPrivate(data, streamLength, style);
72
WavPack::Properties::~Properties()
77
int WavPack::Properties::length() const
82
int WavPack::Properties::bitrate() const
87
int WavPack::Properties::sampleRate() const
92
int WavPack::Properties::channels() const
97
int WavPack::Properties::version() const
102
int WavPack::Properties::bitsPerSample() const
104
return d->bitsPerSample;
107
////////////////////////////////////////////////////////////////////////////////
109
////////////////////////////////////////////////////////////////////////////////
111
static const unsigned int sample_rates[] = { 6000, 8000, 9600, 11025, 12000,
112
16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
114
#define BYTES_STORED 3
118
#define SHIFT_MASK (0x1fL << SHIFT_LSB)
121
#define SRATE_MASK (0xfL << SRATE_LSB)
123
void WavPack::Properties::read()
125
if(!d->data.startsWith("wvpk"))
128
d->version = d->data.mid(8, 2).toShort(false);
130
unsigned int flags = d->data.mid(24, 4).toUInt(false);
131
d->bitsPerSample = ((flags & BYTES_STORED) + 1) * 8 -
132
((flags & SHIFT_MASK) >> SHIFT_LSB);
133
d->sampleRate = sample_rates[(flags & SRATE_MASK) >> SRATE_LSB];
134
d->channels = (flags & MONO_FLAG) ? 1 : 2;
136
unsigned int samples = d->data.mid(12, 4).toUInt(false);
137
d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
139
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;