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

Implement audio sample rate selection #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vladisslav2011
Copy link
Contributor

@vladisslav2011 vladisslav2011 commented Dec 28, 2021

Close #615
Includes #1036, that closes #1030 and #1018.

@argilo
Copy link
Member

argilo commented Dec 30, 2021

Could you please limit this pull request to just the audio rate selection? As I've mentioned previously, combining multiple changes into a single pull request makes it difficult to review.

@vladisslav2011
Copy link
Contributor Author

Could you please limit this pull request to just the audio rate selection?

Making audio rate selection work properly automatically closes #1030 and #1018.
I can split bug fixes into separate PR and make this PR depend on new one.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from ececbfe to 8eba911 Compare December 30, 2021 11:13
audio_snk = gr::audio::sink::make(d_audio_rate, audio_device, true);
#endif

make_audio_device(audio_device);
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be clearer and more consistent with the rest of the code if make_audio_device returned the device instead of internally assigning it to audio_snk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make_audio_device

Just a bad name selection.
Renamed to create_audio_device. I hope, this should not interfere with GNU Radio naming conventions.
This function was created to eliminate some common code and get rid of some #ifdefs. Making it return the device would add more #ifdefs.

Copy link
Member

Choose a reason for hiding this comment

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

Making it return the device would add more #ifdefs.

I suppose it would. I guess this is fine as it is.

audio_snk = gr::audio::sink::make(d_audio_rate, device, true);
#endif
make_audio_device(device);
std::cerr<<"d_audio_rate="<<d_audio_rate<<std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

Was this just for debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I forgot to remove it.
Removed.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from 8eba911 to e8773cd Compare December 30, 2021 22:16
@argilo
Copy link
Member

argilo commented Dec 30, 2021

I noticed a bug: the frequency axis on the audio FFT seems to be incorrect when lower audio sample rates are used.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from e8773cd to fd69e6e Compare December 30, 2021 22:21
@vladisslav2011
Copy link
Contributor Author

Thanks for a review.

the frequency axis on the audio FFT seems to be incorrect

Confirmed. It may be fixed by setting correct sampling rate on receiver::audio_fft. Wait some minutes, I'll check it and reopen the PR.

@vladisslav2011 vladisslav2011 marked this pull request as draft December 30, 2021 22:26
@argilo
Copy link
Member

argilo commented Dec 30, 2021

Another problem: filter widths are not restricted, and so aliasing can now occur when the audio rate is decreased. For instance, when I widen the USB filter, a tone that is outside the displayed filter skirts can be heard:

Screenshot from 2021-12-30 17-27-14

@argilo
Copy link
Member

argilo commented Dec 30, 2021

This is because the demod ranges defined in selectDemod are built under the assumption that the audio rate will be 48000. For instance:

ui->plotter->setDemodRanges(0, 5000, 100, 40000, false);

@argilo
Copy link
Member

argilo commented Dec 30, 2021

It looks like this will need some careful consideration to account for all the places in the UI and DSP that are making assumptions about the audio rate.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from fd69e6e to a7b2540 Compare December 30, 2021 22:54
@vladisslav2011
Copy link
Contributor Author

For instance, when I widen the USB filter, a tone that is outside the displayed filter skirts can be heard:

That's just filter leakage. It can be heard at 48000Hz rate too. Setting the filter to 'sharp' reduces the peak and tone, setting the filter to 'soft' increases it.
I see no aliasing even when the peak is in filter range:
2021-12-31 02-19-43
Audio is resampled always correctly with filtering applied before decimation. https://github.com/gqrx-sdr/gqrx/blob/master/src/dsp/resampler_xx.cpp#L52-L60

On one hand, limiting the maximum filter width (AM, SSB, CW, RAW IQ modes) to a value, that will always fit into output bandwidth is a good idea, but on the other hand, altering user settings in unexpected way may be bad.
In case of FM the bandwidth includes the deviation, so in case of WFM it can be very wide even when modulating signal bandwidth is narrow. So, we should not limit the filter width in FM modes.
I've fixed the bug with incorrect frequency axis on the audio FFT. Reopening.

@vladisslav2011 vladisslav2011 marked this pull request as ready for review December 30, 2021 23:42
@argilo
Copy link
Member

argilo commented Dec 31, 2021

That's just filter leakage.

Ah, I think you're right. After looking closer, I see that nbrx and wfmrx have audio resamplers late in their receive chains, which should prevent aliasing. My suggestion to limit the demod ranges was based on that incorrect assumption, so I think it's fine to leave them as they are.

I'll still need to do a bit more testing to make sure that there aren't any other bugs.

@argilo
Copy link
Member

argilo commented Dec 31, 2021

I see now why I was confused by the behaviour when I expanded the filter bandwidth. The filter's transition width depends on the low & high filter cutoffs, so it becomes very large when the filter is expanded:

receiver::status receiver::set_filter(double low, double high, filter_shape shape)
{
double trans_width;
if ((low >= high) || (std::abs(high-low) < RX_FILTER_MIN_WIDTH))
return STATUS_ERROR;
switch (shape) {
case FILTER_SHAPE_SOFT:
trans_width = std::abs(high - low) * 0.5;
break;
case FILTER_SHAPE_SHARP:
trans_width = std::abs(high - low) * 0.1;
break;
case FILTER_SHAPE_NORMAL:
default:
trans_width = std::abs(high - low) * 0.2;
break;
}
rx->set_filter(low, high, trans_width);
return STATUS_OK;
}

This is surprising. I would have expected the transition width to depend only on the mode and the filter shape.

@argilo
Copy link
Member

argilo commented Dec 31, 2021

Another issue. While in 8 kHz mode, switching from USB to FM (stereo) leaves the audio FFT in a weird configuration where negative frequencies are displayed:

Screenshot from 2021-12-31 00-47-29

@argilo
Copy link
Member

argilo commented Dec 31, 2021

Maybe that happens because the requested range exceeds what is possible given the current audio sample rate. There's even a FIXME about that:

uiDockAudio->setFftRange(0,24000); /** FIXME: get audio rate from rx **/

Many other modes similarly request FFT ranges that may not be possible.

@argilo
Copy link
Member

argilo commented Dec 31, 2021

I guess all the ranges should be capped to a maximum of half the audio rate.

@vladisslav2011
Copy link
Contributor Author

I guess all the ranges should be capped to a maximum of half the audio rate.

Thanks for suggestion. This works very well.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from eafabd8 to 9a91deb Compare January 11, 2022 20:02
@vladisslav2011
Copy link
Contributor Author

Rebased on top of current master.
It was quite hard. The previous "recreate the demod from scratch" approach was much, much easier.
I was hit by gnuradio/gnuradio#5436 several times during rebase, so this PR needs some testing to ensure, that it is free from regressions...

I have added 88200 Hz and 96000 Hz audio rates (mostly for "RAW IQ" mode).

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from 9a91deb to dadc20b Compare January 13, 2022 16:00
@vladisslav2011
Copy link
Contributor Author

Rebased on top of current master.
And closed by accident.
How can I reopen this PR? Pushing new commits, as github suggests, does not help...

@vladisslav2011
Copy link
Contributor Author

vladisslav2011 commented Jan 13, 2022

OK. Pushing a new commit has solved the issue.

@argilo
Copy link
Member

argilo commented Jan 15, 2022

Sorry, it looks like I caused a merge conflict when I merged #1066.

I just had a quick look over this code and it's looking decent. I think I'll try to including this in the next feature release (2.16) since it's a new feature.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from 9ea8065 to e44afdc Compare January 15, 2022 19:49
@vladisslav2011
Copy link
Contributor Author

I caused a merge conflict

Resolved.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch 2 times, most recently from 3bc3d57 to d929c83 Compare August 21, 2022 00:25
@argilo argilo added the feature label Mar 25, 2023
@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from d929c83 to 9cb19eb Compare July 28, 2023 19:20
src/dsp/fm_deemph.h Outdated Show resolved Hide resolved
@sultanqasim
Copy link
Contributor

Aside from my nitpick regarding the double precision argument to the set_rate function in fm_deemph.h, this patch is working very well for me and I have not noticed any regressions in my testing. I would support this being merged once this the warning causing double precision nitpick is fixed.

@vladisslav2011 vladisslav2011 force-pushed the upstream_audio_sample_rate branch from 9cb19eb to 53cb660 Compare August 12, 2023 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants