diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 05:50:01 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 05:50:01 (GMT) |
commit | 497e692b0d527181a6f6b580da9972a0b32c501f (patch) | |
tree | 973e9db0eb1f17032abe094464488fd89b4d7253 | |
parent | 06e41bbae1b6ab7fa9ed4fdec1b0c8cc1817bf30 (diff) | |
parent | 3464049590db1c8198fcee7d369690a7c18756cc (diff) | |
download | Qt-497e692b0d527181a6f6b580da9972a0b32c501f.zip Qt-497e692b0d527181a6f6b580da9972a0b32c501f.tar.gz Qt-497e692b0d527181a6f6b580da9972a0b32c501f.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.cpp | 62 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput.cpp | 11 |
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 |