1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 10:33:29 -05:00

UDP source: send audio samples always on 16 bits. Options to send raw I/Q in either 16 or 24 bits regardless of sample size at compile time

This commit is contained in:
f4exb 2018-04-19 13:34:22 +02:00
parent da362823dc
commit befc08f2e1
9 changed files with 54 additions and 105 deletions

View File

@ -61,7 +61,6 @@ UDPSrc::UDPSrc(DeviceSourceAPI *deviceAPI) :
m_udpBuffer16 = new UDPSink<Sample16>(this, udpBlockSize, m_settings.m_udpPort); m_udpBuffer16 = new UDPSink<Sample16>(this, udpBlockSize, m_settings.m_udpPort);
m_udpBufferMono16 = new UDPSink<int16_t>(this, udpBlockSize, m_settings.m_udpPort); m_udpBufferMono16 = new UDPSink<int16_t>(this, udpBlockSize, m_settings.m_udpPort);
m_udpBuffer24 = new UDPSink<Sample24>(this, udpBlockSize, m_settings.m_udpPort); m_udpBuffer24 = new UDPSink<Sample24>(this, udpBlockSize, m_settings.m_udpPort);
m_udpBufferMono24 = new UDPSink<int32_t>(this, udpBlockSize, m_settings.m_udpPort);
m_audioSocket = new QUdpSocket(this); m_audioSocket = new QUdpSocket(this);
m_udpAudioBuf = new char[m_udpAudioPayloadSize]; m_udpAudioBuf = new char[m_udpAudioPayloadSize];
@ -113,7 +112,6 @@ UDPSrc::~UDPSrc()
{ {
delete m_audioSocket; delete m_audioSocket;
delete m_udpBuffer24; delete m_udpBuffer24;
delete m_udpBufferMono24;
delete m_udpBuffer16; delete m_udpBuffer16;
delete m_udpBufferMono16; delete m_udpBufferMono16;
delete[] m_udpAudioBuf; delete[] m_udpAudioBuf;
@ -153,7 +151,8 @@ void UDPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector:
if ((m_settings.m_agc) && if ((m_settings.m_agc) &&
(m_settings.m_sampleFormat != UDPSrcSettings::FormatNFM) && (m_settings.m_sampleFormat != UDPSrcSettings::FormatNFM) &&
(m_settings.m_sampleFormat != UDPSrcSettings::FormatNFMMono) && (m_settings.m_sampleFormat != UDPSrcSettings::FormatNFMMono) &&
(m_settings.m_sampleFormat != UDPSrcSettings::FormatIQ)) (m_settings.m_sampleFormat != UDPSrcSettings::FormatIQ16) &&
(m_settings.m_sampleFormat != UDPSrcSettings::FormatIQ24))
{ {
agcFactor = m_agc.feedAndGetValue(ci); agcFactor = m_agc.feedAndGetValue(ci);
inMagSq = m_agc.getMagSq(); inMagSq = m_agc.getMagSq();
@ -494,7 +493,6 @@ void UDPSrc::applySettings(const UDPSrcSettings& settings, bool force)
<< " m_squelchGate" << settings.m_squelchGate << " m_squelchGate" << settings.m_squelchGate
<< " m_agc" << settings.m_agc << " m_agc" << settings.m_agc
<< " m_sampleFormat: " << settings.m_sampleFormat << " m_sampleFormat: " << settings.m_sampleFormat
<< " m_sampleSize: " << 16 + settings.m_sampleSize*8
<< " m_outputSampleRate: " << settings.m_outputSampleRate << " m_outputSampleRate: " << settings.m_outputSampleRate
<< " m_rfBandwidth: " << settings.m_rfBandwidth << " m_rfBandwidth: " << settings.m_rfBandwidth
<< " m_fmDeviation: " << settings.m_fmDeviation << " m_fmDeviation: " << settings.m_fmDeviation
@ -582,7 +580,6 @@ void UDPSrc::applySettings(const UDPSrcSettings& settings, bool force)
m_udpBuffer16->setAddress(const_cast<QString&>(settings.m_udpAddress)); m_udpBuffer16->setAddress(const_cast<QString&>(settings.m_udpAddress));
m_udpBufferMono16->setAddress(const_cast<QString&>(settings.m_udpAddress)); m_udpBufferMono16->setAddress(const_cast<QString&>(settings.m_udpAddress));
m_udpBuffer24->setAddress(const_cast<QString&>(settings.m_udpAddress)); m_udpBuffer24->setAddress(const_cast<QString&>(settings.m_udpAddress));
m_udpBufferMono24->setAddress(const_cast<QString&>(settings.m_udpAddress));
} }
if ((settings.m_udpPort != m_settings.m_udpPort) || force) if ((settings.m_udpPort != m_settings.m_udpPort) || force)
@ -590,7 +587,6 @@ void UDPSrc::applySettings(const UDPSrcSettings& settings, bool force)
m_udpBuffer16->setPort(settings.m_udpPort); m_udpBuffer16->setPort(settings.m_udpPort);
m_udpBufferMono16->setPort(settings.m_udpPort); m_udpBufferMono16->setPort(settings.m_udpPort);
m_udpBuffer24->setPort(settings.m_udpPort); m_udpBuffer24->setPort(settings.m_udpPort);
m_udpBufferMono24->setPort(settings.m_udpPort);
} }
if ((settings.m_audioPort != m_settings.m_audioPort) || force) if ((settings.m_audioPort != m_settings.m_audioPort) || force)

View File

@ -186,7 +186,6 @@ protected:
UDPSink<Sample16> *m_udpBuffer16; UDPSink<Sample16> *m_udpBuffer16;
UDPSink<int16_t> *m_udpBufferMono16; UDPSink<int16_t> *m_udpBufferMono16;
UDPSink<Sample24> *m_udpBuffer24; UDPSink<Sample24> *m_udpBuffer24;
UDPSink<int32_t> *m_udpBufferMono24;
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;
@ -281,18 +280,22 @@ protected:
{ {
if (SDR_RX_SAMP_SZ == 16) if (SDR_RX_SAMP_SZ == 16)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { if (m_settings.m_sampleFormat == UDPSrcSettings::FormatIQ16) {
m_udpBuffer16->write(Sample16(real, imag)); m_udpBuffer16->write(Sample16(real, imag));
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) { } else if (m_settings.m_sampleFormat == UDPSrcSettings::FormatIQ24) {
m_udpBuffer24->write(Sample24(real<<8, imag<<8)); m_udpBuffer24->write(Sample24(real<<8, imag<<8));
} else {
m_udpBuffer16->write(Sample16(real, imag));
} }
} }
else if (SDR_RX_SAMP_SZ == 24) else if (SDR_RX_SAMP_SZ == 24)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { if (m_settings.m_sampleFormat == UDPSrcSettings::FormatIQ16) {
m_udpBuffer16->write(Sample16(real>>8, imag>>8)); m_udpBuffer16->write(Sample16(real>>8, imag>>8));
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) { } else if (m_settings.m_sampleFormat == UDPSrcSettings::FormatIQ24) {
m_udpBuffer24->write(Sample24(real, imag)); m_udpBuffer24->write(Sample24(real, imag));
} else {
m_udpBuffer16->write(Sample16(real>>8, imag>>8));
} }
} }
} }
@ -301,38 +304,22 @@ protected:
{ {
if (SDR_RX_SAMP_SZ == 16) if (SDR_RX_SAMP_SZ == 16)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { m_udpBufferMono16->write(sample);
m_udpBufferMono16->write(sample);
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) {
m_udpBufferMono24->write(sample<<8);
}
} }
else if (SDR_RX_SAMP_SZ == 24) else if (SDR_RX_SAMP_SZ == 24)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { m_udpBufferMono16->write(sample>>8);
m_udpBufferMono16->write(sample>>8);
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) {
m_udpBufferMono24->write(sample);
}
} }
} }
void udpWriteNorm(Real real, Real imag) void udpWriteNorm(Real real, Real imag)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { m_udpBuffer16->write(Sample16(real*32768.0, imag*32768.0));
m_udpBuffer16->write(Sample16(real*32768.0, imag*32768.0));
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) {
m_udpBuffer24->write(Sample24(real*8388608.0, imag*8388608.0));
}
} }
void udpWriteNormMono(Real sample) void udpWriteNormMono(Real sample)
{ {
if (m_settings.m_sampleSize == UDPSrcSettings::Size16bits) { m_udpBufferMono16->write(sample*32768.0);
m_udpBufferMono16->write(sample*32768.0);
} else if (m_settings.m_sampleSize == UDPSrcSettings::Size24bits) {
m_udpBufferMono24->write(sample*8388608.0);
}
} }
}; };

View File

@ -251,36 +251,39 @@ void UDPSrcGUI::setSampleFormatIndex(const UDPSrcSettings::SampleFormat& sampleF
{ {
switch(sampleFormat) switch(sampleFormat)
{ {
case UDPSrcSettings::FormatIQ: case UDPSrcSettings::FormatIQ16:
ui->sampleFormat->setCurrentIndex(0); ui->sampleFormat->setCurrentIndex(0);
break; break;
case UDPSrcSettings::FormatNFM: case UDPSrcSettings::FormatIQ24:
ui->sampleFormat->setCurrentIndex(1); ui->sampleFormat->setCurrentIndex(1);
break; break;
case UDPSrcSettings::FormatNFMMono: case UDPSrcSettings::FormatNFM:
ui->sampleFormat->setCurrentIndex(2); ui->sampleFormat->setCurrentIndex(2);
break; break;
case UDPSrcSettings::FormatLSB: case UDPSrcSettings::FormatNFMMono:
ui->sampleFormat->setCurrentIndex(3); ui->sampleFormat->setCurrentIndex(3);
break; break;
case UDPSrcSettings::FormatUSB: case UDPSrcSettings::FormatLSB:
ui->sampleFormat->setCurrentIndex(4); ui->sampleFormat->setCurrentIndex(4);
break; break;
case UDPSrcSettings::FormatLSBMono: case UDPSrcSettings::FormatUSB:
ui->sampleFormat->setCurrentIndex(5); ui->sampleFormat->setCurrentIndex(5);
break; break;
case UDPSrcSettings::FormatUSBMono: case UDPSrcSettings::FormatLSBMono:
ui->sampleFormat->setCurrentIndex(6); ui->sampleFormat->setCurrentIndex(6);
break; break;
case UDPSrcSettings::FormatAMMono: case UDPSrcSettings::FormatUSBMono:
ui->sampleFormat->setCurrentIndex(7); ui->sampleFormat->setCurrentIndex(7);
break; break;
case UDPSrcSettings::FormatAMNoDCMono: case UDPSrcSettings::FormatAMMono:
ui->sampleFormat->setCurrentIndex(8); ui->sampleFormat->setCurrentIndex(8);
break; break;
case UDPSrcSettings::FormatAMBPFMono: case UDPSrcSettings::FormatAMNoDCMono:
ui->sampleFormat->setCurrentIndex(9); ui->sampleFormat->setCurrentIndex(9);
break; break;
case UDPSrcSettings::FormatAMBPFMono:
ui->sampleFormat->setCurrentIndex(10);
break;
default: default:
ui->sampleFormat->setCurrentIndex(0); ui->sampleFormat->setCurrentIndex(0);
break; break;
@ -292,47 +295,51 @@ void UDPSrcGUI::setSampleFormat(int index)
switch(index) switch(index)
{ {
case 0: case 0:
m_settings.m_sampleFormat = UDPSrcSettings::FormatIQ; m_settings.m_sampleFormat = UDPSrcSettings::FormatIQ16;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 1: case 1:
m_settings.m_sampleFormat = UDPSrcSettings::FormatIQ24;
ui->fmDeviation->setEnabled(false);
break;
case 2:
m_settings.m_sampleFormat = UDPSrcSettings::FormatNFM; m_settings.m_sampleFormat = UDPSrcSettings::FormatNFM;
ui->fmDeviation->setEnabled(true); ui->fmDeviation->setEnabled(true);
break; break;
case 2: case 3:
m_settings.m_sampleFormat = UDPSrcSettings::FormatNFMMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatNFMMono;
ui->fmDeviation->setEnabled(true); ui->fmDeviation->setEnabled(true);
break; break;
case 3: case 4:
m_settings.m_sampleFormat = UDPSrcSettings::FormatLSB; m_settings.m_sampleFormat = UDPSrcSettings::FormatLSB;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 4: case 5:
m_settings.m_sampleFormat = UDPSrcSettings::FormatUSB; m_settings.m_sampleFormat = UDPSrcSettings::FormatUSB;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 5: case 6:
m_settings.m_sampleFormat = UDPSrcSettings::FormatLSBMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatLSBMono;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 6: case 7:
m_settings.m_sampleFormat = UDPSrcSettings::FormatUSBMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatUSBMono;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 7: case 8:
m_settings.m_sampleFormat = UDPSrcSettings::FormatAMMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatAMMono;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 8: case 9:
m_settings.m_sampleFormat = UDPSrcSettings::FormatAMNoDCMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatAMNoDCMono;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
case 9: case 10:
m_settings.m_sampleFormat = UDPSrcSettings::FormatAMBPFMono; m_settings.m_sampleFormat = UDPSrcSettings::FormatAMBPFMono;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
default: default:
m_settings.m_sampleFormat = UDPSrcSettings::FormatIQ; m_settings.m_sampleFormat = UDPSrcSettings::FormatIQ16;
ui->fmDeviation->setEnabled(false); ui->fmDeviation->setEnabled(false);
break; break;
} }
@ -384,18 +391,6 @@ void UDPSrcGUI::on_sampleFormat_currentIndexChanged(int index)
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }"); ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
} }
void UDPSrcGUI::on_sampleSize_currentIndexChanged(int index)
{
if ((index < 0) || (index >= UDPSrcSettings::SizeNone)) {
return;
}
m_settings.m_sampleSize = (UDPSrcSettings::SampleSize) index;
ui->applyBtn->setEnabled(true);
ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }");
}
void UDPSrcGUI::on_sampleRate_textEdited(const QString& arg1 __attribute__((unused))) void UDPSrcGUI::on_sampleRate_textEdited(const QString& arg1 __attribute__((unused)))
{ {
bool ok; bool ok;

View File

@ -94,7 +94,6 @@ private:
private slots: private slots:
void on_deltaFrequency_changed(qint64 value); void on_deltaFrequency_changed(qint64 value);
void on_sampleFormat_currentIndexChanged(int index); void on_sampleFormat_currentIndexChanged(int index);
void on_sampleSize_currentIndexChanged(int index);
void on_sampleRate_textEdited(const QString& arg1); void on_sampleRate_textEdited(const QString& arg1);
void on_rfBandwidth_textEdited(const QString& arg1); void on_rfBandwidth_textEdited(const QString& arg1);
void on_fmDeviation_textEdited(const QString& arg1); void on_fmDeviation_textEdited(const QString& arg1);

View File

@ -386,7 +386,12 @@
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>I/Q</string> <string>I/Q 16bits</string>
</property>
</item>
<item>
<property name="text">
<string>I/Q 24bits</string>
</property> </property>
</item> </item>
<item> <item>
@ -436,23 +441,6 @@
</item> </item>
</widget> </widget>
</item> </item>
<item>
<widget class="QComboBox" name="sampleSize">
<property name="toolTip">
<string>Samples size</string>
</property>
<item>
<property name="text">
<string>16 bits</string>
</property>
</item>
<item>
<property name="text">
<string>24 bits</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">

View File

@ -25,7 +25,7 @@
const PluginDescriptor UDPSrcPlugin::m_pluginDescriptor = { const PluginDescriptor UDPSrcPlugin::m_pluginDescriptor = {
QString("UDP Channel Source"), QString("UDP Channel Source"),
QString("3.12.0"), QString("3.14.3"),
QString("(c) Edouard Griffiths, F4EXB"), QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"), QString("https://github.com/f4exb/sdrangel"),
true, true,

View File

@ -31,8 +31,7 @@ UDPSrcSettings::UDPSrcSettings() :
void UDPSrcSettings::resetToDefaults() void UDPSrcSettings::resetToDefaults()
{ {
m_outputSampleRate = 48000; m_outputSampleRate = 48000;
m_sampleFormat = FormatIQ; m_sampleFormat = FormatIQ16;
m_sampleSize = Size16bits;
m_inputFrequencyOffset = 0; m_inputFrequencyOffset = 0;
m_rfBandwidth = 12500; m_rfBandwidth = 12500;
m_fmDeviation = 2500; m_fmDeviation = 2500;
@ -78,7 +77,6 @@ QByteArray UDPSrcSettings::serialize() const
s.writeS32(17, m_squelchGate); s.writeS32(17, m_squelchGate);
s.writeBool(18, m_agc); s.writeBool(18, m_agc);
s.writeString(19, m_title); s.writeString(19, m_title);
s.writeS32(20, (int) m_sampleFormat);
return s.final(); return s.final();
@ -108,12 +106,12 @@ bool UDPSrcSettings::deserialize(const QByteArray& data)
d.readS32(2, &s32tmp, 0); d.readS32(2, &s32tmp, 0);
m_inputFrequencyOffset = s32tmp; m_inputFrequencyOffset = s32tmp;
d.readS32(3, &s32tmp, FormatIQ); d.readS32(3, &s32tmp, FormatIQ16);
if ((s32tmp >= 0) && (s32tmp < (int) FormatNone)) { if ((s32tmp >= 0) && (s32tmp < (int) FormatNone)) {
m_sampleFormat = (SampleFormat) s32tmp; m_sampleFormat = (SampleFormat) s32tmp;
} else { } else {
m_sampleFormat = FormatIQ; m_sampleFormat = FormatIQ16;
} }
d.readReal(4, &m_outputSampleRate, 48000.0); d.readReal(4, &m_outputSampleRate, 48000.0);
@ -136,14 +134,6 @@ bool UDPSrcSettings::deserialize(const QByteArray& data)
d.readBool(18, &m_agc, false); d.readBool(18, &m_agc, false);
d.readString(19, &m_title, "UDP Sample Source"); d.readString(19, &m_title, "UDP Sample Source");
d.readS32(20, &s32tmp, Size16bits);
if ((s32tmp >= 0) && (s32tmp < (int) SizeNone)) {
m_sampleSize = (SampleSize) s32tmp;
} else {
m_sampleSize = Size16bits;
}
return true; return true;
} }
else else

View File

@ -26,7 +26,8 @@ class Serializable;
struct UDPSrcSettings struct UDPSrcSettings
{ {
enum SampleFormat { enum SampleFormat {
FormatIQ, FormatIQ16,
FormatIQ24,
FormatNFM, FormatNFM,
FormatNFMMono, FormatNFMMono,
FormatLSB, FormatLSB,
@ -39,15 +40,8 @@ struct UDPSrcSettings
FormatNone FormatNone
}; };
enum SampleSize {
Size16bits,
Size24bits,
SizeNone
};
float m_outputSampleRate; float m_outputSampleRate;
SampleFormat m_sampleFormat; SampleFormat m_sampleFormat;
SampleSize m_sampleSize;
int64_t m_inputFrequencyOffset; int64_t m_inputFrequencyOffset;
float m_rfBandwidth; float m_rfBandwidth;
int m_fmDeviation; int m_fmDeviation;

View File

@ -27,7 +27,7 @@
const PluginDescriptor UDPSinkPlugin::m_pluginDescriptor = { const PluginDescriptor UDPSinkPlugin::m_pluginDescriptor = {
QString("UDP Channel Sink"), QString("UDP Channel Sink"),
QString("3.14.2"), QString("3.14.3"),
QString("(c) Edouard Griffiths, F4EXB"), QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"), QString("https://github.com/f4exb/sdrangel"),
true, true,