Listening to the signals

We've done all this work and we haven't even got to listen to the signals coming through the device! Now we will install and set up an Icecast audio server so that the timestamped and hum-filtered signal in the @filtered buffer can be played on any other PC on your network.

Start with

apt-get install -y icecast2

A package configuration screen will appear in your shell. Select No to configure Icecast2, we will configure it manually by editing its configuration file.

Edit the configuration file /etc/icecast2/icecast.xml Unfortunately this is an XML file so it's a bit tedious to edit.

In the limits section, increases sources from 2 to, say, 10, and increase the source timeout from 10 to 30.

In the authentication section, change the source-password, the relay-password, and the admin-password to something else. Then scroll to the bottom to find the security section which looks like

   <security>
        <chroot>0</chroot>
        <!--
        <changeowner>
            <user>nobody</user>
            <group>nogroup</group>
        </changeowner>
        -->
    </security>

Edit it so that it is

   <security>
        <chroot>0</chroot>
        <changeowner>
            <user>icecast2</user>
            <group>icecast</group>
        </changeowner>
    </security>

Save the changes. Then a minor edit to /etc/default/icecast2 to change

ENABLE=false

to

ENABLE=true

Now you run the commands below to start the Icecast service:

systemctl enable icecast2.service
systemctl start icecast2.service

You may find it necessary to reboot the Pi at this point. Check that it is running with

ps ax | grep icecast

which lists every process running with the word icecast in its command line. You should see two,

 1036 ?        Sl     0:00 /usr/bin/icecast2 -b -c /etc/icecast2/icecast.xml
 1047 pts/0    S+     0:00 grep icecast

Icecast2, and your grep command. All being well, you should now be able to view the Icecast status from a web browser on another PC, using a URL like

http://192.168.2.37:8000/

Now we just have to stream the signal from @filtered into Icecast. That's very easy to do using the vtvorbis program. But we almost certainly don't want to stream the full 48kHz bandwidth of the available signal. You can't hear that high anyway. Plus, there are likely to be some strong signals above 18kHz - military MSK transmissions - and these will often overload the audio output of a PC or its amplifier to produce distortion and intermodulation. So we should low-pass filter the stream first, and we might as well do that by reducing the sample rate from 96k/sec down to say, 32k/sec.

Open a shell on the Pi and, assuming for a moment you're using the stereo card and so you have just a single channel in @filtered, run

vtresample -r32000 @filtered:1 | vtvorbis -epv -q0.4 -ktu shout,localhost,8000,/vlf,XXXXX

where you must replace XXXXX with the source-password you put into Icecast's configuration XML file earlier. You should see some messages on the shell like

vtvorbis: uplink: shout,localhost,8000,/vlf
vtvorbis: selected channel: 1 = -:1
vtvorbis: encode channels: 1, sample_rate: 32000
vtvorbis: VBR encoding, q=0.40
vtvorbis: coupling mode: 1
vtvorbis: connected to localhost:8000 /vlf

Now go to your PC and reload that Icecast status URL, http://192.168.2.37:8000/ and your stream should be listed. I've called the stream /vlf in this demo, you can call it what you like but the name must start with / and be a continuous string of characters, no spaces.

You can click on the play button in Icecast's status page, or you can directly open the stream with either

http://192.168.2.37:8000/vlf

or

http://192.168.2.37:8000/vlf.m3u

whichever works or your browser or music playing gadget.

Now it just remains to install that resampling vorbis sending pipeline into the start-up script. You know the routine by now.. CNTL-C to stop the resample/vorbis command, then edit /root/radio so that it looks like

#!/bin/bash

killall -q vtcard
killall -q vttime
killall -q vtfilter
killall -q vtresample
killall -q vtvorbis

if [ "$1" = start -o "$1" = restart ]
then

   sleep 2 # Delay needed when using Octo, the driver is slow to initialise

   vtcard -B -d hw:0,0 -r96000 -b32 -c2 -g-1 -L /run/vtcard.log -v @raw
   vtwait -t @raw

   vttime -B -m pulse+ -c2 -L /tmp/vttime.log -v @raw @timed
   vtwait -t @timed

   vtfilter -B -a th=5 @timed:1 @filtered
   vtwait -t @filtered

   vtresample -B -r32000 @filtered:1 |
      vtvorbis -B -ep -q0.4 -ktu shout,localhost,8000,/vlf,XXXXX
   
fi

The -B option to both commands is by now now familiar, and I've dropped the -v option from vtvorbis because we're not going to bother logging its messages.

Save the changes and restart with

systemctl restart radio.service

Give it a minute to start everything up. While it's doing that you can run the command

vtps

to list the 'vt' programs that are running. When start-up is complete, vtps should show something similar to

  PID RT %CPU %MEM COMMAND
 1113 99  5.7  2.0 vtcard -B -d hw:0,0 -r96000 -b32 -c2 -g-1 -L /run/vtcard.log -v @raw
 1204  - 22.0  4.9 vttime -B -m pulse+ -c2 -L /tmp/vttime.log -v @raw @timed
 1216  - 16.4  2.8 vtfilter -B -a th=5 @timed:1 @filtered
 1229  - 12.2  0.7 vtresample -B -r32000 @filtered:1
 1231  -  5.2  0.4 vtvorbis -B -ep -q0.4 -ktu shout,localhost,8000,/vlf,XXXXX

The vtps command conveniently shows the percentage CPU usage of each process. The Pi has a quad core, so you can use up to a total of 400% CPU. As you can see, there's plenty of spare capacity right now. Note, if you're running the Octo, vttime will be showing over 90% CPU - it has a lot of work to do to with its high quality resampling of six channels.

The above resample/vorbis command was for the stereo card and we send a mono stream to Icecast. With the Octo card, the buffer @filtered contains five channels and you'll have to choose either one or two channels to encoding into a mono or stereo stream. Suppose you want to use channels 2 and 4 for left and right, then your start-up command would be

vtresample -B -r32000 @filtered:2,4 |
    vtvorbis -B -ep -q0.4 -ktu shout,localhost,8000,/vlf,XXXXX

You can run more than one stream - earlier we configured Icecast for up to 10 streams, of course you can change that to many more if you want! Just use commands similar to above with whatever channel or resampling options you want. Invent a different mount point for each one.

We're low-pass filtering the signal just by resampling. Often you want a bit more control over the filtering, perhaps to add a high-pass filter to remove ELF rumble from the stream. Just put in a vtfilter stage between the resampler and vorbis encoder. For example, the start-up command might then be

vtresample -B -r32000 @filtered:2,4 |
    vtfilter -B -h hp,f=500,poles=3 |
    vtvorbis -B -ep -q0.4 -ktu shout,localhost,8000,/vlf,XXXXX

which inserts a high-pass 3 pole filter with corner at 500 Hz. If you have good hearing and are driven mad by the beeps of the Alpha signals between 11.9 kHz and 14.9 kHz, you might notch them out with a band-stop setting in the same filter,

vtfilter -B -h hp,f=500,poles=3 -h bs,f=13400,w=3200 

which places the band-stop at center 13.4 kHz with width 3.2 kHz. You can use as many -h options to vtfilter as you need - it doesn't cost any extra CPU load. But generally the more filtering you do, the less natural it sounds so you have to find a nice balance.


Back to Filter Up to Index   Next to Live