diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-20 12:15:00 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-20 12:15:00 (GMT) |
commit | 8dd178b5143c31cecb4225f33447f6a88ae45a21 (patch) | |
tree | efba3a2d9f443feb485f4983fc58fafd04fd37be | |
parent | 15f1eb3ad010dbfd0941ae32d657d4ddcc07b24e (diff) | |
parent | 497e692b0d527181a6f6b580da9972a0b32c501f (diff) | |
download | Qt-8dd178b5143c31cecb4225f33447f6a88ae45a21.zip Qt-8dd178b5143c31cecb4225f33447f6a88ae45a21.tar.gz Qt-8dd178b5143c31cecb4225f33447f6a88ae45a21.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 |