Skip to content

Commit

Permalink
Possible final fix for gqrx-sdr#1004
Browse files Browse the repository at this point in the history
Partially reverting 8b4c2ef and fixing
DSP restart failure in MainWindow::on_actionIoConfig_triggered allows to
select different device/change sample rate/bandwidth/or other device
options without DSP freeze and device open failure.

Work around GNU Radio bug #3184

Resetting shared_ptr is not enough to close the device.
We have to switch to some other dummy osmosdr source, start the
top_block, then stop it and disconnect dummy source to really close the device.
This may fix some hackrf glitches (at least switching bias tee on the fly) too.

Fix white waterfall and no sound after playing back bad IQ file.

Workaround gnuradio blocks state corruption after device change by recreating dc_corr
(fixes white waterfall and no sound) and resetting the demod (fixes corrupted sound).
It looks like sometimes demodulators are not happy with bad samles too.
We should recreate the graph, temporarily switching out current
demodulator to prevent bad behavior.
  • Loading branch information
vladisslav2011 committed Dec 15, 2021
1 parent c0f9b18 commit 1a9c247
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,9 @@ int MainWindow::on_actionIoConfig_triggered()

if (confres == QDialog::Accepted)
{
if (ui->actionDSP->isChecked())
bool dsp_running = ui->actionDSP->isChecked();

if (dsp_running)
// suspend DSP while we reload settings
on_actionDSP_triggered(false);

Expand All @@ -1866,7 +1868,7 @@ int MainWindow::on_actionIoConfig_triggered()
storeSession();
loadConfig(m_settings->fileName(), false, false);

if (ui->actionDSP->isChecked())
if (dsp_running)
// restsart DSP
on_actionDSP_triggered(true);
}
Expand Down
44 changes: 40 additions & 4 deletions src/applications/gqrx/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,29 @@ void receiver::stop()
*/
void receiver::set_input_device(const std::string device)
{
qDebug() << "Set input device:";
qDebug() << " old:" << input_devstr.c_str();
qDebug() << " new:" << device.c_str();

std::string error = "";

if (device.empty())
return;
if (input_devstr.compare(device) == 0)
{
#ifndef QT_NO_DEBUG_OUTPUT
qDebug() << "No change in input device:";
qDebug() << " old: " << input_devstr.c_str();
qDebug() << " new: " << device.c_str();
#endif
return;
}
else
{
#ifndef QT_NO_DEBUG_OUTPUT
qDebug() << "Set input device:";
qDebug() << " old:" << input_devstr.c_str();
qDebug() << " new:" << device.c_str();
#endif
}



input_devstr = device;

Expand All @@ -208,7 +223,18 @@ void receiver::set_input_device(const std::string device)
tb->disconnect(src, 0, iq_swap, 0);
}

#if GNURADIO_VERSION < 0x030802
//Work around GNU Radio bug #3184
//temporarily connect dummy source to ensure that previous device is closed
src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");
tb->connect(src, 0, iq_swap, 0);
tb->start();
tb->stop();
tb->wait();
tb->disconnect(src, 0, iq_swap, 0);
#else
src.reset();
#endif

try
{
Expand All @@ -218,6 +244,7 @@ void receiver::set_input_device(const std::string device)
{
error = x.what();
src = osmosdr::source::make("file="+escape_filename(get_zero_file())+",freq=428e6,rate=96000,repeat=true,throttle=true");

}

if(src->get_sample_rate() != 0)
Expand All @@ -233,6 +260,12 @@ void receiver::set_input_device(const std::string device)
tb->connect(src, 0, iq_swap, 0);
}

//reset DSP IIR filters to safe initial state from possible runaway after
// playing bad IQ file
auto last_demod = d_demod;
set_demod(RX_DEMOD_OFF, true);
set_demod(last_demod);

if (d_running)
tb->start();

Expand Down Expand Up @@ -1315,6 +1348,7 @@ void receiver::connect_all(rx_chain type)

if (d_dc_cancel)
{
dc_corr = make_dc_corr_cc(d_decim_rate, 1.0);
tb->connect(b, 0, dc_corr, 0);
b = dc_corr;
}
Expand Down Expand Up @@ -1342,6 +1376,8 @@ void receiver::connect_all(rx_chain type)
break;

default:
rx.reset();
rx = make_nbrx(d_quad_rate, d_audio_rate);
break;
}

Expand Down

0 comments on commit 1a9c247

Please sign in to comment.