1 /***************************************************************************
2 copyright : (C) 2004 by Allan Sandfeld Jensen
3 email : kde@carewolf.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
30 #include "mpcproperties.h"
33 using namespace TagLib;
35 class MPC::Properties::PropertiesPrivate
38 PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
58 ////////////////////////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////////////////////////
62 MPC::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
64 d = new PropertiesPrivate(data, streamLength, style);
68 MPC::Properties::~Properties()
73 int MPC::Properties::length() const
78 int MPC::Properties::bitrate() const
83 int MPC::Properties::sampleRate() const
88 int MPC::Properties::channels() const
93 int MPC::Properties::mpcVersion() const
98 ////////////////////////////////////////////////////////////////////////////////
100 ////////////////////////////////////////////////////////////////////////////////
102 static const unsigned short sftable [4] = { 44100, 48000, 37800, 32000 };
104 void MPC::Properties::read()
106 if(!d->data.startsWith("MP+"))
109 d->version = d->data[3] & 15;
113 if(d->version >= 7) {
114 frames = d->data.mid(4, 4).toUInt(false);
116 std::bitset<32> flags = d->data.mid(8, 4).toUInt(false);
117 d->sampleRate = sftable[flags[17] * 2 + flags[16]];
121 uint headerData = d->data.mid(0, 4).toUInt(false);
123 d->bitrate = (headerData >> 23) & 0x01ff;
124 d->version = (headerData >> 11) & 0x03ff;
125 d->sampleRate = 44100;
129 frames = d->data.mid(4, 4).toUInt(false);
131 frames = d->data.mid(6, 2).toUInt(false);
134 uint samples = frames * 1152 - 576;
136 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;