Direwolf: add pre-emphasis to your AFSK signal

Direwolf is very capable software TNC, yet it is not yet possible to add twist between the high and low tone e.g if you want to feed 1200bps to the 9600bps flat audio input of your transceiver.

If you are reading this, you know what pre-emphasis is and why you need to have it. I will not discuss this in great details, others have done way better than I would.

However, here are some quick basics: pre-emphasis consists of passing the audio signal through a single pole high pass filter with a cut-off frequency at about 2500~2800Hz. This results in the 1200 and 2200Hz AFSK packet tones to have an amplitude difference of about 5dB, the 2200Hz tone having the highest amplitude.

Kenwood TM-271 and Orange Pi Zero as a mobile APRS Tracker

It has been a long debate into various mailing lists if Direwolf needs to incorporate pre-emphasis or not. The main argument is, Direwolf does not care about it. Off course, but we do not live in a perfect world and we still have a lot of old TNCs and modems out here who do care about pre-emphasis. So I decided to find a way to add it to my Direwolf setup.

What drove me to do this is the fact that my Kenwood TM-271 does not apply pre-emphasis on the 1K2 packet input. God knows what the engineers at Kenwood have thought of….

These were all my options:

  1. Add a RC Filter somewhere in the audio circuit
  2. Fiddle in the Direwolf code, add pre-emphasis option and submit a pull request.
  3. Add the appropriate high pass filter in the Linux audio chain

Because I am software guy and did not have time and will to deep dive in the tone generation part of the Direwolf source code, I eventually went for option 3 .

I am far from an expert in the Linux audio system (which is quite convoluted), but in the end I got to achieve what I wanted. If something is not described the way it should be feel free to comment.

ALSA (Advanced Linux Sound Architecture) is the first layer of the audio system, it talks to the hardware drivers and presents a unified interface to upper levels e.g. programs.

What we need is a virtual sound device that behaves like high-pass filter with a cutoff frequency set at 2500Hz.

Create the highpass virtual device

All this has been done on Armbian Bullseye. It should work on any Debian derivative like RaspiOS or Ubuntu.

First we need to install the Steve Harris LADSPA plugins and the LADSPA SDK.

sudo apt install swh-plugins ladspa-sdkCode language: Shell Session (shell)

Now create or edit the file /etc/asound.conf and add the following text block

pcm.highpass {
    type ladspa
    slave.pcm "plughw:0,0"; #this is the actual hardware soundcard
    path "/usr/lib/ladspa";
    plugins [{
        label hpf #load the highpass filter plugin
        input {
            controls [ 3000 ] # This is the cut-off frequency,
        }
    }]
}Code language: PHP (php)

The line “slave.pcm” needs to be adjusted to your actual hardware soundcard. The cut-off frequency needs to be somewhat above 2200Hz to make sure both tones (1200 and 2200Hz) are in the slope of the curve, hence the 3000Hz.

If we issue the command

aplay -LCode language: Shell Session (shell)

We see that our highpass virtual device is listed

null
    Discard all samples (playback) or generate zero samples (capture)
highpass
hw:CARD=Codec,DEV=0
    H3 Audio Codec, CDC PCM Codec-0
    Direct hardware device without any conversions
plughw:CARD=Codec,DEV=0
    H3 Audio Codec, CDC PCM Codec-0
    Hardware device with all software conversions
Code language: Shell Session (shell)

Use the virtual device in Direwolf

Direwolf is full of great functionalities. It allows to use different devices for transmit and receive. We only want to apply pre-emphasis to the transmit path. As a matter of fact the ADEVICE line in the Direwolf configuration shall look like this

ADEVICE plughw:0,0 plug:highpassCode language: CSS (css)

plughw:0,0 is the device used for receive and plug:highpass is the device used for transmit. Adjust the receive device to your actual device.

Conclusion and limitations

We now have pre-emphasied audio to feed into our radio’s flat audio input. Do not feed it into the emphasized input, this will get you nowhere.

You also need to carefully adjust your audio levels as to not trigger your radio’s limiter.

When not using the highpass device I am unable to hit a digipeater located 170km from me, with the highpass device I can hit it quite reliably.

The virtual device highpass does not show up in alsamixer, I have no clue how to achieve this. If you wish to adjust the cut-off frequency you’ll have to change it in the /etc/asound.conf file.

Sources and Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.