Advertisements

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…

Advertisements

,

  1. #1 by madbodger on 2016-02-08 - 09:21

    Ah, good old dd. That command is actually very old (hence its truly odd option structure). It was originally the “convert and copy” command, but “cc” was taken (by the C compiler), so in true Unix fashion it was dubbed “dd”. I totally get your disinclination to use Perl (“It’s the vice grips of programming languages: you can do anything with it, and it’s the wrong tool for everything”). PHP is okay for what it’s designed for (providing web content served from a database), but somewhat silly for other purposes.

    • #2 by Ed on 2016-02-08 - 09:30

      Yeah, the astonishing part was seeing the RPi folks recommending dd rather than some friendly piece of, oh, Python scriptage. I suppose as soon as you get away from using NOOB images, you’re presumed to either know what you’re doing or be willing to learn the hard way. AFAICT, there’s no harder way to learn than swapping if and of

    • #3 by Red County Pete on 2016-02-08 - 23:26

      I missed Python, as my programming ended with Dot-Com Bubble implosion V1.0, but back then Perl was the “Swiss Army Chainsaw”. OTOH, I have some interesting scars from chainsaw “incidents”, so the vise-grip point is taken. I have a largish solar system under consideration (backup for refrigeration for when local power goes sideways) that would benefit from some computing power, so something new to learn.

      FWIW, for anybody with a Win 7 box who wants to keep it that way, MS is getting frisky with pushing Win 10. Again. I’m keeping the AskWoody dot com blog on my daily schedule, and use a current copy of GWX control panel in active/monitor mode on the MS machine. Patch Tuesday may be more interesting than normal this month…

  2. #4 by pwillard (@pwillard) on 2016-02-26 - 11:13

    The magic “.local” stuff comes from Apple’s “bonjour” tool part of the zero conf networking solution. Pretty handy.

    • #5 by Ed on 2016-02-26 - 11:39

      Which seems to be called Avahi by the Free Software folks, although I’m obviously hazy on the details.

      Now that I know those names exist, I’m typing them a lot. The router still requires fixed IPs for port forwarding & suchlike, but that’s a rare case around here.

      Thanks for the tip!

  1. Raspberry Pi: USB Keypad Via evdev | The Smell of Molten Projects in the Morning
  2. Raspberry Pi Streaming Radio Player: Minimum Viable Product | The Smell of Molten Projects in the Morning