1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00

NFM Modulator: variable tone frequency. Fixed excursion empirically (not satisfactory)

This commit is contained in:
f4exb 2016-12-01 01:19:50 +01:00
parent 9fdaa29544
commit 328e0ad630
5 changed files with 158 additions and 54 deletions

View File

@ -48,7 +48,8 @@ NFMMod::NFMMod() :
m_config.m_inputFrequencyOffset = 0; m_config.m_inputFrequencyOffset = 0;
m_config.m_rfBandwidth = 12500; m_config.m_rfBandwidth = 12500;
m_config.m_afBandwidth = 3000; m_config.m_afBandwidth = 3000;
m_config.m_fmDeviation = 5000; m_config.m_fmDeviation = 5000.0f;
m_config.m_toneFrequency = 1000.0f;
m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
apply(); apply();
@ -73,11 +74,12 @@ void NFMMod::configure(MessageQueue* messageQueue,
Real rfBandwidth, Real rfBandwidth,
Real afBandwidth, Real afBandwidth,
float fmDeviation, float fmDeviation,
float toneFrequency,
int volumeTenths, int volumeTenths,
bool audioMute, bool audioMute,
bool playLoop) bool playLoop)
{ {
Message* cmd = MsgConfigureNFMMod::create(rfBandwidth, afBandwidth, fmDeviation, volumeTenths, audioMute, playLoop); Message* cmd = MsgConfigureNFMMod::create(rfBandwidth, afBandwidth, fmDeviation, toneFrequency, volumeTenths, audioMute, playLoop);
messageQueue->push(cmd); messageQueue->push(cmd);
} }
@ -126,7 +128,7 @@ void NFMMod::modulateSample()
pullAF(t); pullAF(t);
m_modPhasor += (m_running.m_fmDeviation / (float) m_running.m_audioSampleRate) * m_bandpass.filter(t) * (M_PI / 302.0f); m_modPhasor += (m_running.m_fmDeviation / (float) m_running.m_audioSampleRate) * m_bandpass.filter(t) * (M_PI / 1208.0f);
m_modSample.real(cos(m_modPhasor) * 32678.0f); m_modSample.real(cos(m_modPhasor) * 32678.0f);
m_modSample.imag(sin(m_modPhasor) * 32678.0f); m_modSample.imag(sin(m_modPhasor) * 32678.0f);
} }
@ -217,6 +219,7 @@ bool NFMMod::handleMessage(const Message& cmd)
m_config.m_rfBandwidth = cfg.getRFBandwidth(); m_config.m_rfBandwidth = cfg.getRFBandwidth();
m_config.m_afBandwidth = cfg.getAFBandwidth(); m_config.m_afBandwidth = cfg.getAFBandwidth();
m_config.m_fmDeviation = cfg.getFMDeviation(); m_config.m_fmDeviation = cfg.getFMDeviation();
m_config.m_toneFrequency = cfg.getToneFrequency();
m_config.m_volumeFactor = cfg.getVolumeFactor(); m_config.m_volumeFactor = cfg.getVolumeFactor();
m_config.m_audioMute = cfg.getAudioMute(); m_config.m_audioMute = cfg.getAudioMute();
m_config.m_playLoop = cfg.getPlayLoop(); m_config.m_playLoop = cfg.getPlayLoop();
@ -227,6 +230,7 @@ bool NFMMod::handleMessage(const Message& cmd)
<< " m_rfBandwidth: " << m_config.m_rfBandwidth << " m_rfBandwidth: " << m_config.m_rfBandwidth
<< " m_afBandwidth: " << m_config.m_afBandwidth << " m_afBandwidth: " << m_config.m_afBandwidth
<< " m_fmDeviation: " << m_config.m_fmDeviation << " m_fmDeviation: " << m_config.m_fmDeviation
<< " m_toneFrequency: " << m_config.m_toneFrequency
<< " m_volumeFactor: " << m_config.m_volumeFactor << " m_volumeFactor: " << m_config.m_volumeFactor
<< " m_audioMute: " << m_config.m_audioMute << " m_audioMute: " << m_config.m_audioMute
<< " m_playLoop: " << m_config.m_playLoop; << " m_playLoop: " << m_config.m_playLoop;
@ -308,6 +312,14 @@ void NFMMod::apply()
m_settingsMutex.unlock(); m_settingsMutex.unlock();
} }
if ((m_config.m_toneFrequency != m_running.m_toneFrequency) ||
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
{
m_settingsMutex.lock();
m_toneNco.setFreq(m_config.m_toneFrequency, m_config.m_audioSampleRate);
m_settingsMutex.unlock();
}
m_running.m_outputSampleRate = m_config.m_outputSampleRate; m_running.m_outputSampleRate = m_config.m_outputSampleRate;
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset; m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
m_running.m_rfBandwidth = m_config.m_rfBandwidth; m_running.m_rfBandwidth = m_config.m_rfBandwidth;

View File

@ -175,7 +175,14 @@ public:
NFMMod(); NFMMod();
~NFMMod(); ~NFMMod();
void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float fmDeviation, int volumeFactor, bool audioMute, bool playLoop); void configure(MessageQueue* messageQueue,
Real rfBandwidth,
Real afBandwidth,
float fmDeviation,
float toneFrequency,
int volumeFactor,
bool audioMute,
bool playLoop);
virtual void pull(Sample& sample); virtual void pull(Sample& sample);
virtual void start(); virtual void start();
@ -193,28 +200,31 @@ private:
Real getRFBandwidth() const { return m_rfBandwidth; } Real getRFBandwidth() const { return m_rfBandwidth; }
Real getAFBandwidth() const { return m_afBandwidth; } Real getAFBandwidth() const { return m_afBandwidth; }
float getFMDeviation() const { return m_fmDeviation; } float getFMDeviation() const { return m_fmDeviation; }
float getToneFrequency() const { return m_toneFrequency; }
int getVolumeFactor() const { return m_volumeFactor; } int getVolumeFactor() const { return m_volumeFactor; }
bool getAudioMute() const { return m_audioMute; } bool getAudioMute() const { return m_audioMute; }
bool getPlayLoop() const { return m_playLoop; } bool getPlayLoop() const { return m_playLoop; }
static MsgConfigureNFMMod* create(Real rfBandwidth, Real afBandwidth, float fmDeviation, int volumeFactor, bool audioMute, bool playLoop) static MsgConfigureNFMMod* create(Real rfBandwidth, Real afBandwidth, float fmDeviation, float toneFrequency, int volumeFactor, bool audioMute, bool playLoop)
{ {
return new MsgConfigureNFMMod(rfBandwidth, afBandwidth, fmDeviation, volumeFactor, audioMute, playLoop); return new MsgConfigureNFMMod(rfBandwidth, afBandwidth, fmDeviation, toneFrequency, volumeFactor, audioMute, playLoop);
} }
private: private:
Real m_rfBandwidth; Real m_rfBandwidth;
Real m_afBandwidth; Real m_afBandwidth;
float m_fmDeviation; float m_fmDeviation;
float m_toneFrequency;
int m_volumeFactor; int m_volumeFactor;
bool m_audioMute; bool m_audioMute;
bool m_playLoop; bool m_playLoop;
MsgConfigureNFMMod(Real rfBandwidth, Real afBandwidth, float fmDeviation, int volumeFactor, bool audioMute, bool playLoop) : MsgConfigureNFMMod(Real rfBandwidth, Real afBandwidth, float fmDeviation, float toneFrequency, int volumeFactor, bool audioMute, bool playLoop) :
Message(), Message(),
m_rfBandwidth(rfBandwidth), m_rfBandwidth(rfBandwidth),
m_afBandwidth(afBandwidth), m_afBandwidth(afBandwidth),
m_fmDeviation(fmDeviation), m_fmDeviation(fmDeviation),
m_toneFrequency(toneFrequency),
m_volumeFactor(volumeFactor), m_volumeFactor(volumeFactor),
m_audioMute(audioMute), m_audioMute(audioMute),
m_playLoop(playLoop) m_playLoop(playLoop)
@ -240,6 +250,7 @@ private:
Real m_rfBandwidth; Real m_rfBandwidth;
Real m_afBandwidth; Real m_afBandwidth;
float m_fmDeviation; float m_fmDeviation;
float m_toneFrequency;
int m_volumeFactor; int m_volumeFactor;
quint32 m_audioSampleRate; quint32 m_audioSampleRate;
bool m_audioMute; bool m_audioMute;
@ -250,7 +261,8 @@ private:
m_inputFrequencyOffset(0), m_inputFrequencyOffset(0),
m_rfBandwidth(-1), m_rfBandwidth(-1),
m_afBandwidth(-1), m_afBandwidth(-1),
m_fmDeviation(5.0f), m_fmDeviation(5000.0f),
m_toneFrequency(1000.0f),
m_volumeFactor(20), m_volumeFactor(20),
m_audioSampleRate(0), m_audioSampleRate(0),
m_audioMute(false), m_audioMute(false),

View File

@ -77,6 +77,7 @@ void NFMModGUI::resetToDefaults()
ui->rfBW->setCurrentIndex(6); ui->rfBW->setCurrentIndex(6);
ui->afBW->setValue(3); ui->afBW->setValue(3);
ui->fmDev->setValue(50); ui->fmDev->setValue(50);
ui->toneFrequency->setValue(100);
ui->micVolume->setValue(50); ui->micVolume->setValue(50);
ui->deltaFrequency->setValue(0); ui->deltaFrequency->setValue(0);
@ -92,6 +93,7 @@ QByteArray NFMModGUI::serialize() const
s.writeS32(3, ui->afBW->value()); s.writeS32(3, ui->afBW->value());
s.writeS32(4, ui->fmDev->value()); s.writeS32(4, ui->fmDev->value());
s.writeU32(5, m_channelMarker.getColor().rgb()); s.writeU32(5, m_channelMarker.getColor().rgb());
s.writeS32(6, ui->toneFrequency->value());
return s.final(); return s.final();
} }
@ -128,6 +130,9 @@ bool NFMModGUI::deserialize(const QByteArray& data)
m_channelMarker.setColor(u32tmp); m_channelMarker.setColor(u32tmp);
} }
d.readS32(6, &tmp, 100);
ui->toneFrequency->setValue(tmp);
blockApplySettings(false); blockApplySettings(false);
m_channelMarker.blockSignals(false); m_channelMarker.blockSignals(false);
@ -219,9 +224,9 @@ void NFMModGUI::on_fmDev_valueChanged(int value)
applySettings(); applySettings();
} }
void NFMModGUI::on_micVolume_valueChanged(int value) void NFMModGUI::on_toneFrequency_valueChanged(int value)
{ {
ui->micVolumeText->setText(QString("%1").arg(value)); ui->toneFrequencyText->setText(QString("%1k").arg(value / 100.0, 0, 'f', 2));
applySettings(); applySettings();
} }
@ -407,6 +412,7 @@ void NFMModGUI::applySettings()
m_rfBW[ui->rfBW->currentIndex()], m_rfBW[ui->rfBW->currentIndex()],
ui->afBW->value() * 1000.0, ui->afBW->value() * 1000.0,
ui->fmDev->value() * 100.0f, // value is in '100 Hz ui->fmDev->value() * 100.0f, // value is in '100 Hz
ui->toneFrequency->value() * 10.0f,
ui->micVolume->value(), ui->micVolume->value(),
ui->audioMute->isChecked(), ui->audioMute->isChecked(),
ui->playLoop->isChecked()); ui->playLoop->isChecked());

View File

@ -63,8 +63,9 @@ private slots:
void on_deltaMinus_toggled(bool minus); void on_deltaMinus_toggled(bool minus);
void on_rfBW_currentIndexChanged(int index); void on_rfBW_currentIndexChanged(int index);
void on_afBW_valueChanged(int value); void on_afBW_valueChanged(int value);
void on_modPercent_valueChanged(int value);
void on_fmDev_valueChanged(int value); void on_fmDev_valueChanged(int value);
void on_micVolume_valueChanged(int value); void on_toneFrequency_valueChanged(int value);
void on_audioMute_toggled(bool checked); void on_audioMute_toggled(bool checked);
void on_tone_toggled(bool checked); void on_tone_toggled(bool checked);
void on_mic_toggled(bool checked); void on_mic_toggled(bool checked);

View File

@ -6,10 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>295</width> <width>298</width>
<height>181</height> <height>182</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>290</width>
<height>0</height>
</size>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Sans Serif</family> <family>Sans Serif</family>
@ -27,10 +33,16 @@
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>271</width> <width>280</width>
<height>161</height> <height>161</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Settings</string> <string>Settings</string>
</property> </property>
@ -299,7 +311,69 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>5k</string> <string>5.0k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="recordFileSelectLayout">
<item>
<widget class="ButtonSwitch" name="tone">
<property name="toolTip">
<string>Tone modulation (1 kHz)</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../sdrbase/resources/res.qrc">
<normaloff>:/carrier.png</normaloff>:/carrier.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="toneFrequency">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Tone frequency</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>250</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="toneFrequencyText">
<property name="minimumSize">
<size>
<width>36</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Tone frequency (kHz)</string>
</property>
<property name="text">
<string>1.00k</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -307,7 +381,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="line_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
@ -335,11 +409,28 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="ButtonSwitch" name="mic">
<property name="toolTip">
<string>Audio input</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../sdrbase/resources/res.qrc">
<normaloff>:/microphone.png</normaloff>:/microphone.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="micVolumeText"> <widget class="QLabel" name="micVolumeText">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>30</width> <width>20</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
@ -357,41 +448,34 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="recordFileSelectLayout"> <layout class="QHBoxLayout" name="fileNameLayout">
<item> <item>
<widget class="ButtonSwitch" name="tone"> <widget class="QLabel" name="recordFileText">
<property name="toolTip">
<string>Tone modulation (1 kHz)</string>
</property>
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </property>
<property name="icon">
<iconset resource="../../../sdrbase/resources/res.qrc">
<normaloff>:/carrier.png</normaloff>:/carrier.png</iconset>
</property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="ButtonSwitch" name="mic"> <layout class="QHBoxLayout" name="playControllLayout">
<property name="toolTip">
<string>Audio input</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../sdrbase/resources/res.qrc">
<normaloff>:/microphone.png</normaloff>:/microphone.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="showFileDialog"> <widget class="QPushButton" name="showFileDialog">
<property name="minimumSize"> <property name="minimumSize">
@ -418,17 +502,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="recordFileText">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="playControllLayout">
<item> <item>
<widget class="ButtonSwitch" name="playLoop"> <widget class="ButtonSwitch" name="playLoop">
<property name="toolTip"> <property name="toolTip">