Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dsp freeze fix #1004

Merged
merged 2 commits into from
Dec 16, 2021
Merged

Dsp freeze fix #1004

merged 2 commits into from
Dec 16, 2021

Conversation

vladisslav2011
Copy link
Contributor

Fix #1003.
Switching input devices works even on the fly without DSP freeze/open errors.
Changing device options like direct sampling/bias tee works on the fly too.

vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Nov 22, 2021
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).
Pure hack. It is better to find a way to prevent corruption than fix it
this way...
Copy link

@boushley boushley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 I'm new here, but this looks like a clean PR after a couple formatting changes.

qDebug() << " new: " << device.c_str();
#endif
return;
}else{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the rest of the code puts parentheses on their own lines. Should we update this to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 060e0af.

@@ -194,7 +205,7 @@ void receiver::set_input_device(const std::string device)
{
tb->stop();
tb->wait();
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the semicolon here have a purpose? C++ is not my strong suit but I don't think this semicolon is adding any value, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 060e0af.

@@ -206,7 +217,13 @@ void receiver::set_input_device(const std::string device)
tb->disconnect(src, 0, iq_swap, 0);
}

src.reset();
//temporarily connect dummy source to ensure that previous device is closed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful comment explaining the purpose of the dummy device connect 👍

@vladisslav2011 vladisslav2011 mentioned this pull request Dec 2, 2021
vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 2, 2021
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.
Now in case of demodulator internal state corruption, it can be resolved
by switching from nbrx to wbfm and back from GUI or vise versa.
vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 4, 2021
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).
Pure hack. It is better to find a way to prevent corruption than fix it
this way...
@argilo
Copy link
Member

argilo commented Dec 15, 2021

The underlying bug leading to #1003 (and #757) was already fixed in GNU Radio 3.8.1+: gnuradio/gnuradio#3184

As a result, I think any changes to receiver::set_input_device should be confined to an #if GNURADIO_VERSION < 0x030801 block.

@argilo
Copy link
Member

argilo commented Dec 15, 2021

Or perhaps #if GNURADIO_VERSION < 0x030802, since Ubuntu 20.04 shipped with 3.8.1.0-rc1, a release-candidate version which did not include the fix.

vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 15, 2021
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.
Now in case of demodulator internal state corruption, it can be resolved
by switching from nbrx to wbfm and back from GUI or vise versa.
vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 15, 2021
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.
@vladisslav2011
Copy link
Contributor Author

Thanks for suggestion.
I've added GNU Radio version check and provided better fix for white waterfall/no sound after playing back bad IQ file.

vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 15, 2021
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.
@argilo
Copy link
Member

argilo commented Dec 15, 2021

and provided better fix for white waterfall/no sound after playing back bad IQ file

This change seems unrelated to the first one. Could you please split it off into its own pull request so that it can be reviewed separately?

std::string error = "";

if (device.empty())
return;
if (input_devstr.compare(device) == 0)
{
#ifndef QT_NO_DEBUG_OUTPUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is #ifndef QT_NO_DEBUG_OUTPUT needed? Doesn't setting that disable qDebug() automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where did I took this from. No useful information in case, the input device did not change. So, reverted to previous state and added a check for changed device string as it was done before, but removed later for some unknown purpose.
Why should we always reopen a device even if it did not change? If we have to work around some buggy device, then it is better to check for it's specific device string and reopen if it matches.
Moved this to #1021.

vladisslav2011 added a commit to vladisslav2011/gqrx that referenced this pull request Dec 15, 2021
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.
@vladisslav2011
Copy link
Contributor Author

Could you please split it off into its own pull request so that it can be reviewed separately?

OK. I've opened 2 new issues #1018 and #1019, and corresponding pull requests #1020 and #1021

@argilo
Copy link
Member

argilo commented Dec 16, 2021

Thanks for splitting those out!

At a glance the change looks good. I'll merge once I've verified that things work well with an older GNU Radio version.

vladisslav2011 and others added 2 commits December 16, 2021 12:16
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.
Copy link
Member

@argilo argilo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Ubuntu 18.04, and this works well. I'll merge once CI passes.

@argilo argilo merged commit c061525 into gqrx-sdr:master Dec 16, 2021
@vladisslav2011 vladisslav2011 deleted the dsp_freeze_fix branch December 16, 2021 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DSP freeze and device lost after sample rate change
3 participants