kopia lustrzana https://gitlab.com/eliggett/wfview
Fixed up signals and slots related to audio levels, removed extra junk
code, added preliminary RMS and Peak audio availablility.monitor
rodzic
d90eb6f11f
commit
4ea7ec8090
|
@ -271,17 +271,10 @@ void audioHandler::convertedOutput(audioPacket packet) {
|
|||
*/
|
||||
lastSentSeq = packet.seq;
|
||||
amplitude = packet.amplitudePeak;
|
||||
computeLevels();
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), static_cast<quint16>(packet.amplitudeRMS * 255.0), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
void audioHandler::computeLevels()
|
||||
{
|
||||
if(levelMean)
|
||||
levelMean[(levelPosition++)%levelSize] = amplitude * 255;
|
||||
}
|
||||
|
||||
void audioHandler::getNextAudioChunk()
|
||||
{
|
||||
if (audioDevice) {
|
||||
|
@ -319,7 +312,7 @@ void audioHandler::convertedInput(audioPacket audio)
|
|||
}
|
||||
lastReceived = QTime::currentTime();
|
||||
amplitude = audio.amplitudePeak;
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), audio.amplitudeRMS, setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ signals:
|
|||
void audioMessage(QString message);
|
||||
void sendLatency(quint16 newSize);
|
||||
void haveAudioData(const audioPacket& data);
|
||||
void haveLevels(quint16 amplitude,quint16 latency,quint16 current,bool under,bool over);
|
||||
void haveLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency,quint16 current,bool under,bool over);
|
||||
void setupConverter(QAudioFormat in, QAudioFormat out, quint8 opus, quint8 resamp);
|
||||
void sendToConverter(audioPacket audio);
|
||||
|
||||
|
@ -116,12 +116,6 @@ private:
|
|||
float amplitude=0.0;
|
||||
qreal volume = 1.0;
|
||||
|
||||
unsigned char *levelMean = Q_NULLPTR;
|
||||
unsigned char *levelPeak = Q_NULLPTR;
|
||||
unsigned char levelSize = 50;
|
||||
unsigned char levelPosition = 0;
|
||||
void computeLevels();
|
||||
|
||||
audioSetup setup;
|
||||
|
||||
OpusEncoder* encoder = Q_NULLPTR;
|
||||
|
|
|
@ -279,7 +279,7 @@ void paHandler::convertedOutput(audioPacket packet) {
|
|||
}
|
||||
|
||||
amplitude = packet.amplitudePeak;
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), static_cast<quint16>(packet.amplitudeRMS * 255.0), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ void paHandler::convertedInput(audioPacket packet)
|
|||
amplitude = packet.amplitudePeak;
|
||||
const PaStreamInfo* info = Pa_GetStreamInfo(audio);
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (info->inputLatency * 1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), packet.amplitudeRMS, setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ signals:
|
|||
void audioMessage(QString message);
|
||||
void sendLatency(quint16 newSize);
|
||||
void haveAudioData(const audioPacket& data);
|
||||
void haveLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void haveLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void setupConverter(QAudioFormat in, QAudioFormat out, quint8 opus, quint8 resamp);
|
||||
void sendToConverter(audioPacket audio);
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ void rtHandler::convertedOutput(audioPacket packet)
|
|||
audioMutex.unlock();
|
||||
amplitude = packet.amplitudePeak;
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * (outFormat.sampleSize() / 8) * outFormat.channelCount())/1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), packet.amplitudeRMS, setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
|
||||
|
||||
|
@ -344,7 +344,7 @@ void rtHandler::convertedInput(audioPacket packet)
|
|||
emit haveAudioData(packet);
|
||||
amplitude = packet.amplitudePeak;
|
||||
currentLatency = packet.time.msecsTo(QTime::currentTime()) + (outFormat.durationForBytes(audio->getStreamLatency() * (outFormat.sampleSize() / 8) * outFormat.channelCount())/1000);
|
||||
emit haveLevels(getAmplitude(), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
emit haveLevels(getAmplitude(), static_cast<quint16>(packet.amplitudeRMS * 255.0), setup.latency, currentLatency, isUnderrun, isOverrun);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ signals:
|
|||
void audioMessage(QString message);
|
||||
void sendLatency(quint16 newSize);
|
||||
void haveAudioData(const audioPacket& data);
|
||||
void haveLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void haveLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void setupConverter(QAudioFormat in, QAudioFormat out, quint8 opus, quint8 resamp);
|
||||
void sendToConverter(audioPacket audio);
|
||||
|
||||
|
|
12
udpaudio.cpp
12
udpaudio.cpp
|
@ -159,13 +159,13 @@ void udpAudio::setVolume(unsigned char value)
|
|||
emit haveSetVolume(value);
|
||||
}
|
||||
|
||||
void udpAudio::getRxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over) {
|
||||
void udpAudio::getRxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over) {
|
||||
|
||||
emit haveRxLevels(amplitude, latency, current, under, over);
|
||||
emit haveRxLevels(amplitudePeak, amplitudeRMS, latency, current, under, over);
|
||||
}
|
||||
|
||||
void udpAudio::getTxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over) {
|
||||
emit haveTxLevels(amplitude, latency, current, under, over);
|
||||
void udpAudio::getTxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over) {
|
||||
emit haveTxLevels(amplitudePeak, amplitudeRMS, latency, current, under, over);
|
||||
}
|
||||
|
||||
void udpAudio::dataReceived()
|
||||
|
@ -256,7 +256,7 @@ void udpAudio::startAudio() {
|
|||
connect(this, SIGNAL(haveAudioData(audioPacket)), rxaudio, SLOT(incomingAudio(audioPacket)));
|
||||
connect(this, SIGNAL(haveChangeLatency(quint16)), rxaudio, SLOT(changeLatency(quint16)));
|
||||
connect(this, SIGNAL(haveSetVolume(unsigned char)), rxaudio, SLOT(setVolume(unsigned char)));
|
||||
connect(rxaudio, SIGNAL(haveLevels(quint16, quint16, quint16, bool, bool)), this, SLOT(getRxLevels(quint16, quint16, quint16, bool, bool)));
|
||||
connect(rxaudio, SIGNAL(haveLevels(quint16, quint16, quint16, quint16, bool, bool)), this, SLOT(getRxLevels(quint16, quint16, quint16, quint16, bool, bool)));
|
||||
connect(rxAudioThread, SIGNAL(finished()), rxaudio, SLOT(deleteLater()));
|
||||
|
||||
|
||||
|
@ -290,7 +290,7 @@ void udpAudio::startAudio() {
|
|||
|
||||
connect(this, SIGNAL(setupTxAudio(audioSetup)), txaudio, SLOT(init(audioSetup)));
|
||||
connect(txaudio, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket)));
|
||||
connect(txaudio, SIGNAL(haveLevels(quint16, quint16, quint16, bool, bool)), this, SLOT(getTxLevels(quint16, quint16, quint16, bool, bool)));
|
||||
connect(txaudio, SIGNAL(haveLevels(quint16, quint16, quint16, quint16, bool, bool)), this, SLOT(getTxLevels(quint16, quint16, quint16, quint16, bool, bool)));
|
||||
|
||||
connect(txAudioThread, SIGNAL(finished()), txaudio, SLOT(deleteLater()));
|
||||
emit setupTxAudio(txSetup);
|
||||
|
|
10
udpaudio.h
10
udpaudio.h
|
@ -51,14 +51,14 @@ signals:
|
|||
|
||||
void haveChangeLatency(quint16 value);
|
||||
void haveSetVolume(unsigned char value);
|
||||
void haveRxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void haveTxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void haveRxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void haveTxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
|
||||
public slots:
|
||||
void changeLatency(quint16 value);
|
||||
void setVolume(unsigned char value);
|
||||
void getRxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void getTxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void getRxLevels(quint16 amplitude, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void getTxLevels(quint16 amplitude, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void receiveAudioData(audioPacket audio);
|
||||
|
||||
private:
|
||||
|
@ -85,4 +85,4 @@ private:
|
|||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -143,41 +143,50 @@ void udpHandler::receiveDataFromUserToRig(QByteArray data)
|
|||
}
|
||||
}
|
||||
|
||||
void udpHandler::getRxLevels(quint16 amplitude,quint16 latency,quint16 current, bool under, bool over) {
|
||||
status.rxAudioLevel = amplitude;
|
||||
void udpHandler::getRxLevels(quint16 amplitudePeak, quint16 amplitudeRMS,quint16 latency,quint16 current, bool under, bool over) {
|
||||
status.rxAudioLevel = amplitudePeak;
|
||||
status.rxLatency = latency;
|
||||
status.rxCurrentLatency = current;
|
||||
status.rxUnderrun = under;
|
||||
status.rxOverrun = over;
|
||||
audioLevelsRxPeak[(audioLevelsRxPeakPosition++)%audioLevelBufferSize] = amplitude;
|
||||
if((audioLevelsRxPeakPosition++)%3 == 0)
|
||||
audioLevelsRxPeak[(audioLevelsRxPosition)%audioLevelBufferSize] = amplitudePeak;
|
||||
audioLevelsRxRMS[(audioLevelsRxPosition)%audioLevelBufferSize] = amplitudeRMS;
|
||||
|
||||
if((audioLevelsRxPosition)%3 == 0)
|
||||
{
|
||||
// calculate mean and emit signal
|
||||
unsigned char mean = findMean(audioLevelsRxPeak);
|
||||
unsigned char meanPeak = findMax(audioLevelsRxPeak);
|
||||
unsigned char meanRMS = findMean(audioLevelsRxRMS);
|
||||
networkAudioLevels l;
|
||||
l.haveRxLevels = true;
|
||||
l.rxAudioPeak = mean;
|
||||
//qDebug(logSystem()) << "audio level meter being emitted from udpHandler";
|
||||
l.rxAudioPeak = meanPeak;
|
||||
l.rxAudioRMS = meanRMS;
|
||||
emit haveNetworkAudioLevels(l);
|
||||
}
|
||||
audioLevelsRxPosition++;
|
||||
}
|
||||
|
||||
void udpHandler::getTxLevels(quint16 amplitude,quint16 latency, quint16 current, bool under, bool over) {
|
||||
status.txAudioLevel = amplitude;
|
||||
void udpHandler::getTxLevels(quint16 amplitudePeak, quint16 amplitudeRMS ,quint16 latency, quint16 current, bool under, bool over) {
|
||||
status.txAudioLevel = amplitudePeak;
|
||||
status.txLatency = latency;
|
||||
status.txCurrentLatency = current;
|
||||
status.txUnderrun = under;
|
||||
status.txOverrun = over;
|
||||
audioLevelsTxPeak[(audioLevelsTxPeakPosition++)%audioLevelBufferSize] = amplitude;
|
||||
if((audioLevelsTxPeakPosition++)%3 == 0)
|
||||
audioLevelsTxPeak[(audioLevelsTxPosition)%audioLevelBufferSize] = amplitudePeak;
|
||||
audioLevelsTxRMS[(audioLevelsTxPosition)%audioLevelBufferSize] = amplitudeRMS;
|
||||
|
||||
if((audioLevelsTxPosition)%3 == 0)
|
||||
{
|
||||
// calculate mean and emit signal
|
||||
unsigned char mean = findMean(audioLevelsTxPeak);
|
||||
unsigned char meanPeak = findMax(audioLevelsTxPeak);
|
||||
unsigned char meanRMS = findMean(audioLevelsTxRMS);
|
||||
networkAudioLevels l;
|
||||
l.haveTxLevels = true;
|
||||
l.txAudioPeak = mean;
|
||||
l.txAudioPeak = meanPeak;
|
||||
l.txAudioRMS = meanRMS;
|
||||
emit haveNetworkAudioLevels(l);
|
||||
}
|
||||
audioLevelsTxPosition++;
|
||||
}
|
||||
|
||||
unsigned char udpHandler::findMean(unsigned char *data)
|
||||
|
@ -190,6 +199,17 @@ unsigned char udpHandler::findMean(unsigned char *data)
|
|||
return sum / audioLevelBufferSize;
|
||||
}
|
||||
|
||||
unsigned char udpHandler::findMax(unsigned char *data)
|
||||
{
|
||||
unsigned int max=0;
|
||||
for(int p=0; p < audioLevelBufferSize; p++)
|
||||
{
|
||||
if(data[p] > max)
|
||||
max = data[p];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
void udpHandler::dataReceived()
|
||||
{
|
||||
while (udp->hasPendingDatagrams()) {
|
||||
|
@ -348,8 +368,8 @@ void udpHandler::dataReceived()
|
|||
QObject::connect(audio, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket)));
|
||||
QObject::connect(this, SIGNAL(haveChangeLatency(quint16)), audio, SLOT(changeLatency(quint16)));
|
||||
QObject::connect(this, SIGNAL(haveSetVolume(unsigned char)), audio, SLOT(setVolume(unsigned char)));
|
||||
QObject::connect(audio, SIGNAL(haveRxLevels(quint16, quint16, quint16, bool, bool)), this, SLOT(getRxLevels(quint16, quint16, quint16, bool, bool)));
|
||||
QObject::connect(audio, SIGNAL(haveTxLevels(quint16, quint16, quint16, bool, bool)), this, SLOT(getTxLevels(quint16, quint16, quint16, bool, bool)));
|
||||
QObject::connect(audio, SIGNAL(haveRxLevels(quint16, quint16, quint16, quint16, bool, bool)), this, SLOT(getRxLevels(quint16, quint16, quint16, quint16, bool, bool)));
|
||||
QObject::connect(audio, SIGNAL(haveTxLevels(quint16, quint16, quint16, quint16, bool, bool)), this, SLOT(getTxLevels(quint16, quint16, quint16, quint16, bool, bool)));
|
||||
}
|
||||
|
||||
qInfo(logUdp()) << this->metaObject()->className() << "Got serial and audio request success, device name: " << devName;
|
||||
|
|
15
udphandler.h
15
udphandler.h
|
@ -56,10 +56,8 @@ public slots:
|
|||
void setVolume(unsigned char value);
|
||||
void init();
|
||||
void setCurrentRadio(quint8 radio);
|
||||
void getRxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
void getTxLevels(quint16 amplitude, quint16 latency, quint16 current, bool under, bool over);
|
||||
//void handleRxLevels(networkAudioLevels);
|
||||
//void handleTxLevels(networkAudioLevels);
|
||||
void getRxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
void getTxLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
||||
|
||||
signals:
|
||||
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
|
||||
|
@ -127,9 +125,14 @@ private:
|
|||
|
||||
unsigned char audioLevelsTxPeak[audioLevelBufferSize];
|
||||
unsigned char audioLevelsRxPeak[audioLevelBufferSize];
|
||||
unsigned char audioLevelsTxPeakPosition = 0;
|
||||
unsigned char audioLevelsRxPeakPosition = 0;
|
||||
|
||||
unsigned char audioLevelsTxRMS[audioLevelBufferSize];
|
||||
unsigned char audioLevelsRxRMS[audioLevelBufferSize];
|
||||
|
||||
unsigned char audioLevelsTxPosition = 0;
|
||||
unsigned char audioLevelsRxPosition = 0;
|
||||
unsigned char findMean(unsigned char *d);
|
||||
unsigned char findMax(unsigned char *d);
|
||||
|
||||
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue