~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to kid3/taglibext/wavpack/wvproperties.cpp

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston,            *
23
 
 *   MA  02110-1301  USA                                                   *
24
 
 ***************************************************************************/
25
 
 
26
 
#include <tstring.h>
27
 
#if 0
28
 
#include <tdebug.h>
29
 
#endif
30
 
#include <bitset>
31
 
 
32
 
#include "wvproperties.h"
33
 
#include "wvfile.h"
34
 
 
35
 
using namespace TagLib;
36
 
 
37
 
class WavPack::Properties::PropertiesPrivate
38
 
{
39
 
public:
40
 
  PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
41
 
    data(d),
42
 
    streamLength(length), 
43
 
    style(s),
44
 
    length(0),
45
 
    bitrate(0),
46
 
    sampleRate(0),
47
 
    channels(0),
48
 
    version(0),
49
 
    bitsPerSample(0) {}
50
 
 
51
 
  ByteVector data;
52
 
  long streamLength; 
53
 
  ReadStyle style;
54
 
  int length;
55
 
  int bitrate;
56
 
  int sampleRate;
57
 
  int channels;
58
 
  int version;
59
 
  int bitsPerSample;
60
 
};
61
 
 
62
 
////////////////////////////////////////////////////////////////////////////////
63
 
// public members
64
 
////////////////////////////////////////////////////////////////////////////////
65
 
 
66
 
WavPack::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
67
 
{
68
 
  d = new PropertiesPrivate(data, streamLength, style);
69
 
  read();
70
 
}
71
 
 
72
 
WavPack::Properties::~Properties()
73
 
{
74
 
  delete d;
75
 
}
76
 
 
77
 
int WavPack::Properties::length() const
78
 
{
79
 
  return d->length;
80
 
}
81
 
 
82
 
int WavPack::Properties::bitrate() const
83
 
{
84
 
  return d->bitrate;
85
 
}
86
 
 
87
 
int WavPack::Properties::sampleRate() const
88
 
{
89
 
  return d->sampleRate;
90
 
}
91
 
 
92
 
int WavPack::Properties::channels() const
93
 
{
94
 
  return d->channels;
95
 
}
96
 
 
97
 
int WavPack::Properties::version() const
98
 
{
99
 
  return d->version;
100
 
}
101
 
 
102
 
int WavPack::Properties::bitsPerSample() const
103
 
{
104
 
  return d->bitsPerSample;
105
 
}
106
 
 
107
 
////////////////////////////////////////////////////////////////////////////////
108
 
// private members
109
 
////////////////////////////////////////////////////////////////////////////////
110
 
 
111
 
static const unsigned int sample_rates[] = { 6000, 8000, 9600, 11025, 12000,
112
 
    16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 };
113
 
 
114
 
#define BYTES_STORED    3
115
 
#define MONO_FLAG       4
116
 
    
117
 
#define SHIFT_LSB       13
118
 
#define SHIFT_MASK      (0x1fL << SHIFT_LSB)
119
 
 
120
 
#define SRATE_LSB       23
121
 
#define SRATE_MASK      (0xfL << SRATE_LSB)
122
 
    
123
 
void WavPack::Properties::read()
124
 
{
125
 
  if(!d->data.startsWith("wvpk"))
126
 
    return;
127
 
 
128
 
  d->version = d->data.mid(8, 2).toShort(false);
129
 
  
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;
135
 
  
136
 
  unsigned int samples = d->data.mid(12, 4).toUInt(false);
137
 
  d->length = d->sampleRate > 0 ? (samples + (d->sampleRate / 2)) / d->sampleRate : 0;
138
 
  
139
 
  d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
140
 
}
141