The purpose of this document if to provide a simple method of getting pulseaudio to work on Raspberry Pi with either Speaker pHAT or pHAT DAC.
Please see Software installer for Speaker pHAT or Setting up pHAT DAC for the more official guide / installer. The idea behind this guide is to provide you with a more manual alternative that lets you have a minimal setup.
- Enable I2C, I2S and HiFiBerry DAC by appending these lines to
/boot/config.txt
:
dtoverlay=i2s-mmap
dtoverlay=hifiberry-dac
dtparam=i2c_arm=on
- Install ALSA and pulseaudio packages:
sudo apt-get install alsa-utils pulseaudio
-
Reboot the device.
-
Create
/etc/systemd/system/pulseaudio.service
with the following contents:
[Unit]
Description=PulseAudio Daemon
After=sound.target
Requires=sound.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio --realtime --disallow-exit --no-cpu-limit --daemonize=no --system --log-target=journal
- Enable and start the newly-created service:
sudo systemctl --system enable pulseaudio.service
sudo systemctl --system start pulseaudio.service
- Add the current user to the
pulse-access
group:
sudo adduser $USER pulse-access
- Test and ensure everything works at this stage:
speaker-test
- (Optional) Increase the realtime priority which usually helps with stuttering. Append this line to
/etc/pulse/daemon.conf
:
realtime-priority = 9
- (Optional) Increase time before the sink is suspended by pulseaudio by editing
/etc/pulse/system.pa
and replacing
load-module module-suspend-on-idle
with
load-module module-suspend-on-idle timeout=604800
Once sound works on your Pi, you can play files remotely from your PC thanks to pulseaudio.
Do these steps on your server (Raspberry Pi).
- Install the zeroconf module and avahi:
sudo apt-get install pulseaudio-module-zeroconf avahi-daemon
- Update
/etc/systemd/system/pulseaudio.service
to require and wait for avahi:
[Unit]
Description=PulseAudio Daemon
After=sound.target network.target avahi-daemon.service
Requires=sound.target
Wants=avahi-daemon.service
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio --realtime --disallow-exit --no-cpu-limit --daemonize=no --system --log-target=journal
-
Reboot the device.
-
Append these lines to
/etc/pulse/system.pa
to enable zeroconf for your server:
load-module module-native-protocol-tcp auth-ip-acl=192.168.0.0/24 auth-anonymous=1
load-module module-zeroconf-publish
Note: This gives access to anyone in the IP range 192.168.0.1 - 192.168.0.254 to broadcast sound to your Pi. If you'd like to limit to a single IP, for example 10.0.0.1, replace module-native-protocol-tcp auth-ip-acl=192.168.0.0/24
with module-native-protocol-tcp auth-ip-acl=10.0.0.1
.
- Restart pulse:
sudo systemctl --system restart pulseaudio.service
Do these steps on the machine where you'd like to play sound from.
- Install the zeroconf module and avahi:
sudo apt-get install pulseaudio-module-zeroconf avahi-daemon
- Append this line to
/etc/pulse/default.pa
to enable zeroconf discovery:
load-module module-zeroconf-discover
-
Reboot the machine.
-
Check to make sure the new sink is detected:
pacmd list-sinks | grep -B 1 'name: <tunnel'
# Example output:
#
# index: 8
# name: <tunnel.raspberry.local.alsa_output.platform-soc_sound.analog-stereo>
- Set the default sink to the one printed previously:
pacmd set-default-sink 8