1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QDebug>
#include <QtMultimedia/qaudioformat.h>
QT_BEGIN_NAMESPACE
class QAudioFormatPrivate : public QSharedData
{
public:
QAudioFormatPrivate()
{
frequency = -1;
channels = -1;
sampleSize = -1;
byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder);
sampleType = QAudioFormat::Unknown;
}
QAudioFormatPrivate(const QAudioFormatPrivate &other):
QSharedData(other),
codec(other.codec),
byteOrder(other.byteOrder),
sampleType(other.sampleType),
frequency(other.frequency),
channels(other.channels),
sampleSize(other.sampleSize)
{
}
QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other)
{
codec = other.codec;
byteOrder = other.byteOrder;
sampleType = other.sampleType;
frequency = other.frequency;
channels = other.channels;
sampleSize = other.sampleSize;
return *this;
}
QString codec;
QAudioFormat::Endian byteOrder;
QAudioFormat::SampleType sampleType;
int frequency;
int channels;
int sampleSize;
};
/*!
\class QAudioFormat
\brief The QAudioFormat class stores audio parameter information.
\inmodule QtMultimedia
\ingroup multimedia
\since 4.6
An audio format specifies how data in an audio stream is arranged,
i.e, how the stream is to be interpreted. The encoding itself is
specified by the codec() used for the stream.
In addition to the encoding, QAudioFormat contains other
parameters that further specify how the audio data is arranged.
These are the frequency, the number of channels, the sample size,
the sample type, and the byte order. The following table describes
these in more detail.
\table
\header
\o Parameter
\o Description
\row
\o Frequency
\o Samples per second of audio data in Hertz.
\row
\o Number of channels
\o The number of audio channels (typically one for mono
or two for stereo)
\row
\o Sample size
\o How much data is stored in each sample (typically 8
or 16)
\row
\o Sample type
\o Numerical representation of sample (typically signed integer,
unsigned integer or float)
\row
\o Byte order
\o Byte ordering of sample (typically little endian, big endian)
\endtable
You can obtain audio formats compatible with the audio device used
through functions in QAudioDeviceInfo. This class also lets you
query available parameter values for a device, so that you can set
the parameters yourself. See the QAudioDeviceInfo class
description for details. You need to know the format of the audio
streams you wish to play. Qt does not set up formats for you.
*/
/*!
Construct a new audio format.
Values are initialized as follows:
\list
\o frequency() = -1
\o channels() = -1
\o sampleSize() = -1
\o byteOrder() = QAudioFormat::Endian(QSysInfo::ByteOrder)
\o sampleType() = QAudioFormat::Unknown
\c codec() = ""
\endlist
*/
QAudioFormat::QAudioFormat():
d(new QAudioFormatPrivate)
{
}
/*!
Construct a new audio format using \a other.
*/
QAudioFormat::QAudioFormat(const QAudioFormat &other):
d(other.d)
{
}
/*!
Destroy this audio format.
*/
QAudioFormat::~QAudioFormat()
{
}
/*!
Assigns \a other to this QAudioFormat implementation.
*/
QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other)
{
d = other.d;
return *this;
}
/*!
Returns true if this QAudioFormat is equal to the \a other
QAudioFormat; otherwise returns false.
All elements of QAudioFormat are used for the comparison.
*/
bool QAudioFormat::operator==(const QAudioFormat &other) const
{
return d->frequency == other.d->frequency &&
d->channels == other.d->channels &&
d->sampleSize == other.d->sampleSize &&
d->byteOrder == other.d->byteOrder &&
d->codec == other.d->codec &&
d->sampleType == other.d->sampleType;
}
/*!
Returns true if this QAudioFormat is not equal to the \a other
QAudioFormat; otherwise returns false.
All elements of QAudioFormat are used for the comparison.
*/
bool QAudioFormat::operator!=(const QAudioFormat& other) const
{
return !(*this == other);
}
/*!
Returns true if all of the parameters are valid.
*/
bool QAudioFormat::isValid() const
{
return d->frequency != -1 && d->channels != -1 && d->sampleSize != -1 &&
d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty();
}
/*!
Sets the frequency to \a frequency.
*/
void QAudioFormat::setFrequency(int frequency)
{
d->frequency = frequency;
}
/*!
Returns the current frequency value.
*/
int QAudioFormat::frequency() const
{
return d->frequency;
}
/*!
Sets the channels to \a channels.
*/
void QAudioFormat::setChannels(int channels)
{
d->channels = channels;
}
/*!
Returns the current channel value.
*/
int QAudioFormat::channels() const
{
return d->channels;
}
/*!
Sets the sampleSize to \a sampleSize.
*/
void QAudioFormat::setSampleSize(int sampleSize)
{
d->sampleSize = sampleSize;
}
/*!
Returns the current sampleSize value.
*/
int QAudioFormat::sampleSize() const
{
return d->sampleSize;
}
/*!
Sets the codec to \a codec.
\sa QAudioDeviceInfo::supportedCodecs()
*/
void QAudioFormat::setCodec(const QString &codec)
{
d->codec = codec;
}
/*!
Returns the current codec value.
\sa QAudioDeviceInfo::supportedCodecs()
*/
QString QAudioFormat::codec() const
{
return d->codec;
}
/*!
Sets the byteOrder to \a byteOrder.
*/
void QAudioFormat::setByteOrder(QAudioFormat::Endian byteOrder)
{
d->byteOrder = byteOrder;
}
/*!
Returns the current byteOrder value.
*/
QAudioFormat::Endian QAudioFormat::byteOrder() const
{
return d->byteOrder;
}
/*!
Sets the sampleType to \a sampleType.
*/
void QAudioFormat::setSampleType(QAudioFormat::SampleType sampleType)
{
d->sampleType = sampleType;
}
/*!
Returns the current SampleType value.
*/
QAudioFormat::SampleType QAudioFormat::sampleType() const
{
return d->sampleType;
}
/*!
\enum QAudioFormat::SampleType
\value Unknown Not Set
\value SignedInt samples are signed integers
\value UnSignedInt samples are unsigned intergers
\value Float samples are floats
*/
/*!
\enum QAudioFormat::Endian
\value BigEndian samples are big endian byte order
\value LittleEndian samples are little endian byte order
*/
QT_END_NAMESPACE
|