1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-07-30 14:04:18 -04:00

NFM Modulator: basic input volume gauge

This commit is contained in:
f4exb
2016-12-02 02:00:53 +01:00
parent ab60cac358
commit 7a07b56b01
8 changed files with 436 additions and 77 deletions
+27 -2
View File
@@ -19,6 +19,7 @@
#include <QMutexLocker>
#include <stdio.h>
#include <complex.h>
#include <algorithm>
#include <dsp/upchannelizer.h>
#include "dsp/dspengine.h"
#include "dsp/pidcontroller.h"
@@ -32,6 +33,7 @@ MESSAGE_CLASS_DEFINITION(NFMMod::MsgConfigureFileSourceStreamTiming, Message)
MESSAGE_CLASS_DEFINITION(NFMMod::MsgReportFileSourceStreamData, Message)
MESSAGE_CLASS_DEFINITION(NFMMod::MsgReportFileSourceStreamTiming, Message)
const int NFMMod::m_levelNbSamples = 480; // every 10ms
NFMMod::NFMMod() :
m_modPhasor(0.0f),
@@ -40,7 +42,10 @@ NFMMod::NFMMod() :
m_fileSize(0),
m_recordLength(0),
m_sampleRate(48000),
m_afInput(NFMModInputNone)
m_afInput(NFMModInputNone),
m_levelCalcCount(0),
m_peakLevel(0.0f),
m_levelSum(0.0f)
{
setObjectName("NFMod");
@@ -127,6 +132,7 @@ void NFMMod::modulateSample()
Real t;
pullAF(t);
calculateLevel(t);
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);
@@ -173,7 +179,7 @@ void NFMMod::pullAF(Real& sample)
break;
case NFMModInputAudio:
m_audioFifo.read(reinterpret_cast<quint8*>(audioSample), 1, 10);
sample = ((audioSample[0] + audioSample[1]) / 131072.0f) * m_running.m_volumeFactor;
sample = ((audioSample[0] + audioSample[1]) / 65536.0f) * m_running.m_volumeFactor;
break;
case NFMModInputNone:
default:
@@ -182,6 +188,25 @@ void NFMMod::pullAF(Real& sample)
}
}
void NFMMod::calculateLevel(Real& sample)
{
if (m_levelCalcCount < m_levelNbSamples)
{
m_peakLevel = std::max(std::fabs(m_peakLevel), sample);
m_levelSum += sample * sample;
m_levelCalcCount++;
}
else
{
qreal rmsLevel = sqrt(m_levelSum / m_levelNbSamples);
//qDebug("NFMMod::calculateLevel: %f %f", rmsLevel, m_peakLevel);
emit levelChanged(rmsLevel, m_peakLevel, m_levelNbSamples);
m_peakLevel = 0.0f;
m_levelSum = 0.0f;
m_levelCalcCount = 0;
}
}
void NFMMod::start()
{
qDebug() << "NFMMod::start: m_outputSampleRate: " << m_config.m_outputSampleRate
+15
View File
@@ -191,6 +191,16 @@ public:
Real getMagSq() const { return m_magsq; }
signals:
/**
* Level changed
* \param rmsLevel RMS level in range 0.0 - 1.0
* \param peakLevel Peak level in range 0.0 - 1.0
* \param numSamples Number of audio samples analyzed
*/
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples);
private:
class MsgConfigureNFMMod : public Message
{
@@ -304,9 +314,14 @@ private:
int m_sampleRate;
NFMModInputAF m_afInput;
quint32 m_levelCalcCount;
Real m_peakLevel;
Real m_levelSum;
static const int m_levelNbSamples;
void apply();
void pullAF(Real& sample);
void calculateLevel(Real& sample);
void modulateSample();
void openFileStream();
void seekFileStream(int seekPercentage);
+7 -6
View File
@@ -78,7 +78,7 @@ void NFMModGUI::resetToDefaults()
ui->afBW->setValue(3);
ui->fmDev->setValue(50);
ui->toneFrequency->setValue(100);
ui->micVolume->setValue(10);
ui->volume->setValue(10);
ui->deltaFrequency->setValue(0);
blockApplySettings(false);
@@ -94,7 +94,7 @@ QByteArray NFMModGUI::serialize() const
s.writeS32(4, ui->fmDev->value());
s.writeU32(5, m_channelMarker.getColor().rgb());
s.writeS32(6, ui->toneFrequency->value());
s.writeS32(7, ui->micVolume->value());
s.writeS32(7, ui->volume->value());
return s.final();
}
@@ -134,7 +134,7 @@ bool NFMModGUI::deserialize(const QByteArray& data)
d.readS32(6, &tmp, 100);
ui->toneFrequency->setValue(tmp);
d.readS32(7, &tmp, 10);
ui->micVolume->setValue(tmp);
ui->volume->setValue(tmp);
blockApplySettings(false);
m_channelMarker.blockSignals(false);
@@ -227,9 +227,9 @@ void NFMModGUI::on_fmDev_valueChanged(int value)
applySettings();
}
void NFMModGUI::on_micVolume_valueChanged(int value)
void NFMModGUI::on_volume_valueChanged(int value)
{
ui->micVolumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1));
ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1));
applySettings();
}
@@ -386,6 +386,7 @@ NFMModGUI::NFMModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa
applySettings();
connect(m_nfmMod->getOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
connect(m_nfmMod, SIGNAL(levelChanged(qreal, qreal, int)), ui->volumeMeter, SLOT(levelChanged(qreal, qreal, int)));
}
NFMModGUI::~NFMModGUI()
@@ -422,7 +423,7 @@ void NFMModGUI::applySettings()
ui->afBW->value() * 1000.0,
ui->fmDev->value() * 100.0f, // value is in '100 Hz
ui->toneFrequency->value() * 10.0f,
ui->micVolume->value() / 10.0f,
ui->volume->value() / 10.0f,
ui->audioMute->isChecked(),
ui->playLoop->isChecked());
}
+1 -1
View File
@@ -65,7 +65,7 @@ private slots:
void on_afBW_valueChanged(int value);
void on_fmDev_valueChanged(int value);
void on_toneFrequency_valueChanged(int value);
void on_micVolume_valueChanged(int value);
void on_volume_valueChanged(int value);
void on_audioMute_toggled(bool checked);
void on_tone_toggled(bool checked);
void on_mic_toggled(bool checked);
+86 -68
View File
@@ -50,16 +50,7 @@
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>2</number>
</property>
<item>
@@ -329,6 +320,78 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="volumeLayout">
<item>
<widget class="QLabel" name="volLabel">
<property name="text">
<string>Vol</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="volume">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Audio input volume</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="volumeText">
<property name="minimumSize">
<size>
<width>25</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Audio input volume level</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="text">
<string>1.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="LevelMeter" name="volumeMeter" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="recordFileSelectLayout">
<item>
@@ -426,66 +489,15 @@
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="volLabel">
<property name="text">
<string>Vol</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="micVolume">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Audio input volume</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="micVolumeText">
<property name="minimumSize">
<size>
<width>25</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Audio input volume level</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="text">
<string>1.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="fileNameLayout">
<item>
@@ -670,6 +682,12 @@
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
<customwidget>
<class>LevelMeter</class>
<extends>QWidget</extends>
<header>gui/levelmeter.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../sdrbase/resources/res.qrc"/>