Being kind of a newbie regarding linux, it was quite hard for me to pull this of. However, with a little help from my friend, who gave me the right tools to work with, I finally got this mojo working! This is the story of how I managed to get Spotify to play on my Amiga 🙂
I got the idea after I played an mp3 via my A314 - a trapdoor expansion with a Raspberry Pi as co-processor. The PiAudio-service is piping the audio via an Advanced Linux Sound Architecture (ALSA) plug called amiga. This plug pipes the raw audio via the memory that the Raspberry Pi and the Amiga shares. On the Amiga side the piped audio goes to the sound chip Paula, that takes care of the playback. Note that the Raspberry Pi takes care of the decoding.
The example for PiAudio at A314@GitHub uses mpg123 to play song.mp3:
mpg123 -a amiga song.mp3
-a amiga sends the sound stream to the device of your choice, in this case the A314's ALSA plug amiga.
However, the mpg123 is not very convenient when it comes to playing mp3's. This made me think of Spotify and the nice Spotify Connect solution.
- Now that would be convenient, maybe you could pipe that to the ALSA plug!
I mentioned this to my friend David - a couple of minutes later he sent me a link to raspotify, and that lit my fire!
For some reason I did not manage to pipe the audio from librespot (that raspotify uses) to my ALSA plug. After many hours of googling, all I had learnt was to understand how the ALSA plug worked, and managed to rewrite the original to a more readable form. Not too bad, but very frustrating!
After some more discussion with my friend David, he gave me this great tool - SoX, Sound eXchange - that finally got me in the right direction. After a couple of hours, I nailed it! Below follows the instructions on how to setup your Raspberry Pi and Amiga to be able to play Spotify through your Paula chip.
Setting up Raspotify - a Spotify Connect client for Raspberry Pi.
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
Move raspotify.service to a <folder-path> of your choice for storage. You will need to temporarily put it back for updates, or if you want to remove the installation:
sudo mv /lib/systemd/system/raspotify.service <folder-path>
Install SoX, and needed libraries:
sudo apt install sox libsox-fmt-all
sudo apt install libasound2-plugins libasound2-dev
To launch Raspotify from your Amiga, you will have to make an executable bash script. This script will launch the Spotify Connect device called "A314spot" and pipe the audio to SoX. SoX will receive the raw data and put it through another pipe to our ALSA plug called amiga. The ALSA plug will then finally pipe it to your Amiga.
To do this, first log in as super user (su):
Create a bash script called Spotify. Copy and paste all text below, and hit <enter>:
echo '#\!/bin/sh' > /usr/local/bin/Spotify
echo 'librespot --name A314spot --device-type computer \
--initial-volume 100 --backend pipe | \
sox -t raw -b 16 -e signed -c 2 -r 44.1k - \
-b 16 -e signed -c 2 -r 44.1k -t alsa amiga' >> /usr/local/bin/Spotify
Make file executable for all users:
chmod a+x /usr/local/bin/Spotify
Press <ctrl+d> to exit su promt.
Edit Shell-startup on your Amiga.
Add the following line to SYS:S/Shell-Startup:
Alias spotify pi bash Spotify
Time to play.
I presume that you already have followed my tutorial that sets up the Amiga side with PiAudio, otherwise take a look at the Edit SYS:S/Shell-Startup-part.
Now you should be ready to rock the world!
Start your AmigaShell and enter:
Be sure that your "smart device" has WiFi turned on and then start the Spotify app,
go to settings and scroll down to Devices,
click Connect to a device and choose A314spot,
pick a song or album then hit play and enjoy!
I hope that you'll like this sound-mojo of mine.
Please stay tuned for more tips and trix! 🙂