summaryrefslogtreecommitdiff
path: root/tests/auto/integration/qaudioinput
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2021-02-03 15:45:51 +0100
committerLars Knoll <lars.knoll@qt.io>2021-02-09 14:35:19 +0000
commit177dd889e1f1a046c04770e4afe85d29b1476a84 (patch)
treea22652008ff48e57f636ef6b54421b3b3ace89de /tests/auto/integration/qaudioinput
parent0eb4012490601a3d45bd7239e117ae583d71dc97 (diff)
downloadqtmultimedia-177dd889e1f1a046c04770e4afe85d29b1476a84.tar.gz
Unify support for .wav files into one public class
There are several implementations for reading/writing of .wav files across tests and examples. Remove them and use the implementations in the QWaveDecoder class instead. Add writing support for .wav files in this class and make it public for now. Change-Id: I81ad984f30b3b668f92a5a0a56e33289c70fad45 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/integration/qaudioinput')
-rw-r--r--tests/auto/integration/qaudioinput/CMakeLists.txt1
-rw-r--r--tests/auto/integration/qaudioinput/qaudioinput.pro3
-rw-r--r--tests/auto/integration/qaudioinput/tst_qaudioinput.cpp38
-rw-r--r--tests/auto/integration/qaudioinput/wavheader.cpp192
-rw-r--r--tests/auto/integration/qaudioinput/wavheader.h67
5 files changed, 26 insertions, 275 deletions
diff --git a/tests/auto/integration/qaudioinput/CMakeLists.txt b/tests/auto/integration/qaudioinput/CMakeLists.txt
index ed808deb5..6a92dac78 100644
--- a/tests/auto/integration/qaudioinput/CMakeLists.txt
+++ b/tests/auto/integration/qaudioinput/CMakeLists.txt
@@ -7,7 +7,6 @@
qt_add_test(tst_qaudioinput
SOURCES
tst_qaudioinput.cpp
- wavheader.cpp wavheader.h
PUBLIC_LIBRARIES
Qt::Gui
Qt::MultimediaPrivate
diff --git a/tests/auto/integration/qaudioinput/qaudioinput.pro b/tests/auto/integration/qaudioinput/qaudioinput.pro
index 31de98eb0..b2e2cfd7e 100644
--- a/tests/auto/integration/qaudioinput/qaudioinput.pro
+++ b/tests/auto/integration/qaudioinput/qaudioinput.pro
@@ -5,5 +5,4 @@ QT += core multimedia-private testlib
# This is more of a system test
CONFIG += testcase
-HEADERS += wavheader.h
-SOURCES += wavheader.cpp tst_qaudioinput.cpp
+SOURCES += tst_qaudioinput.cpp
diff --git a/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp b/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp
index 300dc9116..bd20468e1 100644
--- a/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp
+++ b/tests/auto/integration/qaudioinput/tst_qaudioinput.cpp
@@ -38,7 +38,7 @@
#include <qaudio.h>
#include <qmediadevicemanager.h>
-#include "wavheader.h"
+#include <qwavedecoder.h>
//TESTED_COMPONENT=src/multimedia
@@ -440,8 +440,9 @@ void tst_QAudioInput::pull()
audioFile->close();
audioFile->open(QIODevice::WriteOnly);
- WavHeader wavHeader(audioFormat);
- QVERIFY(wavHeader.write(*audioFile));
+ QWaveDecoder waveDecoder(audioFile.data(), audioFormat);
+ QVERIFY(waveDecoder.open(QIODevice::WriteOnly));
+ QCOMPARE(waveDecoder.size(), QWaveDecoder::headerLength());
audioInput.start(audioFile.data());
@@ -476,7 +477,9 @@ void tst_QAudioInput::pull()
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
QVERIFY2(notifySignal.count() > 0, "not emitting notify() signal");
- WavHeader::writeDataLength(*audioFile, audioFile->pos() - WavHeader::headerLength());
+ //QWaveHeader::writeDataLength(*audioFile, audioFile->pos() - WavHeader::headerLength());
+ //waveDecoder.writeDataLength();
+ waveDecoder.close();
audioFile->close();
}
@@ -504,8 +507,9 @@ void tst_QAudioInput::pullSuspendResume()
audioFile->close();
audioFile->open(QIODevice::WriteOnly);
- WavHeader wavHeader(audioFormat);
- QVERIFY(wavHeader.write(*audioFile));
+ QWaveDecoder waveDecoder(audioFile.get(), audioFormat);
+ QVERIFY(waveDecoder.open(QIODevice::WriteOnly));
+ QCOMPARE(waveDecoder.size(), QWaveDecoder::headerLength());
audioInput.start(audioFile.data());
@@ -574,7 +578,9 @@ void tst_QAudioInput::pullSuspendResume()
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
QVERIFY2(notifySignal.count() > 0, "not emitting notify() signal");
- WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //waveDecoder.writeDataLength();
+ waveDecoder.close();
audioFile->close();
}
@@ -597,8 +603,9 @@ void tst_QAudioInput::push()
audioFile->close();
audioFile->open(QIODevice::WriteOnly);
- WavHeader wavHeader(audioFormat);
- QVERIFY(wavHeader.write(*audioFile));
+ QWaveDecoder waveDecoder(audioFile.get(), audioFormat);
+ QVERIFY(waveDecoder.open(QIODevice::WriteOnly));
+ QCOMPARE(waveDecoder.size(), QWaveDecoder::headerLength());
// Set a large buffer to avoid underruns during QTest::qWaits
audioInput.setBufferSize(audioFormat.bytesForDuration(1000000));
@@ -654,7 +661,9 @@ void tst_QAudioInput::push()
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
QVERIFY2(notifySignal.count() > 0, "not emitting notify() signal");
- WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //waveDecoder.writeDataLength();
+ waveDecoder.close();
audioFile->close();
}
@@ -681,8 +690,9 @@ void tst_QAudioInput::pushSuspendResume()
audioFile->close();
audioFile->open(QIODevice::WriteOnly);
- WavHeader wavHeader(audioFormat);
- QVERIFY(wavHeader.write(*audioFile));
+ QWaveDecoder waveDecoder(audioFile.get(), audioFormat);
+ QVERIFY(waveDecoder.open(QIODevice::WriteOnly));
+ QCOMPARE(waveDecoder.size(), QWaveDecoder::headerLength());
QIODevice* feed = audioInput.start();
@@ -777,7 +787,9 @@ void tst_QAudioInput::pushSuspendResume()
QString("processedUSecs() doesn't fall in acceptable range, should be 2040000 (%1)").arg(processedUs).toLocal8Bit().constData());
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
- WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
+ //waveDecoder.writeDataLength();
+ waveDecoder.close();
audioFile->close();
}
diff --git a/tests/auto/integration/qaudioinput/wavheader.cpp b/tests/auto/integration/qaudioinput/wavheader.cpp
deleted file mode 100644
index b53bd5f0b..000000000
--- a/tests/auto/integration/qaudioinput/wavheader.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qendian.h>
-#include "wavheader.h"
-
-
-struct chunk
-{
- char id[4];
- quint32 size;
-};
-
-struct RIFFHeader
-{
- chunk descriptor; // "RIFF"
- char type[4]; // "WAVE"
-};
-
-struct WAVEHeader
-{
- chunk descriptor;
- quint16 audioFormat;
- quint16 numChannels;
- quint32 sampleRate;
- quint32 byteRate;
- quint16 blockAlign;
- quint16 bitsPerSample;
-};
-
-struct DATAHeader
-{
- chunk descriptor;
-};
-
-struct CombinedHeader
-{
- RIFFHeader riff;
- WAVEHeader wave;
- DATAHeader data;
-};
-
-static const int HeaderLength = sizeof(CombinedHeader);
-
-
-WavHeader::WavHeader(const QAudioFormat &format, qint64 dataLength)
- : m_format(format)
- , m_dataLength(dataLength)
-{
-
-}
-
-bool WavHeader::read(QIODevice &device)
-{
- bool result = true;
-
- if (!device.isSequential())
- result = device.seek(0);
- // else, assume that current position is the start of the header
-
- if (result) {
- CombinedHeader header;
- result = (device.read(reinterpret_cast<char *>(&header), HeaderLength) == HeaderLength);
- if (result) {
- if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0
- || memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0)
- && memcmp(&header.riff.type, "WAVE", 4) == 0
- && memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0
- && header.wave.audioFormat == 1 // PCM
- ) {
- // ### FIX Big endian handling
-// if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0)
-// m_format.setByteOrder(QAudioFormat::LittleEndian);
-// else
-// m_format.setByteOrder(QAudioFormat::BigEndian);
-
- m_format.setChannelCount(qFromLittleEndian<quint16>(header.wave.numChannels));
- m_format.setSampleRate(qFromLittleEndian<quint32>(header.wave.sampleRate));
-
- switch(header.wave.bitsPerSample) {
- case 8:
- m_format.setSampleFormat(QAudioFormat::UInt8);
- break;
- case 16:
- m_format.setSampleFormat(QAudioFormat::Int16);
- break;
- default:
- result = false;
- }
-
- m_dataLength = device.size() - HeaderLength;
- } else {
- result = false;
- }
- }
- }
-
- return result;
-}
-
-bool WavHeader::write(QIODevice &device)
-{
- CombinedHeader header;
-
- memset(&header, 0, HeaderLength);
-
- // RIFF header
- // ### handle big endian
-// if (m_format.byteOrder() == QAudioFormat::LittleEndian)
- memcpy(header.riff.descriptor.id,"RIFF",4);
-// else
-// memcpy(header.riff.descriptor.id,"RIFX",4);
- qToLittleEndian<quint32>(quint32(m_dataLength + HeaderLength - 8),
- reinterpret_cast<unsigned char*>(&header.riff.descriptor.size));
- memcpy(header.riff.type, "WAVE",4);
-
- // WAVE header
- memcpy(header.wave.descriptor.id,"fmt ",4);
- qToLittleEndian<quint32>(quint32(16),
- reinterpret_cast<unsigned char*>(&header.wave.descriptor.size));
- qToLittleEndian<quint16>(quint16(1),
- reinterpret_cast<unsigned char*>(&header.wave.audioFormat));
- qToLittleEndian<quint16>(quint16(m_format.channelCount()),
- reinterpret_cast<unsigned char*>(&header.wave.numChannels));
- qToLittleEndian<quint32>(quint32(m_format.sampleRate()),
- reinterpret_cast<unsigned char*>(&header.wave.sampleRate));
- qToLittleEndian<quint32>(quint32(m_format.sampleRate() * m_format.bytesPerFrame()),
- reinterpret_cast<unsigned char*>(&header.wave.byteRate));
- qToLittleEndian<quint16>(quint16(m_format.bytesPerFrame()),
- reinterpret_cast<unsigned char*>(&header.wave.blockAlign));
- qToLittleEndian<quint16>(quint16(m_format.bytesPerSample() * 8),
- reinterpret_cast<unsigned char*>(&header.wave.bitsPerSample));
-
- // DATA header
- memcpy(header.data.descriptor.id,"data",4);
- qToLittleEndian<quint32>(quint32(m_dataLength),
- reinterpret_cast<unsigned char*>(&header.data.descriptor.size));
-
- return (device.write(reinterpret_cast<const char *>(&header), HeaderLength) == HeaderLength);
-}
-
-const QAudioFormat& WavHeader::format() const
-{
- return m_format;
-}
-
-qint64 WavHeader::dataLength() const
-{
- return m_dataLength;
-}
-
-qint64 WavHeader::headerLength()
-{
- return HeaderLength;
-}
-
-bool WavHeader::writeDataLength(QIODevice &device, qint64 dataLength)
-{
- bool result = false;
- if (!device.isSequential()) {
- device.seek(40);
- unsigned char dataLengthLE[4];
- qToLittleEndian<quint32>(quint32(dataLength), dataLengthLE);
- result = (device.write(reinterpret_cast<const char *>(dataLengthLE), 4) == 4);
- }
- return result;
-}
diff --git a/tests/auto/integration/qaudioinput/wavheader.h b/tests/auto/integration/qaudioinput/wavheader.h
deleted file mode 100644
index b9595cffc..000000000
--- a/tests/auto/integration/qaudioinput/wavheader.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-
-#ifndef WAVHEADER_H
-#define WAVHEADER_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qfile.h>
-#include <qaudioformat.h>
-
-/**
- * Helper class for parsing WAV file headers.
- *
- * See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
- */
-class WavHeader
-{
-public:
- WavHeader(const QAudioFormat &format = QAudioFormat(),
- qint64 dataLength = 0);
-
- // Reads WAV header and seeks to start of data
- bool read(QIODevice &device);
-
- // Writes WAV header
- bool write(QIODevice &device);
-
- const QAudioFormat& format() const;
- qint64 dataLength() const;
-
- static qint64 headerLength();
-
- static bool writeDataLength(QIODevice &device, qint64 dataLength);
-
-private:
- QAudioFormat m_format;
- qint64 m_dataLength;
-};
-
-#endif
-