Building a Wifi Radio – Part 5, Let’s Make Some Noise!

November 8th, 2008 by Jeff

This is the fifth part of an ongoing series at mightyOhm about building a low cost, open source streaming internet radio.  If you haven’t already, check out the previous parts below for some background about the project.

Building a Wifi Radio – Part 1, Introduction

Building a Wifi Radio – Part 2, Choosing an Embedded Platform

Building a Wifi Radio – Part 3, Hacking the Asus WL-520GU

Building a Wifi Radio – Part 4, Installing OpenWrt

Note:

The instructions that follow assume that you have an Asus WL-520GU wireless router with the following modifications: an externally accessible serial port, OpenWrt installed and working, and a configured network connection on the router.  If not, check out the previous parts of the series to learn more.

Using opkg to customize OpenWrt:

OpenWrt includes a utility called opkg that allows the end user to easily add and remove optional software packages.  These packages include functionality that is not a part of the OpenWrt base image, such as hardware drivers (including USB), optional software, and utilities.  Most packages are not installed by default (after all, the router only contains 4MB of flash storage).  The OpenWrt Community Wiki includes a very helpful page about Packages that contains a lot of useful information about configuring and using opkg.

Before we can use opkg we need to configure it.  The file /etc/opkg.conf contains a few options, including the URL of the server opkg uses to find and download packages.  We need to change this server from the default by modifying the config file:

root@OpenWrt:~# vi /etc/opkg.conf

Modify the first line to look like this:

src/gz snapshots http://mightyohm.com/files/kamikaze-2.4/packages/mipsel 
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists

You can also download the complete set of packages and set up a server of your own for opkg to access.  I have had great success using the apache server included with OS X, but I won’t cover the setup here.

The following command tells opkg to fetch a list of available packages from the server:

root@OpenWrt:~# opkg update

You should see the following response:

Downloading http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz
Connecting to mightyohm.com (72.32.209.132:80)
Packages.gz          100% |*******************************|  8326  --:--:-- ETA
Inflating http://mightyohm.com/files/kamikaze-2.4/packages/mipsel/Packages.gz
Updated list of available packages in /var/opkg-lists/snapshots
Signiture check for snapshots skipped because GPG support was not enabled in this build

Now we can start installing packages.  To access our USB-audio converter, we need to install USB 1.1 (OHCI) support and some sound drivers:

root@OpenWrt:~# opkg install kmod-usb-audio kmod-usb-ohci

This should automatically install kmod-usb-core and kmod-sound-core, but if not you can also install them manually with the opkg install command.

At this point you should insert the USB-audio converter if you haven’t already.  Then reboot the router:

root@OpenWrt:~# reboot

As the router is booting again, watch for new status messages like these:

...
usb-ohci.c: USB OHCI at membase 0xb8003000, IRQ 6
usb-ohci.c: usb-00:03.0, PCI device 14e4:471a
usb.c: new USB bus registered, assigned bus number 1
usb.c: registered new driver audio
audio.c: v1.0.0:USB Audio Class driver
usbaudio: device 2 audiocontrol interface 0 has 1 input and 1 output AudioStreaming interfaces
usbaudio: device 2 interface 2 altsetting 1 channels 1 framesize 2 configured
usbaudio: valid input sample rate 48000
usbaudio: valid input sample rate 44100
usbaudio: device 2 interface 2 altsetting 1: format 0x00000010 sratelo 44100 sratehi 48000 attributes 0x01
...
usbaudio: registered dsp 14,3
usbaudio: constructing mixer for Terminal 6 type 0x0301
...

If you see this, the USB-audio converter is most likely working and the correct drivers have been loaded.  At this point the green LED inside the USB-audio converter should be lit, another sign that everything is working correctly.

Installing mpd:

To actually play some tunes we need to install some additional software.  We can use opkg to do this, as follows:

root@OpenWrt:~# opkg update

root@OpenWrt:~# opkg install mpd mpc

This command installs mpd, the music player daemon.  mpd is an open source music server that can be accessed locally or across a network by using a variety of clients, which are available for many different platforms.  This includes the command line client mpc which is also now installed on the router.

mpd requires some setup before we can use it:

root@OpenWrt:~# cd ~
root@OpenWrt:~# mkdir .mpd
root@OpenWrt:~# mkdir music
root@OpenWrt:~# mkdir .mpd/playlists
root@OpenWrt:~# vi /etc/mpd.conf

Scroll down and look for the audio_output section of the mpd configuration file, and change the reference to /dev/dsp to make it look like this:

# An example of an OSS output:
#
audio_output {
        type                    "oss"
        name                    "My OSS Device"
        device                  "/dev/sound/dsp"
        format                  "44100:16:2"
}

There are many other options you can play with; mpd is very powerful.  There is a list of features here and a lot more information on the mpd wiki.

Exit vi, saving the changes to mpd.conf.  Now launch mpd with the following command:

root@OpenWrt:~# mpd

The player should start silently, without errors.  Run mpc and verify that it can talk to the server:

root@OpenWrt:~# mpc
volume:100%   repeat: off   random: off

If you see this, good news, the server is running and we have the ability to control it with mpc!

Now would be a good time to connect speakers or headphones to the USB-audio adapter’s headphone output.  Warning – the initial volume can be VERY LOUD. Don’t wear headphones during testing!  PC speakers with a volume control are best.  Start at a low volume.  (My ears are still ringing!)

We can add a streaming radio server to the playlist by executing

root@OpenWrt:~# mpc add http://relay3.slayradio.org:8000/
adding: http://relay3.slayradio.org:8000/

And finally, the moment of truth:

root@OpenWrt:~# mpc play
http://relay3.slayradio.org:8000/
[playing] #1/1   0:00/0:00 (100%)
volume:100%   repeat: off   random: off
root@OpenWrt:~#

If all goes well, within a few seconds you should hear Slay Radio playing on your headphones or speakers.  The Air light on the router should flicker as traffic crosses the WiFi interface, and the green light on the USB-audio converter should flash repeatedly to indicate that audio is being sent to the device.

If you’ve made it this far, I recommend celebrating with your favorite beverage and enjoying some tunes!  Congratulations!

You can add other servers to the playlist by executing the mpc add command again, and then play them with the mpc play n command, where n is the position of the server in the playlist.  mpc playlist will display the current playlist. mpc help will give you a list of available commands.

One very powerful feature of mpd is that it operates as a server on port 6600 of the router, so it can be controlled from any other device on your local network.  If you download an mpd client such as Theramin, you can control the router remotely from your desktop computer.  There is an excellent client for the iPhone too.

That’s it for part five.  I hope you have enjoyed the series thus far.  In part six, we’ll start writing some scripts to control mpd and talk about options for a user interface.  If you are building a Wifi Radio of your own, I’d love to hear about it – leave a comment below!

Update: Part six is now available.

Related posts:

Tags: , , , , , , , ,

64 Responses to “Building a Wifi Radio – Part 5, Let’s Make Some Noise!”

  1. Dan says:

    Has anyone tried to record sound using the 520gu, OpenWRT, and the USB device suggested here? If so, I’d appreciate any advice you could offer. Ideally, there would be a simple, lighweight command-line app to capture wav files at various sample rates and bits/sample.

    I havent been able to find a way to use ‘cat /dev/sound/dsp > filename’ because the raw storage format sounds horrible (or I can’t figure out what format it’s using or adjust the format settings).

    And I haven’t been able to successfully install sox to try that app because it’s too big to fit in flash (thanks to dependencies like libvorbis) and opkg seems to underestimate the amount of space available on my 256MB thumb drive so I can’t install it there.

  2. Sean says:

    Not sure where its going out of whack, but it’s probably a routing problem. I can ping the world, but can’t connect. I have an internal web server, so I hosted all the packages on it (thank you for letting us know that detail!!!) and proceeded to get all the packages loaded.

    When I first saw your WiFi radio articles, all I wanted out of it was a nifty Icecast client to provide input for my stereo. I already had MPD loaded and functioning on the Linux system from when I first read through your articles and had discovered that it will serve as an Icecast music source.

    MPD is serving on Linux, Icecast is streaming and MPD is picking up on the WL-520GU and putting Claire De Lune into my headset as I type this. Presently I’m using Glurp as the MPD client. It will attach to both the Linux system and the WL-520GU for controlling MPD.

    I have some setup issues to deal with MPD dropping between songs (software issue -> probably an MPD setting) but the sound is doing quite well!

    Next to get that routing issue fixed, and I’ll have more than I wanted.

    Outlay so far:

    Linux Server with MPD -> IceCast -> WL-520GU with MPD -> Stereo Headset

  3. Sean says:

    The MPD dropping after song finish seems to be due to needing to tell MPC on the WL-520GU to repeat song play which forces it to pick up the start of the next song.

  4. Jeff says:

    I haven’t used Glurp before but I’ll check it out. I will definitely check out Icecast as well.

    A couple things that help make life easier when dealing with mpd on the router:

    You can set up mpd to start on boot by making a softlink in /etc/rc.d:

    root@OpenWrt:/etc/rc.d# ln -s /etc/init.d/mpd /etc/rc.d/S93mpd
    

    There’s a setting in the mpd.conf file to retain the last played song as well. If you set that up you can power cycle the router and it will usually come back playing where it left off – very nice.

  5. Hot damn! I have sound! Next step: getting the 4GB flash drive to mount so I can try my hand at some additional software. Like espeak.

  6. pavlos says:

    Its working! i am very enthousiasted! ole ole. But there is a small problem : there are many delays and stops in the music. What might be the problem? The usb converter? Or the cpu of the modem? Any ideas?

  7. Jeff says:

    Try another stream – I noticed problems with one stream I tried, not sure at this point what is going on. It may be a sample rate problem. The router may not have enough horsepower to both resample and decode mp3. It could also be your network connection, make sure the stream plays ok on another computer!

  8. Nick says:

    @Durin – what did you use to mount samba shares? I can’t seemed to get either mount.cifs or smbmount to work.

  9. abel says:

    how to update to mpd version 0.14?
    thanks

  10. Jeff says:

    abel – I don’t see a precompiled package on openwrt.org, so you’ll have to cross-compile it from source. I spent some time porting a SID player to Openwrt and the process is fairly involved – you’ll need a computer running Linux and a working Openwrt build environment (there are some notes about this in part 4).

    There are some basic instructions here but they may be outdated, your mileage may vary:
    http://downloads.openwrt.org/docs/buildroot-documentation.html

  11. Peter says:

    I’m getting a continuous beep from mpd whenever i try to play something. Is this related to the fact that my USB sound adapter only supports a sampling rate of 48000Hz and not 44100 as well.
    usbaudio: valid input sample rate 48000
    Or is this a completely different problem. Any help appreciated.

  12. Jeff says:

    Did you try changing the audio settings in mpd.conf?

    If yes, I’d try another USB-audio adapter.

  13. Peter says:

    Yes. I changed the relevant settings in mpd.conf. With mpd log_level set to verbose I get the following in mpd.log
    Jan 01 00:10 : oss device “/dev/sound/dsp” will be playing 16 bit 2 channel audio at 48000 Hz
    And yet all I still get is a single tone at the output.

  14. Jeff says:

    What do you see in syslog when you plug in the USB audio adapter? I wonder if the kernel usb-audio module doesn’t support your device or isn’t initializing it correctly.

  15. Peter says:

    I got it working by installing the kmod-alsa module and stopping audio.o from being loaded.
    usb.c: USB device 2 (vend/prod 0×1130/0xf211) is not claimed by any active driver.
    usb.c: registered new driver snd-usb-audio

    Seems like now snd-usb-audio.o is being used as opposed to audio.o?

    • Regiscruzbr says:

      Hi Peter.

      I have the same problem, but I don’t know how to fix it.
      Can you give a step by step in the Forum?
      http://mightyohm.com/forum/viewforum.php?f=2
      Thanks

      • Stig Hess says:

        Also have this annoying problem with a cheap USB sound card from China. Did you figure out how to install the kmod-alsa-modules? I can’t find them in mightyohms repository, is there somewhere else we can get them.

        I’ve figured out how to disable audio, though, comment it out in /etc/modules.d/60-usb-audio. That stops the beep, but of course, there’s no sound at all….

        • Stig Hess says:

          Ok. Got it working:
          Comment out “audio” in the file /etc/modules.d/60-usb-audio

          Change repository in /etc/opkg.conf to

          src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/brcm-2.4/packages /

          I also had to change dest to “dest root /jffs”

          opkg update
          opkg install kmod-alsa

          Reboot. That’s it!!

          • Ralf says:

            Thanks for the hint, my soundcard also required the ALSA module. By the way, do you guys have quality issues? My soundstick produces a rather rasping sound when being plugged into the WL-520gU – it sounds good on the PC though. Any ideas why this could happen?

  16. Peter says:

    Seems like my el-cheapo 99c eBay USB audio adapter works with ALSA and not OSS.

  17. Jeff says:

    Weird! Has anyone else had issues with this?

    Peter, thank you very much for figuring this out and posting your solution.

  18. Cyk says:

    Hi.

    The (very short) data sheet of the Marvell chip says that ist has 2 USB interfaces.
    Are the signals available on the PCB?
    It dosen’t look like they are, but maybe someone knows more.
    So: Is it possible to add an internal USB?

    thanls
    Cyk

  19. Anup Vasudev says:

    Hi, great blog! I am starting a similar project…well not exactly similar… I need to stream video over Wi-Fi on to a portable device like an iphone. Can i use this router to do it? The router becomes a ‘transmitter’ rather than a ‘receiver’ for my project Are there packages to support video like kmod-usb-audio ? The idea is to build a ‘remote control’ with a video feed. Am very new to all this actually(wrt hardware and linux). Any info/help is appreciated! Thank You!

  20. pavlos says:

    Hi,
    Do you have any ideas on how i can play files in mms (WinMedia) form, like for example : mms://kissfm.live24.gr/kiss2111?MSWMExt=.asf
    Is it possible or mpd just plays m3u files? Thanks in advance

    Pavlos

  21. me says:

    hi again jeff, i followed your tip and was able to get openwrt installed and mpd working great! thank you very much! i installed the firmware file you supplied, modified the network settings as directed, and am now able to ssh into the router without hacking a serial port in (yet).

    what i would like to do next is allow mpd to access my music library stored on a smb share. do you have any tips on doing this? im running into ‘out-of-space’ problems when installing some of the smb-client options suggested on the openwrt site… or maybe i should see if i can get mpd using a mt-daapd library? hmmm..

    me

  22. me says:

    @durin and @Nick, I would love to hear from you if you were able to get smb shares mounted. i wouldn’t mind turning this into a jukebox that can access a large library of mp3s, although i suspect i will have to install a usb drive for the mpd database.. could you post some tips? sounds like durin was able to get smb working – any ideas?

  23. I`m working on WL500GPv2.
    I can`t rmmod usbcore for some reason (unloaded all other usb-related modules).
    The sound adaptor is chinese pd552. It works unless i load ehci-hcd.o. Then I have usb2.0 support, but no sound.
    It seems that in kernel2.6 there is an option CONFIG_USB_EHCI_SPLIT_ISO, which should be enabled to allow usb1.1 sound cards to work on ehci hubs. I don`t know if this is available or `d help with kernel2.4/openwrt/mipsel.

  24. Jeff says:

    I have heard this before somewhere in the comments, I can’t find the post right now. I think the original poster was having issues with USB-audio on a high speed hub, as I believe you are. I have not been able to find that option in the 2.4 kernel, so I think it’s 2.6 only.

    You may want to try asking about this in the mightyohm.com forums or over on openwrt.org.

    This is probably a good excuse for someone to try and get the 2.6 kernel working on the WL-520gU. Wish it could be me, but I have too many other things going on now. :-(

  25. jonnas says:

    hi,

    I would like to know how to stream through mms protocol, using wma instead of mp3???? Many radio stations uses that obviously.

    Danke

    • Jeff says:

      mpd 0.15 (curently in beta) is supposed to have support for MMS. There may be some work required to port it to the router. mpd 0.14 became very bloated and was pushing the flash capacity of the 520 due to a glib2 dependency. I listen primarily to Shoutcast so I have not run into this issue – what streams are using MMS?

  26. Ken says:

    I got the console port up with a MAX3232 chip and 5 .1uF caps.

    This is where I am stuck at the moment:

    When I type mpd, it says:

    mpd: can’t load library ‘libstdc++.so.6′

    • Jeff says:

      Ken,

      I haven’t seen this one before. Are you using the firmware on this site as opposed to compiling your own or using an image from openwrt.org? Did you see any other errors in the rest of steps to this point?

      I recommend re-posting this over on the forums where myself and others can better help you get things working.

      Jeff

  27. Rubi says:

    You are the greatest!
    Everything worked after the first try.
    Awesome tutorial.
    I have a wlan radio, I cannot believe it.

    Thank you so much !!!!

    Radio Slay is also awesome, I like it.

    Only thing, I got an error after starting mpd
    unable to open db file “/root/.mpd/mpd.db”: No such file or directory
    current locale is “C”

    I am afraid I have to find out what that means.
    But since it works I can live with this. :)

    Thank you!

  28. Jeff says:

    I haven’t noticed any quality issues beyond some digital noise creeping into the audio output. It isn’t severe but may be objectionable to an audiophile. If you have severe distortion, try another sound device. I know the SYBA works fine, but I have never tried any other USB to audio adapters.

Leave a Reply


www.flickr.com
mightyohm More of mightyohm