PulseAudio

From ProAudioOverlay

Jump to: navigation, search

This Howto is a translation, a debugging and an adaptation for gentoo of some parts of the PulseAudio article on the French Linux MAO website. Changes and additional informations from several discussions on #pulseaudio on irc.freenode.org are incorporated.

Contents

Introduction

PulseAudio is a next generation networked sound server. It fits between the applications (or the multimedia framework) and the sound driver (ALSA, OSS, or other). It allows for an ease of use with "on the fly" connection capability.

As an example, you can send some sounds to the headset output and other sounds to the speaker output.

Here we will focus on PulseAudio capability to serve as a bridge between professional audio applications using JACK, and the audio applications using another sound server like ALSA.

PulseAudio uses a sink / source terminology. A sink is a PulseAudio output plugin module and a source is a PulseAudio input module. For example, we can daisy-chain the ALSA pulse plugin, module-jack-sink, module-jack-source and the ALSA pulse plugin. This setting will do the following:

ALSA application -> ALSA pulse plugin -> PulseAudio -> JACK -> PulseAudio -> ALSA pulse plugin -> ALSA application.

PulseAudio will take care of all the format and sampling rate conversion. It uses high quality conversion algorithms; the price to pay is a heavy processor load.

Requirements

PulseAudio is in Portage and emerge will install all the needed dependencies.

PulseAudio uses a lot of processor power, so I guess that a high-end box is needed in order to get a stable and low latency setup (if possible, see below).

Installation

Just follow the "PulseAudio" section of the Digital Audio Workstation article.

Configuration

We will setup a 2-channel bridge from ALSA output and JACK input.

Miscellaneous Setting

PulseAudio comes with 3 pulse related groups: pulse-access is for the case when the daemon runs system-wide, so we don't need to belong to this group; pulse-rt is for when PulseAudio is suid root and you want to use realtime-scheduling. We will remove this suid root permission later, therefore we don't need to belong to this group either.

The pulse group is the group of the user pulse, which runs the daemon in system-wide mode. We don't need to belong to that group either.

You must just to be sure that you are of the audio group and that this group has realtime privilege as explained in the Realtime (RT) Kernel page.

JACK

Nothing to do. It's cool! Just run it as usual.

In practice, the PulseAudio processor load will be huge, so try to increase JACK latency or to use the same sample rate than Jackd in your ALSA application (see the troubleshooting section below).

ALSA

You must have the following in your ~/.asoundrc :

pcm.!default {
   type pulse
}
## Not mandatory
ctl!default {
   type pulse
}

PulseAudio

Create the 2 following files:

  1. ~/.pulse/daemon.conf
    realtime-scheduling = yes

    PulseAudio uses a high quality resampling algorithm, therefore there is no need to specify a default sample rate in ~/.pulse/daemon.conf. However, it is possible to specify which algorithm to use. To get a list of those:

    $ pulseaudio --dump-resample-methods

    In order to get the highest quality, use one of the following: speex-float-10 or src‑sinc‑best‑quality, but be warned that these use an enormous amount of CPU. About that, add something like the following line to ~/.pulse/daemon.conf:

    resample-method = speex-float-10

    The default is speex-float-3.

  2. ~/.pulse/default.pa
    load-module module-jack-sink channels=2 channel_map=front-left,front-right
    #load-module module-jack-source channels=2 channel_map=front-left,front-right
    load-module module-native-protocol-unix
    ## The following is not mandatory
    load-module module-volume-restore
    load-module module-default-device-restore
    load-module module-rescue-streams
    .nofail
    .ifexists /usr/lib/pulse-0.9/modules/module-x11-publish.so
    load-module module-x11-publish
    .endif
    ## The following can conflict with this config.
    #.ifexists /usr/lib/pulse-0.9/modules/module-gconf.so
    #load-module module-gconf
    #.endif
    set-default-sink jack_out
    set-default-source jack_in
    

    In order to add a bridge between JACK output and ALSA input, comment out the module‑jack‑source line in ~/.pulse/default.pa.

Usage and test

Start QjackCtl as usual. Be sure that Jackd is running.

Start PulseAudio:

pulseaudio

You will get a stereo "PulseAudio JACK Sink" into the Readable Clients of QjackCtl's audio connection window (and a "PulseAudio Jack Source" if you commented out the related line in the config).

Let's test it:

aplay "some file.wav"

or launch AlsaPlayer

PulseAudio related programs

Other applications and PulseAudio

For now, just take a look at The Perfect Setup (This setting works very well for me)

Troubleshooting

In case of problem, please keep things simple and ensure that Padevchooser is not running. If it is, stop it, then stop and restart PulseAudio. In some cases, it may be necessary to stop JACK and restart Alsasound ('/etc/init.d/alsasound restart'). Be careful during testing, as it can "freeze" your whole system.

If the problem persists, increase JACK latency again as much as necessary.

I was able to get PulseAudio to be 100% stable only with a 42.7 msec JACK latency (1024 frames, 48 kHz, 2 periods). That on a P4 @ 2.4 gHz and an Audigy (16-channel JACK setup).

Some ALSA applications can use a defined sample rate instead of the default 44.1 kHz. For example:

alsaplayer -F 48000

This will use a lot less processor power as to let PulseAudio do the resampling, but the best way to go in case of stability problem is to increase JACK latency or to choose a less CPU-hungry resampling method in PulseAudio.

Links

Greetings

tanuk on #pulseaudio on irc.freenode.org

To Do

  • Add an example with multi-channel configuration.
  • Add an example with client-server configuration.
  • Add examples from different hardware with their performances.

Use the discussion page for any comments or suggestion.

Personal tools