Skip to content

Commit

Permalink
AM Modulator: audio input (mic) basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Nov 29, 2016
1 parent 4c3db01 commit c5f1acd
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 67 deletions.
9 changes: 4 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ From version 2 SDRangel can integrate more than one hardware device running conc

Transmission or signal generation support for eligible devices (BladeRF and HackRF) is progressively introduced with the following roadmap:

- Phase 1: version 2.2.0: generation to file (File Sink) with AM modulator with simple sine modulation. Fixed sample rate of 48 kS/s (no effective interpolation)
- Phase 2: version 2.2.x: full baseband interpolation chain: in AM modulator and Up Channelizer.
- Phase 1: version 2.2.0: generation to file (File Sink) with AM modulator with simple sine modulation. Fixed sample rate of 48 kS/s (no effective interpolation)
- Phase 2: version 2.2.2: full baseband interpolation chain: in AM modulator and Up Channelizer.
- 2.3.0: SDRplay came into play ...
- Phase 3a: version 2.3.1: Improve AM modulator with audio file input
- Phase 3b: version 2.3.x: Improve AM modulator with audio input (Mic) support
- Phase 3: version 2.3.1: Improve AM modulator with audio file input and audio input (Mic) support
- Phase 4a: version 2.4.0: FM modulator
- Phase 4b: version 2.4.x: WFM modulator
- Phase 4c: version 2.4.x: SSB modulator
- phase 5: version 3.0.0: BladeRF and HackRF support including final interpolation stage.
- phase 5: version 3.0.0: BladeRF and HackRF support including final interpolation stage.

<h2>Airspy</h2>

Expand Down
18 changes: 14 additions & 4 deletions plugins/channeltx/modam/ammod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamTiming, Message)


AMMod::AMMod() :
m_audioFifo(4, 48000),
m_settingsMutex(QMutex::Recursive),
m_fileSize(0),
m_recordLength(0),
Expand All @@ -52,28 +53,31 @@ AMMod::AMMod() :

apply();

m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
//m_audioBuffer.resize(1<<14);
//m_audioBufferFill = 0;

m_movingAverage.resize(16, 0);
m_volumeAGC.resize(4096, 0.003, 0);
m_magsq = 0.0;

m_toneNco.setFreq(1000.0, m_config.m_audioSampleRate);
DSPEngine::instance()->addAudioSource(&m_audioFifo);

This comment has been minimized.

Copy link
@f4exb

f4exb Dec 25, 2016

Author Owner

This causes lockup reported in issue #11 The same exists in other modulators

}

AMMod::~AMMod()
{
DSPEngine::instance()->removeAudioSource(&m_audioFifo);
}

void AMMod::configure(MessageQueue* messageQueue,
Real rfBandwidth,
Real afBandwidth,
float modFactor,
int volumeTenths,
bool audioMute,
bool playLoop)
{
Message* cmd = MsgConfigureAMMod::create(rfBandwidth, afBandwidth, modFactor, audioMute, playLoop);
Message* cmd = MsgConfigureAMMod::create(rfBandwidth, afBandwidth, modFactor, volumeTenths, audioMute, playLoop);
messageQueue->push(cmd);
}

Expand Down Expand Up @@ -124,6 +128,8 @@ void AMMod::pull(Sample& sample)

void AMMod::pullAF(Real& sample)
{
int16_t audioSample[2];

switch (m_afInput)
{
case AMModInputTone:
Expand Down Expand Up @@ -158,7 +164,8 @@ void AMMod::pullAF(Real& sample)
}
break;
case AMModInputAudio:
sample = 0.0f; // TODO
m_audioFifo.read(reinterpret_cast<quint8*>(audioSample), 1, 10);
sample = ((audioSample[0] + audioSample[1]) * m_running.m_volumeFactor) / 6553600.0f;
break;
case AMModInputNone:
default:
Expand Down Expand Up @@ -205,6 +212,7 @@ bool AMMod::handleMessage(const Message& cmd)
m_config.m_rfBandwidth = cfg.getRFBandwidth();
m_config.m_afBandwidth = cfg.getAFBandwidth();
m_config.m_modFactor = cfg.getModFactor();
m_config.m_volumeFactor = cfg.getVolumeFactor();
m_config.m_audioMute = cfg.getAudioMute();
m_config.m_playLoop = cfg.getPlayLoop();

Expand All @@ -214,6 +222,7 @@ bool AMMod::handleMessage(const Message& cmd)
<< " m_rfBandwidth: " << m_config.m_rfBandwidth
<< " m_afBandwidth: " << m_config.m_afBandwidth
<< " m_modFactor: " << m_config.m_modFactor
<< " m_volumeFactor: " << m_config.m_volumeFactor
<< " m_audioMute: " << m_config.m_audioMute
<< " m_playLoop: " << m_config.m_playLoop;

Expand Down Expand Up @@ -298,6 +307,7 @@ void AMMod::apply()
m_running.m_rfBandwidth = m_config.m_rfBandwidth;
m_running.m_afBandwidth = m_config.m_afBandwidth;
m_running.m_modFactor = m_config.m_modFactor;
m_running.m_volumeFactor = m_config.m_volumeFactor;
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
m_running.m_audioMute = m_config.m_audioMute;
m_running.m_playLoop = m_config.m_playLoop;
Expand Down
17 changes: 11 additions & 6 deletions plugins/channeltx/modam/ammod.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class AMMod : public BasebandSampleSource {
AMMod();
~AMMod();

void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop);
void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, float modFactor, int volumeFactor, bool audioMute, bool playLoop);

virtual void pull(Sample& sample);
virtual void start();
Expand All @@ -192,26 +192,29 @@ class AMMod : public BasebandSampleSource {
Real getRFBandwidth() const { return m_rfBandwidth; }
Real getAFBandwidth() const { return m_afBandwidth; }
float getModFactor() const { return m_modFactor; }
int getVolumeFactor() const { return m_volumeFactor; }
bool getAudioMute() const { return m_audioMute; }
bool getPlayLoop() const { return m_playLoop; }

static MsgConfigureAMMod* create(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop)
static MsgConfigureAMMod* create(Real rfBandwidth, Real afBandwidth, float modFactor, int volumeFactor, bool audioMute, bool playLoop)
{
return new MsgConfigureAMMod(rfBandwidth, afBandwidth, modFactor, audioMute, playLoop);
return new MsgConfigureAMMod(rfBandwidth, afBandwidth, modFactor, volumeFactor, audioMute, playLoop);
}

private:
Real m_rfBandwidth;
Real m_afBandwidth;
float m_modFactor;
int m_volumeFactor;
bool m_audioMute;
bool m_playLoop;

MsgConfigureAMMod(Real rfBandwidth, Real afBandwidth, float modFactor, bool audioMute, bool playLoop) :
MsgConfigureAMMod(Real rfBandwidth, Real afBandwidth, float modFactor, int volumeFactor, bool audioMute, bool playLoop) :
Message(),
m_rfBandwidth(rfBandwidth),
m_afBandwidth(afBandwidth),
m_modFactor(modFactor),
m_volumeFactor(volumeFactor),
m_audioMute(audioMute),
m_playLoop(playLoop)
{ }
Expand All @@ -236,6 +239,7 @@ class AMMod : public BasebandSampleSource {
Real m_rfBandwidth;
Real m_afBandwidth;
float m_modFactor;
int m_volumeFactor;
quint32 m_audioSampleRate;
bool m_audioMute;
bool m_playLoop;
Expand All @@ -246,6 +250,7 @@ class AMMod : public BasebandSampleSource {
m_rfBandwidth(-1),
m_afBandwidth(-1),
m_modFactor(0.2f),
m_volumeFactor(20),
m_audioSampleRate(0),
m_audioMute(false),
m_playLoop(false)
Expand All @@ -270,8 +275,8 @@ class AMMod : public BasebandSampleSource {
MovingAverage<Real> m_movingAverage;
SimpleAGC m_volumeAGC;

AudioVector m_audioBuffer;
uint m_audioBufferFill;
//AudioVector m_audioBuffer;
//uint m_audioBufferFill;

AudioFifo m_audioFifo;
SampleVector m_sampleBuffer;
Expand Down
8 changes: 8 additions & 0 deletions plugins/channeltx/modam/ammodgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void AMModGUI::resetToDefaults()
ui->rfBW->setValue(6);
ui->afBW->setValue(3);
ui->modPercent->setValue(20);
ui->micVolume->setValue(50);
ui->deltaFrequency->setValue(0);

blockApplySettings(false);
Expand Down Expand Up @@ -219,6 +220,12 @@ void AMModGUI::on_modPercent_valueChanged(int value)
applySettings();
}

void AMModGUI::on_micVolume_valueChanged(int value)
{
ui->micVolumeText->setText(QString("%1").arg(value));
applySettings();
}

void AMModGUI::on_audioMute_toggled(bool checked)
{
applySettings();
Expand Down Expand Up @@ -391,6 +398,7 @@ void AMModGUI::applySettings()
m_rfBW[ui->rfBW->value()],
ui->afBW->value() * 1000.0,
ui->modPercent->value() / 100.0f,
ui->micVolume->value(),
ui->audioMute->isChecked(),
ui->playLoop->isChecked());
}
Expand Down
1 change: 1 addition & 0 deletions plugins/channeltx/modam/ammodgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private slots:
void on_rfBW_valueChanged(int value);
void on_afBW_valueChanged(int value);
void on_modPercent_valueChanged(int value);
void on_micVolume_valueChanged(int value);
void on_audioMute_toggled(bool checked);
void on_tone_toggled(bool checked);
void on_mic_toggled(bool checked);
Expand Down
82 changes: 68 additions & 14 deletions plugins/channeltx/modam/ammodgui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>261</width>
<height>180</height>
<width>266</width>
<height>190</height>
</rect>
</property>
<property name="font">
Expand All @@ -27,7 +27,7 @@
<rect>
<x>10</x>
<y>10</y>
<width>241</width>
<width>251</width>
<height>161</height>
</rect>
</property>
Expand All @@ -38,16 +38,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>
Expand Down Expand Up @@ -276,6 +267,18 @@
</item>
<item>
<widget class="QSlider" name="modPercent">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Modulation percentage</string>
</property>
Expand All @@ -297,7 +300,7 @@
<widget class="QLabel" name="modPercentText">
<property name="minimumSize">
<size>
<width>50</width>
<width>30</width>
<height>0</height>
</size>
</property>
Expand All @@ -309,6 +312,57 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</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>50</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="micVolumeText">
<property name="minimumSize">
<size>
<width>30</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>50</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
5 changes: 3 additions & 2 deletions plugins/samplesink/filesink/filesinkgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,14 @@ void FileSinkGui::on_startStop_toggled(bool checked)
{
qDebug("FileSinkGui::on_startStop_toggled: device start failed");
}
// DSPEngine::instance()->startAudio(); // TODO: activate when audio input is available

DSPEngine::instance()->startAudioInput();
}
}
else
{
m_deviceAPI->stopGeneration();
// DSPEngine::instance()->stopAudio(); // TODO: activate when audio input is available
DSPEngine::instance()->stopAudioInput();
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/samplesource/airspy/airspygui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ void AirspyGui::on_startStop_toggled(bool checked)
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudio();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudio();
DSPEngine::instance()->stopAudioOutput();
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/samplesource/bladerf/bladerfgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ void BladerfGui::on_startStop_toggled(bool checked)
if (m_deviceAPI->initAcquisition())
{
m_deviceAPI->startAcquisition();
DSPEngine::instance()->startAudio();
DSPEngine::instance()->startAudioOutput();
}
}
else
{
m_deviceAPI->stopAcquisition();
DSPEngine::instance()->stopAudio();
DSPEngine::instance()->stopAudioOutput();
}
}

Expand Down
Loading

0 comments on commit c5f1acd

Please sign in to comment.