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 <<
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
", bits" << inFormat.sampleSize() <<
|
||||
", bits" << radioFormat.sampleSize() <<
|
||||
#else
|
||||
", format" << inFormat.sampleFormat() <<
|
||||
", format" << radioFormat.sampleFormat() <<
|
||||
#endif
|
||||
", codec" << setup.codec <<
|
||||
", latency" << setup.latency <<
|
||||
", localAFGain" << setup.localAFgain <<
|
||||
", radioChan" << inFormat.channelCount() <<
|
||||
", radioChan" << radioFormat.channelCount() <<
|
||||
", resampleQuality" << setup.resampleQuality <<
|
||||
", samplerate" << inFormat.sampleRate() <<
|
||||
", samplerate" << radioFormat.sampleRate() <<
|
||||
", uLaw" << setup.ulaw;
|
||||
|
||||
inFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
||||
radioFormat = toQAudioFormat(setup.codec, setup.sampleRate);
|
||||
codec = LPCM;
|
||||
if (setup.codec == 0x01 || setup.codec == 0x20)
|
||||
codec = PCMU;
|
||||
|
@ -76,72 +76,72 @@ audioHandler::~audioHandler()
|
|||
codec = OPUS;
|
||||
|
||||
|
||||
outFormat = setup.port.preferredFormat();
|
||||
nativeFormat = setup.port.preferredFormat();
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||
#else
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate();
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Preferred Format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate();
|
||||
#endif
|
||||
if (outFormat.channelCount() > 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (nativeFormat.channelCount() > 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.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (!setup.port.isFormatSupported(outFormat)) {
|
||||
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||
nativeFormat.setChannelCount(2);
|
||||
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot request stereo reverting to mono";
|
||||
outFormat.setChannelCount(1);
|
||||
nativeFormat.setChannelCount(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (outFormat.sampleRate() < 48000) {
|
||||
int tempRate=outFormat.sampleRate();
|
||||
outFormat.setSampleRate(48000);
|
||||
if (!setup.port.isFormatSupported(outFormat)) {
|
||||
if (nativeFormat.sampleRate() < 48000) {
|
||||
int tempRate=nativeFormat.sampleRate();
|
||||
nativeFormat.setSampleRate(48000);
|
||||
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||
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 (outFormat.sampleType() == QAudioFormat::UnSignedInt && outFormat.sampleSize() == 8) {
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(16);
|
||||
if (nativeFormat.sampleType() == QAudioFormat::UnSignedInt && nativeFormat.sampleSize() == 8) {
|
||||
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
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";
|
||||
outFormat.setSampleType(QAudioFormat::UnSignedInt);
|
||||
outFormat.setSampleSize(8);
|
||||
nativeFormat.setSampleType(QAudioFormat::UnSignedInt);
|
||||
nativeFormat.setSampleSize(8);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (outFormat.sampleFormat() == QAudioFormat::UInt8) {
|
||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
if (nativeFormat.sampleFormat() == QAudioFormat::UInt8) {
|
||||
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";
|
||||
outFormat.setSampleFormat(QAudioFormat::UInt8);
|
||||
nativeFormat.setSampleFormat(QAudioFormat::UInt8);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
if (outFormat.sampleType()==QAudioFormat::SignedInt) {
|
||||
outFormat.setSampleType(QAudioFormat::Float);
|
||||
outFormat.setSampleSize(32);
|
||||
if (!setup.port.isFormatSupported(outFormat)) {
|
||||
if (nativeFormat.sampleType()==QAudioFormat::SignedInt) {
|
||||
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||
nativeFormat.setSampleSize(32);
|
||||
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select 32bit Float failed, reverting to SignedInt";
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(16);
|
||||
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
nativeFormat.setSampleSize(16);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -149,22 +149,22 @@ audioHandler::~audioHandler()
|
|||
|
||||
#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.
|
||||
outFormat.setSampleSize(32);
|
||||
if (!setup.port.isFormatSupported(outFormat)) {
|
||||
nativeFormat.setSampleSize(32);
|
||||
if (!setup.port.isFormatSupported(nativeFormat)) {
|
||||
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() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||
#else
|
||||
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -188,24 +188,24 @@ audioHandler::~audioHandler()
|
|||
if (setup.isinput) {
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
audioInput = new QAudioInput(setup.port, outFormat, this);
|
||||
audioInput = new QAudioInput(setup.port, nativeFormat, this);
|
||||
#else
|
||||
audioInput = new QAudioSource(setup.port, outFormat, this);
|
||||
audioInput = new QAudioSource(setup.port, nativeFormat, this);
|
||||
#endif
|
||||
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)));
|
||||
}
|
||||
else {
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
audioOutput = new QAudioOutput(setup.port, outFormat, this);
|
||||
audioOutput = new QAudioOutput(setup.port, nativeFormat, this);
|
||||
#else
|
||||
audioOutput = new QAudioSink(setup.port, outFormat, this);
|
||||
audioOutput = new QAudioSink(setup.port, nativeFormat, this);
|
||||
#endif
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
@ -232,9 +232,9 @@ void audioHandler::start()
|
|||
//this->open(QIODevice::WriteOnly);
|
||||
//audioInput->start(this);
|
||||
#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
|
||||
audioInput->setBufferSize(inFormat.bytesForDuration(setup.latency * 1000));
|
||||
audioInput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 1000));
|
||||
#endif
|
||||
audioDevice = audioInput->start();
|
||||
connect(audioInput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
||||
|
@ -245,9 +245,9 @@ void audioHandler::start()
|
|||
else {
|
||||
// Buffer size must be set before audio is started.
|
||||
#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
|
||||
audioOutput->setBufferSize(outFormat.bytesForDuration(setup.latency * 1000));
|
||||
audioOutput->setBufferSize(nativeFormat.bytesForDuration(setup.latency * 1000));
|
||||
#endif
|
||||
audioDevice = audioOutput->start();
|
||||
connect(audioOutput, SIGNAL(destroyed()), audioDevice, SLOT(deleteLater()), Qt::UniqueConnection);
|
||||
|
@ -298,7 +298,7 @@ void audioHandler::convertedOutput(audioPacket packet) {
|
|||
|
||||
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->write(packet.data) < packet.data.size()) {
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Buffer full!";
|
||||
|
@ -328,7 +328,7 @@ void audioHandler::getNextAudioChunk()
|
|||
if (audioDevice) {
|
||||
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;
|
||||
packet.time = QTime::currentTime();
|
||||
packet.sent = 0;
|
||||
|
@ -336,14 +336,14 @@ void audioHandler::getNextAudioChunk()
|
|||
memcpy(&packet.guid, setup.guid, GUIDLEN);
|
||||
//QTime startProcessing = QTime::currentTime();
|
||||
packet.data.clear();
|
||||
packet.data = tempBuf.data.mid(0, outFormat.bytesForDuration(setup.blockSize * 1000));
|
||||
tempBuf.data.remove(0, outFormat.bytesForDuration(setup.blockSize * 1000));
|
||||
packet.data = tempBuf.data.mid(0, nativeFormat.bytesForDuration(setup.blockSize * 1000));
|
||||
tempBuf.data.remove(0, nativeFormat.bytesForDuration(setup.blockSize * 1000));
|
||||
|
||||
emit sendToConverter(packet);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,7 @@ void audioHandler::changeLatency(const quint16 newSize)
|
|||
stop();
|
||||
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()
|
||||
|
|
|
@ -99,8 +99,8 @@ private:
|
|||
|
||||
QIODevice* audioDevice=Q_NULLPTR;
|
||||
|
||||
QAudioFormat inFormat;
|
||||
QAudioFormat outFormat;
|
||||
QAudioFormat radioFormat;
|
||||
QAudioFormat nativeFormat;
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
QAudioOutput* audioOutput = Q_NULLPTR;
|
||||
QAudioInput* audioInput = Q_NULLPTR;
|
||||
|
|
|
@ -42,20 +42,20 @@ bool paHandler::init(audioSetup setup)
|
|||
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 <<
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
", bits" << inFormat.sampleSize() <<
|
||||
", bits" << radioFormat.sampleSize() <<
|
||||
#else
|
||||
", format" << inFormat.sampleFormat() <<
|
||||
", format" << radioFormat.sampleFormat() <<
|
||||
#endif
|
||||
", codec" << setup.codec <<
|
||||
", latency" << setup.latency <<
|
||||
", localAFGain" << setup.localAFgain <<
|
||||
", radioChan" << inFormat.channelCount() <<
|
||||
", radioChan" << radioFormat.channelCount() <<
|
||||
", resampleQuality" << setup.resampleQuality <<
|
||||
", samplerate" << inFormat.sampleRate() <<
|
||||
", samplerate" << radioFormat.sampleRate() <<
|
||||
", uLaw" << setup.ulaw;
|
||||
|
||||
PaError err;
|
||||
|
@ -85,51 +85,51 @@ bool paHandler::init(audioSetup setup)
|
|||
|
||||
|
||||
if (setup.isinput) {
|
||||
outFormat.setChannelCount(info->maxInputChannels);
|
||||
nativeFormat.setChannelCount(info->maxInputChannels);
|
||||
}
|
||||
else {
|
||||
outFormat.setChannelCount(info->maxOutputChannels);
|
||||
nativeFormat.setChannelCount(info->maxOutputChannels);
|
||||
}
|
||||
|
||||
aParams.suggestedLatency = (float)setup.latency / 1000.0f;
|
||||
outFormat.setSampleRate(info->defaultSampleRate);
|
||||
nativeFormat.setSampleRate(info->defaultSampleRate);
|
||||
aParams.sampleFormat = paFloat32;
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
outFormat.setSampleSize(32);
|
||||
outFormat.setSampleType(QAudioFormat::Float);
|
||||
outFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
outFormat.setCodec("audio/pcm");
|
||||
nativeFormat.setSampleSize(32);
|
||||
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||
nativeFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
nativeFormat.setCodec("audio/pcm");
|
||||
#else
|
||||
outFormat.setSampleFormat(QAudioFormat::Float);
|
||||
nativeFormat.setSampleFormat(QAudioFormat::Float);
|
||||
#endif
|
||||
|
||||
if (outFormat.channelCount() > 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (nativeFormat.channelCount() > 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.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||
nativeFormat.setChannelCount(2);
|
||||
}
|
||||
|
||||
aParams.channelCount = outFormat.channelCount();
|
||||
aParams.channelCount = nativeFormat.channelCount();
|
||||
|
||||
if (outFormat.sampleRate() < 44100) {
|
||||
outFormat.setSampleRate(48000);
|
||||
if (nativeFormat.sampleRate() < 44100) {
|
||||
nativeFormat.setSampleRate(48000);
|
||||
}
|
||||
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec << "Sample Type" << outFormat.sampleType();
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec << "Sample Type" << nativeFormat.sampleType();
|
||||
#else
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
// Check the format is supported
|
||||
|
@ -163,39 +163,39 @@ bool paHandler::init(audioSetup setup)
|
|||
int errCount = 0;
|
||||
while (err != paNoError) {
|
||||
if (setup.isinput) {
|
||||
err = Pa_IsFormatSupported(&aParams, NULL, outFormat.sampleRate());
|
||||
err = Pa_IsFormatSupported(&aParams, NULL, nativeFormat.sampleRate());
|
||||
}
|
||||
else
|
||||
{
|
||||
err = Pa_IsFormatSupported(NULL, &aParams, outFormat.sampleRate());
|
||||
err = Pa_IsFormatSupported(NULL, &aParams, nativeFormat.sampleRate());
|
||||
}
|
||||
if (err == paInvalidChannelCount)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported channel count" << aParams.channelCount;
|
||||
if (aParams.channelCount == 2) {
|
||||
aParams.channelCount = 1;
|
||||
outFormat.setChannelCount(1);
|
||||
nativeFormat.setChannelCount(1);
|
||||
}
|
||||
else {
|
||||
aParams.channelCount = 2;
|
||||
outFormat.setChannelCount(2);
|
||||
nativeFormat.setChannelCount(2);
|
||||
}
|
||||
}
|
||||
if (err == paInvalidSampleRate)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample rate" << outFormat.sampleRate();
|
||||
outFormat.setSampleRate(44100);
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample rate" << nativeFormat.sampleRate();
|
||||
nativeFormat.setSampleRate(44100);
|
||||
}
|
||||
if (err == paSampleFormatNotSupported)
|
||||
{
|
||||
aParams.sampleFormat = paInt16;
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << outFormat.sampleType();
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(16);
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << nativeFormat.sampleType();
|
||||
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
nativeFormat.setSampleSize(16);
|
||||
#else
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << outFormat.sampleFormat();
|
||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample Format" << nativeFormat.sampleFormat();
|
||||
nativeFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -208,13 +208,13 @@ bool paHandler::init(audioSetup setup)
|
|||
|
||||
if (setup.isinput) {
|
||||
|
||||
err = Pa_OpenStream(&audio, &aParams, 0, outFormat.sampleRate(), this->chunkSize, paNoFlag, &paHandler::staticWrite, (void*)this);
|
||||
emit setupConverter(outFormat, codecType::LPCM, inFormat, codec, 7, setup.resampleQuality);
|
||||
err = Pa_OpenStream(&audio, &aParams, 0, nativeFormat.sampleRate(), this->chunkSize, paNoFlag, &paHandler::staticWrite, (void*)this);
|
||||
emit setupConverter(nativeFormat, codecType::LPCM, radioFormat, codec, 7, setup.resampleQuality);
|
||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||
}
|
||||
else {
|
||||
err = Pa_OpenStream(&audio, 0, &aParams, outFormat.sampleRate(), this->chunkSize, paNoFlag, NULL, NULL);
|
||||
emit setupConverter(inFormat, codec, outFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||
err = Pa_OpenStream(&audio, 0, &aParams, nativeFormat.sampleRate(), this->chunkSize, paNoFlag, NULL, NULL);
|
||||
emit setupConverter(radioFormat, codec, nativeFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||
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.volume = volume;
|
||||
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);
|
||||
|
||||
if (status == paInputUnderflow) {
|
||||
|
@ -296,7 +296,7 @@ void paHandler::convertedOutput(audioPacket packet) {
|
|||
|
||||
if (Pa_IsStreamActive(audio) == 1) {
|
||||
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) {
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Error writing audio!";
|
||||
|
|
|
@ -85,8 +85,8 @@ private:
|
|||
qreal volume = 1.0;
|
||||
|
||||
audioSetup setup;
|
||||
QAudioFormat inFormat;
|
||||
QAudioFormat outFormat;
|
||||
QAudioFormat radioFormat;
|
||||
QAudioFormat nativeFormat;
|
||||
audioConverter* converter = Q_NULLPTR;
|
||||
QThread* converterThread = Q_NULLPTR;
|
||||
bool isUnderrun = false;
|
||||
|
|
|
@ -55,20 +55,20 @@ bool rtHandler::init(audioSetup setup)
|
|||
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 <<
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
", bits" << inFormat.sampleSize() <<
|
||||
", bits" << radioFormat.sampleSize() <<
|
||||
#else
|
||||
", format" << inFormat.sampleFormat() <<
|
||||
", format" << radioFormat.sampleFormat() <<
|
||||
#endif
|
||||
", codec" << setup.codec <<
|
||||
", latency" << setup.latency <<
|
||||
", localAFGain" << setup.localAFgain <<
|
||||
", radioChan" << inFormat.channelCount() <<
|
||||
", radioChan" << radioFormat.channelCount() <<
|
||||
", resampleQuality" << setup.resampleQuality <<
|
||||
", samplerate" << inFormat.sampleRate() <<
|
||||
", samplerate" << radioFormat.sampleRate() <<
|
||||
", uLaw" << setup.ulaw;
|
||||
|
||||
#if !defined(Q_OS_MACX)
|
||||
|
@ -123,8 +123,8 @@ bool rtHandler::init(audioSetup setup)
|
|||
RtAudioFormat sampleFormat;
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
outFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
outFormat.setCodec("audio/pcm");
|
||||
nativeFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
nativeFormat.setCodec("audio/pcm");
|
||||
#endif
|
||||
|
||||
if (info.nativeFormats == 0)
|
||||
|
@ -143,60 +143,60 @@ bool rtHandler::init(audioSetup setup)
|
|||
|
||||
qInfo(logAudio()) << " Preferred sample rate:" << info.preferredSampleRate;
|
||||
if (setup.isinput) {
|
||||
outFormat.setChannelCount(info.inputChannels);
|
||||
nativeFormat.setChannelCount(info.inputChannels);
|
||||
}
|
||||
else {
|
||||
outFormat.setChannelCount(info.outputChannels);
|
||||
nativeFormat.setChannelCount(info.outputChannels);
|
||||
}
|
||||
|
||||
qInfo(logAudio()) << " Channels:" << outFormat.channelCount();
|
||||
qInfo(logAudio()) << " Channels:" << nativeFormat.channelCount();
|
||||
|
||||
if (outFormat.channelCount() > 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (nativeFormat.channelCount() > 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.";
|
||||
goto errorHandler;
|
||||
}
|
||||
|
||||
if (outFormat.channelCount() == 1 && inFormat.channelCount() == 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
if (nativeFormat.channelCount() == 1 && radioFormat.channelCount() == 2) {
|
||||
nativeFormat.setChannelCount(2);
|
||||
}
|
||||
|
||||
aParams.nChannels = outFormat.channelCount();
|
||||
aParams.nChannels = nativeFormat.channelCount();
|
||||
|
||||
|
||||
outFormat.setSampleRate(info.preferredSampleRate);
|
||||
nativeFormat.setSampleRate(info.preferredSampleRate);
|
||||
|
||||
if (outFormat.sampleRate() < 44100) {
|
||||
outFormat.setSampleRate(48000);
|
||||
if (nativeFormat.sampleRate() < 44100) {
|
||||
nativeFormat.setSampleRate(48000);
|
||||
}
|
||||
|
||||
if (info.nativeFormats & RTAUDIO_FLOAT32) {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
outFormat.setSampleType(QAudioFormat::Float);
|
||||
outFormat.setSampleSize(32);
|
||||
nativeFormat.setSampleType(QAudioFormat::Float);
|
||||
nativeFormat.setSampleSize(32);
|
||||
#else
|
||||
outFormat.setSampleFormat(QAudioFormat::Float);
|
||||
nativeFormat.setSampleFormat(QAudioFormat::Float);
|
||||
#endif
|
||||
sampleFormat = RTAUDIO_FLOAT32;
|
||||
}
|
||||
else if (info.nativeFormats & RTAUDIO_SINT32) {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(32);
|
||||
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
nativeFormat.setSampleSize(32);
|
||||
#else
|
||||
outFormat.setSampleFormat(QAudioFormat::Int32);
|
||||
nativeFormat.setSampleFormat(QAudioFormat::Int32);
|
||||
#endif
|
||||
sampleFormat = RTAUDIO_SINT32;
|
||||
}
|
||||
else if (info.nativeFormats & RTAUDIO_SINT16) {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(16);
|
||||
nativeFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
nativeFormat.setSampleSize(16);
|
||||
#else
|
||||
outFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
nativeFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
#endif
|
||||
sampleFormat = RTAUDIO_SINT16;
|
||||
}
|
||||
|
@ -207,11 +207,11 @@ bool rtHandler::init(audioSetup setup)
|
|||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << outFormat.sampleSize() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << outFormat.codec() << "Sample Type" << outFormat.sampleType();
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << nativeFormat.sampleSize() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << nativeFormat.codec() << "Sample Type" << nativeFormat.sampleType();
|
||||
#else
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << outFormat.sampleFormat() << "Channel Count" << outFormat.channelCount() <<
|
||||
"Sample Rate" << outFormat.sampleRate() << "Codec" << codec;
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleFormat" << nativeFormat.sampleFormat() << "Channel Count" << nativeFormat.channelCount() <<
|
||||
"Sample Rate" << nativeFormat.sampleRate() << "Codec" << codec;
|
||||
#endif
|
||||
|
||||
// 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.
|
||||
this->chunkSize = outFormat.framesForDuration(setup.blockSize * 1000);
|
||||
this->chunkSize = nativeFormat.framesForDuration(setup.blockSize * 1000);
|
||||
|
||||
#ifdef RT_EXCEPTION
|
||||
try {
|
||||
#endif
|
||||
if (setup.isinput) {
|
||||
audio->openStream(NULL, &aParams, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options);
|
||||
emit setupConverter(outFormat, codecType::LPCM, inFormat, codec, 7, setup.resampleQuality);
|
||||
audio->openStream(NULL, &aParams, sampleFormat, nativeFormat.sampleRate(), &this->chunkSize, &staticWrite, this, &options);
|
||||
emit setupConverter(nativeFormat, codecType::LPCM, radioFormat, codec, 7, setup.resampleQuality);
|
||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||
}
|
||||
else {
|
||||
audio->openStream(&aParams, NULL, sampleFormat, outFormat.sampleRate(), &this->chunkSize, &staticRead, this , &options);
|
||||
emit setupConverter(inFormat, codec, outFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||
audio->openStream(&aParams, NULL, sampleFormat, nativeFormat.sampleRate(), &this->chunkSize, &staticRead, this , &options);
|
||||
emit setupConverter(radioFormat, codec, nativeFormat, codecType::LPCM, 7, setup.resampleQuality);
|
||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedOutput(audioPacket)));
|
||||
}
|
||||
audio->startStream();
|
||||
|
@ -305,7 +305,7 @@ int rtHandler::readData(void* outputBuffer, void* inputBuffer,
|
|||
{
|
||||
Q_UNUSED(inputBuffer);
|
||||
Q_UNUSED(streamTime);
|
||||
int nBytes = nFrames * outFormat.bytesPerFrame();
|
||||
int nBytes = nFrames * nativeFormat.bytesPerFrame();
|
||||
//lastSentSeq = packet.seq;
|
||||
if (arrayBuffer.length() >= nBytes) {
|
||||
if (audioMutex.tryLock(0)) {
|
||||
|
@ -341,7 +341,7 @@ int rtHandler::writeData(void* outputBuffer, void* inputBuffer,
|
|||
packet.sent = 0;
|
||||
packet.volume = volume;
|
||||
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);
|
||||
|
||||
if (status == RTAUDIO_INPUT_OVERFLOW) {
|
||||
|
@ -366,7 +366,7 @@ void rtHandler::convertedOutput(audioPacket packet)
|
|||
arrayBuffer.append(packet.data);
|
||||
audioMutex.unlock();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ void rtHandler::convertedInput(audioPacket packet)
|
|||
if (packet.data.size() > 0) {
|
||||
emit haveAudioData(packet);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,8 +101,8 @@ private:
|
|||
qreal volume = 1.0;
|
||||
|
||||
audioSetup setup;
|
||||
QAudioFormat inFormat;
|
||||
QAudioFormat outFormat;
|
||||
QAudioFormat radioFormat;
|
||||
QAudioFormat nativeFormat;
|
||||
audioConverter* converter = Q_NULLPTR;
|
||||
QThread* converterThread = Q_NULLPTR;
|
||||
QByteArray arrayBuffer;
|
||||
|
|
Ładowanie…
Reference in New Issue