From c2091e9c4ea6ea624dd1425a39aba7ff727ca3dd Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Mon, 22 Mar 2021 18:53:34 +0000 Subject: [PATCH] Add local volume control for UDP connections. --- audiohandler.cpp | 3 ++- audiohandler.h | 2 +- rigcommander.cpp | 8 +++++++- rigcommander.h | 1 + udphandler.cpp | 14 ++++++++++++-- udphandler.h | 6 +++++- wfmain.cpp | 2 +- wfview.vcxproj | 2 +- wfview.vcxproj.filters | 1 + 9 files changed, 31 insertions(+), 8 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index cd728d6..165a456 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -827,8 +827,9 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 return isInitialized; } -void audioHandler::setVolume(quint8 volume) +void audioHandler::setVolume(unsigned char volume) { + qDebug(logAudio()) << (isInput ? "Input" : "Output") << " setVolume: " << volume; if (audioOutput != Q_NULLPTR) { audioOutput->setVolume((qreal)(volume / 255.0)); } diff --git a/audiohandler.h b/audiohandler.h index 5d1b6db..b8fc942 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -46,7 +46,6 @@ public: bool setDevice(QAudioDeviceInfo deviceInfo); void start(); - void setVolume(quint8 volume); void flush(); void stop(); @@ -64,6 +63,7 @@ public slots: private slots: void notified(); void stateChanged(QAudio::State state); + void setVolume(unsigned char volume); signals: void audioMessage(QString message); diff --git a/rigcommander.cpp b/rigcommander.cpp index 91f6372..b96c57b 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -130,6 +130,7 @@ void rigCommander::commSetup(unsigned char rigCivAddr, udpPreferences prefs) connect(ptty, SIGNAL(haveDataFromPort(QByteArray)), udp, SLOT(receiveDataFromUserToRig(QByteArray))); connect(this, SIGNAL(haveChangeLatency(quint16)), udp, SLOT(changeLatency(quint16))); + connect(this, SIGNAL(haveSetVolume(unsigned char)), udp, SLOT(setVolume(unsigned char))); // Connect for errors/alerts connect(udp, SIGNAL(haveNetworkError(QString, QString)), this, SLOT(handleSerialPortError(QString, QString))); @@ -1597,7 +1598,12 @@ void rigCommander::setRfGain(unsigned char level) void rigCommander::setAfGain(unsigned char level) { - sendLevelCmd(0x01, level); + if (udp == Q_NULLPTR) { + sendLevelCmd(0x01, level); + } + else { + emit haveSetVolume(level); + } } void rigCommander::setRefAdjustCourse(unsigned char level) diff --git a/rigcommander.h b/rigcommander.h index ed306ab..006d881 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -216,6 +216,7 @@ signals: void haveDataForServer(QByteArray outData); void haveAudioData(audioPacket data); void initUdpHandler(); + void haveSetVolume(unsigned char level); private: void setup(); diff --git a/udphandler.cpp b/udphandler.cpp index ef5d20d..8d28536 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -119,6 +119,11 @@ void udpHandler::changeLatency(quint16 value) emit haveChangeLatency(value); } +void udpHandler::setVolume(unsigned char value) +{ + emit haveSetVolume(value); +} + void udpHandler::receiveFromCivStream(QByteArray data) { emit haveDataFromPort(data); @@ -312,7 +317,8 @@ void udpHandler::dataReceived() QObject::connect(civ, SIGNAL(receive(QByteArray)), this, SLOT(receiveFromCivStream(QByteArray))); QObject::connect(audio, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket))); - QObject::connect(this, SIGNAL(haveChangeLatency(quint16)), audio, SLOT(changeLatency(quint16))); + QObject::connect(this, SIGNAL(haveChangeLatency(quint16)), audio, SLOT(changeLatency(quint16))); + QObject::connect(this, SIGNAL(haveSetVolume(unsigned char)), audio, SLOT(setVolume(unsigned char))); streamOpened = true; @@ -695,6 +701,7 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint qRegisterMetaType(); 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(rxAudioThread, SIGNAL(finished()), rxaudio, SLOT(deleteLater())); if (txCodec == 0x01) @@ -815,7 +822,10 @@ void udpAudio::changeLatency(quint16 value) emit haveChangeLatency(value); } - +void udpAudio::setVolume(unsigned char value) +{ + emit haveSetVolume(value); +} void udpAudio::dataReceived() { diff --git a/udphandler.h b/udphandler.h index b55faa6..8310881 100644 --- a/udphandler.h +++ b/udphandler.h @@ -179,9 +179,11 @@ signals: void setupRxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput, QString port, quint8 resampleQuality); void haveChangeLatency(quint16 value); + void haveSetVolume(unsigned char value); public slots: void changeLatency(quint16 value); + void setVolume(unsigned char value); private: @@ -238,14 +240,16 @@ public slots: void receiveFromCivStream(QByteArray); void receiveAudioData(const audioPacket &data); void changeLatency(quint16 value); + void setVolume(unsigned char value); void init(); signals: void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander void haveAudioData(audioPacket data); // emit this when we have data, connect to rigcommander void haveNetworkError(QString, QString); - void haveNetworkStatus(QString); void haveChangeLatency(quint16 value); + void haveSetVolume(unsigned char value); + void haveNetworkStatus(QString); private: diff --git a/wfmain.cpp b/wfmain.cpp index eaa0077..c767191 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -2860,7 +2860,7 @@ void wfmain::on_rfGainSlider_valueChanged(int value) void wfmain::on_afGainSlider_valueChanged(int value) { // qDebug(logSystem()) << "Setting AF gain to " << value; - emit setAfGain((unsigned char) value); + emit setAfGain((unsigned char)value); } void wfmain::receiveRfGain(unsigned char level) diff --git a/wfview.vcxproj b/wfview.vcxproj index 1a65ae5..e1ff0d0 100644 --- a/wfview.vcxproj +++ b/wfview.vcxproj @@ -69,7 +69,7 @@ msvc2019_64_5 - core;opengl;network;gui;multimedia;widgets;serialport;printsupport + core;network;gui;multimedia;widgets;serialport;printsupport msvc2019_64_5 diff --git a/wfview.vcxproj.filters b/wfview.vcxproj.filters index 8114315..d186e3c 100644 --- a/wfview.vcxproj.filters +++ b/wfview.vcxproj.filters @@ -330,6 +330,7 @@ +