1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

AM demod: implement RTP over UDP for audio copy

This commit is contained in:
f4exb 2018-03-07 00:55:08 +01:00
parent 5b8a5efd3f
commit 1200e09012
7 changed files with 69 additions and 7 deletions

View File

@ -58,7 +58,8 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
m_magsq = 0.0;
DSPEngine::instance()->addAudioSink(&m_audioFifo);
m_udpBufferAudio = new UDPSink<qint16>(this, m_udpBlockSize, m_settings.m_udpPort);
m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically
m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort);
m_channelizer = new DownChannelizer(this);
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
@ -72,13 +73,18 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) :
AMDemod::~AMDemod()
{
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
delete m_udpBufferAudio;
delete m_audioNetSink;
m_deviceAPI->removeChannelAPI(this);
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
}
bool AMDemod::isAudioNetSinkRTPCapable() const
{
return m_audioNetSink && m_audioNetSink->isRTPCapable();
}
void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
{
Complex ci;
@ -226,6 +232,7 @@ void AMDemod::applySettings(const AMDemodSettings& settings, bool force)
<< " m_audioMute: " << settings.m_audioMute
<< " m_bandpassEnable: " << settings.m_bandpassEnable
<< " m_copyAudioToUDP: " << settings.m_copyAudioToUDP
<< " m_copyAudioUseRTP: " << settings.m_copyAudioUseRTP
<< " m_udpAddress: " << settings.m_udpAddress
<< " m_udpPort: " << settings.m_udpPort
<< " force: " << force;
@ -250,8 +257,27 @@ void AMDemod::applySettings(const AMDemodSettings& settings, bool force)
if ((m_settings.m_udpAddress != settings.m_udpAddress)
|| (m_settings.m_udpPort != settings.m_udpPort) || force)
{
m_udpBufferAudio->setAddress(const_cast<QString&>(settings.m_udpAddress));
m_udpBufferAudio->setPort(settings.m_udpPort);
m_audioNetSink->setDestination(settings.m_udpAddress, settings.m_udpPort);
}
if ((settings.m_copyAudioUseRTP != m_settings.m_copyAudioUseRTP) || force)
{
if (settings.m_copyAudioUseRTP)
{
if (m_audioNetSink->selectType(AudioNetSink::SinkRTP)) {
qDebug("NFMDemod::applySettings: set audio sink to RTP mode");
} else {
qWarning("NFMDemod::applySettings: RTP support for audio sink not available. Fall back too UDP");
}
}
else
{
if (m_audioNetSink->selectType(AudioNetSink::SinkUDP)) {
qDebug("NFMDemod::applySettings: set audio sink to UDP mode");
} else {
qWarning("NFMDemod::applySettings: failed to set audio sink to UDP mode");
}
}
}
m_settings = settings;

View File

@ -30,6 +30,7 @@
#include "audio/audiofifo.h"
#include "util/message.h"
#include "amdemodsettings.h"
#include "audio/audionetsink.h"
class DeviceSourceAPI;
class DownChannelizer;
@ -113,6 +114,8 @@ public:
m_magsqCount = 0;
}
bool isAudioNetSinkRTPCapable() const;
static const QString m_channelIdURI;
static const QString m_channelId;
@ -151,7 +154,7 @@ private:
AudioVector m_audioBuffer;
uint32_t m_audioBufferFill;
AudioFifo m_audioFifo;
UDPSink<qint16> *m_udpBufferAudio;
AudioNetSink *m_audioNetSink;
static const int m_udpBlockSize;
@ -207,14 +210,18 @@ private:
Real attack = (m_squelchCount - 0.05f * m_settings.m_audioSampleRate) / (0.05f * m_settings.m_audioSampleRate);
sample = demod * attack * 2048 * m_settings.m_volume;
if (m_settings.m_copyAudioToUDP) m_udpBufferAudio->write(demod * attack * SDR_RX_SCALEF);
if (m_settings.m_copyAudioToUDP) {
m_audioNetSink->write(demod * attack * 32768.0f);
}
m_squelchOpen = true;
}
else
{
sample = 0;
if (m_settings.m_copyAudioToUDP) m_udpBufferAudio->write(0);
if (m_settings.m_copyAudioToUDP) {
m_audioNetSink->write(0);
}
m_squelchOpen = false;
}

View File

@ -153,6 +153,12 @@ void AMDemodGUI::on_copyAudioToUDP_toggled(bool checked)
applySettings();
}
void AMDemodGUI::on_useRTP_toggled(bool checked)
{
m_settings.m_copyAudioUseRTP = checked;
applySettings();
}
void AMDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool rollDown __attribute__((unused)))
{
/*
@ -221,6 +227,10 @@ AMDemodGUI::AMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandS
m_deviceUISet->addChannelMarker(&m_channelMarker);
m_deviceUISet->addRollupWidget(this);
if (!m_amDemod->isAudioNetSinkRTPCapable()) {
ui->useRTP->hide();
}
connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor()));
@ -285,6 +295,10 @@ void AMDemodGUI::displaySettings()
ui->bandpassEnable->setChecked(m_settings.m_bandpassEnable);
ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP);
if (m_amDemod->isAudioNetSinkRTPCapable()) {
ui->useRTP->setChecked(m_settings.m_copyAudioUseRTP);
}
blockApplySettings(false);
}

View File

@ -72,6 +72,7 @@ private slots:
void on_squelch_valueChanged(int value);
void on_audioMute_toggled(bool checked);
void on_copyAudioToUDP_toggled(bool copy);
void on_useRTP_toggled(bool checked);
void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDialogCalled(const QPoint& p);
void tick();

View File

@ -199,6 +199,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="useRTP">
<property name="toolTip">
<string>Use RTP protocol for audio copy to UDP</string>
</property>
<property name="text">
<string>R</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -37,6 +37,7 @@ void AMDemodSettings::resetToDefaults()
m_audioMute = false;
m_bandpassEnable = false;
m_copyAudioToUDP = false;
m_copyAudioUseRTP = false;
m_udpAddress = "127.0.0.1";
m_udpPort = 9999;
m_rgbColor = QColor(255, 255, 0).rgb();
@ -58,6 +59,7 @@ QByteArray AMDemodSettings::serialize() const
s.writeU32(7, m_rgbColor);
s.writeBool(8, m_bandpassEnable);
s.writeString(9, m_title);
s.writeBool(10, m_copyAudioUseRTP);
return s.final();
}
@ -93,6 +95,7 @@ bool AMDemodSettings::deserialize(const QByteArray& data)
d.readU32(7, &m_rgbColor);
d.readBool(8, &m_bandpassEnable, false);
d.readString(9, &m_title, "AM Demodulator");
d.readBool(10, &m_copyAudioUseRTP, false);
return true;
}

View File

@ -31,6 +31,7 @@ struct AMDemodSettings
bool m_audioMute;
bool m_bandpassEnable;
bool m_copyAudioToUDP;
bool m_copyAudioUseRTP;
QString m_udpAddress;
quint16 m_udpPort;
quint32 m_rgbColor;