summaryrefslogtreecommitdiffstats
path: root/tests/auto/unit
diff options
context:
space:
mode:
authorMichael Goddard <michael.goddard@nokia.com>2012-07-10 14:26:58 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-11 08:01:45 +0200
commit4d13a15bae0e4ad978e7c455dc26650f6d879862 (patch)
tree196bd714b3bc5ebc355e88d48b220377dfaf9d37 /tests/auto/unit
parent68079a5e220d9ae76ca1ba7a3983dd98dae21634 (diff)
Clarify API/docs by introducing the audio "frame", and add helpers.
The frame is the interleaved set of one sample for each channel. Add some docs and some methods that make working with samples a bit more convenient. Adjusted QAudioBuffer to use these helper functions and terminology. Change-Id: I96db48e659561972d6de2aa19893d29f9a828cd3 Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
Diffstat (limited to 'tests/auto/unit')
-rw-r--r--tests/auto/unit/qaudiobuffer/tst_qaudiobuffer.cpp28
-rw-r--r--tests/auto/unit/qaudioformat/tst_qaudioformat.cpp94
2 files changed, 112 insertions, 10 deletions
diff --git a/tests/auto/unit/qaudiobuffer/tst_qaudiobuffer.cpp b/tests/auto/unit/qaudiobuffer/tst_qaudiobuffer.cpp
index ff403b33b..bf38d8bfa 100644
--- a/tests/auto/unit/qaudiobuffer/tst_qaudiobuffer.cpp
+++ b/tests/auto/unit/qaudiobuffer/tst_qaudiobuffer.cpp
@@ -76,11 +76,11 @@ tst_QAudioBuffer::tst_QAudioBuffer()
mFormat.setSampleSize(16);
mFormat.setSampleType(QAudioFormat::UnSignedInt);
mFormat.setSampleRate(10000);
- mFormat.setCodec("audio/x-pcm"); // XXX this is not a good fit?
+ mFormat.setCodec("audio/pcm");
QByteArray b(4000, 0x80);
mNull = new QAudioBuffer;
- mEmpty = new QAudioBuffer(1000, mFormat); // 1000 samples of 16 bits -> 2KB
+ mEmpty = new QAudioBuffer(500, mFormat); // 500 stereo frames of 16 bits -> 2KB
mFromArray = new QAudioBuffer(b, mFormat);
}
@@ -102,6 +102,7 @@ void tst_QAudioBuffer::ctors()
QCOMPARE(mNull->duration(), 0LL);
QCOMPARE(mNull->byteCount(), 0);
QCOMPARE(mNull->sampleCount(), 0);
+ QCOMPARE(mNull->frameCount(), 0);
QCOMPARE(mNull->startTime(), -1LL);
// Empty buffer
@@ -110,6 +111,7 @@ void tst_QAudioBuffer::ctors()
QVERIFY(mEmpty->data() != 0);
QVERIFY(((const QAudioBuffer*)mEmpty)->data() != 0);
QCOMPARE(mEmpty->sampleCount(), 1000);
+ QCOMPARE(mEmpty->frameCount(), 500);
QCOMPARE(mEmpty->duration(), 50000LL);
QCOMPARE(mEmpty->byteCount(), 2000);
QCOMPARE(mEmpty->startTime(), -1LL);
@@ -123,6 +125,7 @@ void tst_QAudioBuffer::ctors()
QCOMPARE(mFromArray->duration(), 100000LL);
QCOMPARE(mFromArray->byteCount(), 4000);
QCOMPARE(mFromArray->sampleCount(), 2000);
+ QCOMPARE(mFromArray->frameCount(), 1000);
QCOMPARE(mFromArray->startTime(), -1LL);
@@ -135,6 +138,7 @@ void tst_QAudioBuffer::ctors()
QCOMPARE(badFormat.duration(), 0LL);
QCOMPARE(badFormat.byteCount(), 0);
QCOMPARE(badFormat.sampleCount(), 0);
+ QCOMPARE(badFormat.frameCount(), 0);
QCOMPARE(badFormat.startTime(), -1LL);
QAudioBuffer badArray(QByteArray(), mFormat);
@@ -145,6 +149,7 @@ void tst_QAudioBuffer::ctors()
QCOMPARE(badArray.duration(), 0LL);
QCOMPARE(badArray.byteCount(), 0);
QCOMPARE(badArray.sampleCount(), 0);
+ QCOMPARE(badArray.frameCount(), 0);
QCOMPARE(badArray.startTime(), -1LL);
QAudioBuffer badBoth = QAudioBuffer(QByteArray(), QAudioFormat());
@@ -155,12 +160,13 @@ void tst_QAudioBuffer::ctors()
QCOMPARE(badBoth.duration(), 0LL);
QCOMPARE(badBoth.byteCount(), 0);
QCOMPARE(badBoth.sampleCount(), 0);
+ QCOMPARE(badBoth.frameCount(), 0);
QCOMPARE(badBoth.startTime(), -1LL);
}
void tst_QAudioBuffer::assign()
{
- // Needs strong behaviour definition
+ // TODO Needs strong behaviour definition
}
void tst_QAudioBuffer::constData() const
@@ -245,7 +251,8 @@ void tst_QAudioBuffer::durations()
{
QFETCH(int, channelCount);
QFETCH(int, sampleSize);
- QFETCH(int, sampleCount);
+ QFETCH(int, frameCount);
+ int sampleCount = frameCount * channelCount;
QFETCH(QAudioFormat::SampleType, sampleType);
QFETCH(int, sampleRate);
QFETCH(qint64, duration);
@@ -256,10 +263,11 @@ void tst_QAudioBuffer::durations()
f.setSampleType(sampleType);
f.setSampleSize(sampleSize);
f.setSampleRate(sampleRate);
- f.setCodec("audio/x-pcm"); // XXX this is not a good fit?
+ f.setCodec("audio/pcm");
- QAudioBuffer b(sampleCount, f);
+ QAudioBuffer b(frameCount, f);
+ QCOMPARE(b.frameCount(), frameCount);
QCOMPARE(b.sampleCount(), sampleCount);
QCOMPARE(b.duration(), duration);
QCOMPARE(b.byteCount(), byteCount);
@@ -269,7 +277,7 @@ void tst_QAudioBuffer::durations_data()
{
QTest::addColumn<int>("channelCount");
QTest::addColumn<int>("sampleSize");
- QTest::addColumn<int>("sampleCount");
+ QTest::addColumn<int>("frameCount");
QTest::addColumn<QAudioFormat::SampleType>("sampleType");
QTest::addColumn<int>("sampleRate");
QTest::addColumn<qint64>("duration");
@@ -278,11 +286,11 @@ void tst_QAudioBuffer::durations_data()
QTest::newRow("M8_2000_8K") << 1 << 8 << 2000 << QAudioFormat::UnSignedInt << 8000 << 250000LL << 2000;
QTest::newRow("M8_1000_4K") << 1 << 8 << 1000 << QAudioFormat::UnSignedInt << 4000 << 250000LL << 1000;
- QTest::newRow("S8_1000_8K") << 2 << 8 << 1000 << QAudioFormat::UnSignedInt << 8000 << 62500LL << 1000;
+ QTest::newRow("S8_1000_8K") << 2 << 8 << 500 << QAudioFormat::UnSignedInt << 8000 << 62500LL << 1000;
- QTest::newRow("SF_1000_8K") << 2 << 32 << 1000 << QAudioFormat::Float << 8000 << 62500LL << 4000;
+ QTest::newRow("SF_1000_8K") << 2 << 32 << 500 << QAudioFormat::Float << 8000 << 62500LL << 4000;
- QTest::newRow("4x128_1000_16K") << 4 << 128 << 1000 << QAudioFormat::SignedInt << 16000 << 15625LL << 16000;
+ QTest::newRow("4x128_1000_16K") << 4 << 128 << 250 << QAudioFormat::SignedInt << 16000 << 15625LL << 16000;
}
void tst_QAudioBuffer::stereoSample()
diff --git a/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp
index b5bb1a811..7193cb2cc 100644
--- a/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp
+++ b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp
@@ -67,6 +67,9 @@ private slots:
void checkSampleRate();
void checkChannelCount();
+ void checkSizes();
+ void checkSizes_data();
+
void debugOperator();
void debugOperator_data();
};
@@ -222,6 +225,97 @@ void tst_QAudioFormat::checkChannelCount()
QVERIFY(audioFormat.channelCount() == 5);
}
+void tst_QAudioFormat::checkSizes()
+{
+ QFETCH(QAudioFormat, format);
+ QFETCH(int, frameSize);
+ QFETCH(int, byteCount);
+ QFETCH(int, frameCount);
+ QFETCH(qint64, durationForByte);
+ QFETCH(int, byteForFrame);
+ QFETCH(qint64, durationForByteForDuration);
+ QFETCH(int, byteForDuration);
+ QFETCH(int, framesForDuration);
+
+ QCOMPARE(format.bytesPerFrame(), frameSize);
+
+ // Byte input
+ QCOMPARE(format.framesForBytes(byteCount), frameCount);
+ QCOMPARE(format.durationForBytes(byteCount), durationForByte);
+
+ // Framecount input
+ QCOMPARE(format.bytesForFrames(frameCount), byteForFrame);
+ QCOMPARE(format.durationForFrames(frameCount), durationForByte);
+
+ // Duration input
+ QCOMPARE(format.bytesForDuration(durationForByteForDuration), byteForDuration);
+ QCOMPARE(format.framesForDuration(durationForByte), frameCount);
+ QCOMPARE(format.framesForDuration(durationForByteForDuration), framesForDuration);
+}
+
+void tst_QAudioFormat::checkSizes_data()
+{
+ QTest::addColumn<QAudioFormat>("format");
+ QTest::addColumn<int>("frameSize");
+ QTest::addColumn<int>("byteCount");
+ QTest::addColumn<qint64>("durationForByte");
+ QTest::addColumn<int>("frameCount"); // output of sampleCountforByte, input for byteForFrame
+ QTest::addColumn<int>("byteForFrame");
+ QTest::addColumn<qint64>("durationForByteForDuration"); // input for byteForDuration
+ QTest::addColumn<int>("byteForDuration");
+ QTest::addColumn<int>("framesForDuration");
+
+ QAudioFormat f;
+ QTest::newRow("invalid") << f << 0 << 0 << 0LL << 0 << 0 << 0LL << 0 << 0;
+
+ f.setByteOrder(QAudioFormat::LittleEndian);
+ f.setChannelCount(1);
+ f.setSampleRate(8000);
+ f.setCodec("audio/pcm");
+ f.setSampleSize(8);
+ f.setSampleType(QAudioFormat::SignedInt);
+
+ qint64 qrtr = 250000LL;
+ qint64 half = 500000LL;
+ qint64 one = 1000000LL;
+ qint64 two = 2000000LL;
+
+ // No rounding errors with mono 8 bit
+ QTest::newRow("1ch_8b_8k_signed_4000") << f << 1 << 4000 << half << 4000 << 4000 << half << 4000 << 4000;
+ QTest::newRow("1ch_8b_8k_signed_8000") << f << 1 << 8000 << one << 8000 << 8000 << one << 8000 << 8000;
+ QTest::newRow("1ch_8b_8k_signed_16000") << f << 1 << 16000 << two << 16000 << 16000 << two << 16000 << 16000;
+
+ // Mono 16bit
+ f.setSampleSize(16);
+ QTest::newRow("1ch_16b_8k_signed_8000") << f << 2 << 8000 << half << 4000 << 8000 << half << 8000 << 4000;
+ QTest::newRow("1ch_16b_8k_signed_16000") << f << 2 << 16000 << one << 8000 << 16000 << one << 16000 << 8000;
+
+ // Rounding errors
+ QTest::newRow("1ch_16b_8k_signed_8001") << f << 2 << 8001 << half << 4000 << 8000 << half << 8000 << 4000;
+ QTest::newRow("1ch_16b_8k_signed_8000_duration1") << f << 2 << 8000 << half << 4000 << 8000 << half + 1 << 8000 << 4000;
+ QTest::newRow("1ch_16b_8k_signed_8000_duration2") << f << 2 << 8000 << half << 4000 << 8000 << half + 124 << 8000 << 4000;
+ QTest::newRow("1ch_16b_8k_signed_8000_duration3") << f << 2 << 8000 << half << 4000 << 8000 << half + 125 << 8002 << 4001;
+ QTest::newRow("1ch_16b_8k_signed_8000_duration4") << f << 2 << 8000 << half << 4000 << 8000 << half + 126 << 8002 << 4001;
+
+ // Stereo 16 bit
+ f.setChannelCount(2);
+ QTest::newRow("2ch_16b_8k_signed_8000") << f << 4 << 8000 << qrtr << 2000 << 8000 << qrtr << 8000 << 2000;
+ QTest::newRow("2ch_16b_8k_signed_16000") << f << 4 << 16000 << half << 4000 << 16000 << half << 16000 << 4000;
+
+ // More rounding errors
+ // First rounding bytes
+ QTest::newRow("2ch_16b_8k_signed_8001") << f << 4 << 8001 << qrtr << 2000 << 8000 << qrtr << 8000 << 2000;
+ QTest::newRow("2ch_16b_8k_signed_8002") << f << 4 << 8002 << qrtr << 2000 << 8000 << qrtr << 8000 << 2000;
+ QTest::newRow("2ch_16b_8k_signed_8003") << f << 4 << 8003 << qrtr << 2000 << 8000 << qrtr << 8000 << 2000;
+
+ // Then rounding duration
+ // 8khz = 125us per frame
+ QTest::newRow("2ch_16b_8k_signed_8000_duration1") << f << 4 << 8000 << qrtr << 2000 << 8000 << qrtr + 1 << 8000 << 2000;
+ QTest::newRow("2ch_16b_8k_signed_8000_duration2") << f << 4 << 8000 << qrtr << 2000 << 8000 << qrtr + 124 << 8000 << 2000;
+ QTest::newRow("2ch_16b_8k_signed_8000_duration3") << f << 4 << 8000 << qrtr << 2000 << 8000 << qrtr + 125 << 8004 << 2001;
+ QTest::newRow("2ch_16b_8k_signed_8000_duration4") << f << 4 << 8000 << qrtr << 2000 << 8000 << qrtr + 126 << 8004 << 2001;
+}
+
void tst_QAudioFormat::debugOperator_data()
{
QTest::addColumn<QAudioFormat>("format");