UDP Source: implemented audio enable and volume change

pull/6/head
f4exb 2015-12-04 03:46:51 +01:00
rodzic eeecaf5d3f
commit c1f1c741f1
5 zmienionych plików z 215 dodań i 44 usunięć

Wyświetl plik

@ -24,11 +24,14 @@
#include "udpsrcgui.h" #include "udpsrcgui.h"
MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigure, Message) MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigure, Message)
MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigureImmediate, Message)
MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcSpectrum, Message) MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcSpectrum, Message)
UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum) : UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum) :
m_settingsMutex(QMutex::Recursive), m_settingsMutex(QMutex::Recursive),
m_audioFifo(4, 24000) m_audioFifo(4, 24000),
m_audioActive(false),
m_volume(20)
{ {
setObjectName("UDPSrc"); setObjectName("UDPSrc");
@ -71,7 +74,7 @@ UDPSrc::UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* s
qWarning("UDPSrc::UDPSrc: cannot bind audio port"); qWarning("UDPSrc::UDPSrc: cannot bind audio port");
} }
DSPEngine::instance()->addAudioSink(&m_audioFifo); //DSPEngine::instance()->addAudioSink(&m_audioFifo);
} }
UDPSrc::~UDPSrc() UDPSrc::~UDPSrc()
@ -79,12 +82,33 @@ UDPSrc::~UDPSrc()
delete m_audioSocket; delete m_audioSocket;
delete m_socket; delete m_socket;
if (UDPFilter) delete UDPFilter; 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); messageQueue->push(cmd);
} }
@ -217,6 +241,31 @@ bool UDPSrc::handleMessage(const Message& cmd)
return true; 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)) else if (MsgUDPSrcConfigure::match(cmd))
{ {
MsgUDPSrcConfigure& cfg = (MsgUDPSrcConfigure&) 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_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; 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); 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(); m_settingsMutex.unlock();
qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigure: m_sampleFormat: " << m_sampleFormat qDebug() << "UDPSrc::handleMessage: MsgUDPSrcConfigure: m_sampleFormat: " << m_sampleFormat
@ -262,7 +325,8 @@ bool UDPSrc::handleMessage(const Message& cmd)
<< " m_rfBandwidth: " << m_rfBandwidth << " m_rfBandwidth: " << m_rfBandwidth
<< " m_boost: " << m_boost << " m_boost: " << m_boost
<< " m_udpAddress: " << cfg.getUDPAddress() << " m_udpAddress: " << cfg.getUDPAddress()
<< " m_udpPort: " << m_udpPort; << " m_udpPort: " << m_udpPort
<< " m+audioActive: " << m_audioActive;
return true; return true;
} }
@ -299,33 +363,36 @@ void UDPSrc::audioReadyRead()
m_audioSocket->readDatagram(buffer.data(), buffer.size(), 0, 0); m_audioSocket->readDatagram(buffer.data(), buffer.size(), 0, 0);
//qDebug("UDPSrc::audioReadyRead: %d", buffer.size()); //qDebug("UDPSrc::audioReadyRead: %d", buffer.size());
for (int i = 0; i < buffer.size() - 3; i += 4) if (m_audioActive)
{
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)
{ {
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"); //qDebug("UDPSrc::audioReadyRead: done");

Wyświetl plik

@ -37,7 +37,16 @@ public:
UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum); UDPSrc(MessageQueue* uiMessageQueue, UDPSrcGUI* udpSrcGUI, SampleSink* spectrum);
virtual ~UDPSrc(); 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); void setSpectrum(MessageQueue* messageQueue, bool enabled);
Real getMagSq() const { return m_magsq; } Real getMagSq() const { return m_magsq; }
@ -59,11 +68,22 @@ protected:
Real getRFBandwidth() const { return m_rfBandwidth; } Real getRFBandwidth() const { return m_rfBandwidth; }
const QString& getUDPAddress() const { return m_udpAddress; } const QString& getUDPAddress() const { return m_udpAddress; }
int getUDPPort() const { return m_udpPort; } 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: private:
@ -72,18 +92,53 @@ protected:
Real m_rfBandwidth; Real m_rfBandwidth;
QString m_udpAddress; QString m_udpAddress;
int m_udpPort; 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(), Message(),
m_sampleFormat(sampleFormat), m_sampleFormat(sampleFormat),
m_outputSampleRate(outputSampleRate), m_outputSampleRate(outputSampleRate),
m_rfBandwidth(rfBandwidth), m_rfBandwidth(rfBandwidth),
m_udpAddress(udpAddress), m_udpAddress(udpAddress),
m_udpPort(udpPort), 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 { class MsgUDPSrcSpectrum : public Message {
MESSAGE_CLASS_DECLARATION MESSAGE_CLASS_DECLARATION
@ -117,6 +172,8 @@ protected:
QHostAddress m_udpAddress; QHostAddress m_udpAddress;
quint16 m_udpPort; quint16 m_udpPort;
int m_boost; int m_boost;
bool m_audioActive;
int m_volume;
Real m_magsq; Real m_magsq;
Real m_scale; Real m_scale;

Wyświetl plik

@ -55,8 +55,11 @@ void UDPSrcGUI::resetToDefaults()
ui->udpPort->setText("9999"); ui->udpPort->setText("9999");
ui->spectrumGUI->resetToDefaults(); ui->spectrumGUI->resetToDefaults();
ui->boost->setValue(1); ui->boost->setValue(1);
ui->volume->setValue(20);
ui->audioActive->setChecked(false);
blockApplySettings(false); blockApplySettings(false);
applySettingsImmediate();
applySettings(); applySettings();
} }
@ -73,6 +76,8 @@ QByteArray UDPSrcGUI::serialize() const
s.writeS32(8, (qint32)m_boost); s.writeS32(8, (qint32)m_boost);
s.writeS32(9, m_channelMarker.getCenterFrequency()); s.writeS32(9, m_channelMarker.getCenterFrequency());
s.writeString(10, m_udpAddress); s.writeString(10, m_udpAddress);
s.writeBool(11, m_audioActive);
s.writeS32(12, (qint32)m_volume);
return s.final(); return s.final();
} }
@ -92,6 +97,7 @@ bool UDPSrcGUI::deserialize(const QByteArray& data)
QString strtmp; QString strtmp;
qint32 s32tmp; qint32 s32tmp;
Real realtmp; Real realtmp;
bool booltmp;
blockApplySettings(true); blockApplySettings(true);
m_channelMarker.blockSignals(true); m_channelMarker.blockSignals(true);
@ -129,10 +135,15 @@ bool UDPSrcGUI::deserialize(const QByteArray& data)
m_channelMarker.setCenterFrequency(s32tmp); m_channelMarker.setCenterFrequency(s32tmp);
d.readString(10, &strtmp, "127.0.0.1"); d.readString(10, &strtmp, "127.0.0.1");
ui->udpAddress->setText(strtmp); ui->udpAddress->setText(strtmp);
d.readBool(11, &booltmp, false);
ui->audioActive->setChecked(booltmp);
d.readS32(12, &s32tmp, 20);
ui->volume->setValue(s32tmp);
blockApplySettings(false); blockApplySettings(false);
m_channelMarker.blockSignals(false); m_channelMarker.blockSignals(false);
applySettingsImmediate();
applySettings(); applySettings();
return true; return true;
} }
@ -169,7 +180,9 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) :
m_channelMarker(this), m_channelMarker(this),
m_channelPowerDbAvg(40,0), m_channelPowerDbAvg(40,0),
m_basicSettingsShown(false), m_basicSettingsShown(false),
m_doApplySettings(true) m_doApplySettings(true),
m_boost(1),
m_volume(20)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); 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); ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
applySettingsImmediate();
applySettings(); applySettings();
} }
@ -224,6 +238,20 @@ void UDPSrcGUI::blockApplySettings(bool block)
m_doApplySettings = !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() void UDPSrcGUI::applySettings()
{ {
if (m_doApplySettings) if (m_doApplySettings)
@ -253,6 +281,7 @@ void UDPSrcGUI::applySettings()
} }
int boost = ui->boost->value(); int boost = ui->boost->value();
bool audioActive = ui->audioActive->isChecked();
setTitleColor(m_channelMarker.getColor()); setTitleColor(m_channelMarker.getColor());
ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency())); ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
@ -294,6 +323,7 @@ void UDPSrcGUI::applySettings()
m_rfBandwidth = rfBandwidth; m_rfBandwidth = rfBandwidth;
m_udpPort = udpPort; m_udpPort = udpPort;
m_boost = boost; m_boost = boost;
m_audioActive = audioActive;
m_udpSrc->configure(m_udpSrc->getInputMessageQueue(), m_udpSrc->configure(m_udpSrc->getInputMessageQueue(),
sampleFormat, sampleFormat,
@ -301,7 +331,7 @@ void UDPSrcGUI::applySettings()
rfBandwidth, rfBandwidth,
m_udpAddress, m_udpAddress,
udpPort, udpPort,
boost); audioActive);
ui->applyBtn->setEnabled(false); ui->applyBtn->setEnabled(false);
} }
@ -352,11 +382,23 @@ void UDPSrcGUI::on_applyBtn_clicked()
applySettings(); applySettings();
} }
void UDPSrcGUI::on_audioActive_toggled(bool checked)
{
ui->applyBtn->setEnabled(true);
}
void UDPSrcGUI::on_boost_valueChanged(int value) void UDPSrcGUI::on_boost_valueChanged(int value)
{ {
ui->boost->setValue(value); ui->boost->setValue(value);
ui->boostText->setText(QString("%1").arg(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) void UDPSrcGUI::onWidgetRolled(QWidget* widget, bool rollDown)

Wyświetl plik

@ -46,10 +46,12 @@ private slots:
void on_rfBandwidth_textEdited(const QString& arg1); void on_rfBandwidth_textEdited(const QString& arg1);
void on_udpAddress_textEdited(const QString& arg1); void on_udpAddress_textEdited(const QString& arg1);
void on_udpPort_textEdited(const QString& arg1); void on_udpPort_textEdited(const QString& arg1);
void on_audioActive_toggled(bool checked);
void on_applyBtn_clicked(); void on_applyBtn_clicked();
void onWidgetRolled(QWidget* widget, bool rollDown); void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDoubleClicked(); void onMenuDoubleClicked();
void on_boost_valueChanged(int value); void on_boost_valueChanged(int value);
void on_volume_valueChanged(int value);
void tick(); void tick();
private: private:
@ -64,6 +66,8 @@ private:
Real m_outputSampleRate; Real m_outputSampleRate;
Real m_rfBandwidth; Real m_rfBandwidth;
int m_boost; int m_boost;
bool m_audioActive;
int m_volume;
QString m_udpAddress; QString m_udpAddress;
int m_udpPort; int m_udpPort;
bool m_basicSettingsShown; bool m_basicSettingsShown;
@ -79,6 +83,7 @@ private:
void blockApplySettings(bool block); void blockApplySettings(bool block);
void applySettings(); void applySettings();
void applySettingsImmediate();
}; };
#endif // INCLUDE_UDPSRCGUI_H #endif // INCLUDE_UDPSRCGUI_H

Wyświetl plik

@ -155,7 +155,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="volimeText"> <widget class="QLabel" name="volumeText">
<property name="text"> <property name="text">
<string>20</string> <string>20</string>
</property> </property>
@ -324,7 +324,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBox"> <widget class="QCheckBox" name="audioActive">
<property name="toolTip"> <property name="toolTip">
<string>Activate audio</string> <string>Activate audio</string>
</property> </property>