This is it. The big one. Last time I just set up my Raspberry to log in with a key pair, but this time I will actually begin streaming audio.
First, since I forgot to do it last time, I will just quickly change the hostname of the Raspberry by changing
Now I can log in again with
ssh pi@soundpi. The reason I did this was that I will eventually have more Raspberries on the network, and they can’t all be called
Now, let’s begin for real. I install PulseAudio on the Raspberry:
pi@soundpi:~ $ sudo apt-get install pulseaudio
Since I want PulseAudio to run any time the Raspberry is turned on, without having to log in, I add it as a service by creating a file
/etc/systemd/system/pulseaudio.service with the following contents:
[Unit] Description=PulseAudio Daemon [Install] WantedBy=multi-user.target [Service] Type=simple PrivateTmp=true ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit
(Thanks to this post for the file) Then I run:
pi@soundpi:~ $ sudo systemctl enable pulseaudio Created symlink /etc/systemd/system/multi-user.target.wants/pulseaudio.service → /etc/systemd/system/pulseaudio.service. pi@soundpi:~ $ sudo systemctl start pulseaudio
I am going to use the Raspberry as a PulseAudio server. To allow connections I add the following lines to the end of
/etc/pulse/system.pa (because PulseAudio is running in system mode) on the Raspberry:
### Configure streaming load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24 auth-anonymous=1
This allows anyone on my LAN to connect to the PulseAudio server on the Raspberry, without authentication. I do not judge this to be a risk.
Then I find
; default-server = in
/etc/pulse/client.conf on the computer I want to stream from, and change it to
default-server = soundpi.
At this point I realize that I never actually configured Raspbian to use the DAC. I do that quickly by adding the following to
/etc/pulse/system.pa on the Raspberry:
### Use DAC set-default-sink 1 set-sink-volume 1 32768
And now it works! In addition to setting the DAC to be the default output, I also set the default volume to 50% instead of 100%. If I adjust the volume knob on the amplifier to make that a comfortable volume, I can then increase or decrease the volume using the volume control buttons on my keyboard (instead of only decreasing).
The DAC I bought has its own hardware volume control. I haven’t found out how to use that yet, but that would allow better sound since setting the volume to 50% in software reduces the bit depth. The difference is probably slight, but it might be interesting to do in the future.
The next step, though, is to harden the Raspberry against power loss by making the SD card read-only.