Guide Setting up a MP3 player and media streamer on a cheap router...

Status
Not open for further replies.
Setting up a Router as MP3 player and Media Streamer...

I have been considering hosting all my music collection in a central place in the house to reduce redundancy with the many gadgets we use now a days. A dedicated NAS machine was not a good option simply because electricity is precious and expensive in India. And then the cost of dedicating a 24/7 hardware to host files is also not a great idea. Even if I used a small NAS box to save power, it still does not allow me to play the music anywhere I want. I need clients everywhere that can browse network shares and play the music.

Secondly, the charm of a radio station is the unpredictability of what plays next. The charm never works with a music collection where we tend to play the same songs we like over and over again. So I have also been fascinated with the idea of streaming my own English collection randomly, possibly because there is not a single FM radio station in Bangalore that is dedicated to English music.

The other requirement is that I should be able to control the music in various ways, primarily through the Phones and PC's at home. After considering various high cost alternatives (in terms of hardware cost), I think I have found pretty much the perfect option. A low cost router that can do all the above :-)

Now, why did I document it when there are tons of people who have tried the same on various forums and many have succeeded over the years ? Well, all of them have scattered bits and pieces of information dating back to three years ago when openwrt was small and could easily fit the 4mb flash on the Asus 520gu. The older versions of mpd (music player deamon) were also used, mpd has grown to gigantic proportions in the meantime (by router standards) and none of the forums have consolidated information on how to run audio on the router with the latest features of mpd.

So after one week of piecing together various options and trying out build after build, here is a precise walk through.

What do you need :

1. A router compatible with either OpenWRT or Tomato open source with a available USB port. I personally started with the ASUS WL-520gU, primarily because it is available for less than Rs 2000 everywhere. Later on, I figured out that I could have made my life a lot easier with a router that ships with more than 4mb memory. My old Buffalo WZR-HP-G300NH was the second experiment and it was much easier to configure.

Anyways, this article will focus on the low cost ASUS WL-520gU.

2. A cheap USB hub, maybe a Belkin 4 port USB hub that is available for Rs 250. A powered hub is a better choice if you intend to keep a lot of music in multiple usb drives. I personally had a Logitech 4 port hub.

3. A cheap 1gb or 2gb USB drive that will host the OS files.

4. A big kick ass usb drive which can hold all your music collection. I personally went with a 32gb drive !

5. A cheap USB sound adaptor with any C-Media chipset that is available for Rs 100 in ebay or everywhere in local shops. ( Check MightyOHM forum for more options). And yes, if you want a high end Optical output, there are a few options there also.

Now we start :-)


Setting up the router with Tomato Firmware :


1. Download the Tomato firmware for the router from Download - TomatoUSB

I personally recommend the Kernel 2.4 Lite version at Tomato 2.4 Lite

Also download the Asus Utility package for the router from their website. You need the Asus Firmware Restoration utility.

2. Connect the computer with a Ethernet cable to the port closest to the WAN port and setup the ip on your computer to 192.168.1.2 manually. No other connections should be active on the PC.

3. Press the reset button on the router and connect the power cord to it even as the button is pressed. You will see the Power LED blink slowly, now release the button.

4. Start the Asus firmware utility, select the firmware file you downloaded and start the process. Allow it to reboot and get ready for a full 5 minutes.

5. Change the IP address back to automatic on your PC and check that the Asus router now gives you a DHCP ip address.

6. Go to http://192.168.1.1 and login with the default user and password, both being "admin".

7. Now connect a WAN link to the router and power off and on the router. It should come up and start acting like a router !

Setting up the router with the necessary configuration and libraries:


1. Go to http://192.168.1.1 and choose the "USB and NAS" option in the Tomato menu and enable "Core USB Support", disable printing support, and enable USB Storage Support.

2. Using a existing linux machine, partition your USB pen drive with a 256mb SWAP named partition and the remaining as a ext2 partition named OPT (do not choose ext3 as it reduces the life of the pen drive with frequent writes). The partition names of SWAP and OPT are important.

3. Now connect the USB hub to the router and connect the swap/ext2 formatted Pen drive to it. You should be able to see it mounted on the Tomato web interface immediately.

4. Enable ssh interface in the web interface and set the admin password. Now ssh into the router ip (192.168.1.1) using user "root" and password as you just defined.


We are in the SSH world now and ready to install the software we need :


1. Edit /etc/fstab and add these two lines to the file:

LABEL=SWAP none swap sw 0 0
LABEL=OPT /opt ext2 rw,noatime 1 1

2. Issues these commands to make the mount of /opt permanent.

nvram setfile2nvram /etc/fstab
nvram commit
reboot

Wait for the reboot and SSH again to the router. Now you should be able to see the ext2 partition mounted as /opt and the swap active in the web interface or via the mount command.

3. Issue the following commands to enable download of optware packages.

mkdir -p /opt/tmp
cd /opt/tmp
wget http://tomatousb.org/local--files/tut:optware-installation/optware-install.sh -O - | tr -d '\r' > /tmp/optware-install.sh
chmod +x /tmp/optware-install.sh
sh /tmp/optware-install.sh

This will take a little while. Make sure there are no errors reported.​

Now we install mpd and mpc plus the dependencies. The problem with the packaged mpd is that it does not seem to work well with httpd streaming, and hangs a lot. So we circumvented with additional packages from other sources and copying some libraries over existing ones to get the latest versions :

ipkg update

cd /opt/tmp
wget http://tomato.groov.pl/repo/mpd_0.16.2-2_mipsel.ipk
wget http://tomato.groov.pl/repo/gettext_0.14.5-2_mipsel.ipk

ipkg install mpd_0.16.2-2_mipsel.ipk

echo src optware Directory index · styled with h5ai > /opt/tmp/optware.conf
echo dest /opt/ / >> /opt/tmp/optware.conf
ipkg -f /opt/tmp/optware.conf update
ipkg -f /opt/tmp/optware.conf install gettext_0.14.5-2_mipsel.ipk
cp /opt/lib/libintl.so.0 /opt/lib/libintl.so.3

ipkg update
ipkg install sqlite libuclibc++
ipkg install mpc

The above install of mpd will install quite a few dependencies. Wait till all is done.​


Do drop a note of thanks to shibby20 at either of the links below as we used his hosted links on tomatousb. The mpd version in the tomato repository is older and not as efficient, this is his private compiled version of mpd 0.16.2 which works well. Here are the links that detail this:

http://www.wikidot.com/user:info/shibby20
http://tomatousb.org/forum/t-362104/usb-sound-on-asus-wl-520gu

4. Run mpd on the command line. It should now run and give functional errors, but not crib about any dependencies.​


Setting up the audio interface


1. Insert the USB audio device to the usb hub. Make sure that the router recognized the insertion by typing the "dmesg" command, you should see a few lines about the audio device insertion

2. Issue the following commands :

cd /opt/tmp
wget http://tomatousb.org/local--files/doc/audio_control_files.tar.gz
cd /
tar zxvf /opt/tmp/audio_control_files.tar.gz opt
cd /opt/tmp
tar zxvf /opt/tmp/audio_control_files.tar.gz autoruns-to-use
cp /opt/tmp/autoruns-to-use/80-start-audio.autorun /opt
rm /opt/mpd/playlists/radio.m3u

Scripts obtained from this link. The link was my first starting point for this project, so a big thanks to the folks out there. Especially the startup scripts are a godsend and make sure that the music starts streaming the moment you switch on the router.

3. Edit this file : /opt/etc/mpd.conf

Remove the existing state_file line and add this instead:

state_file "/opt/etc/mpd.state"
pid_file "/opt/mpd/mpd.pid"

Having the pid file isvery usefull while you are experimenting. Just use the "mpd --kill" command to kill the existing mpd proess instead of. Similarly, the state file is used to save the state information every time mpd exists. So you start the next round from the song you stopped the router at.​

3. Edit this file : /opt/etc/mpd.conf

Remove the existing audio_output section and add these sections :

audio_output {
type "oss"
name "My USB Sound Device"
mixer_type "software"
device "/dev/sound/dsp"
}

audio_output {
type "httpd"
name "My HTTP Stream"
encoder "wave"
port "8000"
bitrate "128"
encoding "mp3"
format "44100:16:2"
}

Notes : The audio output section literally took me days to get it right with the right balance of quality and usability. The Asus 520gu does not have the horsepower in the CPU to do vorbis or lame encoding on the fly. The router just crashes. The wave encoder is the only one that works reliable on the 520gu, but if you have a slightly better cpu power in your router, fell free to change it to lame and check. vorbis encoder always crashers in any router, do not know why.

Also, if you need only the http streaming or just the audio output, then remove the other section to save some cpu cycles for the router.

3. Now it is time to run the daemon to check. Insert some speakers or headphones into the audio adaptor and run the following commands:

/opt/80-start-audio.autorun
mpd
mpc update
mpc add /
mpc volume 50
mpc play

You should hear the one song that was added from the zip file you unpacked. Yippeee.

4. Now it is time to check if the same music is ALSO being streamed over http.

Start up vlc on your PC. Issue the mpc play command again (the song is short) and connect vlc to http://192.168.1.1:8000 and press play. You should hear the streamed music on your PC. Yippeee again !

This is a good place to make the router enter your existing network and free it of Ethernet cables.

Tomato has a great option to make the Wireless interface in the router act as a bridge to your existing wireless network. Just choose the bridge option in Wireless, provide your wireless network credentials and reboot, you will be on your home network wirelessly and the WAN cable would no longer be required.


Now to add your local music collection for random play.


1. Copy all your mp3's to another pen drive, preferably formatted to fat and insert the pen drive to the hub.

2. Note down the mount point in the tomato web interface and change the "music_directory" path to the same in /opt/etc/mpd.conf

3. Issue the commands :

mpd --kill
mpd
mpc add /
mpc update
mpc random on
mpc play

And Voila, you should hear random songs from your entire collection being simultaneously played on the audio adaptor and streamed to your local network. You can control the playlist and the collection by installing Gnome music player client (GMPC) on Windows. Or on Android or iPhone via the mpc ports, they both have lovely interfaces.

You can also add internet radio stations to the playlist. In this case the router serves as a nice Internet radio station streamer.

I also ordered a hi-end FM transmitter and intend to connect the same to the audio output of the router. That way, I get to play the random songs on any FM radio in the house 24/7 !!! Finally my dream of a English FM radio station at home for cheap, with approximately 7 watts of power being used :-)

P.S : This entire guide along with alternate private download locations for the files used above is also on my blog at Random Musings
 
  • Like
Reactions: 11 people
This is great....
I was thinking of buying an Apple Airport for audio streaming... I can save that expense for now...
Thanks a lot for this article... Will try to do it on my router... (ASUS WL-500GP V2)
Reps added....
 
Thanks for the reps. The steps for Tomato will work as is on the ASUS WL-500GP V2 as it is also a broadcom chipset. But if you are willing to experiment, you could try Openwrt as the hardware is capable of running it. You will also not need to setup the usb drive for opt because the flash is over 4mb on your router. Also the latest Openwrt will have full support for Alsa. Let us know how it goes.


This is great....
I was thinking of buying an Apple Airport for audio streaming... I can save that expense for now...
Thanks a lot for this article... Will try to do it on my router... (ASUS WL-500GP V2)
Reps added....
 
Am waiting for the usb sound card to arrive to complete this. Have a few queries

Does the quality of the sound card has any impact on the sound quality ?

Tomato lite build (2.6) has usb support. Can we use that kernel and appropriate sound modules ?

As always high quality stuff from you Vinayaga. This is the 2'nd time am building something following your guide. Thanks a lot.
 
good job , reps added , was planning the same but with optical output and your article makes it damn easy
 
Thanks. If you want to use 2.6, you have to go with a different router that has more memory. The 520gu seems to struggle with the 2.6 kernel, I have tried multiple times and never got the combination right till now.

On normal speakers, I could not make out any difference between the carious cards I got. But when connected to the Amp, I can clearly make out the difference between the plantronics sound card versus the cheapo one I have. And a huge upgrade when I use the Turtle beach adaptor. So it all depends on your use case.


Am waiting for the usb sound card to arrive to complete this. Have a few queries

Does the quality of the sound card has any impact on the sound quality ?

Tomato lite build (2.6) has usb support. Can we use that kernel and appropriate sound modules ?

As always high quality stuff from you Vinayaga. This is the 2'nd time am building something following your guide. Thanks a lot.


---------- Post added at 10:12 AM ---------- Previous post was at 10:08 AM ----------

good job , reps added , was planning the same but with optical output and your article makes it damn easy

I used the Turtle beach Micro II adaptor with optical out, it is amazing clarity and convenience at $25. Give it a shot. But to be honest, I have got in working only in one 520gu, somehow the other 520GU is not working with a similar configuration, so it might be a little extra work !

By the way folks, it seems that there are a few 520gu in ebay with bill and warranty for less than Rs 1500. I got a few of them and they work great and look brand new. They claim its new, but I get the feeling they are refurbished and released for Asia as new :annoyed:
 
>>I tried with the 2.6 kernel and it plays the song in the audio_control_files.tar.gz perfectly. You need to change the line "device /dev/sound/dsp" to "device /dev/dsp" in the mpd.conf. When i stream via http the load avg shoots up above 2. Will check with high >>bitrate mp3 today and report.

Vinayaga, you are right. The 2.6 kernel wont cut it. Flashed back the the tomatousb lite based on 2.4. Just finished everything and it is working great.

Cannot find any fault with the 100 Rs usb sound card when playing music on my ATP3.

Am using this app as the remote control from my android phone.

Was about to gift the router to somebody, glad that it is now put to good use :)
 
@vinayaga @bobbyprajan
I have a belkin router running on " Tomato v1.28.7498 MIPSR2-Toastman-RT K26 USB Ext".I followed your steps but when I check with "dmesg" it giving an error "version magic '2.6.22.19 mod_unload MIPS32_R1 32BIT ' should be '2.6.22.19 mod_unload MIPS32_R2 32BIT ".Can you kindly explain me why its giving this error.From my little knowledge I hope it has to do something with different versions.Thanks in advance
 
@Tom

Most probably you are trying to use a module which is compiled for kernel 2.4 with kernel 2.6

Somehow missed your post, saw it just now only
 
@Tom

Most probably you are trying to use a module which is compiled for kernel 2.4 with kernel 2.6

Somehow missed your post, saw it just now only

You were right.
The problem was getting the right 2.6 modules.later i figured it out. I replaced the 2.4 modules with 2.6 and it worked . thank you
 
@vinayaga
I am on Shibbys latest tomato , Router is Belkin F78301 . I have 2 TB in one of the usb ports which has HD movies , pics and music only . My main requirement is DLNA function of the router . I am able to use the samba correctly on any device but DLNA is not working correctly . I have not made the pendrive with optware as per post for swap and stuff .
The issue is that DLNA scan never completes and my collection is not visible in my DLNA compliant WIFI speaker . How to ensure that it correctly scans everything . I have even left the scan running for a night but it still gets stuck in between . Will adding the pendrive with optware as per post on second usb drive improve things ? I have database location in JFFS . Will adding the pendrive with optware packages and giving pendrive as database location improve things
I do not want the usb audio interface .

thanks
 
Last edited by a moderator:
Status
Not open for further replies.