It has been quite a while when did my 'audiophile' music player built.
raspberry-pi-with-balanced-output
It has been almost a decade now and there is a zillion of dedicated distro's around to make this really easy.
Just google: RPI musicplayer.
All really nice and slick..but..taking..ages..to..boot, certainly on older PI's
So while reviving this old project to include a transformer balanced output, (driven with a class A running NE5532! ) I worked myself through the big pile of clogged info to get a faster booting system.
Now the easiest way would be to get yourself a custom build image using a build system like buildroot, yocto, openwrt.
I did have a go at all of them but the easiest way to get yourself (like me total noob) going would be to start off with buildroot.
Just follow the walk through (maybe add in a SSH client like dropbear) and you will quickly get your own fast booting image. That is: it isn't complicated but the compilation takes hours!
The bit more nasty part comes when you want to take it further: not many people talking about this, so for future reference here's some reminders.(as long as this will be of any value in the allways changing wonderful world of linux 😂)
RPI has it's own rather special way of booting at which time you can configure all kinds of hardware add-ons by using so called dtoverlays.
If you have been working with RPI and audio you will have come across these: to configure edit the config.txt file in the 'boot' partition of your disk image. (sometimes it will have just a number instead of the name 'boot')
For a first test add 'dtparams=audio=on' to this file. This will select the onboard shitty audio out. In theory. But the inner workings of linux in these buildroot-builts don't seem to be loading the necessary kernel modules. Something with udev and dts / dto. Complicated stuff. Tell us when you know how to do this!
I got it working with 'modprobe snd-bcm2835'.
We did select the packages to get alsa and other obvious stuff like mpd, mpc and a texteditor in our simple build, right?
Now to play some music (from that USB stick) you will have to mount it first: 'blkid' will give you a device name or UUID, create a mount point and mount. Configure '/etc/mpd.conf' to point to that music directory and also add a default alsa-audio-out setting while you're there.
Restart MPD: first kill it by PID number found by 'ps' then start by mpd (no sysctl or systemd in default busybox) . Now mpc will have hopefully controle and some information on mpd.
Now on to even more remarkable easy to forget nooks and crannies:
We do want that i2s-dac thing running. In the picture is a simple (i2s-slave) interface that doesn't need any configuration (by i2c). I think most of these simple boards will work, this one is an old hifiberry-dac with a pcm5102a. That is a significant hint to get it going:
First comment out the 'dtparams=audio=on' and add in 'dtoverlay=hifiberry-dac' in the aforementioned config.txt file.
But you will not have any overlays in that 'boot' directory. So download it from some github or strip it from some other distro. Probably kernel versions and .dtbo file will have some relation...
Now for the similar modprobing:
You need the 4 of them to get it going:
snd-soc-bcm2835-i2s, snd-soc-core, snd-soc-pcm5102a, snd-soc-rpi-simple-soundcard.
Finally! Audio from your i2s board!
Now to make it persistent after reboot, you have to make a little script in the '/etc/init.d' . Give it number some lower as the mpd-start-stop script, which in my case was S95. (that's capital S!)
Don't forget to mount your USB-music-drive before starting mpd. I edited the mpd start script to mount the drive: the usual fstab methode doesn't work to well. Presumably the default mpd start script will be started before the USB drive is ready for mount.
Other nice stuff to implement:
We can us sysfs-kernel modules to manipulate GPIO ports. Make sure the pins are not in use for other functions (like i2s..duh). Here is a small script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | #!/bin/sh
#gpio17 to drive a led:
echo 17 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio17/direction
#gpio27 to have a push button to do "mpc next":
echo 27 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio27/direction
while true
do
if mpc status | grep -q 'playing'; then
echo 1 > /sys/class/gpio/gpio17/value
else
echo 0 > /sys/class/gpio/gpio17/value
fi
if cat /sys/class/gpio/gpio27/value | grep -q '1'; then
mpc next
fi
sleep 0.5
done
|
Oh, and one more thing:
Before starting to use something like 'buildroot' think of a way to separate everything from your everyday-work-computer. It will give a big mess if you don't. I used VMware. Do configure for plenty of drive space!