/A/ /M/A/G/N/I/F/I/C/E/N/T/ /P/L/A/C/E/ 

January 2017

18:25 Wednesday 11 January 2017

Media Streaming with Linux on the Home Network

I've been playing a little with a Raspberry Pi (or two) over the past year. I've chosen OSMC for the OS which automatically runs Kodi on boot. Kodi allows me to watch iPlayer, Youtube, Redbull etc on a senile old TV. I have a NAS drive for storing my personal media such as photos, home videos, and an archive of music from purchased CDs.

I haven't been satisfied with the audio output of the RPi nor do I like using Kodi for playing music. I'm unfussy about the audio quality for watching TV, but for listening to music connected to the HiFi it's not up to scratch.

I splashed out on a HiFiBerry DAC+ which sits (like a hat) on top of the RPi and provides stereo RCA output for connecting to an amp. Audio quality is much improved.

But for general usage of the Pi I soon disliked having audio through the amp all the time. For one, it meant three seperate devices required to be turned on (TV, Pi, amp) - and two - unlike the amp & speakers, the TV can be loud enough to hear the quieter moments without the louder moments shaking the building.

So MPD to the rescue! The Music Player Daemon runs on the Pi alongside Kodi and starts automatically at boot each time the Pi is turned on. It outputs audio to the HiFiBerry DAC+ while Kodi outputs audio (and video) through HDMI. Both can be used simultaneously.

We have had the TV on in the background more and more lately and I've missed listening to music as frequently as I used to. I have a DAB for my HiFi amp but reception is too poor to use it. My fiance uses the TV to listen to the radio but it's generally not my cup of tea. I felt we could have a greater variety of radio to listen to if MPD played internet radio streams. I might even find a station I actually liked rather than endured, but for no justifiable reason, internet radio was something I had never properly tried.

I found out MPD can play internet radio and using Sonata - a GUI client for MPD that runs on desktop PC and Android devices (MPDroid) - it's relatively easy to add internet radio streams to MPD's playlist. I expected to find the streams for BBC radio on the BBC website but after digging around for a while it seemed they don't advertise them. Eventually I found the stream URLs on the website.

Listening to music via the network requires at least three devices - the amplifier & speakers, the Raspberry Pi, and a device (PC/Android/etc) to control MPD (and four if you include the NAS on which the music is stored when not playing an internet radio stream... five if you include the router... six if you include the additional switch).

So this was good for a few days but while configuring MPD and using it to listen to internet radio, I became aware its also possible to stream the output of MPD over the network via Icecast. I soon set this up so I could control MPD with my phone while it's output also streamed to my phone for when using the amp was not possible (ie I was in the other room). In my experience this is a better solution than using the mobile to directly accessing music on the NAS with SAMBA.

Wow, the wonders of modern technology eh!? So what does this mean? What is still missing? The last piece of the puzzle I've long been certain is possible is to stream audio transparently from my desktop PC to the RPi so I can listen to anything on my desktop PC through the amp without yet another cable trailing from one side of the room to the other.

Seeing as the RPi runs a version of Linux, and it can stream, I can use the same software on my Linux Desktop PC to do the same. But how to get all audio output from the PC to be streamed by Icecast? The solution lies with another piece of software DarkIce.

Just a matter of configuring DarkIce then. After a bit of trial and error I had it up and running. The Icecast webpage was being served by my desktop PC and the mount point for DarkIce was showing and I could use Sonata to play the stream from my PC on the RPi. Unfortunately it was totally silent as I couldn't figure out the most important part of the configuration - figuring out which single ALSA device for my computer's soundcard to specify. Easier said than done due to my soundcard providing a series of mono outputs rather than pairs of stereo outputs. Rooting around with expert ALSA configuration proved fruitless even after finding an old post on Linux Audio User which appeared would solve the problem but didn't.

While attempting to configure ALSA I had a nagging feeling the soundcard, an M-Audio Delta 66 (Ice1712 chipset) has the capability to do so in hardware. I needed to install specific software for the hardware to see what I could do with it. The answer lies with the fact the soundcard has a hardware mixer outputting to a stereo channel. I just needed to reconfigure the audio routing of the soundcard so the digital mixer became the main output of the card, while all desktop audio went through the mixer instead of being directly ouput. Easy with the chipset specific mixer software - Envy24control.

I still didn't know however the name of the ALSA device for digital mixer to use to configure Dark Ice. One final dig around lead me to another old post on Linux Audio User containing the solution at last (it's still a somewhat expert example of ALSA configuration but much less complex than my earlier efforts might have turned out if I had stuck with them).

On the plus side of this approach for streaming audio from the PC to the Pi, once it's setup there's no messing about, just switch MPD on the Pi to play the audio stream coming from the PC (it starts streaming after boot). The problem however is the delay due to the usage of buffering for streaming - one buffer for DarkIce, and another for Icecast. With the default configuration of both the delay is an unwieldy 15 seconds. With a bit of configuration it can be brought down to a tenth of that which is just about bearable for listening to (rather than watching) music videos on youtube. It's also possible to create a feedback loop with this too. And for bonus points with partner, I can also setup audio streaming from her laptop so she can have Spotify play music on the stereo.

15:36 Wednesday 11 January 2017


2016: Almost zero attempts to produce anything artistic. Zero substantial coding efforts. Reduced entries to the journal. Cycling goal of 5000 miles for the year missed by 300 miles. Failed personal challenge to enter one or more mountain bike cross country races each month. Failed to even get to two of the races I paid to enter! Fell sick with the trots on my first trip mountain biking around Les Arcs in the Alps left me unable to ride for over half the week. Failed to complete the Brighton Big Dog six hour solo cross country mountain bike race and bailed out just before four hours was up (then was vomitting about an hour later). Combination of mountain biking and upper bodyweight exercises near end of year result in minor case of cubital tunnel syndrome (pinched ulnar nerve where it runs through elbow).

On the positive side: at the end of the year my partner and I welcomed our baby boy into the world.



A page detailing new stuff and other random noise.

The journal is a general place for writing about what I am doing, or for making more official announcements concerning the things I do. It's also a place where I can write freely about my ideas, or just play with words and language.

DISCLAIMER: The opinions and attitudes of James W. Morris as expressed here in the past may or may not accurately reflect the opinions and attitudes of James W. Morris at present, moreover, they may never have.

this page last updated:29th April 2013 (C) 2003 - 2017 James W. Morris

script time:0.0406