Play audio with USB audio adapter

https://docs.google.com/document/d/1hI0_rwkZYX_FUP5_no60MfBqOfSMMPFnrwKe4YotkJ0/edit?hl=en

It is possible to use your Tomato router to play music and internet radio. Not merely as a music server, but to actually play music on the router itself.

All you need is a USB audio adapter like this one:
flickr:5452555144

This adapter is available from many internet and ebay vendors. I purchased mine for $1.55 (including shipping) from http://stores.ebay.com/Eunion4u. Look for “USB 2.0 to 3D AUDIO SOUND CARD ADAPTER” Mine is able to drive a cheap set of unpowered speakers to adequate volume.

Of course, you also need a set of speakers or headphones with a standard 3.5MM stereo audio plug.
Other USB audio adapters will probably work, too. This just happens to be the one I bought-because it was cheap.

The Music Playing Software

All the necessary software packages are free. The software on the router is optware, so you need to have optware & ipkg already set up.

The package is mpd (Music Player Daemon), plus the requisite audio codec libraries.

The control interface to MPD is either MPC (a command-line program on the router) or a remote program that runs on your desktop Windows or Linux computer.
I use Bills Jammin Jukebox, but there are others.
Download from: http://www.thejavashop.net/bjj/

I rarely use MPC. I mainly use the remote control program from my Windows machine. With it, I can change the playlist, change the volume, etc.

The Music to Play

MPD will play music that resides on any storage device on the router—USB hard drive, USB flash drive, or /cifsN samba share. Since MPD is optware, you already have a suitable device on the router.

MPD will also play internet streaming radio stations. Personally, I find this more useful than the ability to play mp3 files. I already have plenty of stand-alone MP3 players and CD players. I don’t have anything else that will play internet radio stations.

Installation, Control, and Configuration Files

The install scripts and control/config files are in a tarball that can be downloaded from:
http://ray123.fileave.com/audio_control_files.tar.gz or on this page.

MPD is quite large and depends on a large number of libraries, and a few kernel modules that are not in the standard Tomato build. It is based on optware, so you must have optware installed. You also will need to have a swap partition active. The exact modules, and the exact configuration settings are slightly different, depending on the Linux kernel version — 2.4 or 2.6.

These files are set up so that when I plug in the USB audio adapter or when the router boots up, it will start playing an internet radio station at a volume that is comfortable for me. The default volume is probably not right for you or for a different set of speakers, so you’ll probably need to change the default volume level in the config file (/opt/etc/mpdconf).

When the audio adapter is plugged in, the software is loaded and mpd begins playing. When the adapter gets unplugged, the software is unloaded.

The commands to install everything

These are the commands to install the software:
ipkg update
ipkg install mpc mpd
ipkg install sqlite libuclibc++

Note that installing mpd will also install a lot of other packages that mpd depends on.

These are the commands to download and install the config and control files:
cd /mnt/your-disk (that is, the top directory of your disk)
wget http://ray123.fileave.com/audio_control_files.tar.gz
tar xzf audio_control_files.tar.gz

(Or see below for alternate link.)

This depends on the particular setup of your /opt. The directory configuration in the tarball is for a setup where /opt is the opt sub-directory of the disk, such as "/mnt/your-disk/opt"
If your setup is different, you'll have to manually copy the files to the right spot.

Next, copy the files from the directory "autoruns-to-use/" to the root directory of the drive. They are in this separate directory in case you already have autorun files which set up /opt and swapping, and don't want yours to be over-ridden.

Configuration items specific to the USB audio adapter

MPD needs to know the name of the mixer channel that is the volume control. This is specified by the “mixer_control” parameter in /opt/etc/mpd.conf.

Kernel version 2.4

In the adapter mentioned above, this is "Vol". Also common is “PCM”. If this is different for your adapter, there will be error messages in syslog (/var/log/messages) and you won't be able to change the volume in MPD.

If this happens, look in syslog after you plug in the adapter for a line such as this:
user.warn kernel: usbaudio: OSS mixer channel is 0 (mixer_control: "PCM ")
or
user.warn kernel: usbaudio: OSS mixer channel is 0 (mixer_control: "Vol ")
A line that says:
user.warn kernel: usbaudio: OSS mixer channel is 7 (mixer_control: "Mic ")
is not the one you want. That’s the microphone input volume, which we are not using.

There will be one line for each mixer, so you might have to experiment to see which one is for output volume. Then edit mpd.conf and look for the line that says:
mixer_control "vol"
and change "vol" to the mixer_control name as shown in syslog.

Kernel version 2.6

Linux 2.6 audio subsystem is ALSA, and 2.4 is OSS. Linux 2.6 emulates OSS, and has to cross-reference the OSS mixer name to the actual ALSA mixer.
The volume mixer name will generally be “Speaker” or “Headphone”. In order to see the mixer names do “cat /proc/asound/card0/oss_mixer”. You’ll see something like the below. Just try different names until you get one that works.
SPEAKER "" 0
LINE "" 0
MIC "Mic" 0
PHONEOUT "Speaker" 0

EDIT
New files in the tarball, 5/23/2011. This now has all the kernel modules and scripts for kernel 2.4, 2.6 (R1) and 2.6(R2). The mpd.conf is configured for K2.6. To tailor it for K2.4 just uncomment the necessary lines at the bottom of the file.

The link for this document is
https://docs.google.com/document/d/1hI0_rwkZYX_FUP5_no60MfBqOfSMMPFnrwKe4YotkJ0/edit?hl=en
The tarball link is: http://ray123.fileave.com/audio_control_files.tar.gz
Another link: http://tomatousb.org/local--files/doc/audio_control_files.tar.gz

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License