it took me some time to gather the information, work around a bug and assemble the steps to write them down. Maybe it helps someone out there with your ideas!
"This guide is made with love while listening to good music." ;-)
Stream any analog source to one or more targets.
In my case the idea was born to be able to stream the output of my phono preamp to a headphone amp that is not located near the turntable.
But one might use any analog source that puts out signals at line level.
Think about integrating vintage analog gear in a streaming environment or link them to active speakers if they are connected by a device that can deal with the software (Snapcast) used in this guide.
Also one might hook this setup to the pre-outs of a main Amplifier and use its output somewhere else in the house.
A HiFiBerryOS equipped Raspberry Pi is used as an endpoint (client).
I chose Snapcast because it seems quite lightweight to me and it is supported by HiFiBerry as well as Volumio (with plugin) as source.
Also i found it quite easy to set up and understand. It plays well with alsa and it proved reliable enough the times i used it so far.
There is a slight delay in playback due to precessing and buffering.
The Audio is recorded by a HiFiBerry DAC+ ADC Pro and is then streamed as 48kHz, 16Bit lossless FLAC to clients
- Raspberry Pi 4
- HiFiBerry DAC+ ADC Pro (the non pro will do as well but was not in stock when i ordered)
- 2nd Raspberry Pi as client (HiFiBerryOS or Volumio with snapcast Plugin was tested)
- analog source
- Raspian Buster 10 light
- Snapcast (in this case the snapserver part of it)
- arecord of alsa
- 1 second long 48kHz 16Bit WAV file (put this WAV file in your home directory an your Pi -> /home/pi/)
- Raspian: https://www.raspberrypi.org/downloads/raspbian/
- Snapcast: https://mjaggard.github.io/snapcast/
- Snapcast release page: https://github.com/badaix/snapcast/releases/
- alsa: https://www.alsa-project.org/
- nano: https://en.wikipedia.org/wiki/GNU_nano
- Note: i carried out all the following tasks using a ssh connection to my Pi using Terminal on MacOS. Edits in config files are done with nano editor. You might need to use sudo to edit some files. I might have forgotten occasionally to mention when to use sudo in this guide, sorry.
- Note 2: This is the first guide of this length i've written for such an installation and configuration. So please be kind if some parts seem confusing or plain do not work. ;-) The guide is not as detailed as i'd like it to be, but you get the outline on how to set it up. Some basic skills are required. Also i will assume that you are aware how to set up the clients (HiFiBerryOS or Volumio or whatever works as snapcast client.
Download Raspian Buster light from here:
Install to SD-Card using the method of your choice.
Boot and configure the system on the Pi using your knowledge or available guides. Make sure you enable ssh login.
When configured, login to your Pi via ssh.
It may be necessary to add/change the following line in /boot/config.txt:
This is to make sure that the correct type of HiFiBerry card is used. I might be the case that it is detected wrong - depending on the
Raspian used and possible bugs related with it. Better be safe than sorry. ;-)
Remove the following line in /boot/config.txt
Login to your Pi via ssh.
Install Snapcast using the following command. Be sure to check on the Snapcast release page which version is recent. Adjust the filename accordingly.
Install snapserver by:
sudo dpkg -i snapserver_0.x.x_armhf.deb
This will throw an error that some dependencies are missing. Acknowledge with "y".
Install dependencies by:
sudo apt-get -f install
The defaults in /etc/snapserver.conf should work out of the box.
But to be sure i made these changes by uncommenting the lines (remove the #):
threads = -1
stream = pipe:///tmp/snapfifo?name=default
sampleformat = 48000:16:2
codec = flac
At this point you might want to reboot and check if it will actually works.
Connect a line source to your DAC+ADC (Pro), connect your client by LAN or WiFi and issue the following command on your Pi:
arecord -f dat > /tmp/snapfifo
At this time there is a bug in the driver for the DAC+ADC (Pro), that requires to first play something before you can record something.
So, first play something:
aplay -d 1 test.wav
arecord -f dat > /tmp/snapfifo
If everything went right you should hear the source on your client.
As it would be tedious to always log in to your pi and issue the arecord command, let's start the snapserver streaming at boot time.
For this i used systemd.
Create the file arecord.service in /lib/systemd/system/
It should contain (as far as i think and tested):
ExecStart=/bin/bash -c "/usr/bin/aplay -d 1 /home/pi/test.wav; /usr/bin/arecord -Dhw:0,0 -f dat > /tmp/snapfifo 2>&1"
systemd waits for the snapserver.service to be ready and then starts the arecord.service.
Note the line #Restart=on-failure - i haven't tested it so far but this should restart the service, if it aborts for some reason. Until now it was stable enough so i left it deactivated.
Set the correct permissions to the file by issuing:
sudo chmod 644 /lib/systemd/system/arecord.service
Enable the service by:
sudo systemctl --system enable arecord.service
sudo systemctl --system start arecord.service
Reboot and check if everything is working as expected. If you want to check if the service is running:
systemctl --system status arecord.service
For peace of mind you might activate the Overlay FS after everything works. This will limit writes to your SD-Card.
Short version how to do it via raspi-config command:
7 Advanced Options > AB Overlay FS > "Yes" > does things > "OK" > "would you like the boot partition to be write protected?" > "Yes" > "OK" > "Finish" > "Would you like to reboot now?" > "Yes"