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.
6 Comments to Using GStreamer and PulseAudio to direct computer audio output to a Squeezebox
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.
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.
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?
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!
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
Categories
Archives
- March 2013
- February 2013
- May 2012
- February 2012
- July 2011
- June 2011
- November 2010
- October 2010
- April 2010
- November 2009
- October 2009
- June 2009
- May 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- December 2006
- November 2006
- October 2006
- September 2006
- June 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- June 2004
- April 2004
- February 2004
- November 2003
- January 2003
- November 2002
March 18, 2011