1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

WFM Moduletor

This commit is contained in:
f4exb 2016-12-17 19:09:07 +01:00
parent d09f0d2ede
commit 95a8eb9856
5 changed files with 42 additions and 54 deletions

View File

@ -249,8 +249,6 @@ void NFMMod::stop()
bool NFMMod::handleMessage(const Message& cmd)
{
qDebug() << "NFMMod::handleMessage";
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
{
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;

View File

@ -96,30 +96,23 @@ void WFMMod::configure(MessageQueue* messageQueue,
void WFMMod::pull(Sample& sample)
{
Complex ci;
Complex ci, ri;
Real t;
m_settingsMutex.lock();
if (m_interpolatorDistance > 1.0f) // decimate
if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, m_modSample, &ri))
{
modulateSample();
while (!m_interpolator.decimate(&m_interpolatorDistanceRemain, m_modSample, &ci))
{
modulateSample();
}
}
else
{
if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, m_modSample, &ci))
{
modulateSample();
}
pullAF(m_modSample);
calculateLevel(m_modSample.real());
}
m_interpolatorDistanceRemain += m_interpolatorDistance;
m_modPhasor += (m_running.m_fmDeviation / (float) m_running.m_outputSampleRate) * ri.real() * M_PI_2;
ci.real(cos(m_modPhasor) * 32678.0f);
ci.imag(sin(m_modPhasor) * 32678.0f);
ci *= m_carrierNco.nextIQ(); // shift to carrier frequency
m_settingsMutex.unlock();
@ -133,27 +126,15 @@ void WFMMod::pull(Sample& sample)
sample.m_imag = (FixReal) ci.imag();
}
void WFMMod::modulateSample()
{
Real t;
pullAF(t);
calculateLevel(t);
// 378 = 302 * 1.25; 302 = number of filter taps (established experimentally)
m_modPhasor += (m_running.m_fmDeviation / (float) m_running.m_audioSampleRate) * m_bandpass.filter(t) * (M_PI / 378.0f);
m_modSample.real(cos(m_modPhasor) * 32678.0f);
m_modSample.imag(sin(m_modPhasor) * 32678.0f);
}
void WFMMod::pullAF(Real& sample)
void WFMMod::pullAF(Complex& sample)
{
int16_t audioSample[2];
switch (m_afInput)
{
case WFMModInputTone:
sample = m_toneNco.next();
sample.real(m_toneNco.next());
sample.imag(0.0f);
break;
case WFMModInputFile:
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
@ -171,22 +152,32 @@ void WFMMod::pullAF(Real& sample)
if (m_ifstream.eof())
{
sample = 0.0f;
sample.real(0.0f);
sample.imag(0.0f);
}
else
{
m_ifstream.read(reinterpret_cast<char*>(&sample), sizeof(Real));
sample *= m_running.m_volumeFactor;
Real s;
m_ifstream.read(reinterpret_cast<char*>(&s), sizeof(Real));
m_lowpass.filter(s);
sample.real(s * m_running.m_volumeFactor);
sample.imag(0.0f);
}
}
else
{
sample = 0.0f;
sample.real(0.0f);
sample.imag(0.0f);
}
break;
case WFMModInputAudio:
{
Real s = (audioSample[0] + audioSample[1]) / 65536.0f;
m_lowpass.filter(s);
m_audioFifo.read(reinterpret_cast<quint8*>(audioSample), 1, 10);
sample = ((audioSample[0] + audioSample[1]) / 65536.0f) * m_running.m_volumeFactor;
sample.real(s * m_running.m_volumeFactor);
sample.imag(0.0f);
}
break;
case WFMModInputCWTone:
Real fadeFactor;
@ -194,24 +185,28 @@ void WFMMod::pullAF(Real& sample)
if (m_cwKeyer.getSample())
{
m_cwSmoother.getFadeSample(true, fadeFactor);
sample = m_toneNco.next() * fadeFactor;
sample.real(m_toneNco.next() * fadeFactor);
sample.imag(0.0f);
}
else
{
if (m_cwSmoother.getFadeSample(false, fadeFactor))
{
sample = m_toneNco.next() * fadeFactor;
sample.real(m_toneNco.next() * fadeFactor);
sample.imag(0.0f);
}
else
{
sample = 0.0f;
sample.real(0.0f);
sample.imag(0.0f);
m_toneNco.setPhase(0);
}
}
break;
case WFMModInputNone:
default:
sample = 0.0f;
sample.real(0.0f);
sample.imag(0.0f);
break;
}
}
@ -249,8 +244,6 @@ void WFMMod::stop()
bool WFMMod::handleMessage(const Message& cmd)
{
qDebug() << "WFMMod::handleMessage";
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
{
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
@ -353,7 +346,7 @@ void WFMMod::apply()
m_interpolatorDistanceRemain = 0;
m_interpolatorConsumed = false;
m_interpolatorDistance = (Real) m_config.m_audioSampleRate / (Real) m_config.m_outputSampleRate;
m_interpolator.create(48, m_config.m_audioSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
m_interpolator.create(48, m_config.m_audioSampleRate, m_config.m_rfBandwidth, 3.0);
m_settingsMutex.unlock();
}
@ -361,8 +354,7 @@ void WFMMod::apply()
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
{
m_settingsMutex.lock();
m_lowpass.create(301, m_config.m_audioSampleRate, 250.0);
m_bandpass.create(301, m_config.m_audioSampleRate, 300.0, m_config.m_afBandwidth);
m_lowpass.create(101, m_config.m_audioSampleRate, m_config.m_afBandwidth);
m_settingsMutex.unlock();
}

View File

@ -298,7 +298,6 @@ private:
Real m_interpolatorDistanceRemain;
bool m_interpolatorConsumed;
Lowpass<Real> m_lowpass;
Bandpass<Real> m_bandpass;
Real m_magsq;
MovingAverage<Real> m_movingAverage;
@ -326,9 +325,8 @@ private:
static const int m_levelNbSamples;
void apply();
void pullAF(Real& sample);
void pullAF(Complex& sample);
void calculateLevel(Real& sample);
void modulateSample();
void openFileStream();
void seekFileStream(int seekPercentage);
};

View File

@ -436,7 +436,7 @@ void WFMModGUI::applySettings()
m_wfmMod->configure(m_wfmMod->getInputMessageQueue(),
m_rfBW[ui->rfBW->currentIndex()],
ui->afBW->value() * 1000.0,
ui->fmDev->value() * 100.0f, // value is in '100 Hz
ui->fmDev->value() * 1000.0f, // value is in '100 Hz
ui->toneFrequency->value() * 10.0f,
ui->volume->value() / 10.0f,
ui->audioMute->isChecked(),

View File

@ -32,7 +32,7 @@
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>NFM Modulator</string>
<string>WFM Modulator</string>
</property>
<widget class="QWidget" name="settingsContainer" native="true">
<property name="geometry">
@ -243,7 +243,7 @@
<number>1</number>
</property>
<property name="value">
<number>3</number>
<number>8</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -259,7 +259,7 @@
</size>
</property>
<property name="text">
<string>3k</string>
<string>8k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>