Notes on rtl-sdr source code – first impressions

I did a quick read of source code (rtl-fm.c) today.

Basically it opens an input stream of IQ samples from the rtl-sdr device, demodulates filters, and outputs audio.

Other than usual madness with threads and locking – the code is fairly straightforward. Not well commented – but clear enough that we could extract the input streaming and frequency (device) control to make a Max external. One question would be whether or not to do the downsampling in the external, or in Max?

Rough estimate would be this project would involve about 1-2 weeks of analysis and hacking. Possibly less – but there is a learning curve – and a heuristic stuff which is required to work with the hardware.

Fortunately it actually works in MacOS and Windows – and there are plenty of other examples to compare it to. But this is not a casual evening project.

 

Compliling rtl-sdr from source on Mac OS

notes

Just compiled rtl-sdr using  instructions below, from: http://sdr.osmocom.org/trac/wiki/rtl-sdr

!! but did not run: sudo make install – or sudo ldconfig !!

so the programs are just running locally in: tkzic/rtl-sdr/build/src

I didn’t want to overwrite the macports versions which are running in the exec path.

after compiling I was able to successfully test by running this from rtl-sdr/build/src:

./rtl_fm -f 94900000 -W -s 200000 -r 48000 - | play -r48000 -t s16 -L -c 1 -

which caused annoying pre-christmas music from WHOM to ruin this peaceful morning.

—————————————————————

Building the software

rtlsdr library & capture tool

You have to install development packages for libusb1.0 and can either use cmake or autotools to build the software.

Please note: prior pulling a new version from git and compiling it, please do a “make uninstall” first to properly remove the previous version.

Building with cmake:

cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig

In order to be able to use the dongle as a non-root user, you may install the appropriate udev rules file by calling cmake with -DINSTALL_UDEV_RULES=ON argument in the above build steps.

cmake ../ -DINSTALL_UDEV_RULES=ON

Piping raw IQ data from rtl-sdr to Max

notes

Here is a discussion about mkfifo (pipes) but  I can’t seem to get Max to interpret the FIFO as audio samples

http://www.reddit.com/r/RTLSDR/comments/rd15f/some_noob_questions_after_succesfully_getting/

I think I know how to figure out the streaming IQ thing now. Capture samples to a file, then look at the format. Then maybe pipe the file through something like auconvert to make it into a wave file. If that works, then maybe there is a way to to it as streaming.

Or figure out how to stream from tcp/ip version to audio.

rtl-sdr commands for testing

Had to install play (from sox) in /usr/bin

Gqrx came with the rtl command set – you can run the commands from

/Applications/Gqrx.app/Contents/Macos/

This command tunes to FM broadcast and plays

./rtl_fm -f 90100000 -W -s 200000 -r 48000 - | play -r48000 -t s16 -L -c 1 -