Ubuntu Linux has become my current hobby shop. I finally concentrated on fixing some of the more egregious problems I’ve been having with the latest Ubuntu stable release (playing DVDs and music). So now, after much tweaking, I finally have gotten my Radio Shark 2 AM/FM tuner to play in Linux on my laptop, though it was not exactly simple to track down all the required and various information. I figured after all the rabbit holes I went down (like compiling libhid from scratch) to get this to work, it might help to have an updated one-stop for the next poor sot, so I created this “kind of” simple how-to to get your RS2 at least to play in Ubuntu Intrepid. I’ll follow it up with a second post on some more advanced things you can do, like stream radio on your home network. Some very simple compiling of source code is involved and I added basic bash scripts at the end to start up the Radio Shark application. If you follow the step-by-step, it shouldn’t be a big deal (even for a relative noob). There are some cool things I learned in the process. If you are wondering why you would want to play live radio through your computer, read this. Say you want to make decent quality CDs/mp3s of the local classic rock station? I might know someone who has a collection of several hundred songs ripped to an iPod that was recorded this way—uh not me, of course. The powers that be might decide that radio is also copyright protected, and send out the black helicopters…
It is the essence of true geekiness to be able to play and record radio through your computer. It gives your PC that final touch as a true media server, but it’s also useful to be able to stream live radio wirelessly on your home network (come back for the next post, or continue to the bibliography/credits at the bottom for those instructions). The standard Windows application/drivers for the RS allow you to listen/tune, time shift (like Tivo) and record live radio, which is still cool, no doubt (yawn), but check out this web-site to see what you could do with a radio tuner, and a computer…uh huh—geeks started their own home-grown internet radio station with a web server, some flash and a sprinkling of PHP. Now what you got to say, huh!? You can also do twisted stuff like make the shark’s lights change colors (living on the edge now, eh?) I’ll provide some links of places where you might find a Radio Shark. In this first post, I’m just going over the steps to allow you to play and change the stations, etc.
1. First, you need Ubuntu Linux on your computer. If you have Windows, it’s really quite easy to install Intrepid as a second boot option by following the install wizard. Read this for a very simple example, or do a search on-line for “Install Ubuntu”. Linux can be a pain, but it starts/runs/stops faster than Windows Vista. If you simply want to record/listen to music, the RS tuners come with Windows applications included that do this already (Windows users can stop reading now).
2. Second, you need a radio tuner device. In my case, I used the Radio Shark 2, (kids got mine at ThinkGeek.com). The RS is an external USB attached AM/FM tuner. I should think you could do this with other tuner devices, but will likely require you to customize or write new code.
3. Connect the Radio Shark with Linux running. (Open a terminal console (Under Applications >> Accessories) and type “dmesg” to view system log messages. You should see something like below indicating that the RS is connected to your computer and Linux isn’t throwing a fit:
dmesg log trace…
[ 296.877223] input: Griffin Technology, Inc. radioSHARK as /devices/pci0000:00/0000:00:1d.7/usb5/5-4/5-4.2/5-4.2:1.2/input/input13
[ 296.893339] input,hidraw2: USB HID v1.00 Device [Griffin Technology, Inc. radioSHARK] on usb-0000:00:1d.7-4.2
[ 297.157074] usbcore: registered new interface driver snd-usb-audio
Download, Install and configure the code:
4. Open Synaptic Package Manager (System >> Administration >> Synaptic…), and make sure the “universe/multiverse “ repositories are available (see above). Enable them, if need be--the extra goodies make Linux truly excellent--under “Settings” >> “Repositories”… Go here to learn more about Synaptic, which will make Add/Remove in Windows look like a bad joke.
5. You will need the libhid development library, so do a quick search for libhid (search box is at the top of Synaptic), and the manager will reveal those packages (libhid-dev and libhid0). Don’t be intimidated just because it’s called a “library”—Synaptic does all the heavy lifting—it’s point and click just like Windows!
6. Select and install libhid packages (your source code will not compile without these). Synaptic will download and ask you to select required packages. Go have a tea…depending on you network speed.
8. Download shark2.c from here. When it finishes, it will probably be downloaded to your user home directory under “Downloads” by default (in Firefox). The shark program allows you to change bands/tune the RS, and control the lights on the side.
9. In the console window you previously opened, type the following (followed by the enter key after each line):
# cd ~username/Downloads
…change directory to wherever you downloaded the source. Replace “username” with your username of course…
# sudo gcc -g -o shark -lhid shark2.c
…compile shark2.c! gcc stands for gnu compiler collection… You are now only like “this” far away from being a coder yourself (if “this” was years and years of experience writing computer programs, haha…)! When some uber-geek sneers at you, just say…”Lay off dude… I’ve compiled code before”
# sudo cp shark /usr/local/bin
…copy the code to the local user executable directory. This is mainly so that you AND your dog can now run the new shark program.
# sudo /usr/local/bin/shark –blue 60
…change the color of the lights to test if the code is working.
# sudo /usr/local/bin/shark –fm 106.9
Tune the shark to a local FM station in your area (106.9 is classic rock station near me). Cool, now we want it to actually make the radio play, right?
Running ecasound to play the RS:
10. This part is a little more complicated. Like your new shark program, ecasound runs from the command line. So you could just pound in the word ecasound at your terminal console like the previous commands, but WAIT just a minute. You have to give it some extra input parameters. Oh my God! What in the seven hells are “input parameters”, you say!? Nothing big, just extra config information/instructions for the program when it starts up is all. You were already using them in the previous commands for gcc, shark, etc.
11. Type this next command instead (some tweaking may be required):
# ecasound -D -f:s16_le,2ch,48000,inter-leaved -i:/dev/dsp1 -o:/dev/dsp -B:nonrt -z:db -b:4096
This tells ecasound to run with debug on and specifies the sound IO device and buffer settings. Mainly, you want to focus on the sample rate of 48000, and tweak this for better performance or sound quality (and maybe if you have issues). I've seen that other users have successfully used 6400, 8000, and 32000 as well. The higher the sample rate, the better the audio quality that is produced. My RS made a pretty nasty sound at 8000. 48000 sounded great for FM playback.
Automating your Radio Shark in Ubuntu
12. While you could continue to run programs and control devices using old-fashioned command prompts, you might want to take advantage of the more automated capabilities of having a modern computer. So, make a script and a shortcut to easily execute your Radio Shark commands from the Gnome Application Launcher. I like to use VI editor for basic file editing, but you can use your favorite text editor (say gedit which is like notepad). First create a launcher script and then some change station scripts. Use your Terminal console again:
# cd /usr/local/bin
# sudo touch FMstart FMST1
..creates the empty script files..you can create more for fav stations like FMST2, FMST3... etc.
# sudo chmod 755 FM*
..makes them executable so users like you AND your dog can run them
Navigate using Gnome file browser to /usr/local/bin. Save these script contents in the files that you created earlier. Open the files with your editor:
#first line says I'm a bash script
#Second sets RS with my favorite station
#Third turns on the sound and then exits when you stop it
sudo shark -fm 106.9
ecasound -D -f:s16_le,2ch,48000,inter-leaved -i:/dev/dsp1 -o:/dev/dsp -B:nonrt -z:db -b:4096
FMSTN1 (change the freq to a local one in your area):
shark -fm 106.9
Full list of shark commands:
-fm <freqeuncy> : set FM frequency, e.g. '-fm 91.5'
-am <frequency> : set AM frequency, e.g. '-am 730'
-blue <intensity> : turn on blue LED (0-127) '-blue 127'
-red <0/1> : turn on/off red LED '-red 1'
13. Add Application shortcuts to the Gnome panel or the Programs Menu to run your new custom scripts. For instance, you can add the shortcut to the Sound and Video category under the main Applications folder. Simply right-select the Gnome launcher (see below):
In the Launcher Property window, enter the application name you want to assign and the path to your executable script. You can also assign a suitable icon for your program.
Make sure you go into the sound settings in Ubuntu and turn up the correct sound device to hear the radio playback. You can tweak volume levels from the main menu volume control, or by navigating again to the system settings menu. You may need to unplug and plug back in the RS, and rerun the ecasound and shark scripts if you booted with it already plugged in.
Feel free to post your comments. I added links to the source material below, and would like to hear more awesome ways you use Linux. Next post, I’ll add more RS and Ubuntu tips…
How-to stream cast with RS by Javier Rodriguez: http://javier.rodriguez.org.mx/index.php/2006/06/10/griffin-radio-shark-icecast2-on-debian-gnulinux
How-to Play RS on Deb Linux by Javier Rodriguez: http://javier.rodriguez.org.mx/index.php/2007/05/20/use-the-radioshark-2-under-linux-shark2c
New RS 2 code by Hisaaki Shibata (on Javier’s site): http://javier.rodriguez.org.mx/code/shark2.c
Original RS Linux how-to and shark.c: http://wiki.linuxquestions.org/wiki/Audio …code by Michael Rolig
Good example of using Linux to record, play and time-shift using RS: http://whats.all.this.brouhaha.com/2006/01/18/radioshark-in-linux/
Web-site that allows you to control a real live RS tuner over the net: http://www.radioyakima.com/index.php