/libtunepimp-0.5.3/plugins/tta/ttaproperties.cpp
C++ | 134 lines | 81 code | 24 blank | 29 comment | 1 complexity | 1ccefb476d8816918afb671b68ebf388 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-2.0, LGPL-2.0
1/***************************************************************************
2 copyright : (C) 2006 by Luká Lalinský
3 email : lalinsky@gmail.com
4
5 copyright : (C) 2004 by Allan Sandfeld Jensen
6 email : kde@carewolf.org
7 (original MPC implementation)
8 ***************************************************************************/
9
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. *
14 * *
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. *
19 * *
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 *
23 * USA *
24 ***************************************************************************/
25
26#include <tstring.h>
27#if 0
28#include <tdebug.h>
29#endif
30#include <bitset>
31
32#include "ttaproperties.h"
33#include "ttafile.h"
34
35using namespace TagLib;
36
37class TTA::Properties::PropertiesPrivate
38{
39public:
40 PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
41 data(d),
42 streamLength(length),
43 style(s),
44 version(0),
45 length(0),
46 bitrate(0),
47 sampleRate(0),
48 channels(0),
49 bitsPerSample(0) {}
50
51 ByteVector data;
52 long streamLength;
53 ReadStyle style;
54 int version;
55 int length;
56 int bitrate;
57 int sampleRate;
58 int channels;
59 int bitsPerSample;
60};
61
62////////////////////////////////////////////////////////////////////////////////
63// public members
64////////////////////////////////////////////////////////////////////////////////
65
66TTA::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
67{
68 d = new PropertiesPrivate(data, streamLength, style);
69 read();
70}
71
72TTA::Properties::~Properties()
73{
74 delete d;
75}
76
77int TTA::Properties::length() const
78{
79 return d->length;
80}
81
82int TTA::Properties::bitrate() const
83{
84 return d->bitrate;
85}
86
87int TTA::Properties::sampleRate() const
88{
89 return d->sampleRate;
90}
91
92int TTA::Properties::bitsPerSample() const
93{
94 return d->bitsPerSample;
95}
96
97int TTA::Properties::channels() const
98{
99 return d->channels;
100}
101
102int TTA::Properties::ttaVersion() const
103{
104 return d->version;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108// private members
109////////////////////////////////////////////////////////////////////////////////
110
111void TTA::Properties::read()
112{
113 if(!d->data.startsWith("TTA"))
114 return;
115
116 int pos = 3;
117
118 d->version = d->data[pos] - '0';
119 pos += 1 + 2;
120
121 d->channels = d->data.mid(pos, 2).toShort(false);
122 pos += 2;
123
124 d->bitsPerSample = d->data.mid(pos, 2).toShort(false);
125 pos += 2;
126
127 d->sampleRate = d->data.mid(pos, 4).toUInt(false);
128 pos += 4;
129
130 unsigned long samples = d->data.mid(pos, 4).toUInt(false);
131 d->length = samples / d->sampleRate;
132
133 d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
134}