2024-03-05 05:23:25 -05:00
# PulseAudio
2022-03-20 05:12:16 -04:00
2024-03-05 05:23:25 -05:00
You have the choice of running PulseAudio either in system mode or user mode.
2022-03-20 05:12:16 -04:00
For headless servers, i.e. systems without desktop users, system mode is
recommended.
If there is a desktop user logged in most of the time, a setup with network
access via localhost only for daemons is a more appropriate solution, since the
normal user administration (with, e.g., `pulseaudio -k` ) works as advertised.
2024-03-05 05:23:25 -05:00
Also, the user specific configuration for PulseAudio is preserved across
2022-03-20 05:12:16 -04:00
sessions as expected.
- [System mode ](#system-mode-with-bluetooth-support )
- [User mode ](#user-mode-with-network-access )
## System Mode with Bluetooth support
Credit: [Rob Pope ](http://robpope.co.uk/blog/post/setting-up-forked-daapd-with-bluetooth )
This guide was written based on headless Debian Jessie platforms. Most of the
instructions will require that you are root.
2024-03-05 05:23:25 -05:00
### Step 1: Setting up PulseAudio
2022-03-20 05:12:16 -04:00
If you see a "Connection refused" error when starting the server, then you
2024-03-05 05:23:25 -05:00
will probably need to setup PulseAudio to run in system mode [1]. This means
that the PulseAudio daemon will be started during boot and be available to all
2022-03-20 05:12:16 -04:00
users.
2024-03-05 05:23:25 -05:00
How to start PulseAudio depends on your distribution, but in many cases you will
need to add a `pulseaudio.service` file to `/etc/systemd/system` with the
following content:
2022-03-20 05:12:16 -04:00
2024-04-27 15:53:01 -04:00
```conf
2024-03-05 05:23:25 -05:00
# systemd service file for PulseAudio running in system mode
2022-03-20 05:12:16 -04:00
[Unit]
2024-03-05 05:23:25 -05:00
Description=PulseAudio sound server
2022-03-20 05:12:16 -04:00
Before=sound.target
[Service]
ExecStart=/usr/bin/pulseaudio --system --disallow-exit
[Install]
WantedBy=multi-user.target
```
2024-03-05 05:23:25 -05:00
If you want Bluetooth support, you must also configure PulseAudio to load the
2022-03-20 05:12:16 -04:00
Bluetooth module. First install it (Debian:
`apt install pulseaudio-module-bluetooth` ) and then add the following to
/etc/pulse/system.pa:
2024-04-27 15:53:01 -04:00
```conf
2022-03-20 05:12:16 -04:00
#### Enable Bluetooth
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
```
2024-03-05 05:23:25 -05:00
Now you need to make sure that PulseAudio can communicate with the Bluetooth
2022-03-20 05:12:16 -04:00
daemon through D-Bus. On Raspbian this is already enabled, and you can skip this
step. Otherwise do one of the following:
1. Add the pulse user to the bluetooth group: `adduser pulse bluetooth`
2. Edit /etc/dbus-1/system.d/bluetooth.conf and change the policy for `<policy context="default"\>` to "allow"
2024-03-05 05:23:25 -05:00
Phew, almost done with PulseAudio! Now you should:
2022-03-20 05:12:16 -04:00
1. enable system mode on boot with `systemctl enable pulseaudio`
2. reboot (or at least restart dbus and pulseaudio)
3. check that the Bluetooth module is loaded with `pactl list modules short`
### Step 2: Setting up the server
Add the user the server is running as (typically "owntone") to the
"pulse-access" group:
2024-03-05 05:23:25 -05:00
```shell
2022-03-20 05:12:16 -04:00
adduser owntone pulse-access
```
Now (re)start the server.
### Step 3: Adding a Bluetooth device
To connect with the device, run `bluetoothctl` and then:
```
power on
agent on
scan on
**Note MAC address of BT Speaker**
pair [MAC address]
**Type Pin if prompted**
trust [MAC address]
connect [MAC address]
```
2024-03-05 05:23:25 -05:00
Now the speaker should appear. You can also verify that PulseAudio has detected
2022-03-20 05:12:16 -04:00
the speaker with `pactl list sinks short` .
## User Mode with Network Access
Credit: wolfmanx and [this blog ](http://billauer.co.il/blog/2014/01/pa-multiple-users/ )
### Step 1: Copy system pulseaudio configuration to the users home directory
2024-03-05 05:23:25 -05:00
```shell
2022-03-20 05:12:16 -04:00
mkdir -p ~/.pulse
cp /etc/pulse/default.pa ~/.pulse/
```
### Step 2: Enable TCP access from localhost only
Edit the file `~/.pulse/default.pa` , adding the following line at the end:
2024-03-05 05:23:25 -05:00
```shell
2022-03-20 05:12:16 -04:00
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
```
2024-04-27 15:53:01 -04:00
### Step 3: Restart the PulseAudio daemon
2022-03-20 05:12:16 -04:00
2024-03-05 05:23:25 -05:00
```shell
2022-03-20 05:12:16 -04:00
pulseaudio -k
# OR
pulseaudio -D
```
2024-04-27 15:53:01 -04:00
### Step 4: Adjust the Configuration File
2022-03-20 05:12:16 -04:00
In the `audio` section of `/etc/owntone.conf` , set `server` to `localhost` :
2024-04-27 15:53:01 -04:00
```conf
2022-03-20 05:12:16 -04:00
server = "localhost"
```
---
2024-03-05 05:23:25 -05:00
[1] Note that PulseAudio will warn against system mode. However, in this use
case it is actually the solution recommended by the [PulseAudio folks themselves ](https://lists.freedesktop.org/archives/pulseaudio-discuss/2016-August/026823.html ).