Skip to content

Instantly share code, notes, and snippets.

@gbevan
Last active October 26, 2024 13:47
Show Gist options
  • Save gbevan/03c34642fa7fc525b80d8e26f2daba83 to your computer and use it in GitHub Desktop.
Save gbevan/03c34642fa7fc525b80d8e26f2daba83 to your computer and use it in GitHub Desktop.
SunSDR2 Pro on Linux with Alsa Audio Loopback VAC

SunSDR2 Pro on Linux with Alsa Audio Loopback VAC

Capturing my setup for VAC audio without intermittent clicks etc...

PC Config

Component description
OS Ubuntu 22.04
RAM 128GBs (way overspec'd)
CPU AMD Ryzen Threadripper 16 cores / 32 Threads

Monitor Receiver

I used a laptop with hackrf and software gqrx - this also shows a waterfall for the demodulated audio. I placed this in another room (far from the shack) and accessed using ssh setup to allow the gqrx GUI to be tunneled back to me remotely.

The receiver was heavily attenuated by simply having no antenna connected, with strong signals this was further attenuated with a 50ohm terminator. This is to ensure no rf distortion on receive.

Install Low Latency Linux Kernel

aptitude install linux-lowlatency-hwe-22.04

This step gave a significant improvement in the reduction of dropouts / clicks.

Turn off pulseaudio

pulseaudio -k

Configure Alsa Loopback Devices

/etc/modprobe.d/sound.conf:

options snd-hda-intel vid=8086 pid=8ca0 snoop=0 power_save=0

alias snd-card-0 snd-aloop
options snd-aloop enable=1,1,1,1,1 index=10,11,12,13,14 pcm_substreams=1,1,1,1,1

This actually creates 5 loopback virtual soundcards in the kernel, indexed as 10, 11, 12, 13 and 14. (I actually only currently use 2 of them in ExpertSDR2)

~/.asoundrc:

ctl.mixer0 {
    type hw
    card 0
}

pcm.!default {
    rate 48000
}

defaults.pcm.rate_converter "samplerate_best"

Patch for QSSTV

--- ../../../../TARs/qsstv_9.4.4/qsstv/sound/soundalsa.cpp	2019-05-20 11:02:11.000000000 +0100
+++ soundalsa.cpp	2020-09-03 12:07:19.655075615 +0100
@@ -365,7 +365,7 @@
          !deviceName.contains("surround",Qt::CaseInsensitive)
          && !deviceName.contains("dmix",Qt::CaseInsensitive)
          && !deviceName.contains("front",Qt::CaseInsensitive)
-         && !deviceName.contains("plughw",Qt::CaseInsensitive)
+         //&& !deviceName.contains("plughw",Qt::CaseInsensitive)
          && !deviceName.contains("null",Qt::CaseInsensitive)
          && !deviceName.contains("hdmi",Qt::CaseInsensitive)
          && !deviceName.contains("sysdefault",Qt::CaseInsensitive)

This simply enables the plughw: devices to be listed and selectable from the alsa devices config menu.

ExpertSDR2 VAC Settings

Setting Value
RX Alsa: Loopback: PCM (hw:10,0)
TX Alsa: Loopback: PCM (hw:11,1)
Sample Rate 48kHz
Buffer 2048 Samples
RX gain -9dbB
TX gain -10dB

The "TX gain" should be fine tuned using a heavily attenuated receiver - to ensure no audio distortion / harmonics.

ExpertSDR2 has to be started up and the VAC enabled before starting any data modem software to ensure it gets "Ownership" of the audio loopback devices (it complains otherwise).

Running ExpertSDR2 with Realtime Priority

(see update below, i'm not using this anymore. However, enabling rtprio for your user may prepare your system for any future realtime improvements/support in ExpertSDR2)

/etc/security/limits.d/99-realtime.conf

@realtime   -  rtprio     99
@realtime   -  memlock    unlimited

add your login user to be a member of group realtime.

Update the ExpertSDR2 startup script:

#!/bin/sh -x
BASE_DIR=$(dirname "$(readlink -f "$0")")
export LD_LIBRARY_PATH="$BASE_DIR"//lib/:"$BASE_DIR":$LD_LIBRARY_PATH
export QML_IMPORT_PATH="$BASE_DIR"//qml/:QML_IMPORT_PATH
export QML2_IMPORT_PATH="$BASE_DIR"//qml/:QML2_IMPORT_PATH
export QT_PLUGIN_PATH="$BASE_DIR"//plugins/:QT_PLUGIN_PATH
export QTWEBENGINEPROCESS_PATH="$BASE_DIR"//bin//QtWebEngineProcess
export QTDIR="$BASE_DIR"
export QT_QPA_PLATFORM_PLUGIN_PATH="$BASE_DIR"//plugins//platforms:QT_QPA_PLATFORM_PLUGIN_PATH
#chrt -v 99 "$BASE_DIR"//bin/ExpertSDR2 "$@"
"$BASE_DIR"//bin/ExpertSDR2 "$@"

Note the chrt -v 99 ... I added at the end.

Update 2020-10-31: I reverted the chrt -v 99 ... back to normal scheduling, as according to this

ONLY the audio I/O thread and if you do MIDI , the MIDI thread too, MUST run SCHED_FIFO... without SCHED_FIFO you will not get reliable low-latency.

all other threads should run with normal scheduling policy so that if the audio/midi thread needs the CPU, it will get the processing power even if you do heavy disk I/O or heavy CPU work in the background.

Last I checked ExpertSDR2 has 97 threads, so I dont think it is advisable for them all to have realtime priority scheduling. Doing a ps -eflLc | egrep -i "(UID|expert)" I dont see any threads running realtime priority - maybe there is room here for ExpertSDR2 to be improved...

Update 2020-12-18: Trying running ExpertSDR2 with nice value of -20, so it gets a higher dispatching priority. Launcher:

sudo nice -n -20 -- su your_user -c /usr/local/ExpertSDR2/ExpertSDR2_1.3.1_Update5_SunSDR2_Ubuntu_x64/ExpertSDR2.sh

PTT Switching Delay

I experienced a momentary audio blip at the start of each transmission in any digi mode - I noticed the tone was always the same as the last tone sent in the previous transmission. Seemed like the transmission was being stopped before all the audio buffer was sent, and was still a bit buffered on the next transmission.

Setting Options->Device->TX tab->PTT switching delay->Tx to Rx = 75 ms fixed this for me.

2021-01-31 ExpertSDR2 1.3.1 Update8

Upgraded from Update5 to Update8 (with firmware upgrade).

Experienced the zero power on TX issue - fixed by simply re-writing power settings in Options -> Device -> Expert.

Initial tests of audio quality show that the intermittent clicks have now gone.

@Sun-24-ux
Copy link

I have a problem. in Debian 22.04 i always get no dev1rx .Booth devices are dev2tx.
my modeprobe.de/alsa-loopbackdevice.conf:

options snd-aloop index=1,2 enable=1,1 pcm_substreams=2,2 id=dev1rx,dev2tx
Any idea?

@gbevan
Copy link
Author

gbevan commented Oct 25, 2024

Could some other process be "holding" them? e.g. Pulseaudio - in my Pulse Audio Volume Control applet, in Configuration tab, I set all Loopback devices to Profile "Off" - then restart ExpertSDR and see if it appears in VAC settings

@Sun-24-ux
Copy link

For my opinion no other loopback devices are active: the aplay -l gives:
aplay -l
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: HDMI [HDA Intel HDMI], Gerät 3: HDMI 0 [HDMI 0]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 0: HDMI [HDA Intel HDMI], Gerät 7: HDMI 1 [HDMI 1]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 0: HDMI [HDA Intel HDMI], Gerät 8: HDMI 2 [HDMI 2]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 1: PCH [HDA Intel PCH], Gerät 0: ALC283 Analog [ALC283 Analog]
Sub-Geräte: 0/1
Sub-Gerät #0: subdevice #0
Karte 2: dev2tx [Loopback], Gerät 0: Loopback PCM [Loopback PCM]
Sub-Geräte: 1/2
Sub-Gerät #0: subdevice #0
Sub-Gerät #1: subdevice #1
Karte 2: dev2tx [Loopback], Gerät 1: Loopback PCM [Loopback PCM]
Sub-Geräte: 2/2
Sub-Gerät #0: subdevice #0
Sub-Gerät #1: subdevice #1

I miss dev1rx.

@gbevan
Copy link
Author

gbevan commented Oct 25, 2024

I didnt use the id=... parameter in my setup - so not sure about that. perhaps check the docs for that parameter.

@Sun-24-ux
Copy link

Thanks for Your help. i changed a little bi my config and now it works :Here my little howto

Create with gedit in folder /etc/modprobe.d/:

alsa-loopback.conf:

with content:
options snd-hda-intel vid=8086 pid=8ca0 snoop=0 power_save=0
alias snd-card-0 snd-aloop
options snd-aloop enable=1,1 index=10,11 pcm_substreams=1,1 id=dev1rx,dev2tx

activate with

sudo modprobe and aloop

show loop devices with

aplay -l:
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 1: PCH [HDA Intel PCH], Gerät 0: ALC283 Analog [ALC283 Analog]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 10: dev1rx [Loopback], Gerät 0: Loopback PCM [Loopback PCM]
Sub-Geräte: 0/1
Sub-Gerät #0: subdevice #0
Karte 10: dev1rx [Loopback], Gerät 1: Loopback PCM [Loopback PCM]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
Karte 11: dev2tx [Loopback], Gerät 0: Loopback PCM [Loopback PCM]
Sub-Geräte: 0/1
Sub-Gerät #0: subdevice #0
Karte 11: dev2tx [Loopback], Gerät 1: Loopback PCM [Loopback PCM]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0

to start at boot:
edit modules in folder etc as fellow:

/etc/modules: kernel modules to load at boot time.

This file contains the names of kernel modules that should be loaded

at boot time, one per line. Lines beginning with "#" are ignored.

snd-aloop

Configuration VAC unter options in expetsdr2 sowftware

RX : ALSA Loopback:PCM(hw10,1)
TX : ALSA Loopback:PCM(hw11,0)

Configuration WJTX
Setting » Audio
Input: plughw:CARD=dev1rx,DEV0
Output:plughw:CARD=dev2tx,DEV=1

FLDIGI:
Port Audio enable
Aufnahme: Loopback:PCM hw(1,0)
Wiedergabe:Looppback:PCM (hw2,1)

@gbevan
Copy link
Author

gbevan commented Oct 26, 2024

thanks for the update :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment