summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Goddard <michael.goddard@nokia.com>2012-02-21 15:19:38 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-21 07:35:23 +0100
commitb9e2410a2a096a825d0f266598ae816620238ff1 (patch)
tree1c1e36cb3a8aced5765de16f3dceae20d8ad7ed0 /src
parentacbefbf5c6ebfe1987f861737687379c65dc9709 (diff)
Fix QAudioBuffer sampleCount vs. channelCount.
There were some inconsistencies in when the sample count was per channel or in total. The docs mention that it is in total, so fix a few cases where it went wrong and test it. Change-Id: I55c855911fcde66a218d6cdd327e09ad5406d5a4 Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com> Reviewed-by: Lev Zelenskiy <lev.zelenskiy@nokia.com> Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/multimedia/audio/qaudiobuffer.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/multimedia/audio/qaudiobuffer.cpp b/src/multimedia/audio/qaudiobuffer.cpp
index 7fa37f81b..fffa66c4a 100644
--- a/src/multimedia/audio/qaudiobuffer.cpp
+++ b/src/multimedia/audio/qaudiobuffer.cpp
@@ -111,7 +111,7 @@ public:
, mSampleCount(sampleCount)
, mFormat(format)
{
- int numBytes = (sampleCount * format.channelCount() * format.sampleSize()) / 8;
+ int numBytes = (sampleCount * format.sampleSize()) / 8;
if (numBytes > 0) {
mBuffer = malloc(numBytes);
if (!mBuffer) {
@@ -245,9 +245,11 @@ QAudioBuffer::QAudioBuffer(const QAudioBuffer &other)
*/
QAudioBuffer::QAudioBuffer(const QByteArray &data, const QAudioFormat &format)
{
- int sampleSize = (format.sampleSize() * format.channelCount()) / 8;
- int sampleCount = data.size() / sampleSize; // truncate
- d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(data.constData(), sampleCount, format, -1));
+ if (format.isValid()) {
+ int sampleCount = (data.size() * 8) / format.sampleSize(); // truncate
+ d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(data.constData(), sampleCount, format, -1));
+ } else
+ d = 0;
}
/*!
@@ -327,7 +329,7 @@ int QAudioBuffer::sampleCount() const
int QAudioBuffer::byteCount() const
{
const QAudioFormat f(format());
- return (f.channelCount() * f.sampleSize() * sampleCount()) / 8; // sampleSize is in bits
+ return (f.sampleSize() * sampleCount()) / 8; // sampleSize is in bits
}
/*!