Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Initial support for piping audio through external vocoder programs. #719

Open
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

tmiw
Copy link
Collaborator

@tmiw tmiw commented May 1, 2024

Introduction

Add infrastructure so that external vocoders can be used. This is to support demoing of RADAE.

WARNING: This is experimental. You probably don't want to use this right now unless you're helping to test RADAE.

Setup

Linux/macOS

RADAE setup:

$ cd ~
$ git clone https://github.com/drowe67/radae
$ cd radae
$ python3 -m venv radae-venv
$ export PATH=`pwd`/radae-venv/bin:$PATH
$ pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
$ pip3 install matplotlib tqdm
$ mkdir build
$ cd build
$ cmake ..
$ make

freedv-gui:

$ cd ~
$ git clone https://github.com/drowe67/freedv-gui.git
$ cd freedv-gui
$ git checkout ms-external-vocoder
$ ./build_linux.sh [or ./build_osx.sh if on macOS]

Once compiled, go to Tools->Options->Modem and configure External Vocoder (shown below):

image

Each of these should be the full paths to radae_demo_rx.sh and radae_demo_tx.sh respectively. These scripts expect two arguments: the path to your RADAE folder and the path to the Python venv you set up. For example, /home/mooneer/freedv-gui/radae_demo_rx.sh /home/mooneer/radae /home/mooneer/radae/radae-venv.

Windows

  1. Download pre-built version from here and extract it somewhere on your hard drive. (For these instructions, we will assume it got extracted to C:\Users\User\Desktop, creating a folder on the desktop named FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64.)
  2. Install Python 3.12 from here. Make sure to check the checkbox to add python.exe to your PATH in the window that appears before proceeding with the installation.
  3. Download Miniconda from https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe and install it onto your computer.
  4. Go to Start->Anaconda prompt (miniconda3) and then enter the following commands. Make sure to note the "environment location" while you're running the commands; it should be something like C:\Users\User\miniconda3\envs\radae (where User is your username on your PC):
conda create -n radae
conda activate radae
conda install pytorch torchvision torchaudio cpuonly -c pytorch-nightly
conda install matplotlib

(Note: pip is not being used for Windows due to the version of NumPy having performance issues on that platform. The version of NumPy installed by conda uses a different "BLAS" library that is better optimized and is able to run RADAE in real time. Additionally, there is a bug in PyTorch 2.4.0 that affects performance in Windows, which is why we're using nightly builds instead.)

  1. Start freedv.exe in the FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64\bin folder and go to Tools->Options->Modem. Much like with Linux and macOS, you'll need to configure the RX and TX paths to point to radae_rx.bat and radae_tx.bat respectively (along with paths to the conda environment and RADAE). For example:
  • RX command: C:\Users\User\Desktop\FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64\bin\radae_rx.bat C:\Users\User\Desktop\FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64\radae C:\Users\User\miniconda3\envs\radae

  • TX command: C:\Users\User\Desktop\FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64\bin\radae_tx.bat C:\Users\User\Desktop\FreeDV-1.9.10-devel-2024-08-23-37bc8434-windows-x86_64\radae C:\Users\User\miniconda3\envs\radae

Usage

Once set up, you can then choose "External" from the list of modes in the main window and click Start. You should then be able to decode RADAE if you happen to receive a signal. TX should also work, either via the voice keyer or by simply pushing the PTT button.

Limitations:

  • FreeDV Reporter will show "unk" for your current TX mode. It should report when you TX, but it will not report any stations that you receive.
  • PSK Reporter may/may not show you as a listening FreeDV station but you definitely won't report anyone while using RADAE (for the same reasons as with FreeDV Reporter).
  • Multi-RX support does not work. You will have to push Stop, choose another mode and push Start again to go back to current/legacy FreeDV behavior.
  • Timing may not be 100% right yet (i.e. the ends of transmissions may be cut off). Add a bit more of a pause before ending PTT to mitigate this.

Additional Notes

Example of another way (on Linux) to test the scripts without transmitting OTA:

mooneer@ubuntu-vm:~/radae$ sox wav/mooneer.wav -t raw -b 16 -e signed-integer -L -c 1 -r 16000 - | ~/freedv-gui/radae_demo_tx.sh `pwd` `pwd`/radae-venv | ~/freedv-gui/radae_demo_rx.sh `pwd` `pwd`/radae-venv | aplay -f S16_LE -r 16000

radae_demo_rx.sh Outdated
# * Convert the audio into IQ data via zero-padding.
# * Pass the IQ data into the RADAE decoder
# * Send the resulting 16 kHz audio back to freedv-gui.
$RADAE_VENV/bin/python3 $RADAE_PATH/int16tof32.py --zeropad | $RADAE_VENV/bin/python3 $RADAE_PATH/radae_rx.py $RADAE_PATH/model19_check3/checkpoints/checkpoint_epoch_100.pth -v 2 --auxdata | $RADAE_PATH/build/src/lpcnet_demo -fargan-synthesis - -
Copy link
Owner

@drowe67 drowe67 Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

cd $RADAE_PATH
python3 int16tof32.py --zeropad | python3 radae_rx.py model19_check3/checkpoints/checkpoint_epoch_100.pth -v 2 --auxdata | ./build/src/lpcnet_demo -fargan-synthesis - -

Maybe try Ubuntu 22 and see if the VENV issues go away? It's pretty hard to follow the code with all the explicit paths. Apart from that it looks OK. You could maybe test the script stand alone to see if it streams OK. I'm not sure about streaming to and from scripts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I went ahead and cleaned up the scripts so they should be a bit neater now. Thanks for taking a look!

radae_demo_tx.sh Outdated
# * Pass the IQ data into the RADAE encoder
# * Send the resulting 8 kHz audio back to freedv-gui.
export PATH=$RADAE_VENV/bin:$PATH
$RADAE_PATH/build/src/lpcnet_demo -features - - | $RADAE_VENV/bin/python3 $RADAE_PATH/radae_tx.py $RADAE_PATH/model19_check3/checkpoints/checkpoint_epoch_100.pth --auxdata | python3 $RADAE_PATH/f32toint16.py --real --scale 16383
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks 👍 But as above - see if the streaming works when you run the script form the cmd line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they work on the command line. It looks like there's significant latency before they even start encoding or decoding, mainly while PyTorch is setting itself up (hence why I was having the TX problem). This might be able to be worked around by e.g. not constantly killing and restarting the TX process.

tmiw added 30 commits August 21, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants