37

I would like to use my Raspberry Pi as an PulseAudio sink that can play audio via the network.

For starters I want to get Pulseaudio running locally and have run into various errors. I am using the recommended Debian image.

What is the best procedure for getting PulseAudio up and running?


This is what I have tried so far:

Procedure

My procedure so far looked something like the following:

Install Pulseaudio, and VLC:

sudo apt-get install pulseaudio

Configure GStreamer to use the pulseaudio sink:

gconftool-2 -t string --set /system/gstreamer/0.10/default/audiosink pulsesink

Load the kernel module for the audio device

sudo modprobe snd_bcm2835

Run VLC with an mp3

vlc 

Problems

VLC cracks repeatedly, printing this error:

[0x7503d0] alsa audio output error: cannot write: Broken pipe
1
  • Can you show the errors you are getting?
    – darryn.ten
    Commented Jun 26, 2012 at 8:36

3 Answers 3

13

If you want pulseaudio to start at boot, but as a user-level service, you can make a systemd unit file. This may help, as pulseaudio does not prefer to run in systems mode. https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/

Here is the service I wrote in /etc/systemd/system/pulseaudio.service

[Unit]
Description=PulseAudio Sound System
Before=sound.target

[Service]
User=pi
BusName=org.pulseaudio.Server
ExecStart=/usr/bin/pulseaudio
Restart=always  

[Install]
WantedBy=session.target

Before= tells it to wait until after sound.target initializes. BusName= connects it to D-Bus WantedBy=session.target is a helpful default, but I don't really know what it does.

1
  • 1
    Apparently we can put this in ~/.config/systemd/user/pulseaudio.service and use systemd with the --user flag to avoid root privileges.
    – jchook
    Commented Nov 22, 2019 at 2:05
12

I have got it working on my Raspberry Pi using the ALSA sink, with procedure as follows:

To install the necessary files:

sudo apt-get install pulseaudio pulseaudio-module-zeroconf alsa-utils avahi-daemon

To enable ALSA:

sudo modprobe snd-bcm2835                      # load module for single boot
echo "snd-bcm2835" | sudo tee -a /etc/modules  # load module for persistance

To set up networking:

sudo nano /etc/pulse/default.pa

and uncomment the lines:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/16
load-module module-zeroconf-publish

To start the pulseaudio server, use:

pulseaudio -D

You should be able to test that it works by playing a wav file with paplay (sudo apt-get install pulseaudio-utils), and also over the network by selecting the sink in your system's sound control panel.

You might be also be able to set up in system-wide mode with:

sudo pulseaudio --system 
1
  • pulseaudio-module-zeroconf is missing in the apt-get install part. Should mention maybe also the pulseaudio --log-level=debug to troubleshoot any problems. On the sound source (not the raspberry pi), you should launch paprefs to easily overview your pulseaudio conf (if you have X11). And don't forget to restart pulseaudio when in doubt.
    – vaab
    Commented Oct 2, 2012 at 18:15
7

I had a hard time getting pulseaudio running on Wheezy raspbian (2012-10-28) using the analog output. The following is what I did just to get it working in per-session mode (not system mode). System mode may work as well, I haven't attempted it. Setting up server will require some more work. I found this information in various places, hopefully gathering it here will help someone.

Install pulseaudio and make sure user (e.g. eric) is part of the audio group:

sudo apt-get install pulseaudio pulseaudio-utils
sudo adduser eric audio

Change /etc/asound.conf look like the following. This sets up pulseaudio to be used as an alsa device by default so applications use it without any additional configuration. The first two declarations (including the commented one) was in the original file.

pcm.mmap0 {
    type mmap_emul;
    slave {
      pcm "hw:0,0";
    }
}

#pcm.!default {
#  type plug;
#  slave {
#    pcm mmap0;
#  }
#}

pcm.pulse { type pulse }
ctl.pulse { type pulse }
pcm.!default { type pulse }
ctl.!default { type pulse }

Add the following lines to /etc/pulse/daemon.conf:

default-sample-rate = 48000
resample-method = trivial

trivial is the lowest quality method, but uses about 6% cpu. src-sinc-fastest also worked for me, but use about 25% CPU. Others may work as well. This later bit I don't quite understand the need for, but it seemed to be the magic ingredient. You can read more about it here.

Finally, to silence the audio pops between song plays, comment out this line in /etc/pulse/default.pa as follows:

#load-module module-suspend-on-idle

There is still some dropouts when two sources play at once, if I discover a remedy for that I'll add to this answer.

1
  • When playing audio over the network, PulseAudio was using about 16% CPU even with trivial for me. Commented Jul 26, 2013 at 7:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.