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

Create an example of how to use with a RTL SDR #37

Closed
RCGV1 opened this issue May 31, 2024 · 10 comments · Fixed by #38
Closed

Create an example of how to use with a RTL SDR #37

RCGV1 opened this issue May 31, 2024 · 10 comments · Fixed by #38
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@RCGV1
Copy link

RCGV1 commented May 31, 2024

I am confused on how to implement this with an RTL SDR

@cbs228 cbs228 self-assigned this Jun 1, 2024
@cbs228 cbs228 added the documentation Improvements or additions to documentation label Jun 1, 2024
@cbs228
Copy link
Owner

cbs228 commented Jun 1, 2024

Have a look at #38. Do these changes answer your question?

I generally prefer to use gqrx instead of rtl_fm. I think the demodulator and AGC are generally superior to rtl_fm's default options. It also permits me to mute/unmute the audio so I can listen to it. But samedec can be made to work just as well with rtl_fm.

@RCGV1
Copy link
Author

RCGV1 commented Jun 1, 2024

Thanks for the quick response, I was asking about including example code of implementing rtl sdr (using any way that works, was playing around with rtl fm but it didn't work) using sameold.

You included some example code here:

https://docs.rs/sameold/latest/sameold/

@cbs228
Copy link
Owner

cbs228 commented Jun 1, 2024

The changes in #38 are for the samedec (binary program) documentation. They haven't been merged or released yet, so they won't show up on docs.rs or crates.io. I was hoping you could look at the diffs or the topic branch (feature/doc_rtl) and see if they clarify the situation.

I was able to get rtl_fm to work, but it will likely require some tweaking. In particular, you need to set the -g GAIN. The AGC was not working particularly well for me. The diffs in my PR have more details on both this and gqrx.

sameold (not samedec) is the Rust library crate that can be integrated into other Rust projects. Were you looking to try and integrate with the rtl-sdr drivers in Rust? That's a more complicated task.

@cbs228
Copy link
Owner

cbs228 commented Jun 1, 2024

… And if you have not already, I would see the samedec executable. You can either build it from source or use our binary releases here on GH. All you have to do is pipe in audio samples in a particular format, and you can obtain the audio from a variety of sources. Documentation is here or on crates.io.

@RCGV1
Copy link
Author

RCGV1 commented Jun 1, 2024

My project involves integrating this library into a rust project. Im a bit new to rust so an example of how to pass in audio via cqrx would be very helpful.

@cbs228
Copy link
Owner

cbs228 commented Jun 1, 2024

You would need to obtain a Rust wrapper around the existing rtl-sdr drivers, which are native C.

If no such wrapper exists, you will need to write one. Rust can wrap native C libraries with bindgen, but you will need to write unsafe code that creates a safe API around C. This is not an ideal first project in Rust by any means.

Then you need to obtain the raw IQ samples and recover demodulated baseband audio. For NOAA stations, a narrowband FM (NBFM) demodulator suffices. For commercial FM, you will need a wideband FM demodulator (WBFM). For digital commercial radio like NRSC5, you will need to write a digital decoder and things will be very hard. For television—don't bother, you don't have enough bandwidth. librtlsdr does not do any of this for you. An understanding of digital signal processing would be helpful.

Once you have recovered single-channel baseband audio in uncompressed f32 format, you can feed that to sameold by following the example.

I have no examples for this because I have not done it. And if I had done it, samedec would probably support it.

@RCGV1
Copy link
Author

RCGV1 commented Jun 1, 2024

I meant using cqrx into stdin, sort of like how you did it in samedec. Sorry if I am being confusing.

@cbs228
Copy link
Owner

cbs228 commented Jun 1, 2024

I am very confused. What exactly is your final goal? What are you trying to do?

samedec already supports UDP input from gqrx, per its documentation. You just run a program like socat or netcat that receives the UDP and pipes it into samedec. No need to write any Rust. Or, if you must write another executable, the samedec source code is an example for how that can be done.

@RCGV1
Copy link
Author

RCGV1 commented Jun 1, 2024

I was able to use rtl_fm reliably with samedec but after trying to follow what you did in the main samedec code I was unsuccessful with writing my own code using the library.

https://gist.github.com/RCGV1/4f6946bfd49331ea87b022732b2ad0f6

@cbs228
Copy link
Owner

cbs228 commented Jun 2, 2024

// Create a SameReceiver with a 4800 Hz audio sampling rate
let mut rx = SameReceiverBuilder::new(4800)

Did you mean 48000 Hz? A sampling rate mismatch will definitely cause things to not work. Our documentation recommends at least 8000 Hz at the input. sameold is designed to work efficiently even at relatively high sampling rates.

The sample data in the sample/ directory are all 22050 Hz. If you are writing your own executable, you should test against those. Please be sure that rtl_fm is feeding your executable a clean, good-sounding audio feed at the sampling rate you expect. Listen to it with sox or some other audio playback tool. Always test your decoding setup.

I am going to merge #38 and close this issue as it seems that things are working. I am generally unwilling to support executables in other projects. If you discover a bug or missing functionality in sameold or samedec itself, please feel free to open a new issue.

@cbs228 cbs228 closed this as completed in #38 Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants