Skip to content

Commit

Permalink
New rx_agc implementation (4/4)
Browse files Browse the repository at this point in the history
Move common code from nbrx/wfmrx to receiver_base
Move all agc processing into block class rx_agc_2f and eliminate CAgc class
Remove CurrentGainDb and move processing to get_current_gain
Rename SetParameters to set_parameters
Remove ProcessData and move all processing to work
Fix tag propagation setting sample delay
Workaroung GNU Radio < 3.8 tag propagation bug: manually calculate new tag offsets
Small cleanup
Set audio mute by disconnecting audio_snk
Switch to using history to improve performance
Prefill magnitude buffer on buffer size change in running state
Prefill magnitude buffer on enabled state change in running state
  • Loading branch information
vladisslav2011 committed Aug 21, 2022
1 parent 96ee907 commit 5c9a9ff
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 642 deletions.
16 changes: 2 additions & 14 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ void MainWindow::selectDemod(int mode_idx)
//Call wrapper to update enable/disabled state
setAgcOn(uiDockRxOpt->getAgcOn());
rx->set_agc_target_level(uiDockRxOpt->getAgcTargetLevel());
rx->set_agc_manual_gain(uiDockAudio->audioGain());
rx->set_agc_manual_gain(uiDockAudio->audioGain() / 10.0);
rx->set_agc_max_gain(uiDockRxOpt->getAgcMaxGain());
rx->set_agc_attack(uiDockRxOpt->getAgcAttack());
rx->set_agc_decay(uiDockRxOpt->getAgcDecay());
Expand Down Expand Up @@ -1285,19 +1285,7 @@ void MainWindow::setAudioGain(float value)
*/
void MainWindow::setAudioMute(bool mute)
{
if(mute)
{
rx->set_agc_target_level(-80);
rx->set_agc_manual_gain(-80);
if(!uiDockRxOpt->getAgcOn())
uiDockAudio->setGainEnabled(false);
}else{
rx->set_agc_target_level(uiDockRxOpt->getAgcTargetLevel());
rx->set_agc_manual_gain(uiDockAudio->audioGain() / 10.0);
if(!uiDockRxOpt->getAgcOn())
uiDockAudio->setGainEnabled(true);
}

rx->set_mute(mute);
}

/** Set AGC ON/OFF. */
Expand Down
65 changes: 54 additions & 11 deletions src/applications/gqrx/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ receiver::receiver(const std::string input_device,
d_iq_rev(false),
d_dc_cancel(false),
d_iq_balance(false),
d_mute(false),
d_demod(RX_DEMOD_OFF)
{

Expand Down Expand Up @@ -285,7 +286,7 @@ void receiver::set_output_device(const std::string device)
audio_snk = gr::audio::sink::make(d_audio_rate, device, true);
#endif

if (d_demod != RX_DEMOD_OFF)
if ((d_demod != RX_DEMOD_OFF) && !d_mute)
{
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
Expand Down Expand Up @@ -870,6 +871,33 @@ float receiver::get_agc_gain()
return 0;
}

/** Set audio mute. */
receiver::status receiver::set_mute(bool mute)
{
if (d_mute == mute)
return STATUS_OK;
tb->lock();
if (mute)
{
tb->disconnect(rx, 0, audio_snk, 0);
tb->disconnect(rx, 1, audio_snk, 1);
}
else
{
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
}
tb->unlock();
d_mute = mute;
return STATUS_OK;
}

/** Get audio mute. */
bool receiver::get_mute()
{
return d_mute;
}

receiver::status receiver::set_demod(rx_demod demod, bool force)
{
status ret = STATUS_OK;
Expand Down Expand Up @@ -1121,15 +1149,21 @@ receiver::status receiver::start_audio_playback(const std::string filename)

stop();
/* route demodulator output to null sink */
tb->disconnect(rx, 0, audio_snk, 0);
tb->disconnect(rx, 1, audio_snk, 1);
if (!d_mute)
{
tb->disconnect(rx, 0, audio_snk, 0);
tb->disconnect(rx, 1, audio_snk, 1);
}
tb->disconnect(rx, 0, audio_fft, 0);
tb->disconnect(rx, 0, audio_udp_sink, 0);
tb->disconnect(rx, 1, audio_udp_sink, 1);
tb->connect(rx, 0, audio_null_sink0, 0); /** FIXME: other channel? */
tb->connect(rx, 1, audio_null_sink1, 0); /** FIXME: other channel? */
tb->connect(wav_src, 0, audio_snk, 0);
tb->connect(wav_src, 1, audio_snk, 1);
if (!d_mute)
{
tb->connect(wav_src, 0, audio_snk, 0);
tb->connect(wav_src, 1, audio_snk, 1);
}
tb->connect(wav_src, 0, audio_fft, 0);
tb->connect(wav_src, 0, audio_udp_sink, 0);
tb->connect(wav_src, 1, audio_udp_sink, 1);
Expand All @@ -1145,15 +1179,21 @@ receiver::status receiver::stop_audio_playback()
{
/* disconnect wav source and reconnect receiver */
stop();
tb->disconnect(wav_src, 0, audio_snk, 0);
tb->disconnect(wav_src, 1, audio_snk, 1);
if (!d_mute)
{
tb->disconnect(wav_src, 0, audio_snk, 0);
tb->disconnect(wav_src, 1, audio_snk, 1);
}
tb->disconnect(wav_src, 0, audio_fft, 0);
tb->disconnect(wav_src, 0, audio_udp_sink, 0);
tb->disconnect(wav_src, 1, audio_udp_sink, 1);
tb->disconnect(rx, 0, audio_null_sink0, 0);
tb->disconnect(rx, 1, audio_null_sink1, 0);
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
if (!d_mute)
{
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
}
tb->connect(rx, 0, audio_fft, 0); /** FIXME: other channel? */
tb->connect(rx, 0, audio_udp_sink, 0);
tb->connect(rx, 1, audio_udp_sink, 1);
Expand Down Expand Up @@ -1381,8 +1421,11 @@ void receiver::connect_all(rx_chain type)
tb->connect(rx, 0, audio_fft, 0);
tb->connect(rx, 0, audio_udp_sink, 0);
tb->connect(rx, 1, audio_udp_sink, 1);
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
if (!d_mute)
{
tb->connect(rx, 0, audio_snk, 0);
tb->connect(rx, 1, audio_snk, 1);
}
// Recorders and sniffers
if (d_recording_wav)
{
Expand Down
4 changes: 4 additions & 0 deletions src/applications/gqrx/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class receiver
status set_agc_hang(int hang_ms);
float get_agc_gain();

status set_mute(bool mute);
bool get_mute();

status set_demod(rx_demod demod, bool force=false);

/* FM parameters */
Expand Down Expand Up @@ -253,6 +256,7 @@ class receiver
bool d_iq_rev; /*!< Whether I/Q is reversed or not. */
bool d_dc_cancel; /*!< Enable automatic DC removal. */
bool d_iq_balance; /*!< Enable automatic IQ balance. */
bool d_mute; /*!< Enable audio mute. */

std::string input_devstr; /*!< Current input device string. */
std::string output_devstr; /*!< Current output device string. */
Expand Down
2 changes: 0 additions & 2 deletions src/dsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ add_source_files(SRCS_LIST
rds/parser_impl.h
rds/parser.h
rds/tmc_events.h
agc_impl.cpp
agc_impl.h
correct_iq_cc.cpp
correct_iq_cc.h
downconverter.cpp
Expand Down
Loading

0 comments on commit 5c9a9ff

Please sign in to comment.