1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

UDP Sink: use settings in sink (4)

This commit is contained in:
f4exb 2017-10-17 00:14:06 +02:00
parent 7c4aff362a
commit b8564edbc9
3 changed files with 138 additions and 126 deletions

View File

@ -28,6 +28,7 @@ MESSAGE_CLASS_DEFINITION(UDPSink::MsgUDPSinkSpectrum, Message)
MESSAGE_CLASS_DEFINITION(UDPSink::MsgResetReadIndex, Message)
UDPSink::UDPSink(MessageQueue* uiMessageQueue, UDPSinkGUI* udpSinkGUI, BasebandSampleSink* spectrum) :
m_squelch(1e-6),
m_uiMessageQueue(uiMessageQueue),
m_udpSinkGUI(udpSinkGUI),
m_spectrum(spectrum),
@ -53,9 +54,9 @@ UDPSink::UDPSink(MessageQueue* uiMessageQueue, UDPSinkGUI* udpSinkGUI, BasebandS
{
setObjectName("UDPSink");
m_udpHandler.setFeedbackMessageQueue(&m_inputMessageQueue);
m_SSBFilter = new fftfilt(m_running.m_lowCutoff / m_running.m_inputSampleRate, m_running.m_rfBandwidth / m_running.m_inputSampleRate, m_ssbFftLen);
m_SSBFilter = new fftfilt(m_settings.m_lowCutoff / m_settings.m_inputSampleRate, m_settings.m_rfBandwidth / m_settings.m_inputSampleRate, m_ssbFftLen);
m_SSBFilterBuffer = new Complex[m_ssbFftLen>>1]; // filter returns data exactly half of its size
apply(true);
applySettings(m_settings, true);
}
UDPSink::~UDPSink()
@ -76,7 +77,7 @@ void UDPSink::stop()
void UDPSink::pull(Sample& sample)
{
if (m_running.m_channelMute)
if (m_settings.m_channelMute)
{
sample.m_real = 0.0f;
sample.m_imag = 0.0f;
@ -122,7 +123,7 @@ void UDPSink::pull(Sample& sample)
void UDPSink::modulateSample()
{
if (m_running.m_sampleFormat == UDPSinkSettings::FormatS16LE) // Linear I/Q transponding
if (m_settings.m_sampleFormat == UDPSinkSettings::FormatS16LE) // Linear I/Q transponding
{
Sample s;
@ -136,8 +137,8 @@ void UDPSink::modulateSample()
if (m_squelchOpen)
{
m_modSample.real(s.m_real * m_running.m_gainOut);
m_modSample.imag(s.m_imag * m_running.m_gainOut);
m_modSample.real(s.m_real * m_settings.m_gainOut);
m_modSample.imag(s.m_imag * m_settings.m_gainOut);
calculateLevel(m_modSample);
}
else
@ -146,7 +147,7 @@ void UDPSink::modulateSample()
m_modSample.imag(0.0f);
}
}
else if (m_running.m_sampleFormat == UDPSinkSettings::FormatNFM)
else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatNFM)
{
FixReal t;
readMonoSample(t);
@ -158,9 +159,9 @@ void UDPSink::modulateSample()
if (m_squelchOpen)
{
m_modPhasor += (m_running.m_fmDeviation / m_running.m_inputSampleRate) * (t / 32768.0f) * M_PI * 2.0f;
m_modSample.real(cos(m_modPhasor) * 10362.2f * m_running.m_gainOut);
m_modSample.imag(sin(m_modPhasor) * 10362.2f * m_running.m_gainOut);
m_modPhasor += (m_settings.m_fmDeviation / m_settings.m_inputSampleRate) * (t / 32768.0f) * M_PI * 2.0f;
m_modSample.real(cos(m_modPhasor) * 10362.2f * m_settings.m_gainOut);
m_modSample.imag(sin(m_modPhasor) * 10362.2f * m_settings.m_gainOut);
calculateLevel(m_modSample);
}
else
@ -169,7 +170,7 @@ void UDPSink::modulateSample()
m_modSample.imag(0.0f);
}
}
else if (m_running.m_sampleFormat == UDPSinkSettings::FormatAM)
else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatAM)
{
FixReal t;
readMonoSample(t);
@ -180,7 +181,7 @@ void UDPSink::modulateSample()
if (m_squelchOpen)
{
m_modSample.real(((t / 32768.0f)*m_running.m_amModFactor*m_running.m_gainOut + 1.0f) * 16384.0f); // modulate and scale zero frequency carrier
m_modSample.real(((t / 32768.0f)*m_settings.m_amModFactor*m_settings.m_gainOut + 1.0f) * 16384.0f); // modulate and scale zero frequency carrier
m_modSample.imag(0.0f);
calculateLevel(m_modSample);
}
@ -190,7 +191,7 @@ void UDPSink::modulateSample()
m_modSample.imag(0.0f);
}
}
else if ((m_running.m_sampleFormat == UDPSinkSettings::FormatLSB) || (m_running.m_sampleFormat == UDPSinkSettings::FormatUSB))
else if ((m_settings.m_sampleFormat == UDPSinkSettings::FormatLSB) || (m_settings.m_sampleFormat == UDPSinkSettings::FormatUSB))
{
FixReal t;
Complex c, ci;
@ -205,10 +206,10 @@ void UDPSink::modulateSample()
if (m_squelchOpen)
{
ci.real((t / 32768.0f) * m_running.m_gainOut);
ci.real((t / 32768.0f) * m_settings.m_gainOut);
ci.imag(0.0f);
n_out = m_SSBFilter->runSSB(ci, &filtered, (m_running.m_sampleFormat == UDPSinkSettings::FormatUSB));
n_out = m_SSBFilter->runSSB(ci, &filtered, (m_settings.m_sampleFormat == UDPSinkSettings::FormatUSB));
if (n_out > 0)
{
@ -297,16 +298,18 @@ bool UDPSink::handleMessage(const Message& cmd)
{
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
m_config.m_basebandSampleRate = notif.getBasebandSampleRate();
m_config.m_outputSampleRate = notif.getSampleRate();
m_config.m_inputFrequencyOffset = notif.getFrequencyOffset();
UDPSinkSettings settings = m_settings;
apply(false);
settings.m_basebandSampleRate = notif.getBasebandSampleRate();
settings.m_outputSampleRate = notif.getSampleRate();
settings.m_inputFrequencyOffset = notif.getFrequencyOffset();
applySettings(settings);
qDebug() << "UDPSink::handleMessage: MsgChannelizerNotification:"
<< " m_basebandSampleRate: " << m_config.m_basebandSampleRate
<< " m_outputSampleRate: " << m_config.m_outputSampleRate
<< " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset;
<< " m_basebandSampleRate: " << settings.m_basebandSampleRate
<< " m_outputSampleRate: " << settings.m_outputSampleRate
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset;
return true;
}
@ -375,7 +378,7 @@ bool UDPSink::handleMessage(const Message& cmd)
m_config.m_autoRWBalance = cfg.getAutoRWBalance();
m_config.m_stereoInput = cfg.getStereoInput();
apply(cfg.getForce());
//apply(cfg.getForce());
qDebug() << "UDPSink::handleMessage: MsgUDPSinkConfigure:"
<< " m_sampleFormat: " << m_config.m_sampleFormat
@ -402,7 +405,7 @@ bool UDPSink::handleMessage(const Message& cmd)
Real newSampleRate = m_actualInputSampleRate + cfg.getCorrectionFactor() * m_actualInputSampleRate;
// exclude values too way out nominal sample rate (20%)
if ((newSampleRate < m_running.m_inputSampleRate * 1.2) && (newSampleRate > m_running.m_inputSampleRate * 0.8))
if ((newSampleRate < m_settings.m_inputSampleRate * 1.2) && (newSampleRate > m_settings.m_inputSampleRate * 0.8))
{
m_actualInputSampleRate = newSampleRate;
@ -441,8 +444,8 @@ bool UDPSink::handleMessage(const Message& cmd)
m_settingsMutex.lock();
m_interpolatorDistanceRemain = 0;
m_interpolatorConsumed = false;
m_interpolatorDistance = (Real) m_actualInputSampleRate / (Real) m_running.m_outputSampleRate;
//m_interpolator.create(48, m_actualInputSampleRate, m_running.m_rfBandwidth / 2.2, 3.0); // causes clicking: leaving at standard frequency
m_interpolatorDistance = (Real) m_actualInputSampleRate / (Real) m_settings.m_outputSampleRate;
//m_interpolator.create(48, m_actualInputSampleRate, m_settings.m_rfBandwidth / 2.2, 3.0); // causes clicking: leaving at standard frequency
m_settingsMutex.unlock();
}
@ -529,84 +532,84 @@ void UDPSink::resetReadIndex(MessageQueue* messageQueue)
}
void UDPSink::apply(bool force)
{
if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
(m_config.m_outputSampleRate != m_running.m_outputSampleRate) || force)
{
m_settingsMutex.lock();
m_carrierNco.setFreq(m_config.m_inputFrequencyOffset, m_config.m_outputSampleRate);
m_settingsMutex.unlock();
}
if((m_config.m_outputSampleRate != m_running.m_outputSampleRate) ||
(m_config.m_rfBandwidth != m_running.m_rfBandwidth) ||
(m_config.m_inputSampleRate != m_running.m_inputSampleRate) || force)
{
m_settingsMutex.lock();
m_interpolatorDistanceRemain = 0;
m_interpolatorConsumed = false;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
m_actualInputSampleRate = m_config.m_inputSampleRate;
m_udpHandler.resetReadIndex();
m_sampleRateSum = 0.0;
m_sampleRateAvgCounter = 0;
m_spectrumChunkSize = m_config.m_inputSampleRate * 0.05; // 50 ms chunk
m_spectrumChunkCounter = 0;
m_levelNbSamples = m_config.m_inputSampleRate * 0.01; // every 10 ms
m_levelCalcCount = 0;
m_peakLevel = 0.0f;
m_levelSum = 0.0f;
m_udpHandler.resizeBuffer(m_config.m_inputSampleRate);
m_inMovingAverage.resize(m_config.m_inputSampleRate * 0.01, 1e-10); // 10 ms
m_squelchThreshold = m_config.m_inputSampleRate * m_config.m_squelchGate;
initSquelch(m_squelchOpen);
m_SSBFilter->create_filter(m_config.m_lowCutoff / m_config.m_inputSampleRate, m_config.m_rfBandwidth / m_config.m_inputSampleRate);
m_settingsMutex.unlock();
}
if ((m_config.m_squelchGate != m_running.m_squelchGate) || force)
{
m_squelchThreshold = m_config.m_outputSampleRate * m_config.m_squelchGate;
initSquelch(m_squelchOpen);
}
if ((m_config.m_udpAddressStr != m_running.m_udpAddressStr) ||
(m_config.m_udpPort != m_running.m_udpPort) || force)
{
m_settingsMutex.lock();
m_udpHandler.configureUDPLink(m_config.m_udpAddressStr, m_config.m_udpPort);
m_settingsMutex.unlock();
}
if ((m_config.m_channelMute != m_running.m_channelMute) || force)
{
if (!m_config.m_channelMute) {
m_udpHandler.resetReadIndex();
}
}
if ((m_config.m_autoRWBalance != m_running.m_autoRWBalance) || force)
{
m_settingsMutex.lock();
m_udpHandler.setAutoRWBalance(m_config.m_autoRWBalance);
if (!m_config.m_autoRWBalance)
{
m_interpolatorDistanceRemain = 0;
m_interpolatorConsumed = false;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
m_actualInputSampleRate = m_config.m_inputSampleRate;
m_udpHandler.resetReadIndex();
}
m_settingsMutex.unlock();
}
m_running = m_config;
}
//void UDPSink::apply(bool force)
//{
// if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
// (m_config.m_outputSampleRate != m_running.m_outputSampleRate) || force)
// {
// m_settingsMutex.lock();
// m_carrierNco.setFreq(m_config.m_inputFrequencyOffset, m_config.m_outputSampleRate);
// m_settingsMutex.unlock();
// }
//
// if((m_config.m_outputSampleRate != m_running.m_outputSampleRate) ||
// (m_config.m_rfBandwidth != m_running.m_rfBandwidth) ||
// (m_config.m_inputSampleRate != m_running.m_inputSampleRate) || force)
// {
// m_settingsMutex.lock();
// m_interpolatorDistanceRemain = 0;
// m_interpolatorConsumed = false;
// m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
// m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
// m_actualInputSampleRate = m_config.m_inputSampleRate;
// m_udpHandler.resetReadIndex();
// m_sampleRateSum = 0.0;
// m_sampleRateAvgCounter = 0;
// m_spectrumChunkSize = m_config.m_inputSampleRate * 0.05; // 50 ms chunk
// m_spectrumChunkCounter = 0;
// m_levelNbSamples = m_config.m_inputSampleRate * 0.01; // every 10 ms
// m_levelCalcCount = 0;
// m_peakLevel = 0.0f;
// m_levelSum = 0.0f;
// m_udpHandler.resizeBuffer(m_config.m_inputSampleRate);
// m_inMovingAverage.resize(m_config.m_inputSampleRate * 0.01, 1e-10); // 10 ms
// m_squelchThreshold = m_config.m_inputSampleRate * m_config.m_squelchGate;
// initSquelch(m_squelchOpen);
// m_SSBFilter->create_filter(m_config.m_lowCutoff / m_config.m_inputSampleRate, m_config.m_rfBandwidth / m_config.m_inputSampleRate);
// m_settingsMutex.unlock();
// }
//
// if ((m_config.m_squelchGate != m_running.m_squelchGate) || force)
// {
// m_squelchThreshold = m_config.m_outputSampleRate * m_config.m_squelchGate;
// initSquelch(m_squelchOpen);
// }
//
// if ((m_config.m_udpAddressStr != m_running.m_udpAddressStr) ||
// (m_config.m_udpPort != m_running.m_udpPort) || force)
// {
// m_settingsMutex.lock();
// m_udpHandler.configureUDPLink(m_config.m_udpAddressStr, m_config.m_udpPort);
// m_settingsMutex.unlock();
// }
//
// if ((m_config.m_channelMute != m_running.m_channelMute) || force)
// {
// if (!m_config.m_channelMute) {
// m_udpHandler.resetReadIndex();
// }
// }
//
// if ((m_config.m_autoRWBalance != m_running.m_autoRWBalance) || force)
// {
// m_settingsMutex.lock();
// m_udpHandler.setAutoRWBalance(m_config.m_autoRWBalance);
//
// if (!m_config.m_autoRWBalance)
// {
// m_interpolatorDistanceRemain = 0;
// m_interpolatorConsumed = false;
// m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
// m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
// m_actualInputSampleRate = m_config.m_inputSampleRate;
// m_udpHandler.resetReadIndex();
// }
//
// m_settingsMutex.unlock();
// }
//
// m_running = m_config;
//}
void UDPSink::applySettings(const UDPSinkSettings& settings, bool force)
{
@ -645,6 +648,11 @@ void UDPSink::applySettings(const UDPSinkSettings& settings, bool force)
m_settingsMutex.unlock();
}
if ((settings.m_squelch != m_settings.m_squelch) || force)
{
m_squelch = CalcDb::powerFromdB(settings.m_squelch);
}
if ((settings.m_squelchGate != m_settings.m_squelchGate) || force)
{
m_squelchThreshold = settings.m_outputSampleRate * settings.m_squelchGate;

View File

@ -324,6 +324,7 @@ private:
Config m_config;
Config m_running;
UDPSinkSettings m_settings;
Real m_squelch;
NCO m_carrierNco;
Complex m_modSample;
@ -371,7 +372,7 @@ private:
static const int m_sampleRateAverageItems = 17;
static const int m_ssbFftLen = 1024;
void apply(bool force);
//void apply(bool force);
void applySettings(const UDPSinkSettings& settings, bool force = false);
void modulateSample();
void calculateLevel(Real sample);
@ -379,7 +380,7 @@ private:
inline void calculateSquelch(double value)
{
if ((!m_running.m_squelchEnabled) || (value > m_running.m_squelch))
if ((!m_settings.m_squelchEnabled) || (value > m_squelch))
{
if (m_squelchThreshold == 0)
{
@ -439,15 +440,15 @@ private:
{
Sample s;
if (m_running.m_stereoInput)
if (m_settings.m_stereoInput)
{
m_udpHandler.readSample(s);
t = ((s.m_real + s.m_imag) * m_running.m_gainIn) / 2;
t = ((s.m_real + s.m_imag) * m_settings.m_gainIn) / 2;
}
else
{
m_udpHandler.readSample(t);
t *= m_running.m_gainIn;
t *= m_settings.m_gainIn;
}
}
};

View File

@ -281,23 +281,26 @@ void UDPSinkGUI::applySettings(bool force)
m_settings.m_inputSampleRate,
m_settings.m_inputFrequencyOffset);
m_udpSink->configure(m_udpSink->getInputMessageQueue(),
m_settings.m_sampleFormat,
m_settings.m_inputSampleRate,
m_settings.m_rfBandwidth,
m_settings.m_fmDeviation,
m_settings.m_amModFactor,
m_settings.m_udpAddress,
m_settings.m_udpPort,
m_settings.m_channelMute,
m_settings.m_gainIn,
m_settings.m_gainOut,
m_settings.m_squelch,
m_settings.m_squelchGate,
m_settings.m_squelchEnabled,
m_settings.m_autoRWBalance,
m_settings.m_stereoInput,
force);
UDPSink::MsgConfigureUDPSink* message = UDPSink::MsgConfigureUDPSink::create( m_settings, force);
m_udpSink->getInputMessageQueue()->push(message);
// m_udpSink->configure(m_udpSink->getInputMessageQueue(),
// m_settings.m_sampleFormat,
// m_settings.m_inputSampleRate,
// m_settings.m_rfBandwidth,
// m_settings.m_fmDeviation,
// m_settings.m_amModFactor,
// m_settings.m_udpAddress,
// m_settings.m_udpPort,
// m_settings.m_channelMute,
// m_settings.m_gainIn,
// m_settings.m_gainOut,
// m_settings.m_squelch,
// m_settings.m_squelchGate,
// m_settings.m_squelchEnabled,
// m_settings.m_autoRWBalance,
// m_settings.m_stereoInput,
// force);
ui->applyBtn->setEnabled(false);
ui->applyBtn->setStyleSheet("QPushButton { background:rgb(79,79,79); }");