kopia lustrzana https://gitlab.com/eliggett/wfview
Rename in/out Formats to avoid confusion
rodzic
8a4b9f1934
commit
b7f83a7807
124
audiohandler.cpp
124
audiohandler.cpp
|
@ -56,19 +56,19 @@ audioHandler::~audioHandler()
|
||||||
|
|
||||||
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
", bits" << inFormat.sampleSize() <<
|
", bits" << radioFormat.sampleSize() <<
|
||||||
#else
|
#else
|
||||||
", format" << inFormat.sampleFormat() <<
|
", format" << radioFormat.sampleFormat() <<
|
||||||
#endif
|
#endif
|
||||||
", codec" << setup.codec <<
|
", codec" << setup.codec <<
|
||||||
", latency" << setup.latency <<
|
", latency" << setup.latency <<
|
||||||
", localAFGain" << setup.localAFgain <<
|
", localAFGain" << setup.localAFgain <<
|
||||||
", radioChan" << inFormat.channelCount() <<
|
", radioChan" << radioFormat.channelCount() <<
|
||||||
", resampleQuality" << setup.resampleQuality <<
|
", resampleQuality" << setup.resampleQuality <<
|
||||||
", samplerate" << inFormat.sampleRate() <<
|
", samplerate" << radioFormat.sampleRate() <<
|
||||||
", uLaw" << setup.ulaw;
|
", uLaw" << setup.ulaw;
|
||||||
|
|
||||||
inFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
radioFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
||||||
codec = LPCM;
|
codec = LPCM;
|
||||||
if (setup.codec == 0x01 || setup.codec == 0x20)
|
if (setup.codec == 0x01 || setup.codec == 0x20)
|
||||||
codec = PCMU;
|
codec = PCMU;
|
||||||
|
@ -76,72 +76,72 @@ audioHandler::~audioHandler()
|
||||||
codec = OPUS;
|
codec = OPUS;
|
||||||
|
|
||||||
|
|
||||||
outFormat = setup.port.preferredFormat();
|
nativeFormat = setup.port.preferredFormat();
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||||
#else
|
#else
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate();
|
"Sample Rate" << nativeFormat.sampleRate();
|
||||||
#endif
|
#endif
|
||||||
if (outFormat.channelCount() > 2) {
|
if (nativeFormat.channelCount() > 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
else if (outFormat.channelCount() < 1)
|
else if (nativeFormat.channelCount() < 1)
|
||||||
{
|
{
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request stereo reverting to mono";
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request stereo reverting to mono";
|
||||||
outFormat.setChannelCount(1);
|
nativeFormat.setChannelCount(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFormat.sampleRate() < 48000) {
|
if (nativeFormat.sampleRate() < 48000) {
|
||||||
int tempRate=outFormat.sampleRate();
|
int tempRate=nativeFormat.sampleRate();
|
||||||
outFormat.setSampleRate(48000);
|
nativeFormat.setSampleRate(48000);
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 48K, reverting to "<< tempRate;
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 48K, reverting to "<< tempRate;
|
||||||
outFormat.setSampleRate(tempRate);
|
nativeFormat.setSampleRate(tempRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
|
|
||||||
if (outFormat.sampleType() == QAudioFormat::UnSignedInt && outFormat.sampleSize() == 8) {
|
if (nativeFormat.sampleType() == QAudioFormat::UnSignedInt && nativeFormat.sampleSize() == 8) {
|
||||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||||
outFormat.setSampleSize(16);
|
nativeFormat.setSampleSize(16);
|
||||||
|
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 16bit Signed samples, reverting to 8bit Unsigned";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 16bit Signed samples, reverting to 8bit Unsigned";
|
||||||
outFormat.setSampleType(QAudioFormat::UnSignedInt);
|
nativeFormat.setSampleType(QAudioFormat::UnSignedInt);
|
||||||
outFormat.setSampleSize(8);
|
nativeFormat.setSampleSize(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (outFormat.sampleFormat() == QAudioFormat::UInt8) {
|
if (nativeFormat.sampleFormat() == QAudioFormat::UInt8) {
|
||||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
nativeFormat.setSampleFormat(QAudioFormat::Int16);
|
||||||
|
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 16bit Signed samples, reverting to 8bit Unsigned";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request 16bit Signed samples, reverting to 8bit Unsigned";
|
||||||
outFormat.setSampleFormat(QAudioFormat::UInt8);
|
nativeFormat.setSampleFormat(QAudioFormat::UInt8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (outFormat.sampleType()==QAudioFormat::SignedInt) {
|
if (nativeFormat.sampleType()==QAudioFormat::SignedInt) {
|
||||||
outFormat.setSampleType(QAudioFormat::Float);
|
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||||
outFormat.setSampleSize(32);
|
nativeFormat.setSampleSize(32);
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select 32bit Float failed, reverting to SignedInt";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select 32bit Float failed, reverting to SignedInt";
|
||||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||||
outFormat.setSampleSize(16);
|
nativeFormat.setSampleSize(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -149,22 +149,22 @@ audioHandler::~audioHandler()
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
|
|
||||||
if (outFormat.sampleSize() == 24) {
|
if (nativeFormat.sampleSize() == 24) {
|
||||||
// We can't convert this easily so use 32 bit instead.
|
// We can't convert this easily so use 32 bit instead.
|
||||||
outFormat.setSampleSize(32);
|
nativeFormat.setSampleSize(32);
|
||||||
if (!setup.port.isFormatSupported(outFormat)) {
|
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "24 bit requested and 32 bit audio not supported, try 16 bit instead";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "24 bit requested and 32 bit audio not supported, try 16 bit instead";
|
||||||
outFormat.setSampleSize(16);
|
nativeFormat.setSampleSize(16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||||
#else
|
#else
|
||||||
|
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -188,24 +188,24 @@ audioHandler::~audioHandler()
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
audioInput = new QAudioInput(setup.port, outFormat, this);
|
audioInput = new QAudioInput(setup.port, nativeFormat, this);
|
||||||
#else
|
#else
|
||||||
audioInput = new QAudioSource(setup.port, outFormat, this);
|
audioInput = new QAudioSource(setup.port, nativeFormat, this);
|
||||||
#endif
|
#endif
|
||||||
connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
||||||
emit setupConverter(outFormat, codecType::LPCM, inFormat, codec, 7, setup.resampleQuality);
|
emit setupConverter(nativeFormat, codecType::LPCM, radioFormat, codec, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
audioOutput = new QAudioOutput(setup.port, outFormat, this);
|
audioOutput = new QAudioOutput(setup.port, nativeFormat, this);
|
||||||
#else
|
#else
|
||||||
audioOutput = new QAudioSink(setup.port, outFormat, this);
|
audioOutput = new QAudioSink(setup.port, nativeFormat, this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
connect(audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
||||||
emit setupConverter(inFormat, codec, outFormat, codecType::LPCM, 7, setup.resampleQuality);
|
emit setupConverter(radioFormat, codec, nativeFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,9 +232,9 @@ void audioHandler::start()
|
||||||
//this->open(QIODevice::WriteOnly);
|
//this->open(QIODevice::WriteOnly);
|
||||||
//audioInput->start(this);
|
//audioInput->start(this);
|
||||||
#if (defined(Q_OS_WIN) && (QT_VERSION < QT_VERSION_CHECK(6,0,0)))
|
#if (defined(Q_OS_WIN) && (QT_VERSION < QT_VERSION_CHECK(6,0,0)))
|
||||||
audioInput->setBufferSize(inFormat.bytesForDuration(setup.latency * 100));
|
audioInput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 100));
|
||||||
#else
|
#else
|
||||||
audioInput->setBufferSize(inFormat.bytesForDuration(setup.latency * 1000));
|
audioInput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 1000));
|
||||||
#endif
|
#endif
|
||||||
audioDevice = audioInput->start();
|
audioDevice = audioInput->start();
|
||||||
connect(audioInput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
connect(audioInput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
||||||
|
@ -245,9 +245,9 @@ void audioHandler::start()
|
||||||
else {
|
else {
|
||||||
// Buffer size must be set before audio is started.
|
// Buffer size must be set before audio is started.
|
||||||
#if (defined(Q_OS_WIN) && (QT_VERSION < QT_VERSION_CHECK(6,0,0)))
|
#if (defined(Q_OS_WIN) && (QT_VERSION < QT_VERSION_CHECK(6,0,0)))
|
||||||
audioOutput->setBufferSize(outFormat.bytesForDuration(setup.latency * 100));
|
audioOutput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 100));
|
||||||
#else
|
#else
|
||||||
audioOutput->setBufferSize(outFormat.bytesForDuration(setup.latency * 1000));
|
audioOutput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 1000));
|
||||||
#endif
|
#endif
|
||||||
audioDevice = audioOutput->start();
|
audioDevice = audioOutput->start();
|
||||||
connect(audioOutput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
connect(audioOutput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
||||||
|
@ -298,7 +298,7 @@ void audioHandler::convertedOutput(audioPacket packet) {
|
||||||
|
|
||||||
if (packet.data.size() > 0 ) {
|
if (packet.data.size() > 0 ) {
|
||||||
|
|
||||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audioOutput->bufferSize() - audioOutput->bytesFree()) / 1000);
|
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (nativeFormat.durationForBytes(audioOutput->bufferSize() - audioOutput->bytesFree()) / 1000);
|
||||||
if (audioDevice != Q_NULLPTR) {
|
if (audioDevice != Q_NULLPTR) {
|
||||||
if (audioDevice->write(packet.data) < packet.data.size()) {
|
if (audioDevice->write(packet.data) < packet.data.size()) {
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Buffer full!";
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Buffer full!";
|
||||||
|
@ -328,7 +328,7 @@ void audioHandler::getNextAudioChunk()
|
||||||
if (audioDevice) {
|
if (audioDevice) {
|
||||||
tempBuf.data.append(audioDevice->readAll());
|
tempBuf.data.append(audioDevice->readAll());
|
||||||
}
|
}
|
||||||
if (tempBuf.data.length() >= outFormat.bytesForDuration(setup.blockSize * 1000)) {
|
if (tempBuf.data.length() >= nativeFormat.bytesForDuration(setup.blockSize * 1000)) {
|
||||||
audioPacket packet;
|
audioPacket packet;
|
||||||
packet.time = QTime::currentTime();
|
packet.time = QTime::currentTime();
|
||||||
packet.sent = 0;
|
packet.sent = 0;
|
||||||
|
@ -336,14 +336,14 @@ void audioHandler::getNextAudioChunk()
|
||||||
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
||||||
//QTime startProcessing = QTime::currentTime();
|
//QTime startProcessing = QTime::currentTime();
|
||||||
packet.data.clear();
|
packet.data.clear();
|
||||||
packet.data = tempBuf.data.mid(0, outFormat.bytesForDuration(setup.blockSize * 1000));
|
packet.data = tempBuf.data.mid(0, nativeFormat.bytesForDuration(setup.blockSize * 1000));
|
||||||
tempBuf.data.remove(0, outFormat.bytesForDuration(setup.blockSize * 1000));
|
tempBuf.data.remove(0, nativeFormat.bytesForDuration(setup.blockSize * 1000));
|
||||||
|
|
||||||
emit sendToConverter(packet);
|
emit sendToConverter(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there is still enough data in the buffer, call myself again in 20ms */
|
/* If there is still enough data in the buffer, call myself again in 20ms */
|
||||||
if (tempBuf.data.length() >= outFormat.bytesForDuration(setup.blockSize * 1000)) {
|
if (tempBuf.data.length() >= nativeFormat.bytesForDuration(setup.blockSize * 1000)) {
|
||||||
QTimer::singleShot(setup.blockSize, this, &audioHandler::getNextAudioChunk);
|
QTimer::singleShot(setup.blockSize, this, &audioHandler::getNextAudioChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ void audioHandler::changeLatency(const quint16 newSize)
|
||||||
stop();
|
stop();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Configured latency: " << setup.latency << "Buffer Duration:" << outFormat.durationForBytes(audioOutput->bufferSize())/1000 << "ms";
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Configured latency: " << setup.latency << "Buffer Duration:" << nativeFormat.durationForBytes(audioOutput->bufferSize())/1000 << "ms";
|
||||||
|
|
||||||
}
|
}
|
||||||
int audioHandler::getLatency()
|
int audioHandler::getLatency()
|
||||||
|
|
|
@ -99,8 +99,8 @@ private:
|
||||||
|
|
||||||
QIODevice* audioDevice=Q_NULLPTR;
|
QIODevice* audioDevice=Q_NULLPTR;
|
||||||
|
|
||||||
QAudioFormat inFormat;
|
QAudioFormat radioFormat;
|
||||||
QAudioFormat outFormat;
|
QAudioFormat nativeFormat;
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
QAudioOutput* audioOutput = Q_NULLPTR;
|
QAudioOutput* audioOutput = Q_NULLPTR;
|
||||||
QAudioInput* audioInput = Q_NULLPTR;
|
QAudioInput* audioInput = Q_NULLPTR;
|
||||||
|
|
|
@ -42,20 +42,20 @@ bool paHandler::init(audioSetup setup)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
radioFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
||||||
|
|
||||||
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
", bits" << inFormat.sampleSize() <<
|
", bits" << radioFormat.sampleSize() <<
|
||||||
#else
|
#else
|
||||||
", format" << inFormat.sampleFormat() <<
|
", format" << radioFormat.sampleFormat() <<
|
||||||
#endif
|
#endif
|
||||||
", codec" << setup.codec <<
|
", codec" << setup.codec <<
|
||||||
", latency" << setup.latency <<
|
", latency" << setup.latency <<
|
||||||
", localAFGain" << setup.localAFgain <<
|
", localAFGain" << setup.localAFgain <<
|
||||||
", radioChan" << inFormat.channelCount() <<
|
", radioChan" << radioFormat.channelCount() <<
|
||||||
", resampleQuality" << setup.resampleQuality <<
|
", resampleQuality" << setup.resampleQuality <<
|
||||||
", samplerate" << inFormat.sampleRate() <<
|
", samplerate" << radioFormat.sampleRate() <<
|
||||||
", uLaw" << setup.ulaw;
|
", uLaw" << setup.ulaw;
|
||||||
|
|
||||||
PaError err;
|
PaError err;
|
||||||
|
@ -85,51 +85,51 @@ bool paHandler::init(audioSetup setup)
|
||||||
|
|
||||||
|
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
outFormat.setChannelCount(info->maxInputChannels);
|
nativeFormat.setChannelCount(info->maxInputChannels);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
outFormat.setChannelCount(info->maxOutputChannels);
|
nativeFormat.setChannelCount(info->maxOutputChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
aParams.suggestedLatency = (float)setup.latency / 1000.0f;
|
aParams.suggestedLatency = (float)setup.latency / 1000.0f;
|
||||||
outFormat.setSampleRate(info->defaultSampleRate);
|
nativeFormat.setSampleRate(info->defaultSampleRate);
|
||||||
aParams.sampleFormat = paFloat32;
|
aParams.sampleFormat = paFloat32;
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
outFormat.setSampleSize(32);
|
nativeFormat.setSampleSize(32);
|
||||||
outFormat.setSampleType(QAudioFormat::Float);
|
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||||
outFormat.setByteOrder(QAudioFormat::LittleEndian);
|
nativeFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
outFormat.setCodec("audio/pcm");
|
nativeFormat.setCodec("audio/pcm");
|
||||||
#else
|
#else
|
||||||
outFormat.setSampleFormat(QAudioFormat::Float);
|
nativeFormat.setSampleFormat(QAudioFormat::Float);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (outFormat.channelCount() > 2) {
|
if (nativeFormat.channelCount() > 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
else if (outFormat.channelCount() < 1)
|
else if (nativeFormat.channelCount() < 1)
|
||||||
{
|
{
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
aParams.channelCount = outFormat.channelCount();
|
aParams.channelCount = nativeFormat.channelCount();
|
||||||
|
|
||||||
if (outFormat.sampleRate() < 44100) {
|
if (nativeFormat.sampleRate() < 44100) {
|
||||||
outFormat.setSampleRate(48000);
|
nativeFormat.setSampleRate(48000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||||
#else
|
#else
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We "hopefully" now have a valid format that is supported so try connecting
|
// We "hopefully" now have a valid format that is supported so try connecting
|
||||||
|
@ -152,7 +152,7 @@ bool paHandler::init(audioSetup setup)
|
||||||
aParams.hostApiSpecificStreamInfo = NULL;
|
aParams.hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
// Per channel chunk size.
|
// Per channel chunk size.
|
||||||
this->chunkSize = outFormat.framesForDuration(setup.blockSize * 1000);
|
this->chunkSize = nativeFormat.framesForDuration(setup.blockSize * 1000);
|
||||||
|
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Chunk size" << this->chunkSize;
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Chunk size" << this->chunkSize;
|
||||||
// Check the format is supported
|
// Check the format is supported
|
||||||
|
@ -163,39 +163,39 @@ bool paHandler::init(audioSetup setup)
|
||||||
int errCount = 0;
|
int errCount = 0;
|
||||||
while (err != paNoError) {
|
while (err != paNoError) {
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
err = Pa_IsFormatSupported(&aParams, NULL, outFormat.sampleRate());
|
err = Pa_IsFormatSupported(&aParams, NULL, nativeFormat.sampleRate());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = Pa_IsFormatSupported(NULL, &aParams, outFormat.sampleRate());
|
err = Pa_IsFormatSupported(NULL, &aParams, nativeFormat.sampleRate());
|
||||||
}
|
}
|
||||||
if (err == paInvalidChannelCount)
|
if (err == paInvalidChannelCount)
|
||||||
{
|
{
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported channel count" << aParams.channelCount;
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported channel count" << aParams.channelCount;
|
||||||
if (aParams.channelCount == 2) {
|
if (aParams.channelCount == 2) {
|
||||||
aParams.channelCount = 1;
|
aParams.channelCount = 1;
|
||||||
outFormat.setChannelCount(1);
|
nativeFormat.setChannelCount(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
aParams.channelCount = 2;
|
aParams.channelCount = 2;
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err == paInvalidSampleRate)
|
if (err == paInvalidSampleRate)
|
||||||
{
|
{
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample rate" << outFormat.sampleRate();
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample rate" << nativeFormat.sampleRate();
|
||||||
outFormat.setSampleRate(44100);
|
nativeFormat.setSampleRate(44100);
|
||||||
}
|
}
|
||||||
if (err == paSampleFormatNotSupported)
|
if (err == paSampleFormatNotSupported)
|
||||||
{
|
{
|
||||||
aParams.sampleFormat = paInt16;
|
aParams.sampleFormat = paInt16;
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << outFormat.sampleType();
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << nativeFormat.sampleType();
|
||||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||||
outFormat.setSampleSize(16);
|
nativeFormat.setSampleSize(16);
|
||||||
#else
|
#else
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << outFormat.sampleFormat();
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << nativeFormat.sampleFormat();
|
||||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
nativeFormat.setSampleFormat(QAudioFormat::Int16);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,13 +208,13 @@ bool paHandler::init(audioSetup setup)
|
||||||
|
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
|
|
||||||
err = Pa_OpenStream(&audio, &aParams, 0, outFormat.sampleRate(), this->chunkSize, paNoFlag, &paHandler::staticWrite, (void*)this);
|
err = Pa_OpenStream(&audio, &aParams, 0, nativeFormat.sampleRate(), this->chunkSize, paNoFlag, &paHandler::staticWrite, (void*)this);
|
||||||
emit setupConverter(outFormat, codecType::LPCM, inFormat, codec, 7, setup.resampleQuality);
|
emit setupConverter(nativeFormat, codecType::LPCM, radioFormat, codec, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
err = Pa_OpenStream(&audio, 0, &aParams, outFormat.sampleRate(), this->chunkSize, paNoFlag, NULL, NULL);
|
err = Pa_OpenStream(&audio, 0, &aParams, nativeFormat.sampleRate(), this->chunkSize, paNoFlag, NULL, NULL);
|
||||||
emit setupConverter(inFormat, codec, outFormat, codecType::LPCM, 7, setup.resampleQuality);
|
emit setupConverter(radioFormat, codec, nativeFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ int paHandler::writeData(const void* inputBuffer, void* outputBuffer,
|
||||||
packet.sent = 0;
|
packet.sent = 0;
|
||||||
packet.volume = volume;
|
packet.volume = volume;
|
||||||
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
||||||
packet.data.append((char*)inputBuffer, nFrames*outFormat.bytesPerFrame());
|
packet.data.append((char*)inputBuffer, nFrames*nativeFormat.bytesPerFrame());
|
||||||
emit sendToConverter(packet);
|
emit sendToConverter(packet);
|
||||||
|
|
||||||
if (status == paInputUnderflow) {
|
if (status == paInputUnderflow) {
|
||||||
|
@ -296,7 +296,7 @@ void paHandler::convertedOutput(audioPacket packet) {
|
||||||
|
|
||||||
if (Pa_IsStreamActive(audio) == 1) {
|
if (Pa_IsStreamActive(audio) == 1) {
|
||||||
if (currentLatency < (setup.latency+latencyAllowance)) {
|
if (currentLatency < (setup.latency+latencyAllowance)) {
|
||||||
PaError err = Pa_WriteStream(audio, (char*)packet.data.data(), packet.data.size() / outFormat.bytesPerFrame());
|
PaError err = Pa_WriteStream(audio, (char*)packet.data.data(), packet.data.size() / nativeFormat.bytesPerFrame());
|
||||||
|
|
||||||
if (err != paNoError) {
|
if (err != paNoError) {
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Error writing audio!";
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Error writing audio!";
|
||||||
|
|
|
@ -85,8 +85,8 @@ private:
|
||||||
qreal volume = 1.0;
|
qreal volume = 1.0;
|
||||||
|
|
||||||
audioSetup setup;
|
audioSetup setup;
|
||||||
QAudioFormat inFormat;
|
QAudioFormat radioFormat;
|
||||||
QAudioFormat outFormat;
|
QAudioFormat nativeFormat;
|
||||||
audioConverter* converter = Q_NULLPTR;
|
audioConverter* converter = Q_NULLPTR;
|
||||||
QThread* converterThread = Q_NULLPTR;
|
QThread* converterThread = Q_NULLPTR;
|
||||||
bool isUnderrun = false;
|
bool isUnderrun = false;
|
||||||
|
|
|
@ -55,20 +55,20 @@ bool rtHandler::init(audioSetup setup)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
radioFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
||||||
|
|
||||||
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name <<
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
", bits" << inFormat.sampleSize() <<
|
", bits" << radioFormat.sampleSize() <<
|
||||||
#else
|
#else
|
||||||
", format" << inFormat.sampleFormat() <<
|
", format" << radioFormat.sampleFormat() <<
|
||||||
#endif
|
#endif
|
||||||
", codec" << setup.codec <<
|
", codec" << setup.codec <<
|
||||||
", latency" << setup.latency <<
|
", latency" << setup.latency <<
|
||||||
", localAFGain" << setup.localAFgain <<
|
", localAFGain" << setup.localAFgain <<
|
||||||
", radioChan" << inFormat.channelCount() <<
|
", radioChan" << radioFormat.channelCount() <<
|
||||||
", resampleQuality" << setup.resampleQuality <<
|
", resampleQuality" << setup.resampleQuality <<
|
||||||
", samplerate" << inFormat.sampleRate() <<
|
", samplerate" << radioFormat.sampleRate() <<
|
||||||
", uLaw" << setup.ulaw;
|
", uLaw" << setup.ulaw;
|
||||||
|
|
||||||
#if !defined(Q_OS_MACX)
|
#if !defined(Q_OS_MACX)
|
||||||
|
@ -123,8 +123,8 @@ bool rtHandler::init(audioSetup setup)
|
||||||
RtAudioFormat sampleFormat;
|
RtAudioFormat sampleFormat;
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
outFormat.setByteOrder(QAudioFormat::LittleEndian);
|
nativeFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
outFormat.setCodec("audio/pcm");
|
nativeFormat.setCodec("audio/pcm");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (info.nativeFormats == 0)
|
if (info.nativeFormats == 0)
|
||||||
|
@ -143,60 +143,60 @@ bool rtHandler::init(audioSetup setup)
|
||||||
|
|
||||||
qInfo(logAudio()) << " Preferred sample rate:" << info.preferredSampleRate;
|
qInfo(logAudio()) << " Preferred sample rate:" << info.preferredSampleRate;
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
outFormat.setChannelCount(info.inputChannels);
|
nativeFormat.setChannelCount(info.inputChannels);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
outFormat.setChannelCount(info.outputChannels);
|
nativeFormat.setChannelCount(info.outputChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
qInfo(logAudio()) << " Channels:" << outFormat.channelCount();
|
qInfo(logAudio()) << " Channels:" << nativeFormat.channelCount();
|
||||||
|
|
||||||
if (outFormat.channelCount() > 2) {
|
if (nativeFormat.channelCount() > 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
else if (outFormat.channelCount() < 1)
|
else if (nativeFormat.channelCount() < 1)
|
||||||
{
|
{
|
||||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "No channels found, aborting setup.";
|
||||||
goto errorHandler;
|
goto errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||||
outFormat.setChannelCount(2);
|
nativeFormat.setChannelCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
aParams.nChannels = outFormat.channelCount();
|
aParams.nChannels = nativeFormat.channelCount();
|
||||||
|
|
||||||
|
|
||||||
outFormat.setSampleRate(info.preferredSampleRate);
|
nativeFormat.setSampleRate(info.preferredSampleRate);
|
||||||
|
|
||||||
if (outFormat.sampleRate() < 44100) {
|
if (nativeFormat.sampleRate() < 44100) {
|
||||||
outFormat.setSampleRate(48000);
|
nativeFormat.setSampleRate(48000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.nativeFormats & RTAUDIO_FLOAT32) {
|
if (info.nativeFormats & RTAUDIO_FLOAT32) {
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
outFormat.setSampleType(QAudioFormat::Float);
|
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||||
outFormat.setSampleSize(32);
|
nativeFormat.setSampleSize(32);
|
||||||
#else
|
#else
|
||||||
outFormat.setSampleFormat(QAudioFormat::Float);
|
nativeFormat.setSampleFormat(QAudioFormat::Float);
|
||||||
#endif
|
#endif
|
||||||
sampleFormat = RTAUDIO_FLOAT32;
|
sampleFormat = RTAUDIO_FLOAT32;
|
||||||
}
|
}
|
||||||
else if (info.nativeFormats & RTAUDIO_SINT32) {
|
else if (info.nativeFormats & RTAUDIO_SINT32) {
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||||
outFormat.setSampleSize(32);
|
nativeFormat.setSampleSize(32);
|
||||||
#else
|
#else
|
||||||
outFormat.setSampleFormat(QAudioFormat::Int32);
|
nativeFormat.setSampleFormat(QAudioFormat::Int32);
|
||||||
#endif
|
#endif
|
||||||
sampleFormat = RTAUDIO_SINT32;
|
sampleFormat = RTAUDIO_SINT32;
|
||||||
}
|
}
|
||||||
else if (info.nativeFormats & RTAUDIO_SINT16) {
|
else if (info.nativeFormats & RTAUDIO_SINT16) {
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||||
outFormat.setSampleSize(16);
|
nativeFormat.setSampleSize(16);
|
||||||
#else
|
#else
|
||||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
nativeFormat.setSampleFormat(QAudioFormat::Int16);
|
||||||
#endif
|
#endif
|
||||||
sampleFormat = RTAUDIO_SINT16;
|
sampleFormat = RTAUDIO_SINT16;
|
||||||
}
|
}
|
||||||
|
@ -207,11 +207,11 @@ bool rtHandler::init(audioSetup setup)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << outFormat.codec() << "Sample Type" << outFormat.sampleType();
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << nativeFormat.codec() << "Sample Type" << nativeFormat.sampleType();
|
||||||
#else
|
#else
|
||||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We "hopefully" now have a valid format that is supported so try connecting
|
// We "hopefully" now have a valid format that is supported so try connecting
|
||||||
|
@ -232,19 +232,19 @@ bool rtHandler::init(audioSetup setup)
|
||||||
|
|
||||||
|
|
||||||
// Per channel chunk size.
|
// Per channel chunk size.
|
||||||
this->chunkSize = outFormat.framesForDuration(setup.blockSize * 1000);
|
this->chunkSize = nativeFormat.framesForDuration(setup.blockSize * 1000);
|
||||||
|
|
||||||
#ifdef RT_EXCEPTION
|
#ifdef RT_EXCEPTION
|
||||||
try {
|
try {
|
||||||
#endif
|
#endif
|
||||||
if (setup.isinput) {
|
if (setup.isinput) {
|
||||||
audio->openStream(NULL, &aParams, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options);
|
audio->openStream(NULL, &aParams, sampleFormat, nativeFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options);
|
||||||
emit setupConverter(outFormat, codecType::LPCM, inFormat, codec, 7, setup.resampleQuality);
|
emit setupConverter(nativeFormat, codecType::LPCM, radioFormat, codec, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
audio->openStream(&aParams, NULL, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticRead, this , &options);
|
audio->openStream(&aParams, NULL, sampleFormat, nativeFormat.sampleRate(), &this->chunkSize, &staticRead, this , &options);
|
||||||
emit setupConverter(inFormat, codec, outFormat, codecType::LPCM, 7, setup.resampleQuality);
|
emit setupConverter(radioFormat, codec, nativeFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
||||||
}
|
}
|
||||||
audio->startStream();
|
audio->startStream();
|
||||||
|
@ -305,7 +305,7 @@ int rtHandler::readData(void* outputBuffer, void* inputBuffer,
|
||||||
{
|
{
|
||||||
Q_UNUSED(inputBuffer);
|
Q_UNUSED(inputBuffer);
|
||||||
Q_UNUSED(streamTime);
|
Q_UNUSED(streamTime);
|
||||||
int nBytes = nFrames * outFormat.bytesPerFrame();
|
int nBytes = nFrames * nativeFormat.bytesPerFrame();
|
||||||
//lastSentSeq = packet.seq;
|
//lastSentSeq = packet.seq;
|
||||||
if (arrayBuffer.length() >= nBytes) {
|
if (arrayBuffer.length() >= nBytes) {
|
||||||
if (audioMutex.tryLock(0)) {
|
if (audioMutex.tryLock(0)) {
|
||||||
|
@ -341,7 +341,7 @@ int rtHandler::writeData(void* outputBuffer, void* inputBuffer,
|
||||||
packet.sent = 0;
|
packet.sent = 0;
|
||||||
packet.volume = volume;
|
packet.volume = volume;
|
||||||
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
||||||
packet.data.append((char*)inputBuffer, nFrames * outFormat.bytesPerFrame());
|
packet.data.append((char*)inputBuffer, nFrames * nativeFormat.bytesPerFrame());
|
||||||
emit sendToConverter(packet);
|
emit sendToConverter(packet);
|
||||||
|
|
||||||
if (status == RTAUDIO_INPUT_OVERFLOW) {
|
if (status == RTAUDIO_INPUT_OVERFLOW) {
|
||||||
|
@ -366,7 +366,7 @@ void rtHandler::convertedOutput(audioPacket packet)
|
||||||
arrayBuffer.append(packet.data);
|
arrayBuffer.append(packet.data);
|
||||||
audioMutex.unlock();
|
audioMutex.unlock();
|
||||||
amplitude = packet.amplitudePeak;
|
amplitude = packet.amplitudePeak;
|
||||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * outFormat.bytesPerFrame()) / 1000);
|
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (nativeFormat.durationForBytes(audio->getStreamLatency() * nativeFormat.bytesPerFrame()) / 1000);
|
||||||
emit haveLevels(getAmplitude(), packet.amplitudeRMS, setup.latency, currentLatency, isUnderrun, isOverrun);
|
emit haveLevels(getAmplitude(), packet.amplitudeRMS, setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ void rtHandler::convertedInput(audioPacket packet)
|
||||||
if (packet.data.size() > 0) {
|
if (packet.data.size() > 0) {
|
||||||
emit haveAudioData(packet);
|
emit haveAudioData(packet);
|
||||||
amplitude = packet.amplitudePeak;
|
amplitude = packet.amplitudePeak;
|
||||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * outFormat.bytesPerFrame()) / 1000);
|
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (nativeFormat.durationForBytes(audio->getStreamLatency() * nativeFormat.bytesPerFrame()) / 1000);
|
||||||
emit haveLevels(getAmplitude(), static_cast<quint16>(packet.amplitudeRMS * 255.0), setup.latency, currentLatency, isUnderrun, isOverrun);
|
emit haveLevels(getAmplitude(), static_cast<quint16>(packet.amplitudeRMS * 255.0), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,8 @@ private:
|
||||||
qreal volume = 1.0;
|
qreal volume = 1.0;
|
||||||
|
|
||||||
audioSetup setup;
|
audioSetup setup;
|
||||||
QAudioFormat inFormat;
|
QAudioFormat radioFormat;
|
||||||
QAudioFormat outFormat;
|
QAudioFormat nativeFormat;
|
||||||
audioConverter* converter = Q_NULLPTR;
|
audioConverter* converter = Q_NULLPTR;
|
||||||
QThread* converterThread = Q_NULLPTR;
|
QThread* converterThread = Q_NULLPTR;
|
||||||
QByteArray arrayBuffer;
|
QByteArray arrayBuffer;
|
||||||
|
|
Ładowanie…
Reference in New Issue