Colin.Guthr.ie Illegitimi non carborundum

21Dec/104

Bobby Digital: In 5.1 Surround

OK, so this question crops up quite often, so I figured it's worth a post. People often ask how to enable 5.1 digital output with PulseAudio. In the past the answer is typically "you can't because S/PDIF only accepts stereo PCM or passthrough data" and while this is true, we can relatively easily hook up an AC3 encoder which is helpfully provided in the ALSA plugins package.

UPDATE: This guide now also mentions Alexander Patrakov's (G+) DTS encoder dcaenc as an alternative to the alsa-plugins AC3 encoder.

ALSA Plugins: a52

While the "a52" plugin is part of the official ALSA plugins source, some distros do not compile it by default. It's available in Mandriva and Mageia out of the box, but on Ubuntu for example you'll need to compile it yourself or find someone who provides a custom build for you (feel free to suggest a PPA in the comments below). Someone did tell me about pretty good instructions about building the plugin yourself.

So after building the plugin all you need to do is add a snippet of ALSA configuration to setup the a52 plugin with a named PCM that PulseAudio checks for and then everything should work automatically.

Here is the snippet. I'd recommend adding it to your ~/.asoundrc file (just create it if it doesn't exist; ~/ is just a shortcut to your home directory).

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
  }
}

(just as a note, the previously linked article has an error when is suggests using echo to add this to your ~/.asoundrc as it doesn't double escape the $CARD)

DCAENC

As an alternative to the above plugin, if your receiver supports DTS then you can also use Alexander Patrakov's DTS encoder dcaenc. This has the advantage of being stand alone and is very easy to compile and install. It also includes an appropriate alsa config snippet. I would recommend placing this snippet into /usr/share/alsa/alsa.conf.d/ which (at least on recent alsa-lib versions) is automatically scanned for configuration files.

Using it!

Once this is in place, then PulseAudio will automatically probe it and provide you the option of selecting a 5.1 Digitial Output profile. You can use pavucontrol's Configuration tab to pick your profile (or gnome-volume-control or the Speaker Setup tab in KDE).

One other thing you may have to do to get this working properly is change the default sample rate used by PA to be 48kHz. To do this, just edit daemon.conf in either /etc/pulse or ~/.pulse and include the line:

default-sample-rate = 48000

 

What about Proper Passthrough?

At present Passthrough support isn't available in the latest released version of PA (it is supported in git master - UPDATE it's been available for a while now in released PA since v1.0). Even when this is available it will be exclusive (as will any other codec support such as MP3 for Bluetooth and RAOP etc.) and as such mixing will not be available which leads to a whole set of UI and configuration problems, so in many ways using a software AC3/DTS encoding system like the A52 or DCE plugins here has many advantages over using passthrough. Obviously there is processing and mixing overhead but for many people (myself included) this is perfectly acceptable.

One odd thing about the setup is that some applications will consider this an "Analog[ue]" output (e.g. in XBMC I have to select Analog Output and choose 5.1 speakers to get everything working correctly, but at least it works 🙂

PS, yes the title is a Wu-Tang reference 🙂

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Identi.ca
  • Slashdot
  • Unknown

    Dosn’t work, no AC3 sound 🙁

    • Colin

      Well, it works and has been working for me for ages. Without any extra info, it’s really hard to say what you might be doing wrong.

  • InfoJester

    Oh thank God for this post! I finally understand and I’m able to get it to work. Thank you Colin!

    As I’ve seen this sort of information around the internet but hadn’t really understood what was going on ’til I’d got here, I’d like to add these which helped me as well.

    This is the only proper and full description of the theory behind this I have found
    http://msdn.microsoft.com/en-gb/library/windows/hardware/ff538534(v=vs.85).aspx

    And for Fedora users, you don’t have to build the plugin, just install package alsa-plugins-freeworld-a52.

  • Floop

    Working perfectly on Fedora 19 64bit, thank you Colin!