<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digital Ambulation &#187; pulseaudio</title>
	<atom:link href="http://www.alanbriolat.co.uk/tag/pulseaudio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alanbriolat.co.uk</link>
	<description>Life, programming and general geekery</description>
	<lastBuildDate>Mon, 09 Jan 2012 12:07:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MPD + PulseAudio + Ubuntu Intrepid (8.10)</title>
		<link>http://www.alanbriolat.co.uk/2009/03/mpd-pulseaudio-ubuntu-intrepid-810/</link>
		<comments>http://www.alanbriolat.co.uk/2009/03/mpd-pulseaudio-ubuntu-intrepid-810/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 03:15:27 +0000</pubDate>
		<dc:creator>Alan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[pulseaudio]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.alanbriolat.co.uk/?p=186</guid>
		<description><![CDATA[Update (2009-04-12): It appears that in Jaunty everything now obeys the system-wide setting properly, so you only need to edit /etc/default/pulseaudio and add the user to pulse-access. I&#8217;m a big fan of Music Player Daemon (MPD), and up until the last few months I used it almost exclusively.  It&#8217;s lightweight, it&#8217;s good at what it [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update (2009-04-12):</strong> It appears that in Jaunty everything now obeys the system-wide setting properly, so you only need to edit /etc/default/pulseaudio and add the user to pulse-access.</em></p>
<p>I&#8217;m a big fan of <a href="http://www.musicpd.org/">Music Player Daemon (MPD)</a>, and up until the last few months I used it almost exclusively.  It&#8217;s lightweight, it&#8217;s good at what it does, and there are a lot of different frontends available.  One of the things I like most is that it&#8217;s not tied to a graphical session in any way&#8212;you don&#8217;t need a GUI open for it to be playing music.  Normal usage of MPD involves it being started and stopped as a system service.</p>
<p>Unfortunately, this doesn&#8217;t play too nice with the concept of how <a href="http://www.pulseaudio.org/">PulseAudio</a> should be used.  PulseAudio is very user- and session-centric, and the recommended setup means than when nobody is logged in, no sound is going to be playing.  While MPD is capable of <a href="http://mpd.wikia.com/wiki/PulseAudio">playing to a PulseAudio server</a> just fine, having the sound server tied to the graphical session means it doesn&#8217;t have a sound device to attach to at boot, and the sound device suddenly disappears if the user logs off.</p>
<p>Ubuntu has used PulseAudio for as many applications as possible by default since Hardy (8.04), and while it can be removed, doing so can make life difficult.  This led me to pursue the option of a system-wide instance which everything uses, and which is always running.  But no matter how hard I tried, I got stuck with the same bug: starting GNOME would always result in a per-session instance being spawned in addition to the system-wide one, the two would fight over the sound card, and I would have to manually kill the new one every time I logged in.  Eventually I&#8217;d had enough of this and started using something else.</p>
<p>Today, I decided to take another stab at getting this set up properly and finding out where that second PulseAudio instance was coming from.  Thanks to the help of a couple of people in <a href="irc://irc.freenode.net/#pulseaudio">#pulseaudio on FreeNode IRC</a>, I was able to figure out how to do this, so here is the method I used for the benefit of anybody else in the same position.</p>
<h3>Stop PulseAudio spawning per-session</h3>
<p>By default PulseAudio puts a script in /etc/X11/Xsession.d which causes a &#8220;pulseaudio&#8221; instance to be spawned with every X session.  The first step is to move this script somewhere else so it&#8217;s never run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>Xsession.d<span style="color: #000000; font-weight: bold;">/</span>70pulseaudio <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>The second cause of &#8220;pulseaudio&#8221; being spawned is less obvious.  There is an <a href="http://en.wikipedia.org/wiki/Enlightened_Sound_Daemon">Esound</a> compatibility layer for PulseAudio so that applications depending on it still work, transparently.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>esd
lrwxrwxrwx <span style="color: #000000;">1</span> root root <span style="color: #000000;">9</span> <span style="color: #000000;">2009</span>-03-04 <span style="color: #000000;">11</span>:03 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>esd -<span style="color: #000000; font-weight: bold;">&gt;</span> esdcompat</pre></div></div>

<p>However, as of Ubuntu Intrepid (8.10) there is pretty much nothing which depends solely on Esound, but it still gets spawned when GNOME starts.  This causes a PulseAudio session to be spawned for the current user if one can&#8217;t be found.  The simple but ugly fix is to move this link to somewhere else:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>esd <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>esd.bak</pre></div></div>

<h3>Set up a system-wide PulseAudio instance</h3>
<p>To get PulseAudio to actually start on boot, you need to set a variable to tell the init script you want this to happen.  Make sure you have the following line in /etc/default/pulseaudio:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PULSEAUDIO_SYSTEM_START</span>=<span style="color: #000000;">1</span></pre></div></div>

<p>Any users that will be using the system-wide PulseAudio instance need to be members of the correct groups.  This will most likely be your own user, plus whatever user MPD is running as (&#8220;mpd&#8221; by default).  For each of these users, do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> pulse-access <span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> pulse <span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">-a</span> <span style="color: #660033;">-G</span> pulse-rt <span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<h3>Getting it up and running</h3>
<p>First thing&#8217;s first, you need to tell MPD to use PulseAudio.  This can be achieved by adding the following to /etc/mpd.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">audio_output {
       type    &quot;pulse&quot;
       name    &quot;My MPD PulseAudio Output&quot;
}</pre></div></div>

<p>If you&#8217;re feeling lazy, the easiest thing to do right now would be reboot.  Otherwise, you&#8217;ll need to kill all &#8220;pulseaudio&#8221; instances, restart the system-wide instance, and restart MPD.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mpd stop
 <span style="color: #000000; font-weight: bold;">*</span> Stopping Music Player Daemon mpd                   <span style="color: #7a0874; font-weight: bold;">&#91;</span> OK <span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-KILL</span> pulseaudio
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>pulseaudio restart
 <span style="color: #000000; font-weight: bold;">*</span> Stopping PulseAudio Daemon                         <span style="color: #7a0874; font-weight: bold;">&#91;</span> OK <span style="color: #7a0874; font-weight: bold;">&#93;</span>
 <span style="color: #000000; font-weight: bold;">*</span> Starting PulseAudio Daemon                         <span style="color: #7a0874; font-weight: bold;">&#91;</span> OK <span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mpd start
 <span style="color: #000000; font-weight: bold;">*</span> Starting Music Player Daemon mpd                   <span style="color: #7a0874; font-weight: bold;">&#91;</span> OK <span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Finally, log out and log back in again to allow your per-session pulseaudio instance to die and for your new group memberships to take effect.</p>
<h3>Caveats</h3>
<ul>
<li>You get &#8220;real-time&#8221; processing without any extra effort; by default the system-wide instance will run with priority -11.</li>
<li>Some apps are not PulseAudio-aware, but they can usually use an ALSA output; <a href="http://www.pulseaudio.org/wiki/PerfectSetup#ALSAApplications">this guide</a> shows you how to redirect ALSA through PulseAudio if you have any problems with the default setup.</li>
<li>Updates may undo the moving-a-file type of changes.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.alanbriolat.co.uk/2009/03/mpd-pulseaudio-ubuntu-intrepid-810/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

