mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
Ref T730, use m_deviceInfo.nearestFormat (makes player working with WSAPI plugin)
This commit is contained in:
committed by
Mat Sutcliffe
parent
6111c428e9
commit
b65b2caa76
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "threadedtonepairplayer.h"
|
#include "threadedtonepairplayer.h"
|
||||||
|
#include "blackmisc/logmessage.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
@@ -26,20 +28,26 @@ namespace BlackSound
|
|||||||
QMutexLocker ml(&m_mutex);
|
QMutexLocker ml(&m_mutex);
|
||||||
if (m_audioOutput->state() != QAudio::StoppedState) { return; }
|
if (m_audioOutput->state() != QAudio::StoppedState) { return; }
|
||||||
|
|
||||||
m_bufferData = getAudioByTonePairs(tonePairs);
|
m_bufferData = this->getAudioByTonePairs(tonePairs);
|
||||||
m_audioOutput->setVolume(static_cast<qreal>(0.01 * volume));
|
m_audioOutput->setVolume(static_cast<qreal>(0.01 * volume));
|
||||||
QTimer::singleShot(0, this, &CThreadedTonePairPlayer::playBuffer);
|
QTimer::singleShot(0, this, &CThreadedTonePairPlayer::playBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedTonePairPlayer::initialize()
|
void CThreadedTonePairPlayer::initialize()
|
||||||
{
|
{
|
||||||
m_audioFormat.setSampleRate(44100);
|
CLogMessage(this).info(u"CThreadedTonePairPlayer for device '%1'") << m_deviceInfo.deviceName();
|
||||||
m_audioFormat.setChannelCount(1);
|
QAudioFormat format;
|
||||||
m_audioFormat.setSampleSize(16); // 8 or 16 works
|
format.setSampleRate(44100);
|
||||||
m_audioFormat.setCodec("audio/pcm");
|
format.setChannelCount(1);
|
||||||
m_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
|
format.setSampleSize(16); // 8 or 16 works
|
||||||
m_audioFormat.setSampleType(QAudioFormat::SignedInt);
|
format.setCodec("audio/pcm");
|
||||||
|
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
|
format.setSampleType(QAudioFormat::SignedInt);
|
||||||
|
if (!m_deviceInfo.isFormatSupported(format))
|
||||||
|
{
|
||||||
|
format = m_deviceInfo.nearestFormat(format);
|
||||||
|
}
|
||||||
|
m_audioFormat = format;
|
||||||
m_audioOutput = new QAudioOutput(m_deviceInfo, m_audioFormat, this);
|
m_audioOutput = new QAudioOutput(m_deviceInfo, m_audioFormat, this);
|
||||||
connect(m_audioOutput, &QAudioOutput::stateChanged, this, &CThreadedTonePairPlayer::handleStateChanged);
|
connect(m_audioOutput, &QAudioOutput::stateChanged, this, &CThreadedTonePairPlayer::handleStateChanged);
|
||||||
}
|
}
|
||||||
@@ -95,7 +103,7 @@ namespace BlackSound
|
|||||||
|
|
||||||
QByteArray bufferData;
|
QByteArray bufferData;
|
||||||
qint64 bytesPerTonePair = m_audioFormat.sampleRate() * bytesForAllChannels * tonePair.getDurationMs() / 1000;
|
qint64 bytesPerTonePair = m_audioFormat.sampleRate() * bytesForAllChannels * tonePair.getDurationMs() / 1000;
|
||||||
bufferData.resize(bytesPerTonePair);
|
bufferData.resize(static_cast<int>(bytesPerTonePair));
|
||||||
unsigned char *bufferPointer = reinterpret_cast<unsigned char *>(bufferData.data());
|
unsigned char *bufferPointer = reinterpret_cast<unsigned char *>(bufferData.data());
|
||||||
|
|
||||||
qint64 last0AmplitudeSample = bytesPerTonePair; // last sample when amplitude was 0
|
qint64 last0AmplitudeSample = bytesPerTonePair; // last sample when amplitude was 0
|
||||||
@@ -160,7 +168,7 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
Q_ASSERT(this->m_audioFormat.sampleSize() == 16);
|
Q_ASSERT(this->m_audioFormat.sampleSize() == 16);
|
||||||
Q_ASSERT(this->m_audioFormat.sampleType() == QAudioFormat::SignedInt);
|
Q_ASSERT(this->m_audioFormat.sampleType() == QAudioFormat::SignedInt);
|
||||||
Q_ASSERT(this->m_audioFormat.byteOrder() == QAudioFormat::LittleEndian);
|
Q_ASSERT(this->m_audioFormat.byteOrder() == QAudioFormat::LittleEndian);
|
||||||
|
|
||||||
qint16 value = static_cast<qint16>(amplitude * 32767);
|
qint16 value = static_cast<qint16>(amplitude * 32767);
|
||||||
qToLittleEndian<qint16>(value, bufferPointer);
|
qToLittleEndian<qint16>(value, bufferPointer);
|
||||||
|
|||||||
Reference in New Issue
Block a user