1
/***************************************************************************
2
copyright : (C) 2003 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
***************************************************************************/
29
#include "flacproperties.h"
32
using namespace TagLib;
34
class FLAC::Properties::PropertiesPrivate
37
PropertiesPrivate(ByteVector d, long st, ReadStyle s) :
57
////////////////////////////////////////////////////////////////////////////////
59
////////////////////////////////////////////////////////////////////////////////
61
FLAC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style)
63
d = new PropertiesPrivate(data, streamLength, style);
67
FLAC::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
69
d = new PropertiesPrivate(file->streamInfoData(), file->streamLength(), style);
73
FLAC::Properties::~Properties()
78
int FLAC::Properties::length() const
83
int FLAC::Properties::bitrate() const
88
int FLAC::Properties::sampleRate() const
93
int FLAC::Properties::sampleWidth() const
95
return d->sampleWidth;
98
int FLAC::Properties::channels() const
103
////////////////////////////////////////////////////////////////////////////////
105
////////////////////////////////////////////////////////////////////////////////
107
void FLAC::Properties::read()
109
if(d->data.size() < 18) {
110
debug("FLAC::Properties::read() - FLAC properties must contain at least 18 bytes.");
116
// Minimum block size (in samples)
119
// Maximum block size (in samples)
122
// Minimum frame size (in bytes)
125
// Maximum frame size (in bytes)
128
uint flags = d->data.mid(pos, 4).toUInt(true);
129
d->sampleRate = flags >> 12;
130
d->channels = ((flags >> 9) & 7) + 1;
131
d->sampleWidth = ((flags >> 4) & 31) + 1;
133
// The last 4 bits are the most significant 4 bits for the 36 bit
134
// stream length in samples. (Audio files measured in days)
136
uint highLength =d->sampleRate > 0 ? (((flags & 0xf) << 28) / d->sampleRate) << 4 : 0;
139
d->length = d->sampleRate > 0 ?
140
(d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength : 0;
143
// Uncompressed bitrate:
145
//d->bitrate = ((d->sampleRate * d->channels) / 1000) * d->sampleWidth;
149
d->bitrate = d->length > 0 ? ((d->streamLength * 8UL) / d->length) / 1000 : 0;