104 order, channel, codec, frequency, sample rate, and sample type. A |
103 order, channel, codec, frequency, sample rate, and sample type. A |
105 format is represented by the QAudioFormat class. |
104 format is represented by the QAudioFormat class. |
106 |
105 |
107 The values supported by the the device for each of these |
106 The values supported by the the device for each of these |
108 parameters can be fetched with |
107 parameters can be fetched with |
109 supportedByteOrders(), supportedChannels(), supportedCodecs(), |
108 supportedByteOrders(), supportedChannelCounts(), supportedCodecs(), |
110 supportedFrequencies(), supportedSampleSizes(), and |
109 supportedSampleRates(), supportedSampleSizes(), and |
111 supportedSampleTypes(). The combinations supported are dependent on the platform, |
110 supportedSampleTypes(). The combinations supported are dependent on the platform, |
112 audio plugins installed and the audio device capabilities. If you need a specific format, you can check if |
111 audio plugins installed and the audio device capabilities. If you need a specific format, you can check if |
113 the device supports it with isFormatSupported(), or fetch a |
112 the device supports it with isFormatSupported(), or fetch a |
114 supported format that is as close as possible to the format with |
113 supported format that is as close as possible to the format with |
115 nearestFormat(). For instance: |
114 nearestFormat(). For instance: |
237 They also are dependent on the QAudio::Mode being used. |
236 They also are dependent on the QAudio::Mode being used. |
238 */ |
237 */ |
239 |
238 |
240 QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const |
239 QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const |
241 { |
240 { |
242 if (isFormatSupported(settings)) |
241 return isNull() ? QAudioFormat() : d->info->nearestFormat(settings); |
243 return settings; |
|
244 |
|
245 QAudioFormat nearest = settings; |
|
246 |
|
247 nearest.setCodec(QLatin1String("audio/pcm")); |
|
248 |
|
249 if (nearest.sampleType() == QAudioFormat::Unknown) { |
|
250 QAudioFormat preferred = preferredFormat(); |
|
251 nearest.setSampleType(preferred.sampleType()); |
|
252 } |
|
253 |
|
254 QMap<int,int> testFrequencies; |
|
255 QList<int> frequenciesAvailable = supportedFrequencies(); |
|
256 QMap<int,int> testSampleSizes; |
|
257 QList<int> sampleSizesAvailable = supportedSampleSizes(); |
|
258 |
|
259 // Get sorted sampleSizes (equal to and ascending values only) |
|
260 if (sampleSizesAvailable.contains(settings.sampleSize())) |
|
261 testSampleSizes.insert(0,settings.sampleSize()); |
|
262 sampleSizesAvailable.removeAll(settings.sampleSize()); |
|
263 foreach (int size, sampleSizesAvailable) { |
|
264 int larger = (size > settings.sampleSize()) ? size : settings.sampleSize(); |
|
265 int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size; |
|
266 if (size >= settings.sampleSize()) { |
|
267 int diff = larger - smaller; |
|
268 testSampleSizes.insert(diff, size); |
|
269 } |
|
270 } |
|
271 |
|
272 // Get sorted frequencies (equal to and ascending values only) |
|
273 if (frequenciesAvailable.contains(settings.frequency())) |
|
274 testFrequencies.insert(0,settings.frequency()); |
|
275 frequenciesAvailable.removeAll(settings.frequency()); |
|
276 foreach (int frequency, frequenciesAvailable) { |
|
277 int larger = (frequency > settings.frequency()) ? frequency : settings.frequency(); |
|
278 int smaller = (frequency > settings.frequency()) ? settings.frequency() : frequency; |
|
279 if (frequency >= settings.frequency()) { |
|
280 int diff = larger - smaller; |
|
281 testFrequencies.insert(diff, frequency); |
|
282 } |
|
283 } |
|
284 |
|
285 // Try to find nearest |
|
286 // Check ascending frequencies, ascending sampleSizes |
|
287 QMapIterator<int, int> sz(testSampleSizes); |
|
288 while (sz.hasNext()) { |
|
289 sz.next(); |
|
290 nearest.setSampleSize(sz.value()); |
|
291 QMapIterator<int, int> i(testFrequencies); |
|
292 while (i.hasNext()) { |
|
293 i.next(); |
|
294 nearest.setFrequency(i.value()); |
|
295 if (isFormatSupported(nearest)) |
|
296 return nearest; |
|
297 } |
|
298 } |
|
299 |
|
300 //Fallback |
|
301 return preferredFormat(); |
|
302 } |
242 } |
303 |
243 |
304 /*! |
244 /*! |
305 Returns a list of supported codecs. |
245 Returns a list of supported codecs. |
306 |
246 |
317 { |
257 { |
318 return isNull() ? QStringList() : d->info->codecList(); |
258 return isNull() ? QStringList() : d->info->codecList(); |
319 } |
259 } |
320 |
260 |
321 /*! |
261 /*! |
322 Returns a list of supported frequencies. |
262 Returns a list of supported sample rates. |
|
263 |
|
264 \since 4.7 |
|
265 */ |
|
266 |
|
267 QList<int> QAudioDeviceInfo::supportedSampleRates() const |
|
268 { |
|
269 return supportedFrequencies(); |
|
270 } |
|
271 |
|
272 /*! |
|
273 \obsolete |
|
274 |
|
275 Use supportedSampleRates() instead. |
323 */ |
276 */ |
324 |
277 |
325 QList<int> QAudioDeviceInfo::supportedFrequencies() const |
278 QList<int> QAudioDeviceInfo::supportedFrequencies() const |
326 { |
279 { |
327 return isNull() ? QList<int>() : d->info->frequencyList(); |
280 return isNull() ? QList<int>() : d->info->frequencyList(); |
328 } |
281 } |
329 |
282 |
330 /*! |
283 /*! |
331 Returns a list of supported channels. |
284 Returns a list of supported channel counts. |
|
285 |
|
286 \since 4.7 |
|
287 */ |
|
288 |
|
289 QList<int> QAudioDeviceInfo::supportedChannelCounts() const |
|
290 { |
|
291 return supportedChannels(); |
|
292 } |
|
293 |
|
294 /*! |
|
295 \obsolete |
|
296 |
|
297 Use supportedChannelCount() instead. |
332 */ |
298 */ |
333 |
299 |
334 QList<int> QAudioDeviceInfo::supportedChannels() const |
300 QList<int> QAudioDeviceInfo::supportedChannels() const |
335 { |
301 { |
336 return isNull() ? QList<int>() : d->info->channelsList(); |
302 return isNull() ? QList<int>() : d->info->channelsList(); |