PulseAudio

From ProAudioOverlay

Revision as of 10:58, 1 March 2008 by Dominique (Talk | contribs)
Jump to: navigation, search

This Howto is a translation, a debugging and an adaptation for gento of some parts of the PulseAudio article on the 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 is running between the applications (or the multimedia frameworks) and the sound driver (ALSA, OSS, or other). He allows an easiness of use with "on the fly" connection capability.

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

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

PulseAudio use a sink / source terminology. A sink is a PulseAudio output plugin module and a source is a PulseAudio input module. As example, we can make a chain with 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 use high quality conversion algorithms, the price to pay is a somewhat huge processor load.

Requirements

PulseAdio is in portage and emerge will install all the needed dependencies as needed.

PulseAudio use 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 DAW Digital Audio Workstation: PulseAudio.

Configuration

We will setup a 2 channels bridge from alsa output and jack input.

Miscellaneous Setting

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

The pulse group is the group of the user pulse, which run 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 into the audio group and that this group have realtime privilege as explained into Realtime (RT) Kernel

JACK

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

In practice, PulseAudio processor load will be huge, so try to increase jack latency or to use the same sample rate that jackd with your ALSA application (see below the troubleshooting section).

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:

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

PulseAudio use a high quality resampling algorithm, so it 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 algorithm:

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 those eat enormous amount of cpu. For that, add something like the following line into ~/.pulse/daemon.conf:

resample-method = speex-float-10

The default is speex-float-3.

# ~/.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

alsaplayer

PulseAudio related programs

If you want to use padevchooser, avahi must be started. As root, run:

/etc/init.d/avahi-daemon start

If you want to start it at boot time:

rc-update add avahi-daemon default

Now, you can start padevchooser (as user):

padevchooser

This will add a systray icon from which you can control PulseAudio, see informations about the running process, and launch the other PulseAudio programs.

Be aware that padevchooser use its own configuration files. That implies that changes made in the configuration can conflict with the settings in ~/.pulse/*. If you get some stability problems, the first thing to do is to stop or kill the audio applications, quit padevchooser, quit pulseaudio, stop and restart jackd, start pulseaudio and start the audio applications (but don't start padevchooser).

Other applications and PulseAudio

For now, just take a look at Perfect Setup.

Troubleshooting

This setting work very well for me.

In case of problem, please keep things simple and be sure that padevchooser is not running. If it is the case, stop it, stop and restart pulse audio. In some cases, it can be necessary to stop jack and restart alsasound ('/etc/init.d/alsasound restart'). Be careful during testing, the whole system can freeze.

If the problem remain, increase jack latency again and again until it disappear.

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 channels setup in jack).

Some ALSA applications can use a defined sample rate instead of the default 44.1 kHz. 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