Delete obsolete class methods and update related code
Delete obsolete methods from QAudioFormat and QAudioDeviceInfo and update code that relied on the obsolete methods. Change-Id: I007e36375a45399b1d5a289341bc5d5a05dc68cc Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
952bd004be
commit
53fdcca366
@@ -76,8 +76,8 @@ void AudioInputExample::setup()
|
||||
|
||||
QAudioFormat format;
|
||||
// set up the format you want, eg.
|
||||
format.setFrequency(8000);
|
||||
format.setChannels(1);
|
||||
format.setSampleRate(8000);
|
||||
format.setChannelCount(1);
|
||||
format.setSampleSize(8);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -155,8 +155,8 @@ void AudioOutputExample::setup()
|
||||
|
||||
QAudioFormat format;
|
||||
// Set up the format, eg.
|
||||
format.setFrequency(8000);
|
||||
format.setChannels(1);
|
||||
format.setSampleRate(8000);
|
||||
format.setChannelCount(1);
|
||||
format.setSampleSize(8);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -203,7 +203,7 @@ void AudioDeviceInfo()
|
||||
{
|
||||
//! [Setting audio format]
|
||||
QAudioFormat format;
|
||||
format.setFrequency(44100);
|
||||
format.setSampleRate(44100);
|
||||
// ... other format parameters
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ AudioDecoder::AudioDecoder(bool isPlayback, bool isDelete)
|
||||
// Make sure the data we receive is in correct PCM format.
|
||||
// Our wav file writer only supports SignedInt sample type.
|
||||
QAudioFormat format;
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
format.setSampleSize(16);
|
||||
format.setFrequency(48000);
|
||||
format.setSampleRate(48000);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
m_decoder.setAudioFormat(format);
|
||||
|
||||
@@ -152,10 +152,10 @@ bool WaveFileWriter::writeHeader(const QAudioFormat& format)
|
||||
memcpy(header.wave.descriptor.id, "fmt ", 4);
|
||||
header.wave.descriptor.size = quint32(16);
|
||||
header.wave.audioFormat = quint16(1);
|
||||
header.wave.numChannels = quint16(format.channels());
|
||||
header.wave.numChannels = quint16(format.channelCount());
|
||||
header.wave.sampleRate = quint32(format.sampleRate());
|
||||
header.wave.byteRate = quint32(format.sampleRate() * format.channels() * format.sampleSize() / 8);
|
||||
header.wave.blockAlign = quint16(format.channels() * format.sampleSize() / 8);
|
||||
header.wave.byteRate = quint32(format.sampleRate() * format.channelCount() * format.sampleSize() / 8);
|
||||
header.wave.blockAlign = quint16(format.channelCount() * format.sampleSize() / 8);
|
||||
header.wave.bitsPerSample = quint16(format.sampleSize());
|
||||
|
||||
// DATA header
|
||||
|
||||
@@ -96,7 +96,7 @@ AudioTest::AudioTest(QWidget *parent, Qt::WFlags f)
|
||||
connect(testButton, SIGNAL(clicked()), SLOT(test()));
|
||||
connect(modeBox, SIGNAL(activated(int)), SLOT(modeChanged(int)));
|
||||
connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
|
||||
connect(frequencyBox, SIGNAL(activated(int)), SLOT(freqChanged(int)));
|
||||
connect(sampleRateBox, SIGNAL(activated(int)), SLOT(sampleRateChanged(int)));
|
||||
connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int)));
|
||||
connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int)));
|
||||
connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int)));
|
||||
@@ -122,7 +122,7 @@ void AudioTest::test()
|
||||
if (!deviceInfo.isNull()) {
|
||||
if (deviceInfo.isFormatSupported(settings)) {
|
||||
testResult->setText(tr("Success"));
|
||||
nearestFreq->setText("");
|
||||
nearestSampleRate->setText("");
|
||||
nearestChannel->setText("");
|
||||
nearestCodec->setText("");
|
||||
nearestSampleSize->setText("");
|
||||
@@ -131,8 +131,8 @@ void AudioTest::test()
|
||||
} else {
|
||||
QAudioFormat nearest = deviceInfo.nearestFormat(settings);
|
||||
testResult->setText(tr("Failed"));
|
||||
nearestFreq->setText(QString("%1").arg(nearest.frequency()));
|
||||
nearestChannel->setText(QString("%1").arg(nearest.channels()));
|
||||
nearestSampleRate->setText(QString("%1").arg(nearest.sampleRate()));
|
||||
nearestChannel->setText(QString("%1").arg(nearest.channelCount()));
|
||||
nearestCodec->setText(nearest.codec());
|
||||
nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize()));
|
||||
nearestSampleType->setText(toString(nearest.sampleType()));
|
||||
@@ -171,19 +171,19 @@ void AudioTest::deviceChanged(int idx)
|
||||
// device has changed
|
||||
deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>();
|
||||
|
||||
frequencyBox->clear();
|
||||
QList<int> freqz = deviceInfo.supportedFrequencies();
|
||||
for(int i = 0; i < freqz.size(); ++i)
|
||||
frequencyBox->addItem(QString("%1").arg(freqz.at(i)));
|
||||
if(freqz.size())
|
||||
settings.setFrequency(freqz.at(0));
|
||||
sampleRateBox->clear();
|
||||
QList<int> sampleRatez = deviceInfo.supportedSampleRates();
|
||||
for (int i = 0; i < sampleRatez.size(); ++i)
|
||||
sampleRateBox->addItem(QString("%1").arg(sampleRatez.at(i)));
|
||||
if (sampleRatez.size())
|
||||
settings.setSampleRate(sampleRatez.at(0));
|
||||
|
||||
channelsBox->clear();
|
||||
QList<int> chz = deviceInfo.supportedChannels();
|
||||
for(int i = 0; i < chz.size(); ++i)
|
||||
QList<int> chz = deviceInfo.supportedChannelCounts();
|
||||
for (int i = 0; i < chz.size(); ++i)
|
||||
channelsBox->addItem(QString("%1").arg(chz.at(i)));
|
||||
if(chz.size())
|
||||
settings.setChannels(chz.at(0));
|
||||
if (chz.size())
|
||||
settings.setChannelCount(chz.at(0));
|
||||
|
||||
codecsBox->clear();
|
||||
QStringList codecz = deviceInfo.supportedCodecs();
|
||||
@@ -226,10 +226,10 @@ void AudioTest::populateTable()
|
||||
QAudioFormat format;
|
||||
foreach (QString codec, deviceInfo.supportedCodecs()) {
|
||||
format.setCodec(codec);
|
||||
foreach (int frequency, deviceInfo.supportedFrequencies()) {
|
||||
format.setFrequency(frequency);
|
||||
foreach (int channels, deviceInfo.supportedChannels()) {
|
||||
format.setChannels(channels);
|
||||
foreach (int sampleRate, deviceInfo.supportedSampleRates()) {
|
||||
format.setSampleRate(sampleRate);
|
||||
foreach (int channels, deviceInfo.supportedChannelCounts()) {
|
||||
format.setChannelCount(channels);
|
||||
foreach (QAudioFormat::SampleType sampleType, deviceInfo.supportedSampleTypes()) {
|
||||
format.setSampleType(sampleType);
|
||||
foreach (int sampleSize, deviceInfo.supportedSampleSizes()) {
|
||||
@@ -242,10 +242,10 @@ void AudioTest::populateTable()
|
||||
QTableWidgetItem *codecItem = new QTableWidgetItem(format.codec());
|
||||
allFormatsTable->setItem(row, 0, codecItem);
|
||||
|
||||
QTableWidgetItem *frequencyItem = new QTableWidgetItem(QString("%1").arg(format.frequency()));
|
||||
allFormatsTable->setItem(row, 1, frequencyItem);
|
||||
QTableWidgetItem *sampleRateItem = new QTableWidgetItem(QString("%1").arg(format.sampleRate()));
|
||||
allFormatsTable->setItem(row, 1, sampleRateItem);
|
||||
|
||||
QTableWidgetItem *channelsItem = new QTableWidgetItem(QString("%1").arg(format.channels()));
|
||||
QTableWidgetItem *channelsItem = new QTableWidgetItem(QString("%1").arg(format.channelCount()));
|
||||
allFormatsTable->setItem(row, 2, channelsItem);
|
||||
|
||||
QTableWidgetItem *sampleTypeItem = new QTableWidgetItem(toString(format.sampleType()));
|
||||
@@ -267,15 +267,15 @@ void AudioTest::populateTable()
|
||||
}
|
||||
}
|
||||
|
||||
void AudioTest::freqChanged(int idx)
|
||||
void AudioTest::sampleRateChanged(int idx)
|
||||
{
|
||||
// freq has changed
|
||||
settings.setFrequency(frequencyBox->itemText(idx).toInt());
|
||||
// sample rate has changed
|
||||
settings.setSampleRate(sampleRateBox->itemText(idx).toInt());
|
||||
}
|
||||
|
||||
void AudioTest::channelChanged(int idx)
|
||||
{
|
||||
settings.setChannels(channelsBox->itemText(idx).toInt());
|
||||
settings.setChannelCount(channelsBox->itemText(idx).toInt());
|
||||
}
|
||||
|
||||
void AudioTest::codecChanged(int idx)
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
private slots:
|
||||
void modeChanged(int idx);
|
||||
void deviceChanged(int idx);
|
||||
void freqChanged(int idx);
|
||||
void sampleRateChanged(int idx);
|
||||
void channelChanged(int idx);
|
||||
void codecChanged(int idx);
|
||||
void sampleSizeChanged(int idx);
|
||||
|
||||
@@ -134,7 +134,7 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="frequencyBox">
|
||||
<widget class="QComboBox" name="sampleRateBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -144,7 +144,7 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLineEdit" name="nearestFreq">
|
||||
<widget class="QLineEdit" name="nearestSampleRate">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
@@ -321,15 +321,6 @@ p, li { white-space: pre-wrap; }
|
||||
<attribute name="verticalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Codec</string>
|
||||
|
||||
@@ -123,7 +123,7 @@ qint64 AudioInfo::writeData(const char *data, qint64 len)
|
||||
if (m_maxAmplitude) {
|
||||
Q_ASSERT(m_format.sampleSize() % 8 == 0);
|
||||
const int channelBytes = m_format.sampleSize() / 8;
|
||||
const int sampleBytes = m_format.channels() * channelBytes;
|
||||
const int sampleBytes = m_format.channelCount() * channelBytes;
|
||||
Q_ASSERT(len % sampleBytes == 0);
|
||||
const int numSamples = len / sampleBytes;
|
||||
|
||||
@@ -131,7 +131,7 @@ qint64 AudioInfo::writeData(const char *data, qint64 len)
|
||||
const unsigned char *ptr = reinterpret_cast<const unsigned char *>(data);
|
||||
|
||||
for (int i = 0; i < numSamples; ++i) {
|
||||
for(int j = 0; j < m_format.channels(); ++j) {
|
||||
for (int j = 0; j < m_format.channelCount(); ++j) {
|
||||
quint16 value = 0;
|
||||
|
||||
if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
@@ -263,8 +263,8 @@ void InputTest::initializeAudio()
|
||||
{
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setFrequency(8000);
|
||||
m_format.setChannels(1);
|
||||
m_format.setSampleRate(8000);
|
||||
m_format.setChannelCount(1);
|
||||
m_format.setSampleSize(16);
|
||||
m_format.setSampleType(QAudioFormat::SignedInt);
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
|
||||
@@ -54,19 +54,19 @@
|
||||
#define VOLUME_LABEL "Volume:"
|
||||
|
||||
const int DurationSeconds = 1;
|
||||
const int ToneFrequencyHz = 600;
|
||||
const int DataFrequencyHz = 44100;
|
||||
const int ToneSampleRateHz = 600;
|
||||
const int DataSampleRateHz = 44100;
|
||||
const int BufferSize = 32768;
|
||||
|
||||
|
||||
Generator::Generator(const QAudioFormat &format,
|
||||
qint64 durationUs,
|
||||
int frequency,
|
||||
int sampleRate,
|
||||
QObject *parent)
|
||||
: QIODevice(parent)
|
||||
, m_pos(0)
|
||||
{
|
||||
generateData(format, durationUs, frequency);
|
||||
generateData(format, durationUs, sampleRate);
|
||||
}
|
||||
|
||||
Generator::~Generator()
|
||||
@@ -85,12 +85,12 @@ void Generator::stop()
|
||||
close();
|
||||
}
|
||||
|
||||
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency)
|
||||
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int sampleRate)
|
||||
{
|
||||
const int channelBytes = format.sampleSize() / 8;
|
||||
const int sampleBytes = format.channels() * channelBytes;
|
||||
const int sampleBytes = format.channelCount() * channelBytes;
|
||||
|
||||
qint64 length = (format.frequency() * format.channels() * (format.sampleSize() / 8))
|
||||
qint64 length = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
|
||||
* durationUs / 100000;
|
||||
|
||||
Q_ASSERT(length % sampleBytes == 0);
|
||||
@@ -101,8 +101,8 @@ void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int
|
||||
int sampleIndex = 0;
|
||||
|
||||
while (length) {
|
||||
const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency());
|
||||
for (int i=0; i<format.channels(); ++i) {
|
||||
const qreal x = qSin(2 * M_PI * sampleRate * qreal(sampleIndex % format.sampleRate()) / format.sampleRate());
|
||||
for (int i=0; i<format.channelCount(); ++i) {
|
||||
if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255);
|
||||
*reinterpret_cast<quint8*>(ptr) = value;
|
||||
@@ -217,8 +217,8 @@ void AudioTest::initializeAudio()
|
||||
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setFrequency(DataFrequencyHz);
|
||||
m_format.setChannels(1);
|
||||
m_format.setSampleRate(DataSampleRateHz);
|
||||
m_format.setChannelCount(1);
|
||||
m_format.setSampleSize(16);
|
||||
m_format.setCodec("audio/pcm");
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -230,7 +230,7 @@ void AudioTest::initializeAudio()
|
||||
m_format = info.nearestFormat(m_format);
|
||||
}
|
||||
|
||||
m_generator = new Generator(m_format, DurationSeconds*1000000, ToneFrequencyHz, this);
|
||||
m_generator = new Generator(m_format, DurationSeconds*1000000, ToneSampleRateHz, this);
|
||||
|
||||
createAudioOutput();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class Generator : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Generator(const QAudioFormat &format, qint64 durationUs, int frequency, QObject *parent);
|
||||
Generator(const QAudioFormat &format, qint64 durationUs, int sampleRate, QObject *parent);
|
||||
~Generator();
|
||||
|
||||
void start();
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
qint64 bytesAvailable() const;
|
||||
|
||||
private:
|
||||
void generateData(const QAudioFormat &format, qint64 durationUs, int frequency);
|
||||
void generateData(const QAudioFormat &format, qint64 durationUs, int sampleRate);
|
||||
|
||||
private:
|
||||
qint64 m_pos;
|
||||
|
||||
@@ -528,25 +528,25 @@ bool Engine::selectFormat()
|
||||
}
|
||||
} else {
|
||||
|
||||
QList<int> frequenciesList;
|
||||
QList<int> sampleRatesList;
|
||||
#ifdef Q_OS_WIN
|
||||
// The Windows audio backend does not correctly report format support
|
||||
// (see QTBUG-9100). Furthermore, although the audio subsystem captures
|
||||
// at 11025Hz, the resulting audio is corrupted.
|
||||
frequenciesList += 8000;
|
||||
sampleRatesList += 8000;
|
||||
#endif
|
||||
|
||||
if (!m_generateTone)
|
||||
frequenciesList += m_audioInputDevice.supportedFrequencies();
|
||||
sampleRatesList += m_audioInputDevice.supportedSampleRates();
|
||||
|
||||
frequenciesList += m_audioOutputDevice.supportedFrequencies();
|
||||
frequenciesList = frequenciesList.toSet().toList(); // remove duplicates
|
||||
qSort(frequenciesList);
|
||||
ENGINE_DEBUG << "Engine::initialize frequenciesList" << frequenciesList;
|
||||
sampleRatesList += m_audioOutputDevice.supportedSampleRates();
|
||||
sampleRatesList = sampleRatesList.toSet().toList(); // remove duplicates
|
||||
qSort(sampleRatesList);
|
||||
ENGINE_DEBUG << "Engine::initialize frequenciesList" << sampleRatesList;
|
||||
|
||||
QList<int> channelsList;
|
||||
channelsList += m_audioInputDevice.supportedChannels();
|
||||
channelsList += m_audioOutputDevice.supportedChannels();
|
||||
channelsList += m_audioInputDevice.supportedChannelCounts();
|
||||
channelsList += m_audioOutputDevice.supportedChannelCounts();
|
||||
channelsList = channelsList.toSet().toList();
|
||||
qSort(channelsList);
|
||||
ENGINE_DEBUG << "Engine::initialize channelsList" << channelsList;
|
||||
@@ -556,13 +556,13 @@ bool Engine::selectFormat()
|
||||
format.setCodec("audio/pcm");
|
||||
format.setSampleSize(16);
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
int frequency, channels;
|
||||
foreach (frequency, frequenciesList) {
|
||||
int sampleRate, channels;
|
||||
foreach (sampleRate, sampleRatesList) {
|
||||
if (foundSupportedFormat)
|
||||
break;
|
||||
format.setFrequency(frequency);
|
||||
format.setSampleRate(sampleRate);
|
||||
foreach (channels, channelsList) {
|
||||
format.setChannels(channels);
|
||||
format.setChannelCount(channels);
|
||||
const bool inputSupport = m_generateTone ||
|
||||
m_audioInputDevice.isFormatSupported(format);
|
||||
const bool outputSupport = m_audioOutputDevice.isFormatSupported(format);
|
||||
@@ -703,7 +703,7 @@ void Engine::setFormat(const QAudioFormat &format)
|
||||
m_format = format;
|
||||
m_levelBufferLength = audioLength(m_format, LevelWindowUs);
|
||||
m_spectrumBufferLength = SpectrumLengthSamples *
|
||||
(m_format.sampleSize() / 8) * m_format.channels();
|
||||
(m_format.sampleSize() / 8) * m_format.channelCount();
|
||||
if (changed)
|
||||
emit formatChanged(m_format);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ void SpectrumAnalyser::calculate(const QByteArray &buffer,
|
||||
if (isReady()) {
|
||||
Q_ASSERT(isPCMS16LE(format));
|
||||
|
||||
const int bytesPerSample = format.sampleSize() * format.channels() / 8;
|
||||
const int bytesPerSample = format.sampleSize() * format.channelCount() / 8;
|
||||
|
||||
#ifdef DUMP_SPECTRUMANALYSER
|
||||
m_count++;
|
||||
@@ -235,7 +235,7 @@ void SpectrumAnalyser::calculate(const QByteArray &buffer,
|
||||
const bool b = QMetaObject::invokeMethod(m_thread, "calculateSpectrum",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QByteArray, buffer),
|
||||
Q_ARG(int, format.frequency()),
|
||||
Q_ARG(int, format.sampleRate()),
|
||||
Q_ARG(int, bytesPerSample));
|
||||
Q_ASSERT(b);
|
||||
Q_UNUSED(b) // suppress warnings in release builds
|
||||
|
||||
@@ -50,7 +50,7 @@ void generateTone(const SweptTone &tone, const QAudioFormat &format, QByteArray
|
||||
Q_ASSERT(isPCMS16LE(format));
|
||||
|
||||
const int channelBytes = format.sampleSize() / 8;
|
||||
const int sampleBytes = format.channels() * channelBytes;
|
||||
const int sampleBytes = format.channelCount() * channelBytes;
|
||||
int length = buffer.size();
|
||||
const int numSamples = buffer.size() / sampleBytes;
|
||||
|
||||
@@ -61,7 +61,7 @@ void generateTone(const SweptTone &tone, const QAudioFormat &format, QByteArray
|
||||
|
||||
qreal phase = 0.0;
|
||||
|
||||
const qreal d = 2 * M_PI / format.frequency();
|
||||
const qreal d = 2 * M_PI / format.sampleRate();
|
||||
|
||||
// We can't generate a zero-frequency sine wave
|
||||
const qreal startFreq = tone.startFreq ? tone.startFreq : 1.0;
|
||||
@@ -76,7 +76,7 @@ void generateTone(const SweptTone &tone, const QAudioFormat &format, QByteArray
|
||||
while (length) {
|
||||
const qreal x = tone.amplitude * qSin(phase);
|
||||
const qint16 value = realToPcm(x);
|
||||
for (int i=0; i<format.channels(); ++i) {
|
||||
for (int i=0; i<format.channelCount(); ++i) {
|
||||
qToLittleEndian<qint16>(value, ptr);
|
||||
ptr += channelBytes;
|
||||
length -= channelBytes;
|
||||
|
||||
@@ -44,12 +44,12 @@
|
||||
qint64 audioDuration(const QAudioFormat &format, qint64 bytes)
|
||||
{
|
||||
return (bytes * 1000000) /
|
||||
(format.frequency() * format.channels() * (format.sampleSize() / 8));
|
||||
(format.sampleRate() * format.channelCount() * (format.sampleSize() / 8));
|
||||
}
|
||||
|
||||
qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
|
||||
{
|
||||
qint64 result = (format.frequency() * format.channels() * (format.sampleSize() / 8))
|
||||
qint64 result = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8))
|
||||
* microSeconds / 1000000;
|
||||
result -= result % (format.channelCount() * format.sampleSize());
|
||||
return result;
|
||||
@@ -57,7 +57,7 @@ qint64 audioLength(const QAudioFormat &format, qint64 microSeconds)
|
||||
|
||||
qreal nyquistFrequency(const QAudioFormat &format)
|
||||
{
|
||||
return format.frequency() / 2;
|
||||
return format.sampleRate() / 2;
|
||||
}
|
||||
|
||||
QString formatToString(const QAudioFormat &format)
|
||||
@@ -87,8 +87,8 @@ QString formatToString(const QAudioFormat &format)
|
||||
break;
|
||||
}
|
||||
|
||||
QString formatChannels = QString("%1 channels").arg(format.channels());
|
||||
switch (format.channels()) {
|
||||
QString formatChannels = QString("%1 channels").arg(format.channelCount());
|
||||
switch (format.channelCount()) {
|
||||
case 1:
|
||||
formatChannels = "mono";
|
||||
break;
|
||||
@@ -98,7 +98,7 @@ QString formatToString(const QAudioFormat &format)
|
||||
}
|
||||
|
||||
result = QString("%1 Hz %2 bit %3 %4 %5")
|
||||
.arg(format.frequency())
|
||||
.arg(format.sampleRate())
|
||||
.arg(format.sampleSize())
|
||||
.arg(formatType)
|
||||
.arg(formatEndian)
|
||||
|
||||
@@ -366,7 +366,7 @@ void Waveform::paintTile(int index)
|
||||
|
||||
const qint16* base = reinterpret_cast<const qint16*>(m_buffer.constData());
|
||||
const qint16* buffer = base + ((tileStart - m_bufferPosition) / 2);
|
||||
const int numSamples = m_tileLength / (2 * m_format.channels());
|
||||
const int numSamples = m_tileLength / (2 * m_format.channelCount());
|
||||
|
||||
QPainter painter(tile.pixmap);
|
||||
|
||||
@@ -378,7 +378,7 @@ void Waveform::paintTile(int index)
|
||||
// Calculate initial PCM value
|
||||
qint16 previousPcmValue = 0;
|
||||
if (buffer > base)
|
||||
previousPcmValue = *(buffer - m_format.channels());
|
||||
previousPcmValue = *(buffer - m_format.channelCount());
|
||||
|
||||
// Calculate initial point
|
||||
const qreal previousRealValue = pcmToReal(previousPcmValue);
|
||||
@@ -388,7 +388,7 @@ void Waveform::paintTile(int index)
|
||||
QLine line(origin, origin);
|
||||
|
||||
for (int i=0; i<numSamples; ++i) {
|
||||
const qint16* ptr = buffer + i * m_format.channels();
|
||||
const qint16* ptr = buffer + i * m_format.channelCount();
|
||||
|
||||
const int offset = reinterpret_cast<const char*>(ptr) - m_buffer.constData();
|
||||
Q_ASSERT(offset >= 0);
|
||||
@@ -398,7 +398,7 @@ void Waveform::paintTile(int index)
|
||||
const qint16 pcmValue = *ptr;
|
||||
const qreal realValue = pcmToReal(pcmValue);
|
||||
|
||||
const int x = tilePixelOffset(i * 2 * m_format.channels());
|
||||
const int x = tilePixelOffset(i * 2 * m_format.channelCount());
|
||||
const int y = ((realValue + 1.0) / 2) * m_pixmapSize.height();
|
||||
|
||||
line.setP2(QPoint(x, y));
|
||||
|
||||
@@ -137,9 +137,9 @@ bool WavFile::readHeader()
|
||||
m_fileFormat.setByteOrder(QAudioFormat::BigEndian);
|
||||
|
||||
int bps = qFromLittleEndian<quint16>(header.wave.bitsPerSample);
|
||||
m_fileFormat.setChannels(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_fileFormat.setChannelCount(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_fileFormat.setCodec("audio/pcm");
|
||||
m_fileFormat.setFrequency(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_fileFormat.setSampleRate(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_fileFormat.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample));
|
||||
m_fileFormat.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
|
||||
} else {
|
||||
|
||||
@@ -171,7 +171,7 @@ public Q_SLOTS:
|
||||
return;
|
||||
}
|
||||
alBufferData(m_alBuffer, alFormat, m_sample->data().data(),
|
||||
m_sample->data().size(), m_sample->format().frequency());
|
||||
m_sample->data().size(), m_sample->format().sampleRate());
|
||||
|
||||
if (!QAudioEnginePrivate::checkNoError("fill buffer")) {
|
||||
return;
|
||||
|
||||
@@ -49,8 +49,8 @@ QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf)
|
||||
{
|
||||
QAudioFormat audioFormat;
|
||||
|
||||
audioFormat.setFrequency(sf.mSampleRate);
|
||||
audioFormat.setChannels(sf.mChannelsPerFrame);
|
||||
audioFormat.setSampleRate(sf.mSampleRate);
|
||||
audioFormat.setChannelCount(sf.mChannelsPerFrame);
|
||||
audioFormat.setSampleSize(sf.mBitsPerChannel);
|
||||
audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
|
||||
audioFormat.setByteOrder((sf.mFormatFlags & kAudioFormatFlagIsBigEndian) != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian);
|
||||
@@ -69,9 +69,9 @@ AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& au
|
||||
AudioStreamBasicDescription sf;
|
||||
|
||||
sf.mFormatFlags = kAudioFormatFlagIsPacked;
|
||||
sf.mSampleRate = audioFormat.frequency();
|
||||
sf.mSampleRate = audioFormat.sampleRate();
|
||||
sf.mFramesPerPacket = 1;
|
||||
sf.mChannelsPerFrame = audioFormat.channels();
|
||||
sf.mChannelsPerFrame = audioFormat.channelCount();
|
||||
sf.mBitsPerChannel = audioFormat.sampleSize();
|
||||
sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8);
|
||||
sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame;
|
||||
|
||||
@@ -279,12 +279,12 @@ QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
|
||||
QAudioFormat nearest = settings;
|
||||
|
||||
QList<QString> testCodecs = supportedCodecs();
|
||||
QList<int> testChannels = supportedChannels();
|
||||
QList<int> testChannels = supportedChannelCounts();
|
||||
QList<QAudioFormat::Endian> testByteOrders = supportedByteOrders();
|
||||
QList<QAudioFormat::SampleType> testSampleTypes;
|
||||
QList<QAudioFormat::SampleType> sampleTypesAvailable = supportedSampleTypes();
|
||||
QMap<int,int> testFrequencies;
|
||||
QList<int> frequenciesAvailable = supportedFrequencies();
|
||||
QMap<int,int> testSampleRates;
|
||||
QList<int> sampleRatesAvailable = supportedSampleRates();
|
||||
QMap<int,int> testSampleSizes;
|
||||
QList<int> sampleSizesAvailable = supportedSampleSizes();
|
||||
|
||||
@@ -293,8 +293,8 @@ QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
|
||||
testCodecs.removeAll(settings.codec());
|
||||
testCodecs.insert(0, settings.codec());
|
||||
}
|
||||
testChannels.removeAll(settings.channels());
|
||||
testChannels.insert(0, settings.channels());
|
||||
testChannels.removeAll(settings.channelCount());
|
||||
testChannels.insert(0, settings.channelCount());
|
||||
testByteOrders.removeAll(settings.byteOrder());
|
||||
testByteOrders.insert(0, settings.byteOrder());
|
||||
|
||||
@@ -317,15 +317,15 @@ QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
|
||||
int diff = larger - smaller;
|
||||
testSampleSizes.insert((isMultiple ? diff : diff+100000), size);
|
||||
}
|
||||
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 (sampleRatesAvailable.contains(settings.sampleRate()))
|
||||
testSampleRates.insert(0,settings.sampleRate());
|
||||
sampleRatesAvailable.removeAll(settings.sampleRate());
|
||||
foreach (int sampleRate, sampleRatesAvailable) {
|
||||
int larger = (sampleRate > settings.sampleRate()) ? sampleRate : settings.sampleRate();
|
||||
int smaller = (sampleRate > settings.sampleRate()) ? settings.sampleRate() : sampleRate;
|
||||
bool isMultiple = ( 0 == (larger % smaller));
|
||||
int diff = larger - smaller;
|
||||
testFrequencies.insert((isMultiple ? diff : diff+100000), frequency);
|
||||
testSampleRates.insert((isMultiple ? diff : diff+100000), sampleRate);
|
||||
}
|
||||
|
||||
// Try to find nearest
|
||||
@@ -340,11 +340,11 @@ QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
|
||||
sz.next();
|
||||
nearest.setSampleSize(sz.value());
|
||||
foreach (int channel, testChannels) {
|
||||
nearest.setChannels(channel);
|
||||
QMapIterator<int, int> i(testFrequencies);
|
||||
nearest.setChannelCount(channel);
|
||||
QMapIterator<int, int> i(testSampleRates);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
nearest.setFrequency(i.value());
|
||||
nearest.setSampleRate(i.value());
|
||||
if (isFormatSupported(nearest))
|
||||
return nearest;
|
||||
}
|
||||
@@ -378,16 +378,6 @@ QStringList QAudioDeviceInfo::supportedCodecs() const
|
||||
|
||||
*/
|
||||
QList<int> QAudioDeviceInfo::supportedSampleRates() const
|
||||
{
|
||||
return supportedFrequencies();
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use supportedSampleRates() instead.
|
||||
*/
|
||||
QList<int> QAudioDeviceInfo::supportedFrequencies() const
|
||||
{
|
||||
return isNull() ? QList<int>() : d->info->supportedSampleRates();
|
||||
}
|
||||
@@ -399,16 +389,6 @@ QList<int> QAudioDeviceInfo::supportedFrequencies() const
|
||||
|
||||
*/
|
||||
QList<int> QAudioDeviceInfo::supportedChannelCounts() const
|
||||
{
|
||||
return supportedChannels();
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use supportedChannelCount() instead.
|
||||
*/
|
||||
QList<int> QAudioDeviceInfo::supportedChannels() const
|
||||
{
|
||||
return isNull() ? QList<int>() : d->info->supportedChannelCounts();
|
||||
}
|
||||
|
||||
@@ -88,9 +88,7 @@ public:
|
||||
QAudioFormat nearestFormat(const QAudioFormat &format) const;
|
||||
|
||||
QStringList supportedCodecs() const;
|
||||
QList<int> supportedFrequencies() const;
|
||||
QList<int> supportedSampleRates() const;
|
||||
QList<int> supportedChannels() const;
|
||||
QList<int> supportedChannelCounts() const;
|
||||
QList<int> supportedSampleSizes() const;
|
||||
QList<QAudioFormat::Endian> supportedByteOrders() const;
|
||||
|
||||
@@ -80,20 +80,20 @@ QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
|
||||
{
|
||||
QAudioFormat nearest;
|
||||
if(mode == QAudio::AudioOutput) {
|
||||
nearest.setFrequency(44100);
|
||||
nearest.setChannels(2);
|
||||
nearest.setSampleRate(44100);
|
||||
nearest.setChannelCount(2);
|
||||
nearest.setByteOrder(QAudioFormat::LittleEndian);
|
||||
nearest.setSampleType(QAudioFormat::SignedInt);
|
||||
nearest.setSampleSize(16);
|
||||
nearest.setCodec(QLatin1String("audio/pcm"));
|
||||
} else {
|
||||
nearest.setFrequency(8000);
|
||||
nearest.setChannels(1);
|
||||
nearest.setSampleRate(8000);
|
||||
nearest.setChannelCount(1);
|
||||
nearest.setSampleType(QAudioFormat::UnSignedInt);
|
||||
nearest.setSampleSize(8);
|
||||
nearest.setCodec(QLatin1String("audio/pcm"));
|
||||
if(!testSettings(nearest)) {
|
||||
nearest.setChannels(2);
|
||||
nearest.setChannelCount(2);
|
||||
nearest.setSampleSize(16);
|
||||
nearest.setSampleType(QAudioFormat::SignedInt);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ QStringList QAudioDeviceInfoInternal::supportedCodecs()
|
||||
QList<int> QAudioDeviceInfoInternal::supportedSampleRates()
|
||||
{
|
||||
updateLists();
|
||||
return freqz;
|
||||
return sampleRatez;
|
||||
}
|
||||
|
||||
QList<int> QAudioDeviceInfoInternal::supportedChannelCounts()
|
||||
@@ -239,7 +239,7 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
|
||||
bool testChannel = false;
|
||||
bool testCodec = false;
|
||||
bool testFreq = false;
|
||||
bool testSampleRate = false;
|
||||
bool testType = false;
|
||||
bool testSize = false;
|
||||
|
||||
@@ -250,8 +250,8 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
snd_pcm_hw_params_any( handle, params );
|
||||
|
||||
// set the values!
|
||||
snd_pcm_hw_params_set_channels(handle,params,format.channels());
|
||||
snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
|
||||
snd_pcm_hw_params_set_channels(handle,params,format.channelCount());
|
||||
snd_pcm_hw_params_set_rate(handle,params,format.sampleRate(),dir);
|
||||
|
||||
err = -1;
|
||||
|
||||
@@ -295,20 +295,20 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
} else
|
||||
testCodec = true;
|
||||
|
||||
if(err>=0 && format.channels() != -1) {
|
||||
err = snd_pcm_hw_params_test_channels(handle,params,format.channels());
|
||||
if (err>=0 && format.channelCount() != -1) {
|
||||
err = snd_pcm_hw_params_test_channels(handle,params,format.channelCount());
|
||||
if(err>=0)
|
||||
err = snd_pcm_hw_params_set_channels(handle,params,format.channels());
|
||||
err = snd_pcm_hw_params_set_channels(handle,params,format.channelCount());
|
||||
if(err>=0)
|
||||
testChannel = true;
|
||||
}
|
||||
|
||||
if(err>=0 && format.frequency() != -1) {
|
||||
err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0);
|
||||
if (err>=0 && format.sampleRate() != -1) {
|
||||
err = snd_pcm_hw_params_test_rate(handle,params,format.sampleRate(),0);
|
||||
if(err>=0)
|
||||
err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
|
||||
err = snd_pcm_hw_params_set_rate(handle,params,format.sampleRate(),dir);
|
||||
if(err>=0)
|
||||
testFreq = true;
|
||||
testSampleRate = true;
|
||||
}
|
||||
|
||||
if((err>=0 && format.sampleSize() != -1) &&
|
||||
@@ -370,7 +370,7 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
void QAudioDeviceInfoInternal::updateLists()
|
||||
{
|
||||
// redo all lists based on current settings
|
||||
freqz.clear();
|
||||
sampleRatez.clear();
|
||||
channelz.clear();
|
||||
sizez.clear();
|
||||
byteOrderz.clear();
|
||||
@@ -385,7 +385,7 @@ void QAudioDeviceInfoInternal::updateLists()
|
||||
|
||||
for(int i=0; i<(int)MAX_SAMPLE_RATES; i++) {
|
||||
//if(snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0)
|
||||
freqz.append(SAMPLE_RATES[i]);
|
||||
sampleRatez.append(SAMPLE_RATES[i]);
|
||||
}
|
||||
channelz.append(1);
|
||||
channelz.append(2);
|
||||
@@ -493,7 +493,6 @@ QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
|
||||
|
||||
void QAudioDeviceInfoInternal::checkSurround()
|
||||
{
|
||||
QList<QByteArray> devices;
|
||||
surround40 = false;
|
||||
surround51 = false;
|
||||
surround71 = false;
|
||||
|
||||
@@ -110,7 +110,7 @@ private:
|
||||
QString device;
|
||||
QAudio::Mode mode;
|
||||
QAudioFormat nearest;
|
||||
QList<int> freqz;
|
||||
QList<int> sampleRatez;
|
||||
QList<int> channelz;
|
||||
QList<int> sizez;
|
||||
QList<QAudioFormat::Endian> byteOrderz;
|
||||
|
||||
@@ -126,15 +126,15 @@ bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) con
|
||||
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
|
||||
{
|
||||
QAudioFormat nearest;
|
||||
if(mode == QAudio::AudioOutput) {
|
||||
nearest.setFrequency(44100);
|
||||
if (mode == QAudio::AudioOutput) {
|
||||
nearest.setSampleRate(44100);
|
||||
nearest.setChannelCount(2);
|
||||
nearest.setByteOrder(QAudioFormat::LittleEndian);
|
||||
nearest.setSampleType(QAudioFormat::SignedInt);
|
||||
nearest.setSampleSize(16);
|
||||
nearest.setCodec(QLatin1String("audio/pcm"));
|
||||
} else {
|
||||
nearest.setFrequency(11025);
|
||||
nearest.setSampleRate(11025);
|
||||
nearest.setChannelCount(1);
|
||||
nearest.setByteOrder(QAudioFormat::LittleEndian);
|
||||
nearest.setSampleType(QAudioFormat::SignedInt);
|
||||
@@ -158,7 +158,7 @@ QStringList QAudioDeviceInfoInternal::supportedCodecs()
|
||||
QList<int> QAudioDeviceInfoInternal::supportedSampleRates()
|
||||
{
|
||||
updateLists();
|
||||
return freqz;
|
||||
return sampleRatez;
|
||||
}
|
||||
|
||||
QList<int> QAudioDeviceInfoInternal::supportedChannelCounts()
|
||||
@@ -213,8 +213,8 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
// check channel
|
||||
match = false;
|
||||
if (!failed) {
|
||||
for( int i = 0; i < channelz.count(); i++) {
|
||||
if (format.channels() == channelz.at(i)) {
|
||||
for (int i = 0; i < channelz.count(); i++) {
|
||||
if (format.channelCount() == channelz.at(i)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@@ -223,11 +223,11 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
|
||||
failed = true;
|
||||
}
|
||||
|
||||
// check frequency
|
||||
// check sampleRate
|
||||
match = false;
|
||||
if (!failed) {
|
||||
for( int i = 0; i < freqz.count(); i++) {
|
||||
if (format.frequency() == freqz.at(i)) {
|
||||
for (int i = 0; i < sampleRatez.count(); i++) {
|
||||
if (format.sampleRate() == sampleRatez.at(i)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ void QAudioDeviceInfoInternal::updateLists()
|
||||
}
|
||||
}
|
||||
sizez.clear();
|
||||
freqz.clear();
|
||||
sampleRatez.clear();
|
||||
channelz.clear();
|
||||
byteOrderz.clear();
|
||||
typez.clear();
|
||||
@@ -339,31 +339,31 @@ void QAudioDeviceInfoInternal::updateLists()
|
||||
|| (fmt & WAVE_FORMAT_1S08)
|
||||
|| (fmt & WAVE_FORMAT_1M16)
|
||||
|| (fmt & WAVE_FORMAT_1S16)) {
|
||||
freqz.append(11025);
|
||||
sampleRatez.append(11025);
|
||||
}
|
||||
if ((fmt & WAVE_FORMAT_2M08)
|
||||
|| (fmt & WAVE_FORMAT_2S08)
|
||||
|| (fmt & WAVE_FORMAT_2M16)
|
||||
|| (fmt & WAVE_FORMAT_2S16)) {
|
||||
freqz.append(22050);
|
||||
sampleRatez.append(22050);
|
||||
}
|
||||
if ((fmt & WAVE_FORMAT_4M08)
|
||||
|| (fmt & WAVE_FORMAT_4S08)
|
||||
|| (fmt & WAVE_FORMAT_4M16)
|
||||
|| (fmt & WAVE_FORMAT_4S16)) {
|
||||
freqz.append(44100);
|
||||
sampleRatez.append(44100);
|
||||
}
|
||||
if ((fmt & WAVE_FORMAT_48M08)
|
||||
|| (fmt & WAVE_FORMAT_48S08)
|
||||
|| (fmt & WAVE_FORMAT_48M16)
|
||||
|| (fmt & WAVE_FORMAT_48S16)) {
|
||||
freqz.append(48000);
|
||||
sampleRatez.append(48000);
|
||||
}
|
||||
if ((fmt & WAVE_FORMAT_96M08)
|
||||
|| (fmt & WAVE_FORMAT_96S08)
|
||||
|| (fmt & WAVE_FORMAT_96M16)
|
||||
|| (fmt & WAVE_FORMAT_96S16)) {
|
||||
freqz.append(96000);
|
||||
sampleRatez.append(96000);
|
||||
}
|
||||
channelz.append(1);
|
||||
channelz.append(2);
|
||||
@@ -380,8 +380,8 @@ void QAudioDeviceInfoInternal::updateLists()
|
||||
|
||||
codecz.append(QLatin1String("audio/pcm"));
|
||||
}
|
||||
if (freqz.count() > 0)
|
||||
freqz.prepend(8000);
|
||||
if (sampleRatez.count() > 0)
|
||||
sampleRatez.prepend(8000);
|
||||
}
|
||||
|
||||
QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
|
||||
|
||||
@@ -104,7 +104,7 @@ private:
|
||||
QString device;
|
||||
quint32 devId;
|
||||
QAudioFormat nearest;
|
||||
QList<int> freqz;
|
||||
QList<int> sampleRatez;
|
||||
QList<int> channelz;
|
||||
QList<int> sizez;
|
||||
QList<QAudioFormat::Endian> byteOrderz;
|
||||
|
||||
@@ -64,7 +64,7 @@ class QAudioFormatPrivate : public QSharedData
|
||||
public:
|
||||
QAudioFormatPrivate()
|
||||
{
|
||||
frequency = -1;
|
||||
sampleRate = -1;
|
||||
channels = -1;
|
||||
sampleSize = -1;
|
||||
byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder);
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
codec(other.codec),
|
||||
byteOrder(other.byteOrder),
|
||||
sampleType(other.sampleType),
|
||||
frequency(other.frequency),
|
||||
sampleRate(other.sampleRate),
|
||||
channels(other.channels),
|
||||
sampleSize(other.sampleSize)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
codec = other.codec;
|
||||
byteOrder = other.byteOrder;
|
||||
sampleType = other.sampleType;
|
||||
frequency = other.frequency;
|
||||
sampleRate = other.sampleRate;
|
||||
channels = other.channels;
|
||||
sampleSize = other.sampleSize;
|
||||
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
QString codec;
|
||||
QAudioFormat::Endian byteOrder;
|
||||
QAudioFormat::SampleType sampleType;
|
||||
int frequency;
|
||||
int sampleRate;
|
||||
int channels;
|
||||
int sampleSize;
|
||||
};
|
||||
@@ -206,7 +206,7 @@ QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other)
|
||||
*/
|
||||
bool QAudioFormat::operator==(const QAudioFormat &other) const
|
||||
{
|
||||
return d->frequency == other.d->frequency &&
|
||||
return d->sampleRate == other.d->sampleRate &&
|
||||
d->channels == other.d->channels &&
|
||||
d->sampleSize == other.d->sampleSize &&
|
||||
d->byteOrder == other.d->byteOrder &&
|
||||
@@ -230,7 +230,7 @@ bool QAudioFormat::operator!=(const QAudioFormat& other) const
|
||||
*/
|
||||
bool QAudioFormat::isValid() const
|
||||
{
|
||||
return d->frequency != -1 && d->channels != -1 && d->sampleSize != -1 &&
|
||||
return d->sampleRate != -1 && d->channels != -1 && d->sampleSize != -1 &&
|
||||
d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty();
|
||||
}
|
||||
|
||||
@@ -240,17 +240,7 @@ bool QAudioFormat::isValid() const
|
||||
*/
|
||||
void QAudioFormat::setSampleRate(int samplerate)
|
||||
{
|
||||
d->frequency = samplerate;
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use setSampleRate() instead.
|
||||
*/
|
||||
void QAudioFormat::setFrequency(int frequency)
|
||||
{
|
||||
d->frequency = frequency;
|
||||
d->sampleRate = samplerate;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -259,17 +249,7 @@ void QAudioFormat::setFrequency(int frequency)
|
||||
*/
|
||||
int QAudioFormat::sampleRate() const
|
||||
{
|
||||
return d->frequency;
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use sampleRate() instead.
|
||||
*/
|
||||
int QAudioFormat::frequency() const
|
||||
{
|
||||
return d->frequency;
|
||||
return d->sampleRate;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -281,16 +261,6 @@ void QAudioFormat::setChannelCount(int channels)
|
||||
d->channels = channels;
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use setChannelCount() instead.
|
||||
*/
|
||||
void QAudioFormat::setChannels(int channels)
|
||||
{
|
||||
d->channels = channels;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the current channel count value.
|
||||
|
||||
@@ -300,16 +270,6 @@ int QAudioFormat::channelCount() const
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
/*!
|
||||
\obsolete
|
||||
|
||||
Use channelCount() instead.
|
||||
*/
|
||||
int QAudioFormat::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the sample size to the \a sampleSize specified, in bits.
|
||||
|
||||
|
||||
@@ -73,13 +73,9 @@ public:
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
void setFrequency(int frequency);
|
||||
int frequency() const;
|
||||
void setSampleRate(int sampleRate);
|
||||
int sampleRate() const;
|
||||
|
||||
void setChannels(int channels);
|
||||
int channels() const;
|
||||
void setChannelCount(int channelCount);
|
||||
int channelCount() const;
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ bool QAudioInputPrivate::open()
|
||||
int dir;
|
||||
int err = 0;
|
||||
int count=0;
|
||||
unsigned int freakuency=settings.frequency();
|
||||
unsigned int sampleRate=settings.sampleRate();
|
||||
|
||||
if (!settings.isValid()) {
|
||||
qWarning("QAudioOutput: open error, invalid format.");
|
||||
@@ -373,14 +373,14 @@ bool QAudioInputPrivate::open()
|
||||
}
|
||||
}
|
||||
if ( !fatal ) {
|
||||
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
|
||||
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
|
||||
if ( err < 0 ) {
|
||||
fatal = true;
|
||||
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
|
||||
}
|
||||
}
|
||||
if ( !fatal ) {
|
||||
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
|
||||
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
|
||||
if ( err < 0 ) {
|
||||
fatal = true;
|
||||
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
|
||||
@@ -686,8 +686,8 @@ int QAudioInputPrivate::notifyInterval() const
|
||||
qint64 QAudioInputPrivate::processedUSecs() const
|
||||
{
|
||||
qint64 result = qint64(1000000) * totalTimeValue /
|
||||
(settings.channels()*(settings.sampleSize()/8)) /
|
||||
settings.frequency();
|
||||
(settings.channelCount()*(settings.sampleSize()/8)) /
|
||||
settings.sampleRate();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ int QAudioInputPrivate::notifyInterval() const
|
||||
|
||||
qint64 QAudioInputPrivate::processedUSecs() const
|
||||
{
|
||||
return totalFrames * 1000000 / audioFormat.frequency();
|
||||
return totalFrames * 1000000 / audioFormat.sampleRate();
|
||||
}
|
||||
|
||||
qint64 QAudioInputPrivate::elapsedUSecs() const
|
||||
|
||||
@@ -242,12 +242,12 @@ bool QAudioInputPrivate::open()
|
||||
} else if (settings.sampleSize() <= 0) {
|
||||
qWarning("QAudioInput: open error, invalid sample size (%d).",
|
||||
settings.sampleSize());
|
||||
} else if (settings.frequency() < 8000 || settings.frequency() > 96000) {
|
||||
qWarning("QAudioInput: open error, frequency out of range (%d).", settings.frequency());
|
||||
} else if (settings.sampleRate() < 8000 || settings.sampleRate() > 96000) {
|
||||
qWarning("QAudioInput: open error, sample rate out of range (%d).", settings.sampleRate());
|
||||
} else if (buffer_size == 0) {
|
||||
|
||||
buffer_size
|
||||
= (settings.frequency()
|
||||
= (settings.sampleRate()
|
||||
* settings.channelCount()
|
||||
* settings.sampleSize()
|
||||
+ 39) / 40;
|
||||
@@ -265,9 +265,9 @@ bool QAudioInputPrivate::open()
|
||||
|
||||
timeStamp.restart();
|
||||
elapsedTimeOffset = 0;
|
||||
wfx.nSamplesPerSec = settings.frequency();
|
||||
wfx.nSamplesPerSec = settings.sampleRate();
|
||||
wfx.wBitsPerSample = settings.sampleSize();
|
||||
wfx.nChannels = settings.channels();
|
||||
wfx.nChannels = settings.channelCount();
|
||||
wfx.cbSize = 0;
|
||||
|
||||
wfx.wFormatTag = WAVE_FORMAT_PCM;
|
||||
@@ -539,8 +539,8 @@ qint64 QAudioInputPrivate::processedUSecs() const
|
||||
if (deviceState == QAudio::StoppedState)
|
||||
return 0;
|
||||
qint64 result = qint64(1000000) * totalTimeValue /
|
||||
(settings.channels()*(settings.sampleSize()/8)) /
|
||||
settings.frequency();
|
||||
(settings.channelCount()*(settings.sampleSize()/8)) /
|
||||
settings.sampleRate();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ bool QAudioOutputPrivate::open()
|
||||
int dir;
|
||||
int err = 0;
|
||||
int count=0;
|
||||
unsigned int freakuency=settings.frequency();
|
||||
unsigned int sampleRate=settings.sampleRate();
|
||||
|
||||
if (!settings.isValid()) {
|
||||
qWarning("QAudioOutput: open error, invalid format.");
|
||||
@@ -387,14 +387,14 @@ bool QAudioOutputPrivate::open()
|
||||
}
|
||||
}
|
||||
if ( !fatal ) {
|
||||
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
|
||||
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
|
||||
if ( err < 0 ) {
|
||||
fatal = true;
|
||||
errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
|
||||
}
|
||||
}
|
||||
if ( !fatal ) {
|
||||
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
|
||||
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
|
||||
if ( err < 0 ) {
|
||||
fatal = true;
|
||||
errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
|
||||
@@ -630,7 +630,7 @@ int QAudioOutputPrivate::notifyInterval() const
|
||||
|
||||
qint64 QAudioOutputPrivate::processedUSecs() const
|
||||
{
|
||||
return qint64(1000000) * totalTimeValue / settings.frequency();
|
||||
return qint64(1000000) * totalTimeValue / settings.sampleRate();
|
||||
}
|
||||
|
||||
void QAudioOutputPrivate::resume()
|
||||
|
||||
@@ -87,8 +87,8 @@ public:
|
||||
m_device(0)
|
||||
{
|
||||
m_buffer = new QAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize)));
|
||||
m_bytesPerFrame = (audioFormat.sampleSize() / 8) * audioFormat.channels();
|
||||
m_periodTime = m_maxPeriodSize / m_bytesPerFrame * 1000 / audioFormat.frequency();
|
||||
m_bytesPerFrame = (audioFormat.sampleSize() / 8) * audioFormat.channelCount();
|
||||
m_periodTime = m_maxPeriodSize / m_bytesPerFrame * 1000 / audioFormat.sampleRate();
|
||||
|
||||
m_fillTimer = new QTimer(this);
|
||||
connect(m_fillTimer, SIGNAL(timeout()), SLOT(fillBuffer()));
|
||||
@@ -579,7 +579,7 @@ int QAudioOutputPrivate::notifyInterval() const
|
||||
|
||||
qint64 QAudioOutputPrivate::processedUSecs() const
|
||||
{
|
||||
return totalFrames * 1000000 / audioFormat.frequency();
|
||||
return totalFrames * 1000000 / audioFormat.sampleRate();
|
||||
}
|
||||
|
||||
qint64 QAudioOutputPrivate::elapsedUSecs() const
|
||||
|
||||
@@ -280,12 +280,12 @@ bool QAudioOutputPrivate::open()
|
||||
} else if (settings.sampleSize() <= 0) {
|
||||
qWarning("QAudioOutput: open error, invalid sample size (%d).",
|
||||
settings.sampleSize());
|
||||
} else if (settings.frequency() < 8000 || settings.frequency() > 96000) {
|
||||
qWarning("QAudioOutput: open error, frequency out of range (%d).", settings.frequency());
|
||||
} else if (settings.sampleRate() < 8000 || settings.sampleRate() > 96000) {
|
||||
qWarning("QAudioOutput: open error, sample rate out of range (%d).", settings.sampleRate());
|
||||
} else if (buffer_size == 0) {
|
||||
// Default buffer size, 200ms, default period size is 40ms
|
||||
buffer_size
|
||||
= (settings.frequency()
|
||||
= (settings.sampleRate()
|
||||
* settings.channelCount()
|
||||
* settings.sampleSize()
|
||||
+ 39) / 40;
|
||||
@@ -315,14 +315,14 @@ bool QAudioOutputPrivate::open()
|
||||
timeStamp.restart();
|
||||
elapsedTimeOffset = 0;
|
||||
|
||||
wfx.nSamplesPerSec = settings.frequency();
|
||||
wfx.nSamplesPerSec = settings.sampleRate();
|
||||
wfx.wBitsPerSample = settings.sampleSize();
|
||||
wfx.nChannels = settings.channels();
|
||||
wfx.nChannels = settings.channelCount();
|
||||
wfx.cbSize = 0;
|
||||
|
||||
bool surround = false;
|
||||
|
||||
if (settings.channels() > 2)
|
||||
if (settings.channelCount() > 2)
|
||||
surround = true;
|
||||
|
||||
wfx.wFormatTag = WAVE_FORMAT_PCM;
|
||||
@@ -347,9 +347,9 @@ bool QAudioOutputPrivate::open()
|
||||
} else {
|
||||
WAVEFORMATEXTENSIBLE wfex;
|
||||
wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
||||
wfex.Format.nChannels = settings.channels();
|
||||
wfex.Format.nChannels = settings.channelCount();
|
||||
wfex.Format.wBitsPerSample = settings.sampleSize();
|
||||
wfex.Format.nSamplesPerSec = settings.frequency();
|
||||
wfex.Format.nSamplesPerSec = settings.sampleRate();
|
||||
wfex.Format.nBlockAlign = wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
|
||||
wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*wfex.Format.nBlockAlign;
|
||||
wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
|
||||
@@ -359,11 +359,11 @@ bool QAudioOutputPrivate::open()
|
||||
wfex.Format.cbSize=22;
|
||||
|
||||
wfex.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
|
||||
if (settings.channels() >= 4)
|
||||
if (settings.channelCount() >= 4)
|
||||
wfex.dwChannelMask |= SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
|
||||
if (settings.channels() >= 6)
|
||||
if (settings.channelCount() >= 6)
|
||||
wfex.dwChannelMask |= SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY;
|
||||
if (settings.channels() == 8)
|
||||
if (settings.channelCount() == 8)
|
||||
wfex.dwChannelMask |= SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT;
|
||||
|
||||
if (waveOutOpen(&hWaveOut, UINT_PTR(deviceId), &wfex.Format,
|
||||
@@ -401,8 +401,8 @@ void QAudioOutputPrivate::close()
|
||||
|
||||
deviceState = QAudio::StoppedState;
|
||||
errorState = QAudio::NoError;
|
||||
int delay = (buffer_size-bytesFree())*1000/(settings.frequency()
|
||||
*settings.channels()*(settings.sampleSize()/8));
|
||||
int delay = (buffer_size-bytesFree())*1000/(settings.sampleRate()
|
||||
*settings.channelCount()*(settings.sampleSize()/8));
|
||||
waveOutReset(hWaveOut);
|
||||
Sleep(delay+10);
|
||||
|
||||
@@ -452,8 +452,8 @@ qint64 QAudioOutputPrivate::processedUSecs() const
|
||||
if (deviceState == QAudio::StoppedState)
|
||||
return 0;
|
||||
qint64 result = qint64(1000000) * totalTimeValue /
|
||||
(settings.channels()*(settings.sampleSize()/8)) /
|
||||
settings.frequency();
|
||||
(settings.channelCount()*(settings.sampleSize()/8)) /
|
||||
settings.sampleRate();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -553,8 +553,8 @@ void QAudioOutputPrivate::resume()
|
||||
void QAudioOutputPrivate::suspend()
|
||||
{
|
||||
if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) {
|
||||
int delay = (buffer_size-bytesFree())*1000/(settings.frequency()
|
||||
*settings.channels()*(settings.sampleSize()/8));
|
||||
int delay = (buffer_size-bytesFree())*1000/(settings.sampleRate()
|
||||
*settings.channelCount()*(settings.sampleSize()/8));
|
||||
waveOutPause(hWaveOut);
|
||||
Sleep(delay+10);
|
||||
deviceState = QAudio::SuspendedState;
|
||||
|
||||
@@ -76,8 +76,8 @@ inline pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
|
||||
{
|
||||
pa_sample_spec spec;
|
||||
|
||||
spec.rate = format.frequency();
|
||||
spec.channels = format.channels();
|
||||
spec.rate = format.sampleRate();
|
||||
spec.channels = format.channelCount();
|
||||
|
||||
if (format.sampleSize() == 8)
|
||||
spec.format = PA_SAMPLE_U8;
|
||||
|
||||
@@ -74,7 +74,7 @@ QAudioFormat QWaveDecoder::audioFormat() const
|
||||
|
||||
int QWaveDecoder::duration() const
|
||||
{
|
||||
return size() * 1000 / (format.sampleSize() / 8) / format.channels() / format.frequency();
|
||||
return size() * 1000 / (format.sampleSize() / 8) / format.channelCount() / format.sampleRate();
|
||||
}
|
||||
|
||||
qint64 QWaveDecoder::size() const
|
||||
@@ -179,17 +179,17 @@ void QWaveDecoder::handleData()
|
||||
|
||||
format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::BigEndian);
|
||||
format.setFrequency(qFromBigEndian<quint32>(wave.sampleRate));
|
||||
format.setSampleRate(qFromBigEndian<quint32>(wave.sampleRate));
|
||||
format.setSampleSize(bps);
|
||||
format.setChannels(qFromBigEndian<quint16>(wave.numChannels));
|
||||
format.setChannelCount(qFromBigEndian<quint16>(wave.numChannels));
|
||||
} else {
|
||||
int bps = qFromLittleEndian<quint16>(wave.bitsPerSample);
|
||||
|
||||
format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setFrequency(qFromLittleEndian<quint32>(wave.sampleRate));
|
||||
format.setSampleRate(qFromLittleEndian<quint32>(wave.sampleRate));
|
||||
format.setSampleSize(bps);
|
||||
format.setChannels(qFromLittleEndian<quint16>(wave.numChannels));
|
||||
format.setChannelCount(qFromLittleEndian<quint16>(wave.numChannels));
|
||||
}
|
||||
|
||||
state = QWaveDecoder::WaitingForDataState;
|
||||
|
||||
@@ -56,8 +56,8 @@ AudioCaptureSession::AudioCaptureSession(QObject *parent):
|
||||
m_position = 0;
|
||||
m_state = QMediaRecorder::StoppedState;
|
||||
|
||||
m_format.setFrequency(8000);
|
||||
m_format.setChannels(1);
|
||||
m_format.setSampleRate(8000);
|
||||
m_format.setChannelCount(1);
|
||||
m_format.setSampleSize(8);
|
||||
m_format.setSampleType(QAudioFormat::UnSignedInt);
|
||||
m_format.setCodec("audio/pcm");
|
||||
@@ -264,10 +264,10 @@ void AudioCaptureSession::record()
|
||||
memcpy(header.wave.descriptor.id,"fmt ",4);
|
||||
header.wave.descriptor.size = 16;
|
||||
header.wave.audioFormat = 1; // for PCM data
|
||||
header.wave.numChannels = m_format.channels();
|
||||
header.wave.sampleRate = m_format.frequency();
|
||||
header.wave.byteRate = m_format.frequency()*m_format.channels()*m_format.sampleSize()/8;
|
||||
header.wave.blockAlign = m_format.channels()*m_format.sampleSize()/8;
|
||||
header.wave.numChannels = m_format.channelCount();
|
||||
header.wave.sampleRate = m_format.sampleRate();
|
||||
header.wave.byteRate = m_format.sampleRate()*m_format.channelCount()*m_format.sampleSize()/8;
|
||||
header.wave.blockAlign = m_format.channelCount()*m_format.sampleSize()/8;
|
||||
header.wave.bitsPerSample = m_format.sampleSize();
|
||||
memcpy(header.data.descriptor.id,"data",4);
|
||||
header.data.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(),samples*channels*sampleSize/8
|
||||
|
||||
@@ -53,8 +53,8 @@ AudioEncoderControl::AudioEncoderControl(QObject *parent)
|
||||
|
||||
QT_PREPEND_NAMESPACE(QAudioFormat) fmt;
|
||||
fmt.setSampleSize(8);
|
||||
fmt.setChannels(1);
|
||||
fmt.setFrequency(8000);
|
||||
fmt.setChannelCount(1);
|
||||
fmt.setSampleRate(8000);
|
||||
fmt.setSampleType(QT_PREPEND_NAMESPACE(QAudioFormat)::SignedInt);
|
||||
fmt.setCodec("audio/pcm");
|
||||
fmt.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -94,7 +94,7 @@ QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings
|
||||
if (continuous)
|
||||
*continuous = false;
|
||||
|
||||
return m_session->deviceInfo()->supportedFrequencies();
|
||||
return m_session->deviceInfo()->supportedSampleRates();
|
||||
}
|
||||
|
||||
QAudioEncoderSettings AudioEncoderControl::audioSettings() const
|
||||
@@ -109,26 +109,26 @@ void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings
|
||||
if (settings.encodingMode() == QtMultimedia::ConstantQualityEncoding) {
|
||||
if (settings.quality() == QtMultimedia::LowQuality) {
|
||||
fmt.setSampleSize(8);
|
||||
fmt.setChannels(1);
|
||||
fmt.setFrequency(8000);
|
||||
fmt.setChannelCount(1);
|
||||
fmt.setSampleRate(8000);
|
||||
fmt.setSampleType(QAudioFormat::UnSignedInt);
|
||||
|
||||
} else if (settings.quality() == QtMultimedia::NormalQuality) {
|
||||
fmt.setSampleSize(16);
|
||||
fmt.setChannels(1);
|
||||
fmt.setFrequency(22050);
|
||||
fmt.setChannelCount(1);
|
||||
fmt.setSampleRate(22050);
|
||||
fmt.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
} else {
|
||||
fmt.setSampleSize(16);
|
||||
fmt.setChannels(1);
|
||||
fmt.setFrequency(44100);
|
||||
fmt.setChannelCount(1);
|
||||
fmt.setSampleRate(44100);
|
||||
fmt.setSampleType(QAudioFormat::SignedInt);
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.setChannels(settings.channelCount());
|
||||
fmt.setFrequency(settings.sampleRate());
|
||||
fmt.setChannelCount(settings.channelCount());
|
||||
fmt.setSampleRate(settings.sampleRate());
|
||||
if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) {
|
||||
fmt.setSampleType(QAudioFormat::UnSignedInt);
|
||||
fmt.setSampleSize(8);
|
||||
|
||||
@@ -274,7 +274,7 @@ bool QPulseAudioOutput::open()
|
||||
QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
|
||||
pa_threaded_mainloop_lock(pulseEngine->mainloop());
|
||||
|
||||
qint64 bytesPerSecond = m_format.sampleRate() * m_format.channels() * m_format.sampleSize() / 8;
|
||||
qint64 bytesPerSecond = m_format.sampleRate() * m_format.channelCount() * m_format.sampleSize() / 8;
|
||||
|
||||
pa_proplist *propList = pa_proplist_new();
|
||||
if (m_category.isNull()) {
|
||||
@@ -503,8 +503,8 @@ int QPulseAudioOutput::notifyInterval() const
|
||||
qint64 QPulseAudioOutput::processedUSecs() const
|
||||
{
|
||||
qint64 result = qint64(1000000) * m_totalTimeValue /
|
||||
(m_format.channels() * (m_format.sampleSize() / 8)) /
|
||||
m_format.frequency();
|
||||
(m_format.channelCount() * (m_format.sampleSize() / 8)) /
|
||||
m_format.sampleRate();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format)
|
||||
{
|
||||
pa_sample_spec spec;
|
||||
|
||||
spec.rate = format.frequency();
|
||||
spec.channels = format.channels();
|
||||
spec.rate = format.sampleRate();
|
||||
spec.channels = format.channelCount();
|
||||
|
||||
if (format.sampleSize() == 8) {
|
||||
spec.format = PA_SAMPLE_U8;
|
||||
@@ -139,7 +139,7 @@ QString stateToQString(pa_context_state_t state)
|
||||
QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec)
|
||||
{
|
||||
QAudioFormat format;
|
||||
format.setFrequency(spec.rate);
|
||||
format.setSampleRate(spec.rate);
|
||||
format.setChannelCount(spec.channels);
|
||||
format.setCodec("audio/pcm");
|
||||
|
||||
|
||||
@@ -183,9 +183,9 @@ void tst_QAudioDecoderBackend::fileTest()
|
||||
|
||||
// change output audio format
|
||||
QAudioFormat format;
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
format.setSampleSize(8);
|
||||
format.setFrequency(11050);
|
||||
format.setSampleRate(11050);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
@@ -509,9 +509,9 @@ void tst_QAudioDecoderBackend::deviceTest()
|
||||
|
||||
// Now try changing formats
|
||||
QAudioFormat format;
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
format.setSampleSize(8);
|
||||
format.setFrequency(8000);
|
||||
format.setSampleRate(8000);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ private slots:
|
||||
void sampleSizes();
|
||||
void byteOrders();
|
||||
void sampleTypes();
|
||||
void frequencies();
|
||||
void sampleRates();
|
||||
void isFormatSupported();
|
||||
void preferred();
|
||||
void nearest();
|
||||
@@ -112,7 +112,7 @@ void tst_QAudioDeviceInfo::codecs()
|
||||
|
||||
void tst_QAudioDeviceInfo::channels()
|
||||
{
|
||||
QList<int> avail = device->supportedChannels();
|
||||
QList<int> avail = device->supportedChannelCounts();
|
||||
QVERIFY(avail.size() > 0);
|
||||
}
|
||||
|
||||
@@ -134,17 +134,17 @@ void tst_QAudioDeviceInfo::sampleTypes()
|
||||
QVERIFY(avail.size() > 0);
|
||||
}
|
||||
|
||||
void tst_QAudioDeviceInfo::frequencies()
|
||||
void tst_QAudioDeviceInfo::sampleRates()
|
||||
{
|
||||
QList<int> avail = device->supportedFrequencies();
|
||||
QList<int> avail = device->supportedSampleRates();
|
||||
QVERIFY(avail.size() > 0);
|
||||
}
|
||||
|
||||
void tst_QAudioDeviceInfo::isFormatSupported()
|
||||
{
|
||||
QAudioFormat format;
|
||||
format.setFrequency(44100);
|
||||
format.setChannels(2);
|
||||
format.setSampleRate(44100);
|
||||
format.setChannelCount(2);
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setSampleSize(16);
|
||||
@@ -167,13 +167,13 @@ void tst_QAudioDeviceInfo::nearest()
|
||||
{
|
||||
/*
|
||||
QAudioFormat format1, format2;
|
||||
format1.setFrequency(8000);
|
||||
format1.setSampleRate(8000);
|
||||
format2 = device->nearestFormat(format1);
|
||||
QVERIFY(format2.frequency() == 44100);
|
||||
QVERIFY(format2.sampleRate() == 44100);
|
||||
*/
|
||||
QAudioFormat format;
|
||||
format.setFrequency(44100);
|
||||
format.setChannels(2);
|
||||
format.setSampleRate(44100);
|
||||
format.setChannelCount(2);
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setSampleSize(16);
|
||||
@@ -182,7 +182,7 @@ void tst_QAudioDeviceInfo::nearest()
|
||||
QAudioFormat format2 = device->nearestFormat(format);
|
||||
|
||||
// This is definitely dependent on platform support (but isFormatSupported tests that above)
|
||||
QVERIFY(format2.frequency() == 44100);
|
||||
QVERIFY(format2.sampleRate() == 44100);
|
||||
}
|
||||
|
||||
// Returns a list of supported channel counts.
|
||||
|
||||
@@ -128,11 +128,11 @@ QString tst_QAudioInput::formatToFileName(const QAudioFormat &format)
|
||||
? QString("signed") : QString("unsigned");
|
||||
|
||||
return QString("%1_%2_%3_%4_%5")
|
||||
.arg(format.frequency())
|
||||
.arg(format.sampleRate())
|
||||
.arg(format.sampleSize())
|
||||
.arg(formatSigned)
|
||||
.arg(formatEndian)
|
||||
.arg(format.channels());
|
||||
.arg(format.channelCount());
|
||||
}
|
||||
|
||||
void tst_QAudioInput::initTestCase()
|
||||
@@ -157,37 +157,37 @@ void tst_QAudioInput::initTestCase()
|
||||
testFormats.append(audioDevice.preferredFormat());
|
||||
|
||||
// PCM 8000 mono S8
|
||||
format.setFrequency(8000);
|
||||
format.setSampleRate(8000);
|
||||
format.setSampleSize(8);
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setChannels(1);
|
||||
format.setChannelCount(1);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 11025 mono S16LE
|
||||
format.setFrequency(11025);
|
||||
format.setSampleRate(11025);
|
||||
format.setSampleSize(16);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 22050 mono S16LE
|
||||
format.setFrequency(22050);
|
||||
format.setSampleRate(22050);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 22050 stereo S16LE
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 44100 stereo S16LE
|
||||
format.setFrequency(44100);
|
||||
format.setSampleRate(44100);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 48000 stereo S16LE
|
||||
format.setFrequency(48000);
|
||||
format.setSampleRate(48000);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
@@ -217,10 +217,10 @@ void tst_QAudioInput::format()
|
||||
QAudioFormat requested = audioDevice.preferredFormat();
|
||||
QAudioFormat actual = audioInput.format();
|
||||
|
||||
QVERIFY2((requested.channels() == actual.channels()),
|
||||
QString("channels: requested=%1, actual=%2").arg(requested.channels()).arg(actual.channels()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.frequency() == actual.frequency()),
|
||||
QString("frequency: requested=%1, actual=%2").arg(requested.frequency()).arg(actual.frequency()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.channelCount() == actual.channelCount()),
|
||||
QString("channels: requested=%1, actual=%2").arg(requested.channelCount()).arg(actual.channelCount()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.sampleRate() == actual.sampleRate()),
|
||||
QString("sampleRate: requested=%1, actual=%2").arg(requested.sampleRate()).arg(actual.sampleRate()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.sampleSize() == actual.sampleSize()),
|
||||
QString("sampleSize: requested=%1, actual=%2").arg(requested.sampleSize()).arg(actual.sampleSize()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.codec() == actual.codec()),
|
||||
@@ -620,7 +620,7 @@ void tst_QAudioInput::push()
|
||||
qint64 totalBytesRead = 0;
|
||||
bool firstBuffer = true;
|
||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||
qint64 len = (testFormats.at(i).frequency()*testFormats.at(i).channels()*(testFormats.at(i).sampleSize()/8)*2); // 2 seconds
|
||||
qint64 len = (testFormats.at(i).sampleRate()*testFormats.at(i).channelCount()*(testFormats.at(i).sampleSize()/8)*2); // 2 seconds
|
||||
while (totalBytesRead < len) {
|
||||
if (audioInput.bytesReady() >= audioInput.periodSize()) {
|
||||
qint64 bytesRead = feed->read(buffer.data(), audioInput.periodSize());
|
||||
@@ -703,7 +703,7 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
qint64 totalBytesRead = 0;
|
||||
bool firstBuffer = true;
|
||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||
qint64 len = (testFormats.at(i).frequency()*testFormats.at(i).channels()*(testFormats.at(i).sampleSize()/8)); // 1 seconds
|
||||
qint64 len = (testFormats.at(i).sampleRate()*testFormats.at(i).channelCount()*(testFormats.at(i).sampleSize()/8)); // 1 seconds
|
||||
while (totalBytesRead < len) {
|
||||
if (audioInput.bytesReady() >= audioInput.periodSize()) {
|
||||
qint64 bytesRead = feed->read(buffer.data(), audioInput.periodSize());
|
||||
|
||||
@@ -111,9 +111,9 @@ bool WavHeader::read(QIODevice &device)
|
||||
else
|
||||
m_format.setByteOrder(QAudioFormat::BigEndian);
|
||||
|
||||
m_format.setChannels(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_format.setChannelCount(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_format.setCodec("audio/pcm");
|
||||
m_format.setFrequency(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_format.setSampleRate(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_format.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample));
|
||||
|
||||
switch(header.wave.bitsPerSample) {
|
||||
@@ -158,13 +158,13 @@ bool WavHeader::write(QIODevice &device)
|
||||
reinterpret_cast<unsigned char*>(&header.wave.descriptor.size));
|
||||
qToLittleEndian<quint16>(quint16(1),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.audioFormat));
|
||||
qToLittleEndian<quint16>(quint16(m_format.channels()),
|
||||
qToLittleEndian<quint16>(quint16(m_format.channelCount()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.numChannels));
|
||||
qToLittleEndian<quint32>(quint32(m_format.frequency()),
|
||||
qToLittleEndian<quint32>(quint32(m_format.sampleRate()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.sampleRate));
|
||||
qToLittleEndian<quint32>(quint32(m_format.frequency() * m_format.channels() * m_format.sampleSize() / 8),
|
||||
qToLittleEndian<quint32>(quint32(m_format.sampleRate() * m_format.channelCount() * m_format.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.byteRate));
|
||||
qToLittleEndian<quint16>(quint16(m_format.channels() * m_format.sampleSize() / 8),
|
||||
qToLittleEndian<quint16>(quint16(m_format.channelCount() * m_format.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.blockAlign));
|
||||
qToLittleEndian<quint16>(quint16(m_format.sampleSize()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.bitsPerSample));
|
||||
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
typedef QSharedPointer<QFile> FilePtr;
|
||||
|
||||
QString formatToFileName(const QAudioFormat &format);
|
||||
void createSineWaveData(const QAudioFormat &format, qint64 length, int frequency = 440);
|
||||
void createSineWaveData(const QAudioFormat &format, qint64 length, int sampleRate = 440);
|
||||
|
||||
QAudioDeviceInfo audioDevice;
|
||||
QList<QAudioFormat> testFormats;
|
||||
@@ -128,17 +128,17 @@ QString tst_QAudioOutput::formatToFileName(const QAudioFormat &format)
|
||||
? QString("signed") : QString("unsigned");
|
||||
|
||||
return QString("%1_%2_%3_%4_%5")
|
||||
.arg(format.frequency())
|
||||
.arg(format.sampleRate())
|
||||
.arg(format.sampleSize())
|
||||
.arg(formatSigned)
|
||||
.arg(formatEndian)
|
||||
.arg(format.channels());
|
||||
.arg(format.channelCount());
|
||||
}
|
||||
|
||||
void tst_QAudioOutput::createSineWaveData(const QAudioFormat &format, qint64 length, int frequency)
|
||||
void tst_QAudioOutput::createSineWaveData(const QAudioFormat &format, qint64 length, int sampleRate)
|
||||
{
|
||||
const int channelBytes = format.sampleSize() / 8;
|
||||
const int sampleBytes = format.channels() * channelBytes;
|
||||
const int sampleBytes = format.channelCount() * channelBytes;
|
||||
|
||||
Q_ASSERT(length % sampleBytes == 0);
|
||||
Q_UNUSED(sampleBytes) // suppress warning in release builds
|
||||
@@ -148,8 +148,8 @@ void tst_QAudioOutput::createSineWaveData(const QAudioFormat &format, qint64 len
|
||||
int sampleIndex = 0;
|
||||
|
||||
while (length) {
|
||||
const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency());
|
||||
for (int i=0; i<format.channels(); ++i) {
|
||||
const qreal x = qSin(2 * M_PI * sampleRate * qreal(sampleIndex % format.sampleRate()) / format.sampleRate());
|
||||
for (int i=0; i<format.channelCount(); ++i) {
|
||||
if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255);
|
||||
*reinterpret_cast<quint8*>(ptr) = value;
|
||||
@@ -202,37 +202,37 @@ void tst_QAudioOutput::initTestCase()
|
||||
testFormats.append(audioDevice.preferredFormat());
|
||||
|
||||
// PCM 8000 mono S8
|
||||
format.setFrequency(8000);
|
||||
format.setSampleRate(8000);
|
||||
format.setSampleSize(8);
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setChannels(1);
|
||||
format.setChannelCount(1);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 11025 mono S16LE
|
||||
format.setFrequency(11025);
|
||||
format.setSampleRate(11025);
|
||||
format.setSampleSize(16);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 22050 mono S16LE
|
||||
format.setFrequency(22050);
|
||||
format.setSampleRate(22050);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 22050 stereo S16LE
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 44100 stereo S16LE
|
||||
format.setFrequency(44100);
|
||||
format.setSampleRate(44100);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
// PCM 48000 stereo S16LE
|
||||
format.setFrequency(48000);
|
||||
format.setSampleRate(48000);
|
||||
if (audioDevice.isFormatSupported(format))
|
||||
testFormats.append(format);
|
||||
|
||||
@@ -249,7 +249,7 @@ void tst_QAudioOutput::initTestCase()
|
||||
|
||||
const QString temporaryAudioPath = m_temporaryDir->path() + slash;
|
||||
foreach (const QAudioFormat &format, testFormats) {
|
||||
qint64 len = (format.frequency()*format.channels()*(format.sampleSize()/8)*2); // 2 seconds
|
||||
qint64 len = (format.sampleRate()*format.channelCount()*(format.sampleSize()/8)*2); // 2 seconds
|
||||
createSineWaveData(format, len);
|
||||
// Write generate sine wave data to file
|
||||
const QString fileName = temporaryAudioPath + QStringLiteral("generated")
|
||||
@@ -272,10 +272,10 @@ void tst_QAudioOutput::format()
|
||||
QAudioFormat requested = audioDevice.preferredFormat();
|
||||
QAudioFormat actual = audioOutput.format();
|
||||
|
||||
QVERIFY2((requested.channels() == actual.channels()),
|
||||
QString("channels: requested=%1, actual=%2").arg(requested.channels()).arg(actual.channels()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.frequency() == actual.frequency()),
|
||||
QString("frequency: requested=%1, actual=%2").arg(requested.frequency()).arg(actual.frequency()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.channelCount() == actual.channelCount()),
|
||||
QString("channels: requested=%1, actual=%2").arg(requested.channelCount()).arg(actual.channelCount()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.sampleRate() == actual.sampleRate()),
|
||||
QString("sampleRate: requested=%1, actual=%2").arg(requested.sampleRate()).arg(actual.sampleRate()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.sampleSize() == actual.sampleSize()),
|
||||
QString("sampleSize: requested=%1, actual=%2").arg(requested.sampleSize()).arg(actual.sampleSize()).toLocal8Bit().constData());
|
||||
QVERIFY2((requested.codec() == actual.codec()),
|
||||
|
||||
@@ -111,9 +111,9 @@ bool WavHeader::read(QIODevice &device)
|
||||
else
|
||||
m_format.setByteOrder(QAudioFormat::BigEndian);
|
||||
|
||||
m_format.setChannels(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_format.setChannelCount(qFromLittleEndian<quint16>(header.wave.numChannels));
|
||||
m_format.setCodec("audio/pcm");
|
||||
m_format.setFrequency(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_format.setSampleRate(qFromLittleEndian<quint32>(header.wave.sampleRate));
|
||||
m_format.setSampleSize(qFromLittleEndian<quint16>(header.wave.bitsPerSample));
|
||||
|
||||
switch(header.wave.bitsPerSample) {
|
||||
@@ -158,13 +158,13 @@ bool WavHeader::write(QIODevice &device)
|
||||
reinterpret_cast<unsigned char*>(&header.wave.descriptor.size));
|
||||
qToLittleEndian<quint16>(quint16(1),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.audioFormat));
|
||||
qToLittleEndian<quint16>(quint16(m_format.channels()),
|
||||
qToLittleEndian<quint16>(quint16(m_format.channelCount()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.numChannels));
|
||||
qToLittleEndian<quint32>(quint32(m_format.frequency()),
|
||||
qToLittleEndian<quint32>(quint32(m_format.sampleRate()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.sampleRate));
|
||||
qToLittleEndian<quint32>(quint32(m_format.frequency() * m_format.channels() * m_format.sampleSize() / 8),
|
||||
qToLittleEndian<quint32>(quint32(m_format.sampleRate() * m_format.channelCount() * m_format.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.byteRate));
|
||||
qToLittleEndian<quint16>(quint16(m_format.channels() * m_format.sampleSize() / 8),
|
||||
qToLittleEndian<quint16>(quint16(m_format.channelCount() * m_format.sampleSize() / 8),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.blockAlign));
|
||||
qToLittleEndian<quint16>(quint16(m_format.sampleSize()),
|
||||
reinterpret_cast<unsigned char*>(&header.wave.bitsPerSample));
|
||||
|
||||
@@ -362,7 +362,7 @@ void tst_QAudioDecoder::nullControl()
|
||||
QVERIFY(d.sourceDevice() == 0);
|
||||
|
||||
QAudioFormat format;
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
QVERIFY(!d.audioFormat().isValid());
|
||||
d.setAudioFormat(format);
|
||||
QVERIFY(!d.audioFormat().isValid());
|
||||
@@ -403,7 +403,7 @@ void tst_QAudioDecoder::nullService()
|
||||
QVERIFY(d.sourceDevice() == 0);
|
||||
|
||||
QAudioFormat format;
|
||||
format.setChannels(2);
|
||||
format.setChannelCount(2);
|
||||
QVERIFY(!d.audioFormat().isValid());
|
||||
d.setAudioFormat(format);
|
||||
QVERIFY(!d.audioFormat().isValid());
|
||||
|
||||
@@ -58,7 +58,6 @@ public:
|
||||
|
||||
private slots:
|
||||
void checkNull();
|
||||
void checkFrequency();
|
||||
void checkSampleSize();
|
||||
void checkCodec();
|
||||
void checkByteOrder();
|
||||
@@ -82,21 +81,14 @@ void tst_QAudioFormat::checkNull()
|
||||
QAudioFormat audioFormat1(audioFormat0);
|
||||
QVERIFY(!audioFormat1.isValid());
|
||||
|
||||
audioFormat0.setFrequency(44100);
|
||||
audioFormat0.setChannels(2);
|
||||
audioFormat0.setSampleRate(44100);
|
||||
audioFormat0.setChannelCount(2);
|
||||
audioFormat0.setSampleSize(16);
|
||||
audioFormat0.setCodec("audio/pcm");
|
||||
audioFormat0.setSampleType(QAudioFormat::SignedInt);
|
||||
QVERIFY(audioFormat0.isValid());
|
||||
}
|
||||
|
||||
void tst_QAudioFormat::checkFrequency()
|
||||
{
|
||||
QAudioFormat audioFormat;
|
||||
audioFormat.setFrequency(44100);
|
||||
QVERIFY(audioFormat.frequency() == 44100);
|
||||
}
|
||||
|
||||
void tst_QAudioFormat::checkSampleSize()
|
||||
{
|
||||
QAudioFormat audioFormat;
|
||||
@@ -161,15 +153,15 @@ void tst_QAudioFormat::checkEquality()
|
||||
QVERIFY(!(audioFormat0 != audioFormat1));
|
||||
|
||||
// on filled formats
|
||||
audioFormat0.setFrequency(8000);
|
||||
audioFormat0.setChannels(1);
|
||||
audioFormat0.setSampleRate(8000);
|
||||
audioFormat0.setChannelCount(1);
|
||||
audioFormat0.setSampleSize(8);
|
||||
audioFormat0.setCodec("audio/pcm");
|
||||
audioFormat0.setByteOrder(QAudioFormat::LittleEndian);
|
||||
audioFormat0.setSampleType(QAudioFormat::UnSignedInt);
|
||||
|
||||
audioFormat1.setFrequency(8000);
|
||||
audioFormat1.setChannels(1);
|
||||
audioFormat1.setSampleRate(8000);
|
||||
audioFormat1.setChannelCount(1);
|
||||
audioFormat1.setSampleSize(8);
|
||||
audioFormat1.setCodec("audio/pcm");
|
||||
audioFormat1.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -178,7 +170,7 @@ void tst_QAudioFormat::checkEquality()
|
||||
QVERIFY(audioFormat0 == audioFormat1);
|
||||
QVERIFY(!(audioFormat0 != audioFormat1));
|
||||
|
||||
audioFormat0.setFrequency(44100);
|
||||
audioFormat0.setSampleRate(44100);
|
||||
QVERIFY(audioFormat0 != audioFormat1);
|
||||
QVERIFY(!(audioFormat0 == audioFormat1));
|
||||
}
|
||||
@@ -188,8 +180,8 @@ void tst_QAudioFormat::checkAssignment()
|
||||
QAudioFormat audioFormat0;
|
||||
QAudioFormat audioFormat1;
|
||||
|
||||
audioFormat0.setFrequency(8000);
|
||||
audioFormat0.setChannels(1);
|
||||
audioFormat0.setSampleRate(8000);
|
||||
audioFormat0.setChannelCount(1);
|
||||
audioFormat0.setSampleSize(8);
|
||||
audioFormat0.setCodec("audio/pcm");
|
||||
audioFormat0.setByteOrder(QAudioFormat::LittleEndian);
|
||||
@@ -219,15 +211,15 @@ void tst_QAudioFormat::checkChannelCount()
|
||||
// they should always be equal
|
||||
QAudioFormat audioFormat;
|
||||
QVERIFY(audioFormat.channelCount() == -1);
|
||||
QVERIFY(audioFormat.channels() == -1);
|
||||
QVERIFY(audioFormat.channelCount() == -1);
|
||||
|
||||
audioFormat.setChannelCount(123);
|
||||
QVERIFY(audioFormat.channelCount() == 123);
|
||||
QVERIFY(audioFormat.channels() == 123);
|
||||
QVERIFY(audioFormat.channelCount() == 123);
|
||||
|
||||
audioFormat.setChannels(5);
|
||||
audioFormat.setChannelCount(5);
|
||||
QVERIFY(audioFormat.channelCount() == 5);
|
||||
QVERIFY(audioFormat.channelCount() == 5);
|
||||
QVERIFY(audioFormat.channels() == 5);
|
||||
}
|
||||
|
||||
void tst_QAudioFormat::debugOperator_data()
|
||||
|
||||
@@ -71,9 +71,9 @@ public:
|
||||
, mPosition(-1)
|
||||
, mSerial(0)
|
||||
{
|
||||
mFormat.setChannels(1);
|
||||
mFormat.setChannelCount(1);
|
||||
mFormat.setSampleSize(8);
|
||||
mFormat.setFrequency(1000);
|
||||
mFormat.setSampleRate(1000);
|
||||
mFormat.setCodec("audio/x-raw");
|
||||
mFormat.setSampleType(QAudioFormat::UnSignedInt);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public:
|
||||
|
||||
qint64 duration() const
|
||||
{
|
||||
return (sizeof(mSerial) * MOCK_DECODER_MAX_BUFFERS * qint64(1000)) / (mFormat.sampleRate() * mFormat.channels());
|
||||
return (sizeof(mSerial) * MOCK_DECODER_MAX_BUFFERS * qint64(1000)) / (mFormat.sampleRate() * mFormat.channelCount());
|
||||
}
|
||||
|
||||
private slots:
|
||||
@@ -198,7 +198,7 @@ private slots:
|
||||
if (mBuffers.length() < 3) {
|
||||
QByteArray b(sizeof(mSerial), 0);
|
||||
memcpy(b.data(), &mSerial, sizeof(mSerial));
|
||||
qint64 position = (sizeof(mSerial) * mSerial * qint64(1000000)) / (mFormat.sampleRate() * mFormat.channels());
|
||||
qint64 position = (sizeof(mSerial) * mSerial * qint64(1000000)) / (mFormat.sampleRate() * mFormat.channelCount());
|
||||
mSerial++;
|
||||
mBuffers.push_back(QAudioBuffer(b, mFormat, position));
|
||||
emit bufferReady();
|
||||
|
||||
@@ -184,7 +184,7 @@ void tst_QWaveDecoder::file()
|
||||
QVERIFY(waveDecoder.duration() == 250);
|
||||
QAudioFormat format = waveDecoder.audioFormat();
|
||||
QVERIFY(format.isValid());
|
||||
QVERIFY(format.channels() == channels);
|
||||
QVERIFY(format.channelCount() == channels);
|
||||
QVERIFY(format.sampleSize() == samplesize);
|
||||
QVERIFY(format.sampleRate() == samplerate);
|
||||
if (format.sampleSize() != 8) {
|
||||
@@ -247,7 +247,7 @@ void tst_QWaveDecoder::http()
|
||||
QVERIFY(waveDecoder.duration() == 250);
|
||||
QAudioFormat format = waveDecoder.audioFormat();
|
||||
QVERIFY(format.isValid());
|
||||
QVERIFY(format.channels() == channels);
|
||||
QVERIFY(format.channelCount() == channels);
|
||||
QVERIFY(format.sampleSize() == samplesize);
|
||||
QVERIFY(format.sampleRate() == samplerate);
|
||||
if (format.sampleSize() != 8) {
|
||||
|
||||
Reference in New Issue
Block a user