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

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.

83 thoughts on “Building a Wifi Radio – Part 5, Let’s Make Some Noise!”

  1. Hello Jeff
    I’m not familiar to Linux (including chip-size distros for routers). So the story is:
    I have old WRT54GS found somewhere at home. I know this device has only 2Megs of flash. Question is: is it possible to mount 2 usb ports (it is pssible) and put USB audio card into one of them and old 2 Gig flash into second one – to split OpenWRT based radio software both onto internal flash and mounted usb dongle? Did You tried to think about such challenge? 🙂
    I found that router’s 2Gig flash can not handle whole firmware, so I’m looking for some bypass instead of throwing this oldschool router into rubish bin 🙂
    Regards

    1. Does the WRT54GS have USB onboard? I was not aware that it did (even on the PCB).

      It is possible to use a hub with the WL520gU and multiple USB devices. There are some problems with large flash drives on the older kernel versions (like the one I used in my project) but I believe there are workarounds (different filesystems, kernel modules).

      Some of the members of the forums here have used a USB drive to add capacity to the WL-520gU, which barely has enough space as it is. I think you will find using the limited space of the WRT54GS challenging, but that doesn’t mean you should give up on it. 🙂

      1. Heh… My fault. The router I plan to use is WRT54G-TM. First one is working fine under DD-WRT as a “master router” at my flat, second will be turned into radio in case of success ;). This second router is already HW modified by being equiped with USB and SD card reader. Both modifications are working fine so there is a time to force this device to make some sound.

        The additional target is to force ATmega8 to reac RC5 IR remote commands and drive this radio remotelly. But I’m constrained with commands to be sent via UART to router – I need to learn them and to implement them (I’m using Bascom to create programs for AVR uCPUs)

        Anyway – I saw somewhere in the network, that there is possibility to add one USB 1.1 port to WRT54GS too.

        1. I’m not very familiar with other routers, as I concentrated only on the WL-520gU and WL-500. I have some experience with the WRT54GL but have never looked into USB on the WRT54 series routers.

          Sounds like a cool project, and I know others have played with IR. You might want to search the forums to see if anyone else has implemented what you are trying to do.

          http://mightyohm.com/forum

          1. Hello Jeff
            It looks like I stucked at last milestone of router conversion. I have WRT54G-TM running OpenWRT now. All reconfigurations made as You ordered in part 3-5 of this storry. USB sound device is detected. Network reconfigured…
            But… When command mpc play is sent, I can hear only continuous “beeeeep” on the headphones. When “status” is requested to mpc – I can see it is connected to proper stream and is able to display the stream name. This name changes folowing what is sent by the radio station at the moment. I can also change volume of my “beeeep” 😉 So it looks like almost everything is working.

            What I suppose as potential source of problem is, that USB2.0 spec requires 15k pull down resistors whilest i left original SMD elements which are 47k. I’ll try to change these elements and maybe I will win this little war 🙂

            Maybe You can tell me other hints? Maybe driver is not proper one? Did everybody meet the same situation?

            When this issue will be solved – I think about ATmega8 interface for IR remote (commands via ATmega’s UART) and also for 2×16 LCD display (“mpc status” to router and then router’s replay parsind and displaying proprt parts).

            At this time – my respect for Your work for Asus. Folowing this, step by step, a newby like I was able to deal with OpenWRT on WRT54G-TM and almost do the same conversion 🙂
            Regards

          2. Pawel,

            Please please please, post in the forums! The comments section of these posts is not a good place for me to give troubleshooting advice (it gets quickly lost).

            I have heard of issues with a continuous beep before, in fact you are not the only person to run into this problem:

            http://mightyohm.com/forum/viewtopic.php?f=2&t=171&p=849

            I believe the workaround is to load kmod-alsa and enable the ALSA drivers in mpd.conf.

            There can also be sample rate problems. What is dmesg reporting the about your usb-audio device’s capabilities? I think 44kHz is good, 48kHz can cause problems.

  2. How to keep the playlist saved. Right now my playlists get erased when i reboot.????

    1. Edit /etc/mpd.conf to turn on the save state feature.

      If you have any more questions, please post in the forums.

      Thanks!
      Jeff

  3. I have bought a cheap USB sound adapter (The ‘3D’ sound module from eBay), and I get the continuous tone. After installing kmod-alsa, there was no change. I uncommented the alsa output in /etc/mpd.conf, and that also had no effect. I decided to comment out ‘audio’ in /etc/modules.d/60-usb-audio, which simply muted the device. It got rid of the tone, along with any other audio.

    I’m at a loss as to what to do here. Could you link me to the adapter you used? Could you suggest how I can get the kmod-alsa to work?

    1. Dan,

      I used a SYBA SD-CM-UAUD:
      https://mightyohm.com/blog/2008/10/inside-the-syba-sd-cm-uaud-usb-stereo-audio-adapter/

      I have no experience with other brands of USB-audio adapters. I expect that many of them will not work because of the limited USB-audio chipset support built into the Linux kernel on the router. I just got lucky with mine, it was the first one I tried and it still works great.

      To debug the device, I would pay attention to the boot messages on the router (run dmesg) and make sure everything looks good there. If not, chances are you won’t get it working no matter how hard you try. If the kernel isn’t happy, nothing else is going to work.

  4. 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!

  5. 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’

    1. 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

  6. hi,

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

    Danke

    1. 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?

  7. 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. 🙁

  8. 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.

  9. @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?

  10. 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

  11. 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!

  12. 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

  13. I got it working by installing the kmod-alsa module and stopping audio.o from being loaded.
    usb.c: USB device 2 (vend/prod 0x1130/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?

      1. 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….

          1. 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?

          2. 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.

          3. Does not work for me. Perhaps a kernel version problem? I get:

            Packages were found, but non compatible with the architectures configured.

  14. 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. 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.

  16. 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.

  17. 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

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

  19. 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!

  20. 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?

  21. 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.

  22. 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.

  23. 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

  24. 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.

Leave a Reply to PeterCancel reply