PulseAudio

From OLPC
Revision as of 06:29, 7 July 2007 by Erikos (talk | contribs) (Configuration: typo bin->sbin)
Jump to: navigation, search

Pulseaudio on the XO

- XO version: B1
- Build: 406
- pulseaudio version: 0.9.6
- more info: pulseaudio

Install

Basic

These are the basic packages you need to install to run pulseaudio on the XO. The zeroconf module is needed if you want to enable networking of the sound server. zeroconf is used to announce the sound servers on the network.

 pulseaudio pulseaudio-lib-zeroconf pulseaudio-module-zeroconf
 deps: pulseaudio-lib libsamplerate

Extra packages

The utile package contains tools like a soundfile player which is a native pulseaudio client.

 pulseaudio-utils

To configure pulseaudio you may want to install these X tools. You will need them to setup the networking part.

 padevchooser pavucontrol pavumeter panam


Configuration

You can configure pulseaudio using the files /etc/pulse/daemon.conf and /etc/pulse/default.pa and run pulseaudio without any arguments.

To run pulseaudio with a higher priority you have to add yourself to the group pulse-rt (you may have to log out before these changes take effect).

/usr/sbin/usermod -a -G pulse-rt olpc

You can start pulseaudio with the high priority option to prevent clicks when doing UI stuff

pulseaudio --high-priority=1

You will see the following output when pulseaudio succesfully gained the priority.

      I: core-util.c: Successfully gained nice level -15.                                                   
      I: core-util.c: Successfully enabled SCHED_FIFO scheduling.

Tests

Start pulseaudio

pulseaudio -v
pulseaudio --high-priority=1 -v

Native pulseaudio client

In the first test we use a native pulseaudio client to play a sound (paplay is included in pulseaudio-utils)

paplay soundfile.wav

Some numbers:

- top shows a cpu usage of pa of ~2.6 and a memory usage of ~1.2 when not in use
- when playing a soundfile with paplay cpu usage is 7-10 and memory usage 1.7

Gstreamer Applications

Applications using the GStreamer media framework can make use of the PulseAudio through gst-pulse, our PulseAudio plugin for GStreamer. We used the python gstreamer bindings to play a soundfile on the pulseaudio server.

ALSA Applications

To setup pulseaudio to work for alsa applications you have to put these lines into /etc/asound.conf.

   # This following device can fool some applications into using pulseaudio                                 
   pcm.dsp2 {                                                                                               
   type plug                                                                                                
   slave.pcm "pulse"                                                                                        
   }                                                                                                        
                                                                                                            
   pcm.pulse {                                                                                              
   type pulse                                                                                               
   }                                                                                                        
                                                                                                            
   ctl.pulse {                                                                                              
   type pulse                                                                                               
   }                                                                                                        
                                                                                                            
   pcm.!default {                                                                                           
   type pulse                                                                                               
   }                                                                                                        
                                                                                                            
   ctl.!default {                                                                                           
   type pulse                                                                                               
   }                                                                                                        
   

and you need to install the alsa-plugins. I could not find an rpm for Fedora that is why I build and installed the plugins by hand. You can find the sources here: alsa-plugins To test the result I used aplay.

aplay -Dpulse soundfile.wav

Csound

You can run csound as a pulseaudio client as well. To make this work on the XO you have to use big enough buffer sizes (-b -B options).

csound -+rtaudio=alsa -odac:plug:pulse -m0 -d -b1024 -B4096 bilbar.csd

Memosono

Another test was to run memosono (which uses csound to play soundfiles) as a pulseaudio client. The csound instance of memosono runs at 22050Hz. When running the pulseaudio server at 44100Hz I got clicks, that is why I run the server at 22050Hz as well. I guess resampling is the bottle neck here. You can do this by adding these two lines into your default.pa and uncommenting the HAL detection.

add-autoload-sink output module-alsa-sink device=plughw:0,0 rate=22050 sink_name=output
set-default-sink output

Running pulseaudio without the high-priority option resulted in clicks when moving the mouse over the window while sound was playing. With the option enabled I could switch back and forth between views without interruption.

Networking

I was able to send audio data to the XO and from the XO to another machine running the pulseaudio server. To stream audio data from one machine running pulseaudio to another machine you need to setup a few things. To be anounced of available pulseaudio servers on the network you need to install the pulseaudio-module-zeroconf and enable it in your pulseaudio configuration. Add the following line to /etc/pulse/default.pa to do so

load-module module-zeroconf-publish

You can run padevchooser to control the pulseaudio server. This tool will prompt you when a new server on the network has been discovered. You can set the Default Sink and the Default Source here. The discovered pulseaudio servers will be listed in the list of available Sinks and Sources.

Once you selected your Sink you can try to play a sound. It is likely that you will be prompted for an "access denied error". With aplay you get the following error.

*** PULSEAUDIO: Unable to connect: Access denied                                                             
aplay: main:545: audio open error: Connection refused                                                        

This happens because pulseaudio requires authentication before accepting connections to prevent random people from playing audio on your computer. Pulseaudio places a cookie in the home directories of the user running the server. Copy the cookie of the machine you want to send the audio data to, to the home directory of the sender machine. (Alternatively, you may add auth-anonymous=1 to the end of the load-module module-native-protocol-tcp line to disable authentication). You are ready to play networked audio using pulseaudio.