Using GStreamer and PulseAudio to direct computer audio output to a Squeezebox

Sunday, November 7th, 2010 | Uncategorized

I’ve been a big fan of the Squeezebox system from long before Logitech purchased SlimDevices who originally made the device. I keep my music collection in FLAC format on my computer and can easily access it from my Squeezeboxes that play the music synchronised all over the house. As an added bonus, the Squeezebox also supports streaming a lot of different internet radio stations. What it doesn’t support, however, is playing arbitrary audio output from your computer. This might be handy if you’ve got access to a bunch of music through a Flash player and would like to make it available on your normal sound system.

Some plugins have been made to make SqueezeCenter, the management platform for the Squeezeboxes, support fetching audio from specific extra places, but the few that does that for Linux do not mesh very well with PulseAudio, the sound server that e.g. Ubuntu ships with by default. So rather than getting the music directly into SqueezeCenter, we can side-step the entire issue and just provide the audio output as an internet radio station that is only accessible from your local computer; this, the Squeezebox can quite easily play.

I have done this on Ubuntu 10.10, but any system using PulseAudio should be fairly analogous. You need a few prerequisites:

  • icecast2: Ogg vorbis and MP3 streaming server.
  • gstreamer0.10-pulseaudio: GStreamer plugin for PulseAudio.
  • gstreamer0.10-plugins-base: The base set of GStreamer plugins.
  • gstreamer0.10-plugins-good: A set of GStreamer plugins containing interface to icecast2.
  • gstreamer0.10-plugins-ugly-multiverse: A set of GStreamer plugins containing MP3 encoder.
  • gstreamer-tools: tools for use with GStreamer.
  • pavucontrol: PulseAudio Volume Control

Any standard configuration of the icecast2 server will probably do, as long as you can receive music from it and send feeds to it using the configured password you should be good.

First we tell PulseAudio that we have a sink we’d like to register: pactl load-module module-null-sink sink_name=squeezebox

Then we start playback with this easily understood and very apparent command line invocation: gst-launch pulsesrc device=squeezebox.monitor ! audioconvert ! lamemp3enc target=1 bitrate=128 cbr=true ! shout2send ip=127.0.0.1 port=8000 password=PASSWORD mount=mystream.mp3

If you live in parts of the software patent encumbered world, you can probably make it work with Ogg Vorbis instead.

You can now point your Squeezebox at a stream at http://127.0.0.1:8000/mystream.mp3, however, you still won’t have any sound! Why? I hear you pondering… Because above we simply said that we wanted the Squeezebox sink to be the null-sink, i.e. nothing goes on there apart from a timer keeping stuff in sync. In order to hear anything we’ll start up pavucontrol, the PulseAudio Volume Control program and in the Recording tab, we ask it to show all streams and we should be able to see a stream called gst-launch-0.10 and a button next to it that says ‘Monitor of null output’, click this button and select ‘Monitor of your sound card’ and presto, music should appear from your Squeezebox after it’s done buffering (provided, of course, that you are playing something on your computer at the moment).

Just be aware that this plays all audio output from your machine, but it isn’t terribly adequate for watching videos, etc. as there is a noticeable delay between what goes on in the video and when the music appears on the Squeezebox, but for streaming music, it’s perfect.

Tags: , ,

6 Comments to Using GStreamer and PulseAudio to direct computer audio output to a Squeezebox

Erik
March 18, 2011

Is the buffering occuring in pulseaudio or in squeezebox, is it something you can dabble with? I like the near instantaneous sound I get when streaming through pulseaudio to another pulseaudio computer.

Henrik Stuart
April 21, 2011

The buffering is made by squeezeserver when it plays network streams so as to ensure that syncing between multiple players behaves somewhat sanely. You can probably try to write a new source plugin for squeezeserver that will play the pulseaudio stream directly instead.

Max
August 16, 2011

hello i have been trying to stream from my soundcard to icecast2 for a while now using liveice, darkice and some other ways but with bad result. i thought i would make it with liveice but the sound was just a noise..

and i tried this way as you write, and it mount to icecast2 for like 5 sekunds then it stops and im not able to open the stream, but i think its just some configuration who is needed.. have you got any idea? could it be something with that the computer who plays the stream dont use pulseaudio?

Max
August 16, 2011

sorry i didnt read everything… now it should work but i dont have pulseaudio on my iphone so i have to figure out a way to do this.. thank you!

Thierry Dumont
November 12, 2011

hello! This is extremly interesting, but does not work for me.
When I launch gst-launch pulsesrc….
I get the message:

ERROR: Caught a segmentation fault while loading plugin file:
/usr/lib/gstreamer-0.10/libgstgnomevfs.so
Please either:
- remove it and restart.
- run with –gst-disable-segtrap –gst-disable-registry-fork and debug.

I move out libgstgnomevfs.so.
I get the: shout_open() failed: err=Login failed
which I can understand because I did not give any passwd on the command line (after port=8000)

I do it as root. What password is this for?
I am using a Natty Narwhal, server version.

Yours!
t.d.

Leave a comment