summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-05-20 20:14:20 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-05-20 20:14:20 (GMT)
commit2e7c9082fd472911e61e265eb184f408b8ac62e4 (patch)
tree48d30c86d6c126eee077847beea8b02b5f15367d
parentdb87996d4ca90f8fffb5a8e012fa7f2336c038b0 (diff)
parentcddc591fc4c6317bca83c081a62b84c15a0644d1 (diff)
downloadQt-2e7c9082fd472911e61e265eb184f408b8ac62e4.zip
Qt-2e7c9082fd472911e61e265eb184f408b8ac62e4.tar.gz
Qt-2e7c9082fd472911e61e265eb184f408b8ac62e4.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging: QAudioDeviceInfo::nearestFormat() consistent across all platforms The documentation for processedUSecs() is ambiguous
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp62
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp11
2 files changed, 71 insertions, 2 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
index 092efc5..ae65b02 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo.cpp
@@ -43,6 +43,7 @@
#include <QtMultimedia/qaudioengine.h>
#include <QtMultimedia/qaudiodeviceinfo.h>
+#include <QtCore/qmap.h>
QT_BEGIN_NAMESPACE
@@ -238,7 +239,66 @@ QAudioFormat QAudioDeviceInfo::preferredFormat() const
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
- return isNull() ? QAudioFormat() : d->info->nearestFormat(settings);
+ if (isFormatSupported(settings))
+ return settings;
+
+ QAudioFormat nearest = settings;
+
+ nearest.setCodec(QLatin1String("audio/pcm"));
+
+ if (nearest.sampleType() == QAudioFormat::Unknown) {
+ QAudioFormat preferred = preferredFormat();
+ nearest.setSampleType(preferred.sampleType());
+ }
+
+ QMap<int,int> testFrequencies;
+ QList<int> frequenciesAvailable = supportedFrequencies();
+ QMap<int,int> testSampleSizes;
+ QList<int> sampleSizesAvailable = supportedSampleSizes();
+
+ // Get sorted sampleSizes (equal to and ascending values only)
+ if (sampleSizesAvailable.contains(settings.sampleSize()))
+ testSampleSizes.insert(0,settings.sampleSize());
+ sampleSizesAvailable.removeAll(settings.sampleSize());
+ foreach (int size, sampleSizesAvailable) {
+ int larger = (size > settings.sampleSize()) ? size : settings.sampleSize();
+ int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
+ if (size >= settings.sampleSize()) {
+ int diff = larger - smaller;
+ testSampleSizes.insert(diff, size);
+ }
+ }
+
+ // Get sorted frequencies (equal to and ascending values only)
+ if (frequenciesAvailable.contains(settings.frequency()))
+ testFrequencies.insert(0,settings.frequency());
+ frequenciesAvailable.removeAll(settings.frequency());
+ foreach (int frequency, frequenciesAvailable) {
+ int larger = (frequency > settings.frequency()) ? frequency : settings.frequency();
+ int smaller = (frequency > settings.frequency()) ? settings.frequency() : frequency;
+ if (frequency >= settings.frequency()) {
+ int diff = larger - smaller;
+ testFrequencies.insert(diff, frequency);
+ }
+ }
+
+ // Try to find nearest
+ // Check ascending frequencies, ascending sampleSizes
+ QMapIterator<int, int> sz(testSampleSizes);
+ while (sz.hasNext()) {
+ sz.next();
+ nearest.setSampleSize(sz.value());
+ QMapIterator<int, int> i(testFrequencies);
+ while (i.hasNext()) {
+ i.next();
+ nearest.setFrequency(i.value());
+ if (isFormatSupported(nearest))
+ return nearest;
+ }
+ }
+
+ //Fallback
+ return preferredFormat();
}
/*!
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index 371773c..cf3b79c 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -369,8 +369,17 @@ int QAudioOutput::notifyInterval() const
}
/*!
- Returns the amount of audio data processed since start()
+ Returns the amount of audio data processed by the class since start()
was called in microseconds.
+
+ Note: The amount of audio data played can be determined by subtracting
+ the microseconds of audio data still in the systems audio buffer.
+
+ \code
+ qint64 bytesInBuffer = bufferSize() - bytesFree();
+ qint64 usInBuffer = (qint64)(1000000) * bytesInBuffer / ( channels() * sampleSize() / 8 ) / frequency();
+ qint64 usPlayed = processedUSecs() - usInBuffer;
+ \endcode
*/
qint64 QAudioOutput::processedUSecs() const