diff --git a/plugins/channel/udpsrc/udpsrc.cpp b/plugins/channel/udpsrc/udpsrc.cpp
index 14e8c60c5..b1bf3c012 100644
--- a/plugins/channel/udpsrc/udpsrc.cpp
+++ b/plugins/channel/udpsrc/udpsrc.cpp
@@ -24,11 +24,14 @@
#include "udpsrcgui.h"
MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigure, Message)
+MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigureImmediate, Message)
MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcSpectrum, Message)
UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum) :
m_settingsMutex(QMutex::Recursive),
- m_audioFifo(4, 24000)
+ m_audioFifo(4, 24000),
+ m_audioActive(false),
+ m_volume(20)
{
setObjectName("UDPSrc");
@@ -71,7 +74,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s
qWarning("UDPSrc::UDPSrc: cannot bind audio port");
}
- DSPEngine::instance()->addAudioSink(&m_audioFifo);
+ //DSPEngine::instance()->addAudioSink(&m_audioFifo);
}
UDPSrc::~UDPSrc()
@@ -79,12 +82,33 @@ UDPSrc::~UDPSrc()
delete m_audioSocket;
delete m_socket;
if (UDPFilter) delete UDPFilter;
- DSPEngine::instance()->removeAudioSink(&m_audioFifo);
+ if (m_audioActive) DSPEngine::instance()->removeAudioSink(&m_audioFifo);
}
-void UDPSrc::configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, QString& udpAddress, int udpPort, int boost)
+void UDPSrc::configure(MessageQueue* messageQueue,
+ SampleFormat sampleFormat,
+ Real outputSampleRate,
+ Real rfBandwidth,
+ QString& udpAddress,
+ int udpPort,
+ bool audioActive)
{
- Message* cmd = MsgUDPSrcConfigure::create(sampleFormat, outputSampleRate, rfBandwidth, udpAddress, udpPort, boost);
+ Message* cmd = MsgUDPSrcConfigure::create(sampleFormat,
+ outputSampleRate,
+ rfBandwidth,
+ udpAddress,
+ udpPort,
+ audioActive);
+ messageQueue->push(cmd);
+}
+
+void UDPSrc::configureImmediate(MessageQueue* messageQueue,
+ int boost,
+ int volume)
+{
+ Message* cmd = MsgUDPSrcConfigureImmediate::create(
+ boost,
+ volume);
messageQueue->push(cmd);
}
@@ -217,6 +241,31 @@ bool UDPSrc::handleMessage(const Message& cmd)
return true;
}
+ else if (MsgUDPSrcConfigureImmediate::match(cmd))
+ {
+ MsgUDPSrcConfigureImmediate& cfg = (MsgUDPSrcConfigureImmediate&) cmd;
+
+ m_settingsMutex.lock();
+
+ if (cfg.getBoost() != m_boost)
+ {
+ m_boost = cfg.getBoost();
+ }
+
+ if (cfg.getVolume() != m_volume)
+ {
+ m_volume = cfg.getVolume();
+ }
+
+ m_settingsMutex.unlock();
+
+ qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigureImmediate: "
+ << " m_boost: " << m_boost
+ << " m_volume: " << m_volume;
+
+ return true;
+
+ }
else if (MsgUDPSrcConfigure::match(cmd))
{
MsgUDPSrcConfigure& cfg = (MsgUDPSrcConfigure&) cmd;
@@ -242,7 +291,6 @@ bool UDPSrc::handleMessage(const Message& cmd)
}
}
- m_boost = cfg.getBoost();
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
@@ -255,6 +303,21 @@ bool UDPSrc::handleMessage(const Message& cmd)
UDPFilter->create_filter(0.0, m_rfBandwidth / 2.0 / m_outputSampleRate);
}
+ if (cfg.getAudioActive() != m_audioActive)
+ {
+ m_audioActive = cfg.getAudioActive();
+
+ if (m_audioActive)
+ {
+ m_audioBufferFill = 0;
+ DSPEngine::instance()->addAudioSink(&m_audioFifo);
+ }
+ else
+ {
+ DSPEngine::instance()->removeAudioSink(&m_audioFifo);
+ }
+ }
+
m_settingsMutex.unlock();
qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigure: m_sampleFormat: " << m_sampleFormat
@@ -262,7 +325,8 @@ bool UDPSrc::handleMessage(const Message& cmd)
<< " m_rfBandwidth: " << m_rfBandwidth
<< " m_boost: " << m_boost
<< " m_udpAddress: " << cfg.getUDPAddress()
- << " m_udpPort: " << m_udpPort;
+ << " m_udpPort: " << m_udpPort
+ << " m+audioActive: " << m_audioActive;
return true;
}
@@ -299,33 +363,36 @@ void UDPSrc::audioReadyRead()
m_audioSocket->readDatagram(buffer.data(), buffer.size(), 0, 0);
//qDebug("UDPSrc::audioReadyRead: %d", buffer.size());
- for (int i = 0; i < buffer.size() - 3; i += 4)
- {
- qint16 l_sample = (qint16) *(&buffer.data()[i]);
- qint16 r_sample = (qint16) *(&buffer.data()[i+2]);
- m_audioBuffer[m_audioBufferFill].l = l_sample * 100;
- m_audioBuffer[m_audioBufferFill].r = r_sample * 100;
- ++m_audioBufferFill;
-
- if (m_audioBufferFill >= m_audioBuffer.size())
- {
- uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
-
- if (res != m_audioBufferFill)
- {
- qDebug("UDPSrc::audioReadyRead: lost %u samples", m_audioBufferFill - res);
- }
-
- m_audioBufferFill = 0;
- }
- }
-
- if (m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill)
+ if (m_audioActive)
{
- qDebug("UDPSrc::audioReadyRead: lost samples");
- }
+ for (int i = 0; i < buffer.size() - 3; i += 4)
+ {
+ qint16 l_sample = (qint16) *(&buffer.data()[i]);
+ qint16 r_sample = (qint16) *(&buffer.data()[i+2]);
+ m_audioBuffer[m_audioBufferFill].l = l_sample * 10 * m_volume;
+ m_audioBuffer[m_audioBufferFill].r = r_sample * 10 * m_volume;
+ ++m_audioBufferFill;
- m_audioBufferFill = 0;
+ if (m_audioBufferFill >= m_audioBuffer.size())
+ {
+ uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
+
+ if (res != m_audioBufferFill)
+ {
+ qDebug("UDPSrc::audioReadyRead: lost %u samples", m_audioBufferFill - res);
+ }
+
+ m_audioBufferFill = 0;
+ }
+ }
+
+ if (m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill)
+ {
+ qDebug("UDPSrc::audioReadyRead: lost samples");
+ }
+
+ m_audioBufferFill = 0;
+ }
}
//qDebug("UDPSrc::audioReadyRead: done");
diff --git a/plugins/channel/udpsrc/udpsrc.h b/plugins/channel/udpsrc/udpsrc.h
index c50a7fb78..b170286a8 100644
--- a/plugins/channel/udpsrc/udpsrc.h
+++ b/plugins/channel/udpsrc/udpsrc.h
@@ -37,7 +37,16 @@ public:
UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum);
virtual ~UDPSrc();
- void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, QString& udpAddress, int udpPort, int boost);
+ void configure(MessageQueue* messageQueue,
+ SampleFormat sampleFormat,
+ Real outputSampleRate,
+ Real rfBandwidth,
+ QString& udpAddress,
+ int udpPort,
+ bool audioActive);
+ void configureImmediate(MessageQueue* messageQueue,
+ int boost,
+ int volume);
void setSpectrum(MessageQueue* messageQueue, bool enabled);
Real getMagSq() const { return m_magsq; }
@@ -59,11 +68,22 @@ protected:
Real getRFBandwidth() const { return m_rfBandwidth; }
const QString& getUDPAddress() const { return m_udpAddress; }
int getUDPPort() const { return m_udpPort; }
- int getBoost() const { return m_boost; }
+ bool getAudioActive() const { return m_audioActive; }
- static MsgUDPSrcConfigure* create(SampleFormat sampleFormat, Real sampleRate, Real rfBandwidth, QString& udpAddress, int udpPort, int boost)
+ static MsgUDPSrcConfigure* create(SampleFormat
+ sampleFormat,
+ Real sampleRate,
+ Real rfBandwidth,
+ QString& udpAddress,
+ int udpPort,
+ bool audioActive)
{
- return new MsgUDPSrcConfigure(sampleFormat, sampleRate, rfBandwidth, udpAddress, udpPort, boost);
+ return new MsgUDPSrcConfigure(sampleFormat,
+ sampleRate,
+ rfBandwidth,
+ udpAddress,
+ udpPort,
+ audioActive);
}
private:
@@ -72,18 +92,53 @@ protected:
Real m_rfBandwidth;
QString m_udpAddress;
int m_udpPort;
- int m_boost;
+ bool m_audioActive;
- MsgUDPSrcConfigure(SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, QString& udpAddress, int udpPort, int boost) :
+ MsgUDPSrcConfigure(SampleFormat sampleFormat,
+ Real outputSampleRate,
+ Real rfBandwidth,
+ QString& udpAddress,
+ int udpPort,
+ bool audioActive) :
Message(),
m_sampleFormat(sampleFormat),
m_outputSampleRate(outputSampleRate),
m_rfBandwidth(rfBandwidth),
m_udpAddress(udpAddress),
m_udpPort(udpPort),
- m_boost(boost)
+ m_audioActive(audioActive)
{ }
};
+
+ class MsgUDPSrcConfigureImmediate : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ int getBoost() const { return m_boost; }
+ int getVolume() const { return m_volume; }
+
+ static MsgUDPSrcConfigureImmediate* create(
+ int boost,
+ int volume)
+ {
+ return new MsgUDPSrcConfigureImmediate(
+ boost,
+ volume);
+ }
+
+ private:
+ int m_boost;
+ int m_volume;
+
+ MsgUDPSrcConfigureImmediate(
+ int boost,
+ int volume) :
+ Message(),
+ m_boost(boost),
+ m_volume(volume)
+ { }
+ };
+
class MsgUDPSrcSpectrum : public Message {
MESSAGE_CLASS_DECLARATION
@@ -117,6 +172,8 @@ protected:
QHostAddress m_udpAddress;
quint16 m_udpPort;
int m_boost;
+ bool m_audioActive;
+ int m_volume;
Real m_magsq;
Real m_scale;
diff --git a/plugins/channel/udpsrc/udpsrcgui.cpp b/plugins/channel/udpsrc/udpsrcgui.cpp
index 2653f2429..b28d5dc86 100644
--- a/plugins/channel/udpsrc/udpsrcgui.cpp
+++ b/plugins/channel/udpsrc/udpsrcgui.cpp
@@ -55,8 +55,11 @@ void UDPSrcGUI::resetToDefaults()
ui->udpPort->setText("9999");
ui->spectrumGUI->resetToDefaults();
ui->boost->setValue(1);
+ ui->volume->setValue(20);
+ ui->audioActive->setChecked(false);
blockApplySettings(false);
+ applySettingsImmediate();
applySettings();
}
@@ -73,6 +76,8 @@ QByteArray UDPSrcGUI::serialize() const
s.writeS32(8, (qint32)m_boost);
s.writeS32(9, m_channelMarker.getCenterFrequency());
s.writeString(10, m_udpAddress);
+ s.writeBool(11, m_audioActive);
+ s.writeS32(12, (qint32)m_volume);
return s.final();
}
@@ -92,6 +97,7 @@ bool UDPSrcGUI::deserialize(const QByteArray& data)
QString strtmp;
qint32 s32tmp;
Real realtmp;
+ bool booltmp;
blockApplySettings(true);
m_channelMarker.blockSignals(true);
@@ -129,10 +135,15 @@ bool UDPSrcGUI::deserialize(const QByteArray& data)
m_channelMarker.setCenterFrequency(s32tmp);
d.readString(10, &strtmp, "127.0.0.1");
ui->udpAddress->setText(strtmp);
+ d.readBool(11, &booltmp, false);
+ ui->audioActive->setChecked(booltmp);
+ d.readS32(12, &s32tmp, 20);
+ ui->volume->setValue(s32tmp);
blockApplySettings(false);
m_channelMarker.blockSignals(false);
+ applySettingsImmediate();
applySettings();
return true;
}
@@ -169,7 +180,9 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) :
m_channelMarker(this),
m_channelPowerDbAvg(40,0),
m_basicSettingsShown(false),
- m_doApplySettings(true)
+ m_doApplySettings(true),
+ m_boost(1),
+ m_volume(20)
{
ui->setupUi(this);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
@@ -204,6 +217,7 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) :
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
+ applySettingsImmediate();
applySettings();
}
@@ -224,6 +238,20 @@ void UDPSrcGUI::blockApplySettings(bool block)
m_doApplySettings = !block;
}
+void UDPSrcGUI::applySettingsImmediate()
+{
+ if (m_doApplySettings)
+ {
+ m_boost = ui->boost->value();
+ m_volume = ui->volume->value();
+
+ m_udpSrc->configureImmediate(m_udpSrc->getInputMessageQueue(),
+ m_boost,
+ m_volume);
+ }
+}
+
+
void UDPSrcGUI::applySettings()
{
if (m_doApplySettings)
@@ -253,6 +281,7 @@ void UDPSrcGUI::applySettings()
}
int boost = ui->boost->value();
+ bool audioActive = ui->audioActive->isChecked();
setTitleColor(m_channelMarker.getColor());
ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
@@ -294,6 +323,7 @@ void UDPSrcGUI::applySettings()
m_rfBandwidth = rfBandwidth;
m_udpPort = udpPort;
m_boost = boost;
+ m_audioActive = audioActive;
m_udpSrc->configure(m_udpSrc->getInputMessageQueue(),
sampleFormat,
@@ -301,7 +331,7 @@ void UDPSrcGUI::applySettings()
rfBandwidth,
m_udpAddress,
udpPort,
- boost);
+ audioActive);
ui->applyBtn->setEnabled(false);
}
@@ -352,11 +382,23 @@ void UDPSrcGUI::on_applyBtn_clicked()
applySettings();
}
+void UDPSrcGUI::on_audioActive_toggled(bool checked)
+{
+ ui->applyBtn->setEnabled(true);
+}
+
void UDPSrcGUI::on_boost_valueChanged(int value)
{
ui->boost->setValue(value);
ui->boostText->setText(QString("%1").arg(value));
- ui->applyBtn->setEnabled(true);
+ applySettingsImmediate();
+}
+
+void UDPSrcGUI::on_volume_valueChanged(int value)
+{
+ ui->volume->setValue(value);
+ ui->volumeText->setText(QString("%1").arg(value));
+ applySettingsImmediate();
}
void UDPSrcGUI::onWidgetRolled(QWidget* widget, bool rollDown)
diff --git a/plugins/channel/udpsrc/udpsrcgui.h b/plugins/channel/udpsrc/udpsrcgui.h
index 0f9a1c586..87171a92e 100644
--- a/plugins/channel/udpsrc/udpsrcgui.h
+++ b/plugins/channel/udpsrc/udpsrcgui.h
@@ -46,10 +46,12 @@ private slots:
void on_rfBandwidth_textEdited(const QString& arg1);
void on_udpAddress_textEdited(const QString& arg1);
void on_udpPort_textEdited(const QString& arg1);
+ void on_audioActive_toggled(bool checked);
void on_applyBtn_clicked();
void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDoubleClicked();
void on_boost_valueChanged(int value);
+ void on_volume_valueChanged(int value);
void tick();
private:
@@ -64,6 +66,8 @@ private:
Real m_outputSampleRate;
Real m_rfBandwidth;
int m_boost;
+ bool m_audioActive;
+ int m_volume;
QString m_udpAddress;
int m_udpPort;
bool m_basicSettingsShown;
@@ -79,6 +83,7 @@ private:
void blockApplySettings(bool block);
void applySettings();
+ void applySettingsImmediate();
};
#endif // INCLUDE_UDPSRCGUI_H
diff --git a/plugins/channel/udpsrc/udpsrcgui.ui b/plugins/channel/udpsrc/udpsrcgui.ui
index 9221c6fbe..9be79fa62 100644
--- a/plugins/channel/udpsrc/udpsrcgui.ui
+++ b/plugins/channel/udpsrc/udpsrcgui.ui
@@ -155,7 +155,7 @@
-
-
+
20
@@ -324,7 +324,7 @@
-
-
+
Activate audio