PulseAudio for analog/spdif hell – so simple, yet you have to know…

When it comes to a flexible audio setup Alsa starts to suck … hard. If you want output mainly on S/PDIF (be it optical or coax), automatically upmixed to 5.1, then encoded to A52 so your receiver will eat it, but sometimes your general AC3-passthrough 5.1 movie, sometimes maybe even output to your regular analog output … then its quickly becoming clear that ALSA is basically a driver framework, and not a end-user audio application. I found that most audio middlewares i’ve known sucked quite hard: Jack is too unuseable, arts or phonon never did their job, esound is kind of … dead. So what’s left? PulseAudio is left! Its setup seems very quirky to firsttime users and if you come with some strange distro-configuration (*cough*ubuntu*cough*) you may want to throw it against your wall … but actually its super flexible and nice.

If you have a similar setup to mine – read on!

For your most basic setup – a 5.1 upmix, a52encode(!!) and spdif output pulse alone cannot get you to your goal. You need some small piece of alsa configuration so pulseaudio can properly autodetect your spdif output as well as leverage alsas encoder to do the actual work. On any debian-like system (and probably others too) you can just install a *RECENT* pulseaudio (>= 0.9.23) along with pavucontrol and put this piece of config into your

/etc/asound.conf

file, then invoke

/etc/init.d/alsa-utils restart:
==== SNIP ====
pcm.a52 {
  @args [CARD]
  @args.CARD {
    type string
  }
  type rate
  slave {
    pcm {
      type a52
      bitrate 448
      channels 6
      card $CARD
    }
    rate 48000 #required somehow, otherwise nothing happens in PulseAudio
  }
}
pcm.!default {
    type pulse
    # If defaults.namehint.showall is set to off in alsa.conf, then this is
    # necessary to make this pcm show up in the list returned by
    # snd_device_name_hint or aplay -L
    hint.description "Default Audio Device"
}
ctl.!default {
    type pulse
}                                                                                            
==== snap ====

This does the following: It provides a configurable a52 encoder for a variable card to pulseaudio. It also sets the alsa-pcm-default to pulseaudio (which will make all your “legacy” alsa applications use pulse by default) as well as the control default to pulse.

Please note that with this and pulse’ default setup the first application that’ll do audio after boot will start your pulseaudio-server – and the owner of that application will own the pulseaudio server. For example if you use “mpd” or some other daemon audio player which runs as a different user than you he will own the server – which can get inconvenient.

 

The next step is configure pulseaudio itself. In

/etc/pulse/daemon.conf

i had to add

default-sample-rate = 48000
default-sample-channels = 6

to set the default values. After that alls thats left is deciding whether you want autospawning – which you do in

/etc/pulse/client.conf

then start a pulseaudio server, watch the debug output and connect with pavucontrol. Pavucontrol lets you reroute stream to output devices (so you can switch your mplayer live from spdif to analog out to some network device and vice versa) as well as set per-application volumes or set your default output.

All thats left is – if you want networking – on the server to (either in default.pa or dynamicall) load the networking module using:

pacmd 'load-module module-native-protocol-tcp auth-ip-acl=192.168.0.42'

where 192.168.0.42 may be your trusted other party or a whole trusted network in the “<ip>/<decimal netmask>” notation., then on the client you can either use a whole remote server via

"export PULSE_SERVER=YOUR-SERVER-IP"

then start any pulse-aware audio application and it will connect to the remote server, or – more elegant in my view – you can add your remote server as a (tunneled) sink:

pacmd 'load-module module-tunnel-sink server=YOUR-SERVER-IP'

then you’ll have your network output device listed as any other output device in pavucontrol and you can reroute streams (live! although with a short initial lag/stutter period)

This is what my pulseaudio setup looks like – and i’m *really* happy with it. Everything works as expected, including mplayer on 5.1 movies working out of the box! If you have any questions, feel free to ask!

 

NEW INFORMATION! IF PAVUCONTROL DOESN’T SHOW DIGITAL SURROUND AS CONFIGURATION!

I’ve recently had the problem that my Debian Testing box wouldn’t show “Digital Surround (+X)” in PaVuControl, hence i could only output stereo over my S/Pdif line. This obviously sucks, so i’ve started digging. The item shown here would be missing:

The selected item was missing for me!

So, what could cause this? I have (had) Debian-Multimedia in my sources.list, and some libav* packages were installed from there. Turns out libasound2-plugins which provides the a52 stuff requires some libav’s for the actual processing, and the DMO versions are incompatible! So the obvious solution is to downgrade them:

libavformat53 [7:0.10.3-dmo1 (now) -> 6:0.8.6-1 (testing, unstable)]
libpostproc52 [8:1.0.6-dmo2 (now) -> 6:0.8.6-1 (testing, unstable)]
libswscale2 [8:1.0.6-dmo2 (now) -> 6:0.8.6-1 (testing, unstable)]

After these downgrades (or from whereever you are…), and a restart of pulseaudio, the surround configuration appeared again, as you can see in the above screenshot!

2 thoughts on “PulseAudio for analog/spdif hell – so simple, yet you have to know…”

  1. Holy cow! I\’m trying to get this network-thing working since an hour or so and never could get my client to show the server-sink. Then i stumbled upon your one year old post… »pacmd \’load-module module-tunnel-sink server=YOUR-SERVER-IP\’« is all I was looking for! Thanks a lot, made my day.

    Reply

Leave a Comment