mpd on a RPi, streamripper and sox


For some years I have run mpd on an early RPi as a media player, and it has worked very well… better as Raspbian improved in robustness. Playback is controlled mostly from mpdroid on our Android tablets or phones. Playlists switches can be automated using cron on the RPi.

Whilst using Telstra Bigpond ADSL for broadband access we have been unable to stream Shoutcasts (“Internet Radio”) without frequent stops and starts rendering it unusable. The 8Mb/s broadband service performed so badly it would not sustain near real time traffic at 200kbps.

With the experience that Telstra does not maintain sufficient capacity to give its customers good service, we chose another provider once NBN access became available.

The new iinet broadband access (nominally 12Mb/s from a 40Mb/s VDSL2 access pipe) delivers a higher percentage of the claimed speed, and Shoutcast streams are viable, so I have experiemented with receiving music streams and splitting them into separate mp3 files based on the tags embedded in the Shoutcast stream.

An example command is:

streamripper -d ./stream3 --quiet -s --xs_offset=3000 &

This is run in background so that it survives and terminal disconnection. To terminate it, use the jobs command to find the job number, fg command to bring it back into foreground and CTL-C to terminate.

For economy of storage and convenient listening and , I then re-encode each mp3 file and pass it though a compander step using sox:

for i in *.mp3; do
  sox -S "$i" -C 64.01 done/"$i" compand 0.2,5 6:-60,-30 -7 -90 0.2

This sets the bit rate to 64kb/s and encoding quality to the highest.

A script to randomly sequence albums and non-album tracks (those in the @ directory) into the current playlist and then to save it follows.


mpc clear
mpc rm All
mpc update --wait

#mpc ls |while read line
find . -type d -links 2 ! -path ./@ |sed 's/\.\///' |while read line
  printf "$RANDOM\t$line\n"

find @ -name \*.mp3 |sed 's/\.\///' |while read line
  printf "$RANDOM\t$line\n"

) |sort -n |cut -f2 |tee ~/stuff |mpc add
#) |less

mpc save All
mpc play