My partner has been overseas for a few months and was desperately missing a local radio station. It doesn’t have an online stream that she can listen to and so she asked me whether I could record the station for ten hours – this just sounded like a hassle, so I set up an internet streaming station to permanently re-stream the local broadcast over the internet using my Raspberry Pi, a cheap USB sound card, a cheap DAB digial radio, and darkice/icecast to run the streaming server.
The output of lsusb showed the cheap USB sound card to be a “C-Media Electronics, Inc. CM108 Audio Controller”. I found that I could access the device using ALSA and the arecord utility (as long as I didn’t specify 2 channels):
arecord -D hw:1,1 -f s16_le > test.wav
Next, I tried to set up icecast2 with darkice. I’m using Raspbian and the standard raspbian-distributed package for darkice is not compiled with ALSA support, and I nearly fell down a rabbit-hole trying to get OSS-compatible emulation working.
In the end, I was able to compile and install darkice with ALSA and mp3 support by following the excellent instructions here:
http://mattkaar.com/blog/2013/05/26/web-streaming-with-the-raspberry-pi-baby-monitor/
My darkice.cfg file looks like this:
[general] duration = 0 # duration of encoding, in seconds. 0 means forever bufferSecs = 5 # size of internal slip buffer, in seconds reconnect = yes # reconnect to the server(s) if disconnected # this section describes the audio input that will be streamed [input] device = hw:1,0 # Alsa soundcard device for the audio input sampleRate = 44100 # sample rate in Hz. try 11025, 22050 or 44100 bitsPerSample = 16 # bits per sample. try 16 channel = 1 # channels. 1 = mono, 2 = stereo # this section describes a streaming connection to an IceCast2 server # there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7] # these can be mixed with [icecast-x] and [shoutcast-x] sections [icecast2-0] bitrateMode = vbr # variable bit rate format = mp3 # format of the stream: mp3 quality = 0.6 # quality of the stream sent to the server server = localhost # host name of the server port = 8000 # port of the IceCast2 server, usually 8000 password = ****** # source password to the IceCast2 server mountPoint = 1080 # mount point of this stream on the IceCast2 server name = 6ix - Forever Classic # name of the stream description = DarkIce on RasPi # description of the stream #url = http://192.168.88.17 # URL related to the stream genre = Forever Classic # genre of the stream public = no # advertise this stream? localDumpFile = recording.mp3 # Record also to a file
The setup works beautifully and CPU (original rPi) hits around 25% per streaming client. Since I only expect to stream to one client, this is fine.
As AM has quite a limited bandwidth I expect I could drastically lower the bitrate that darkice is encoding at, and also add a highpass parameter to filter out any noise.
To round off the project I also made the rPi serve a little webpage, with a link to .m3u file plus an embedded HTML5 player:
Hear it here: radio.jeremyhall.com.au
Finally, I made darkice run as a service using daemontools using the instructions on this stackexchange post: http://unix.stackexchange.com/questions/92545/starting-darkice-automatically-via-daemontools
Update: It’s still running strong a few months later. Having now joined my partner overseas, we listen to it every day!
Second update (June 2017): The radio station that was being re-streamed has now started their own official stream, so my stream is no longer running.
Leave a Reply