kopia lustrzana https://gitlab.com/eliggett/wfview
Merge branch 'wfserver' into shuttle
commit
19c16daa06
|
@ -82,7 +82,7 @@ private:
|
|||
|
||||
|
||||
bool isUnderrun = false;
|
||||
bool isOverrun = true;
|
||||
bool isOverrun = false;
|
||||
bool isInitialized=false;
|
||||
bool isReady = false;
|
||||
bool audioBuffered = false;
|
||||
|
|
116
pahandler.cpp
116
pahandler.cpp
|
@ -38,7 +38,7 @@ bool paHandler::init(audioSetup setup)
|
|||
this->setup = setup;
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "PortAudio handler starting:" << setup.name;
|
||||
|
||||
if (setup.portInt==-1)
|
||||
if (setup.portInt == -1)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "No audio device was found.";
|
||||
return false;
|
||||
|
@ -82,7 +82,7 @@ bool paHandler::init(audioSetup setup)
|
|||
outFormat.setChannelCount(info->maxOutputChannels);
|
||||
}
|
||||
|
||||
aParams.suggestedLatency = (float)setup.latency/1000.0f;
|
||||
aParams.suggestedLatency = (float)setup.latency / 1000.0f;
|
||||
outFormat.setSampleRate(info->defaultSampleRate);
|
||||
aParams.sampleFormat = paFloat32;
|
||||
outFormat.setSampleSize(32);
|
||||
|
@ -91,11 +91,6 @@ bool paHandler::init(audioSetup setup)
|
|||
outFormat.setCodec("audio/pcm");
|
||||
|
||||
|
||||
if (!setup.isinput)
|
||||
{
|
||||
this->setVolume(setup.localAFgain);
|
||||
}
|
||||
|
||||
if (outFormat.channelCount() > 2) {
|
||||
outFormat.setChannelCount(2);
|
||||
}
|
||||
|
@ -114,7 +109,7 @@ bool paHandler::init(audioSetup setup)
|
|||
if (outFormat.sampleRate() < 44100) {
|
||||
outFormat.setSampleRate(48000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
@ -139,10 +134,59 @@ bool paHandler::init(audioSetup setup)
|
|||
aParams.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
// Per channel chunk size.
|
||||
this->chunkSize = (outFormat.bytesForDuration(setup.blockSize*1000)/sizeof(float))*outFormat.channelCount();
|
||||
this->chunkSize = (outFormat.bytesForDuration(setup.blockSize * 1000) / sizeof(float)) * outFormat.channelCount();
|
||||
|
||||
// Check the format is supported
|
||||
|
||||
|
||||
if (setup.isinput) {
|
||||
err = Pa_IsFormatSupported(&aParams, NULL, outFormat.sampleRate());
|
||||
}
|
||||
else
|
||||
{
|
||||
err = Pa_IsFormatSupported(NULL,&aParams, outFormat.sampleRate());
|
||||
}
|
||||
|
||||
if (err != paNoError) {
|
||||
if (err == paInvalidChannelCount)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported channel count" << aParams.channelCount;
|
||||
if (aParams.channelCount == 2) {
|
||||
aParams.channelCount = 1;
|
||||
outFormat.setChannelCount(1);
|
||||
}
|
||||
else {
|
||||
aParams.channelCount = 2;
|
||||
outFormat.setChannelCount(2);
|
||||
}
|
||||
}
|
||||
else if (err == paInvalidSampleRate)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Unsupported sample rate" << outFormat.sampleRate();
|
||||
outFormat.setSampleRate(44100);
|
||||
}
|
||||
else if (err == paSampleFormatNotSupported)
|
||||
{
|
||||
aParams.sampleFormat = paInt16;
|
||||
outFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
outFormat.setSampleSize(16);
|
||||
}
|
||||
|
||||
if (setup.isinput) {
|
||||
err = Pa_IsFormatSupported(&aParams, NULL, outFormat.sampleRate());
|
||||
}
|
||||
else
|
||||
{
|
||||
err = Pa_IsFormatSupported(NULL, &aParams, outFormat.sampleRate());
|
||||
}
|
||||
if (err != paNoError) {
|
||||
qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Cannot find suitable format, aborting:" << Pa_GetErrorText(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup.isinput) {
|
||||
|
||||
err = Pa_OpenStream(&audio, &aParams, 0, outFormat.sampleRate(), this->chunkSize, paNoFlag, &paHandler::staticWrite, (void*)this);
|
||||
emit setupConverter(outFormat, inFormat, 7, setup.resampleQuality);
|
||||
connect(converter, SIGNAL(converted(audioPacket)), this, SLOT(convertedInput(audioPacket)));
|
||||
|
@ -173,7 +217,11 @@ bool paHandler::init(audioSetup setup)
|
|||
void paHandler::setVolume(unsigned char volume)
|
||||
{
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
this->volume = audiopot[volume] * 5;
|
||||
#else
|
||||
this->volume = audiopot[volume];
|
||||
#endif
|
||||
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "setVolume: " << volume << "(" << this->volume << ")";
|
||||
}
|
||||
|
@ -202,6 +250,18 @@ int paHandler::writeData(const void* inputBuffer, void* outputBuffer,
|
|||
packet.data.append((char*)inputBuffer, nFrames*inFormat.channelCount()*sizeof(float));
|
||||
emit sendToConverter(packet);
|
||||
|
||||
if (status == paInputUnderflow) {
|
||||
isUnderrun = true;
|
||||
}
|
||||
else if (status == paInputOverflow) {
|
||||
isOverrun = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isUnderrun = false;
|
||||
isOverrun = false;
|
||||
}
|
||||
|
||||
return paContinue;
|
||||
}
|
||||
|
||||
|
@ -217,44 +277,24 @@ void paHandler::convertedOutput(audioPacket packet) {
|
|||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Error writing audio!";
|
||||
}
|
||||
const PaStreamInfo* info = Pa_GetStreamInfo(audio);
|
||||
|
||||
//currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->outputLatency * 1000);
|
||||
currentLatency = (info->outputLatency * 1000);
|
||||
|
||||
}
|
||||
/*
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.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!";
|
||||
isOverrun = true;
|
||||
}
|
||||
else {
|
||||
isOverrun = false;
|
||||
}
|
||||
if (lastReceived.msecsTo(QTime::currentTime()) > 100) {
|
||||
qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Time since last audio packet" << lastReceived.msecsTo(QTime::currentTime()) << "Expected around" << setup.blockSize;
|
||||
}
|
||||
lastReceived = QTime::currentTime();
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->outputLatency * 1000);
|
||||
}
|
||||
|
||||
lastSentSeq = packet.seq;
|
||||
|
||||
*/
|
||||
amplitude = packet.amplitude;
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, false, false);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void paHandler::convertedInput(audioPacket audio)
|
||||
void paHandler::convertedInput(audioPacket packet)
|
||||
{
|
||||
if (audio.data.size() > 0) {
|
||||
emit haveAudioData(audio);
|
||||
amplitude = audio.amplitude;
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, false,false);
|
||||
if (packet.data.size() > 0) {
|
||||
emit haveAudioData(packet);
|
||||
amplitude = packet.amplitude;
|
||||
const PaStreamInfo* info = Pa_GetStreamInfo(audio);
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->inputLatency * 1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ private:
|
|||
QAudioFormat outFormat;
|
||||
audioConverter* converter = Q_NULLPTR;
|
||||
QThread* converterThread = Q_NULLPTR;
|
||||
bool isUnderrun = false;
|
||||
bool isOverrun = false;
|
||||
};
|
||||
|
||||
#endif // PAHANDLER_H
|
||||
|
|
|
@ -62,7 +62,7 @@ bool rtHandler::init(audioSetup setup)
|
|||
", uLaw" << setup.ulaw;
|
||||
|
||||
#if !defined(Q_OS_MACX)
|
||||
//options.flags = !RTAUDIO_HOG_DEVICE | RTAUDIO_MINIMIZE_LATENCY;
|
||||
options.flags = ((!RTAUDIO_HOG_DEVICE) | (RTAUDIO_MINIMIZE_LATENCY));
|
||||
//options.flags = RTAUDIO_MINIMIZE_LATENCY;
|
||||
#endif
|
||||
|
||||
|
@ -303,17 +303,18 @@ void rtHandler::convertedOutput(audioPacket packet)
|
|||
arrayBuffer.append(packet.data);
|
||||
audioMutex.unlock();
|
||||
amplitude = packet.amplitude;
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * (outFormat.sampleSize() / 8) * outFormat.channelCount()) * 1000);
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * (outFormat.sampleSize() / 8) * outFormat.channelCount())/1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void rtHandler::convertedInput(audioPacket audio)
|
||||
void rtHandler::convertedInput(audioPacket packet)
|
||||
{
|
||||
if (audio.data.size() > 0) {
|
||||
emit haveAudioData(audio);
|
||||
amplitude = audio.amplitude;
|
||||
if (packet.data.size() > 0) {
|
||||
emit haveAudioData(packet);
|
||||
amplitude = packet.amplitude;
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * (outFormat.sampleSize() / 8) * outFormat.channelCount())/1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ private:
|
|||
QThread* converterThread = Q_NULLPTR;
|
||||
QByteArray arrayBuffer;
|
||||
bool isUnderrun = false;
|
||||
bool isOverrun = true;
|
||||
bool isOverrun = false;
|
||||
QMutex audioMutex;
|
||||
};
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue