summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-05-20 16:24:26 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-05-20 16:24:26 (GMT)
commitcddc591fc4c6317bca83c081a62b84c15a0644d1 (patch)
treec691310c1e78cc4a101c130860a32c9c33d4c6d6
parent1108a20ee3e4190d58dce1efe0a0bf0b3f88491d (diff)
parent8dd178b5143c31cecb4225f33447f6a88ae45a21 (diff)
downloadQt-cddc591fc4c6317bca83c081a62b84c15a0644d1.zip
Qt-cddc591fc4c6317bca83c081a62b84c15a0644d1.tar.gz
Qt-cddc591fc4c6317bca83c081a62b84c15a0644d1.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