Music server based on orange pi zero v.1.5 board, sabre es9023 I2S dac on hw side, and pulse server and mopidy running in docker on sw side.
Kidding, but for comparison i really did started with that and configured everything i would like to have from this project on '5$' raspberry zero. So here it is
What is missing on that images is external usb ethernet card and amp that was used in previous project. In fact i will reuse amp setup in every following configuration since amp part is equally compatible with onion, raspberrypi or orangepi configuration. Green relay module will be described later, but is essentially same relay module that i've used in prev project. But back to topic.
Connection goes this way
And this ends HW part. Than SW part
1) Install pulse server
sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install -y pulseaudio
we need to configure system service, that is when pulseaudio is run with --system switch. Then it will load config from system.pa. Therefore we will edit this one
sudo nano /etc/pulse/system.pa
change this line to allow local usage for every user
load-module module-native-protocol-unix auth-anonymous=1
and enable network server
## enable network server load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.1.0/24 auth-anonymous=1
then we will create system service
sudo nano /etc/systemd/system/pulseaudio.service
and add this content
[Unit] Description=PulseAudio system server [Service] Type=notify ExecStart=/usr/bin/pulseaudio -v --daemonize=no --system --realtime --log-target=journal [Install] WantedBy=multi-user.target
enable and start
sudo systemctl daemon-reload && sudo systemctl start pulseaudio.service && sudo systemctl enable pulseaudio.service
at this point you should see pulse running in processes
and from external device (laptop in my case) you should add this server as target
add this line (change ip appropriately)
load-module module-tunnel-sink-new server=192.168.1.85 sink_name=rpi
then run kill command to sertart pulse.
new sink will appear
at this point pulse part is done
2) Sound card and I2S configuration
we will need to enable I2S and configure card but lucky enough our card is compatible with hifiberry-dac hat, so we only need to enable appropriate DT layer.
sudo nano /boot/config.txt
Edit those lines (last one is commented - not necessary but i prefer to have only one card for simplicity)
dtparam=i2s=on dtoverlay=hifiberry-dac #dtparam=audio=on
then you need to reboor your pi and find new sound card available
aplay -l card 1: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 Subdevices: 1/1 Subdevice #0: subdevice #0
to test sound i use this command
speaker-test -t sine -f 2500 -c 2
you should see beeping sound in both channels
3) last step is to configure relay module. and i will describe it in next instruction since it is exactly the same as for OrangePI. And this project is actualy for latter one, so let's leave something for it.
Next step is actually start adopting this basic setup to OrangePI Zero.
I started working with OrangePI Zero for the sake of price and simplicity. And immediately were struck by the fact that vendor forgot to solder I2S on the board header. In early versions this was solvable by soldering couple of resistors on the board (more details here) but in my revision this possibility was removed. Technicaly speaking the probem is that PA20/PCM0_DOUT pin is used by vendor to enable and disable WIFI module and not available for my use anymore.
This is from early version schematics, but since newer is not published i will work with this one
So what i will do - i will solder out wifi power switch completely (and lose it forever, since i don't need it, but there is also an option also to enable it permanently) and add wire to unit's solder pad.
We are looking for tsot-5 element
And we will find it near wifi chip
(sorry, forgot to make 'before' photo, so this is soldered out state). Pad #3 is where we should solder PA20 header and pad #5 we should solder to +5V to enable wifi permanenty. In my case i skip last part.
Then other connections will look like this:
So far that's it, relay module will be covered later.
Next step is configure Sound Card in Armbian.
Since Armbian 5.30 it switched to device tree to setup device perepherials. Along with this change somehow a lot of features lost their support, therefore it is not as straightforward to enable I2S.
I prepeared github repo to do it quickly
So first get it from github
git clone https://github.com/anabolyc/pcm5102a-for-armbian-orangepi-zero cd pcm5102a-for-armbian-orangepi-zero
We need to add user overlays to enable I2S (disabled by default) and enable sound card on that port
sudo armbian-add-overlay i2s-sound.dts
this will compile overlay script, put compiled file under /boot/overlay-user and add to /boot/armbianEnv.txt line
You need to reboot to changes to take effect, but this will not work just yet. Problem is we are referencing to pcm5102a kernel module there, and this one is not included to armbian for some reason. Therefore we will build it on the same board using current kernel sources. So please check if you have build symlink
ls -al /lib/modules/$(uname -r)/build lrwxrwxrwx 1 root root 36 Nov 17 13:42 /lib/modules/4.14.78-sunxi/build -> /usr/src/linux-headers-4.14.81-sunxi
Iif it is missing - just create it manually be running
sudo ln -s /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build
Now you ready to build. First command produce pcm5102a.ko file among others. Second will copy it to appropriate kernel modules folder.
make all sudo make install
Now we ready to reboot and check if we have sound card listed
$ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: I2Smaster [I2S-master], device 0: 1c22000.i2s-pcm5102a-hifi pcm5102a-hifi-0  Subdevices: 1/1 Subdevice #0: subdevice #0
Check if new module correctly loaded
lsmod | grep snd_soc_pcm5102a snd_soc_pcm5102a 16384 1 snd_soc_core 118784 5 sun4i_i2s,sun8i_codec_analog,snd_soc_simple_card_utils,snd_soc_pcm5102a,snd_soc_simple_card
Note: this will work even if card is not connected, board will output to appropriate pins and it doesn't really care if someone listens or not. So now lets check if audio will produce
speaker-test -t sine -f 2500 -c 2
And finally i can hear beeping sound in both speakers. Hooray!