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>
This commit is contained in:
Michael Goddard
2012-02-21 15:19:38 +10:00
committed by Qt by Nokia
parent acbefbf5c6
commit b9e2410a2a
2 changed files with 48 additions and 13 deletions

View File

@@ -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
}
/*!