Raspberry Pi: Jessie Lite Setup for Streaming Audio

As a first pass at a featureless box that simply streams music from various sources, I set up a Raspberry Pi with a Jessie Lite Raspbian image. I’m mildly astonished that they use dd to transfer the image to the MicroSD card, but it certainly cuts out a whole bunch of felgercarb that comes with a more user-friendly interface.

I used dcfldd (for progress reports while copying) and verify the copied image:

sudo dcfldd statusinterval=10 bs=4M if=/mnt/diskimages/ISOs/Raspberry\ Pi/2015-11-21-raspbian-jessie-lite.img of=/dev/sdb
sudo dcfldd statusinterval=10 bs=4M if=/dev/sdb of=/tmp/rpi.img count=350
truncate --reference /mnt/diskimages/ISOs/Raspberry\ Pi/2015-11-21-raspbian-jessie-lite.img /tmp/rpi.img
diff -s /tmp/rpi.img /mnt/diskimages/ISOs/Raspberry\ Pi/2015-11-21-raspbian-jessie-lite.img

That fits neatly on a minuscule 2 GB MicroSD card:

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.8G  1.1G  549M  67% /
devtmpfs        214M     0  214M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  4.5M  213M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           218M     0  218M   0% /sys/fs/cgroup
/dev/mmcblk0p1   60M   20M   41M  34% /boot

Set the name of the Raspberry Pi to something memorable, perhaps streamer1.

Disable IPV6, because nothing around here supports it, by tweaking /etc/modprobe.d/ipv6.conf:

alias ipv6 off

Enable the USB WiFi dongle by adding network credentials to /etc/wpa_supplicant/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
 ssid="your network SSID goes here"
 psk="pick your own"
}

Nowadays, there’s no need for a fixed IP address, because after adding your public key to the (empty) list in ~/.ssh/authorized_keys, you can sign in using a magic alias:

ssh -p12345 pi@streamer1.local

I have absolutely no idea how that works, nor how to find out. If it ever stops working, I’m doomed.

The Raspberry Pi Model B+ has “improved” audio that, to Mary’s ears, comes across as pure crap; even my deflicted ears can hear low-level hissing and bad distortion at moderate volumes. An old Creative Labs Sound Blaster USB box sidesteps that problem, but requires a tweak in /etc/asound.conf to route the audio to the proper destination:

# Make USB sound gadget the default output

pcm.!default {
 type hw card 1
}
ctl.!default {
 type hw card 1
}

ALSA then seems to default to the wrong channel (or something), although this tweak in the middle of /usr/share/alsa/alsa.conf may not be needed:

#pcm.front cards.pcm.front
pcm.front cards.pcm.default

Good old mplayer seems to handle everything involved in streaming audio from the Interwebs.

Set up blank /etc/mplayer/input.conf and ~/.mplayer/input.conf files to eliminate kvetching:

# Dummy file to quiet the "not found" error message

Set up ~/.mplayer/config thusly:

prefer-ipv4=true
novideo=true
#ao=alsa:device=hw=1.0
ao=alsa
format=s16le
#mixer-channel=Master
softvol=true
volume=25
quiet=true

The commented-out ao option will force the output to the USB gadget if you want to route the default audio to the built-in headphone jack or HDMI output.

Telling mplayer to use its own software volume control eliminates a whole bunch of screwing around with the ALSA mixer configuration.

The quiet option silences the buffer progress display, while still showing the station ID and track information.

With that in hand, the Public Domain Project has a classical music stream that is strictly from noncommercial:

mplayer -playlist http://relay.publicdomainproject.org/classical.aac.m3u

Send them a sack of money if you like them as much as we do.

By contrast, the local NPR station comes across as talk radio:

mplayer http://live.str3am.com:2070/wmht1

You can’t feed nested playlists into mplayer, but fetching the contents of the stream playlists produces a one-station-per-line playlist file that one might call RadioList.txt:

http://relay.publicdomainproject.org:80/classical.aac
http://relay.publicdomainproject.org:80/jazz_swing.aac
http://live.str3am.com:2070/wmht1

So far, I’ve been manually starting mplayer just to get a feel for reliability and suchlike, but the setup really needs an autostart option with some user-friendly way to select various streams, plus a way to cleanly halt the system. A USB numeric keypad may be in order, rather than dinking around with discrete buttons and similar nonsense.

There exists a horrible hack to transfer the stream metadata from mplayer onto an LCD, but I’m flat-out not using PHP or Perl. Perhaps the Python subprocess management module will suffice to auto-start a Python program that:

  • starts mplayer with the default playlist
  • parses mplayer’s piped output
  • updates the LCD accordingly
  • reads / translates keypad input

This being a Pi, not an Arduino, one could actually use a touchscreen LCD without plumbing the depths of absurdity, but that starts looking like a lot of work…