Create an internet radio stream that allows for streaming your records to your Smart Home Audio System or any other internet radio capable endpoint.
-
Set audio device to be streamed in
config/darkice.cfg
file.... device = plughw:3,0 # Audio device for the audio input ...
See section Persistent audio device number for details about determining your audio device.
-
Start docker container.
sudo docker compose up
The numbering of the audio devices is not deterministic and changes randomly on reboot.
The audio systems in modern households are changing drastically and use technologies like Bluetooth or wireless streaming. Additionally, physical connectors are getting removed from the audio equipment. The missing connectors make it harder to connect your record player and listen to your favorite records. This project tackles the problem through the creation of a live internet radio stream in the local network from the current playing record. The internet radio stream can be consumed by any internet radio compatible endpoint in the network. E.g. you can add the created internet radio stream to your smart home audio system from Sonos or Bose Home Audio as well as any other Bluetooth sound system or computer.
There are already a couple of projects describing a similar approach see
section Inspiration. This project attempts to simplify the
setup of such an internet streaming service. The resilience is
increased through dockerization.
The presented solution doesn't claim to be the audiophile's choice. Nevertheless
it creates a suitable solution for connectivity problems with modern
audio systems.
It can also be an alternative to expensive solutions like the Sonos
Amp or the Bose Music Amplifier.
The pipeline begins with the record player which is connected to the USB audio
interface (see architecture overview above). The analog signal from the current
playing record travels through the USB
audio interface into the Raspberry Pi. The program
Darkice encodes the analog audio signal into a
digital audio signal according to your configuration and sends it to a streaming
media server. The streaming media server in this setup is
Icecast. It creates an internet radio station in your
private network. You can listen to it on any device that allows for a
connection with an internet radio stream.
To create a similar set up the following steps need to be completed:
- Organize Hardware.
- Prepare Raspberry Pi.
- Install required software.
- Make number of used audio device persistent.
- Configure Darkice.
- Start the container.
- Test the internet radio stream
- Record player with stereo out.
- USB Audio interface with phono preamp e.g.:
- Behringer U-PHONE UFO202 (tested).
- If your record player has a build in phono preamp or you are using an external phono you can also use audio boards from HifiBerry (not tested).
- Raspberry Pi e.g.:
- Raspberry Pi 4 2GB Ram (tested).
- Other versions should also work.
- Audio System eg.:
- Sonos including Sonos App (tested).
- Any Bluetooth speaker plus internet radio app e.g. TuneIn (tested) or similar.
- Bose Home Audio (not tested) including Bose Music APP (not tested).
Example Hardware Costs:
Hardware | Price |
---|---|
Raspberry Pi 4 B 2GB | 40,00 € |
Power Supply | 10,00 € |
SD Card 16GB | 10,00 € |
Case | 15,00 € |
USB Audio Interface | 24,00 € |
Total: | 99,00 € |
Install a linux operating system of you choice e.g.:
Comments:
- I used arch linux for my setup as I like the rolling-release approach. If you are new to linux and or to Raspberry Pi I would recommend to start with a debian based system like Debian or Ubuntu as the explanations are mostly very comprehensible.
- If you don't know how to access the your Raspberry Pi remotely with SSH the following guide might give you a good starting point Connect to your Raspberry Pi with ssh. I would like to encourage you to research this part on your own and keep following this guide after you have access to your Raspberry Pi's terminal.
Required programs and packages:
- Alsa: API for audio device drivers. No installation required as alsa is part of the Linux Kernel.
- Docker Engine: Program that allows you to run docker containers on your system. Please follow the installation guide from the docker homepage.
- Docker Compose: Tool for defining and running docker containers. Please follow the installation guide from the docker homepage.
- git: Please follow the installation guide from git.
To configure our internet radio stream it is required to inform
Darkice about the source of the audio signal that needs to be encoded. The
command aplay -l
displays a list of known audio devices.
sudo aplay -l
# Example output:
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
The example output displays 4 audio cards available on the Raspberry Pi. Relevant
for the internet radio stream program is card 3
as it is the audio interface
that is connected to the record player. Unlike card 1
card 3
has only one
subdevice. Darkice can be configured to listen to card 3
and subdevice 0
by editing the line starting with device
in config/darkice.cfg
:
...
device = plughw:3,0 # Audio device for the audio input
...
The 3
of plughw:3,0
represents the card number and the 0
the subdevice. If
you start the docker container now your stream would work until the next restart
of the Raspberry Pi. Unfortunately alsa is indexing the available audio devices
randomly on every reboot. In order to make the system reliable it is necessary to make
the numbering of the audio interface persistent. This can be done in various ways as
described here
for arch linux. One approach to resolve this is to set the card number
explicitly in the alsa configuration with the help of the kernel modules.To
determine the kernel module used by the audio device the record player is
connected to follow the steps described below:
-
Unplug the audio device.
-
Restart the Raspberry Pi.
-
List kernel modules. They are listed in the first column of output.
lsmod | grep snd # Example output snd_bcm2835 28672 0
-
Connect the audio device.
-
List the kernel modules again.
# Example output snd_usb_audio 319488 0 snd_usbmidi_lib 36864 1 snd_usb_audio snd_hwdep 20480 1 snd_usb_audio snd_rawmidi 45056 1 snd_usbmidi_lib snd_bcm2835 28672 0 snd_seq_device 20480 1 snd_rawmidi mc 61440 4 videodev,snd_usb_audio,videobuf2_v4l2,videobuf2_common
The USB audio device is using the module snd_usb_audio
. For the sake
of simplicity configure alsa such that the USB audio device is the last card of
the connected cards by editing /etc/modprobe.d/alsa-base.conf
and set the
index of the card using the module snd_usb_audio
to 3:
options snd_usb_audio index=3
The persistence of the card number can be tested by rebooting a couple of times
and checking the numbering of the audio interface after each reboot with the
command sudo aplay -l
. If your card number is always the same keep on with the
configuration of Darkice.
Now it is possible to configure Darkice such that it will keep functioning after
restarts by editing config/darkice.cfg
:
...
device = plughw:3,0 # Audio device for the audio input
...
Last but not least the internet radio streaming container can be started:
sudo docker compose up
This will build the image and start the container. It is configured such that it restarts anytime the host system is restarted.
- Navigate with your browser to
http://<local ip address of raspberry pi>:8000
e.g.http://192.168.178.43:8000
to check if Icecast is up and running. Here you will also see information about your Darkice encoding.
- Try to listen to your record.
- Configure a web radio player and point it to your stream. Your Stream url
is
http://<local ip address of raspberry pi>:8000/turntable.mp3
e.g.http://192.168.178.43:8000/turntable.mp3
: - Start a record on your turntable. The encoding of Darkice causes a slight delay of a few seconds. Be patient!
- Configure a web radio player and point it to your stream. Your Stream url
is
Have fun and enjoy your favorite records anywhere in your household!