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