Tutorials and How-tos/Bubba as Squeezebox

From BubbaWiki
< Tutorials and How-tos
Revision as of 13:38, 18 June 2012 by Johannes (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This how-to will explain you how to get sound out of your Bubba and turn it into a Squeezebox-like music player that can be controlled through the SqueezeBoxServer web interface or even with the SqueezeBox Duet controller.

You will need a USB sound card, enable SqueezeBoxServer on your bubba, build and install the 'Squeezeslave' package and finally make it start automatically at boot-time.

USB sound card

As Bubba does not have a sound output, you will need to get a USB sound card. It is difficult to tell you which USB sound cards are suitable as the sound card has to be supported out-of-the box by Linux. Your best chances are to buy one that does not need additional drivers on a Windows-PC. Most likely it will also be supported by Linux and you can use it with your Bubba. Make sure you can return your device to the store where you bought it in case it doesn't work. From my own experience I can say that a Creative SoundBlaster Play works.

SqueezeBoxServer

Enable the SqueezeBoxServer as described in the Bubba Two user manual in the chapter 'Media Servers'

Squeezeslave

Squeezeslave is a small utility that will do the audio playback and connects to the SqueezeBoxServer. It needs to be build from the source files as explained on the SqueezeboxWiki. The SqueezeboxWiki instructions are adapted to the Bubba situation in this how-to.

First login as root to your Bubba via SSH (see Tutorials and How-tos/Access Server via SSH)

Install the utilities required to get, build and test the application (if you need help, see Tutorials and How-tos/Install Debian Packages):

apt-get install subversion build-essential usbutils

Install additional required packages:

apt-get install libportaudio2 libasound2-dev libasound2 libncurses5-dev liblircclient-dev

Now we are going to download the squeezeslave package. It doesn't really matter which directory you use, we'll use /var/src in this how-to.

mkdir /var/src
cd /var/src
svn checkout http://squeezeslave.googlecode.com/svn/squeezeslave/trunk/squeezeslave

Build the package by using the following commands:

cd squeezeslave
make -f makefile.linux26-ppc-alsa-display realclean
make -f makefile.linux26-ppc-alsa-display

Edit: (replace ppc for armel if you are on B3)


The last command will take around 20 minutes to finish

The program file was created in the bin/ directory. Copy the program file to its final location:

 cp bin/squeezeslave /usr/sbin/

Testing the program

Now it's time to test the program. First connect your USB sound card to one of Bubba's USB ports.

List your usb devices and check that your device is listed:

$ lsusb
Bus 001 Device 016: ID 041e:30d3 Creative Technology, Ltd

List your sound devices to check if your sound card has been recognized:

$ cat /proc/asound/cards
 0 [U0x41e0x30d3   ]: USB-Audio - USB Device 0x41e:0x30d3
                      USB Device 0x41e:0x30d3 at usb-fsl-ehci.0-1.2.3, full speed

Now you're ready to start squeezeslave:

/usr/sbin/squeezeslave

Note that the squeezeslave program will not send any output to the terminal.

Now go to your web-browser and browse to http://bubba:9000. You should be able to select 'Squeezeslave' in the top right corner. Select some music and press 'play'. Connect speakers or a headphone to the output of your USB sound card and enjoy the music !

Once you're done testing, return to your SSH session and press CTRL-C to exit squeezeslave.

Starting squeezeslave at boot-time

This section will describe how to start squeezeslave automatically at boot-time.

First we'll create a new user that we'll use to run squeezeslave

useradd -r -s /bin/false -N -g audio squeezeslave

Next create the file /etc/init.d/squeezeslave with the following content (For a how-to on how to create and edit files via your SSH terminal, see Tutorials and How-tos/Edit Text Files with nano)

#! /bin/sh
### BEGIN INIT INFO
# Provides:          squeezeslave
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts squeezeslave
# Description:       Starts squeezeslave. Will make device a player in a SqueezeBox system
#
### END INIT INFO

# Author: Foo Bar <foobar@baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Squeezeslave"
NAME=squeezeslave
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--retry --daemonize /var/log/squeezeslave.log -m$(ifconfig eth1 | sed -n '/HWaddr/ s/.*HWaddr //p')"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
USER=$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --chuid $USER --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --chuid $USER --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
        #
        # If the daemon can reload its configuration without
        # restarting (for example, when it is sent a SIGHUP),
        # then implement that here.
        #
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
        return 0
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  #reload|force-reload)
        #
        # If do_reload() is not implemented then leave this commented out
        # and leave 'force-reload' as an alias for 'restart'.
        #
        #log_daemon_msg "Reloading $DESC" "$NAME"
        #do_reload
        #log_end_msg $?
        #;;
  restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        #
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 3
        ;;
esac

:

Note that the above file is derived from the /etc/init.d/skeleton example file.

Make the file executable and make it run at boot-time:

chmod u+x /etc/init.d/squeezeslave
update-rc.d squeezeslave defaults

Finally, start squeezeslave manually if you don't want to reboot your system (there is no need to do this)

/etc/init.d/squeezeslave start

Enjoy !