Skip to content

Commit

Permalink
sorting out merge conflicts with main, bbfm_sc_internal fails occasio…
Browse files Browse the repository at this point in the history
…nally so might need tweaking
  • Loading branch information
drowe67 committed Nov 6, 2024
2 parents 0035125 + 63950bf commit 2051de6
Show file tree
Hide file tree
Showing 33 changed files with 65,628 additions and 448 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/run_ctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: ctests
on: [push]

jobs:
run_ctests:
name: Running ctests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
python-version: ["3.10"]

steps:
- name: Checkout radae code
uses: actions/checkout@v4
with:
repository: drowe67/radae
path: ${{github.workspace}}/radae

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install system packages
shell: bash
run: |
sudo apt update
sudo apt install octave octave-common octave-signal sox cmake git python3.10-dev
- name: Install python packages
shell: bash
run: |
pip3 install torch numpy matplotlib tqdm
- name: Install codec2-dev
shell: bash
# we have to use a hard coded path as it seems "~" isn't support by Github Actions
# using "/home/runner" we seem to link to "~"
working-directory: /home/runner/
run: |
git clone https://github.com/drowe67/codec2-dev.git
cd codec2-dev
mkdir build_linux
cd build_linux
cmake -DUNITTEST=1 ..
make ch mksine tlininterp
- name: build radae
shell: bash
working-directory: ${{github.workspace}}/radae
run: |
mkdir build
cd build
cmake ..
make
- name: run ctests
shell: bash
working-directory: ${{github.workspace}}/radae/build
run: |
ctest -V --output-on-failure
113 changes: 96 additions & 17 deletions CMakeLists.txt

Large diffs are not rendered by default.

41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ cmake ..
make
```

### Building on Windows

While most of RADAE is in Python, there is a `lpcnet_demo` application
that is required to be compiled. To do this for Windows, you can run
something like the following from a Linux machine:

```
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz
tar xzf llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz
export PATH=`pwd`/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64/bin:$PATH
export RADAE_PATH=`pwd`/radae
cd $RADAE_PATH
mkdir build_windows
cd build_windows
cmake -DCMAKE_TOOLCHAIN_FILE=$RADAE_PATH/cross-compile/mingw-llvm-x86_64.cmake ..
make
```

(Replace `x86_64` in `mingw-llvm-x86_64.cmake` with either `i686` or `aarch64` for 32-bit x86 or 64-bit ARM, respectively.)

Once done, `lpcnet_demo.exe` will be inside the `src` folder inside `build_windows`.

#### Limitations

* ctests are untested and likely do not work without additional changes.
* Visual Studio is not supported, only MinGW.
* Generating a Windows installer is currently not supported. `lpcnet_demo.exe` is intended to be included with other applications built with MinGW (such as freedv-gui).

# Automated Tests

The `cmake/ctest` framework is being used as a build and test framework. The command lines in `CmakeLists.txt` are a good source of examples, if you are interested in running the code in this repo. The ctests are a work in progress and may not pass on all systems (see Scope above).
Expand Down Expand Up @@ -273,7 +301,7 @@ BER tests are useful to calibrate the system, and measure loss from classical DS
`radae_rx.py` is s streaming receiver that accepts IQ samples on stdin, and outputs z vectors on stdout. To listen to an example decode:
```
./inference.sh model17/checkpoints/checkpoint_epoch_100.pth wav/brian_g8sez.wav /dev/null --rate_Fs --pilots --pilot_eq --eq_ls --cp 0.004 --bottleneck 3 --write_rx rx.f32
./radae_rx.sh model17/checkpoints/checkpoint_epoch_100.pth rx.f32 -
cat rx.f32 | python3 radae_rx.py model17/checkpoints/checkpoint_epoch_100.pth | build/src/lpcnet_demo -fargan-synthesis - - | aplay -f S16_LE -r 16000
```
To run just the core streaming decoder:
```
Expand Down Expand Up @@ -356,7 +384,7 @@ This section is optional - pre-trained models that run on a standard laptop CPU
python3 ./train.py --cuda-visible-devices 0 --sequence-length 400 --batch-size 512 --epochs 100 --lr 0.003 --lr-decay-factor 0.0001 ~/Downloads/tts_speech_16k_speexdsp.f32 model18 --latent-dim 40 --bottleneck 3 --h_file h_nc10_train_mpp.f32 --range_EbNo_start -3 --range_EbNo --plot_loss
```
1, (Aug 2024) Training model with auxillary/embedded data at 25 bits/:
1. (Aug 2024) Training model with auxillary/embedded data at 25 bits/s:
```
python3 train.py --cuda-visible-devices 0 --sequence-length 400 --batch-size 512 --epochs 100 --lr 0.003 --lr-decay-factor 0.0001 ~/Downloads/tts_speech_16k_speexdsp.f32 model19_check3 --bottleneck 3 --h_file h_nc20_train_mpp.f32 --range_EbNo --plot_loss --auxdata
```
Expand Down Expand Up @@ -391,13 +419,16 @@ A log of models trained by the author.
| model05_auxdata | model05 (rate Rs h_nc20_train_mpp.f32) with --auxdata 100 bits/s see PR#13 | Rs | - |
| model05_auxdata25 | model05 (rate Rs h_nc20_train_mpp.f32) with --auxdata 25 bits/s see PR#13 | Rs | - |
| model19 | like model17 but with 25 bits/s auxdata, ep 100 loss 0.124 | Fs | - |
| model19_check3 | model19 but loss function weighting for data symbols redcued fom 1/18 to 0.5/18, which reduced vocoder feature loss with just a small impact on BER. Loss at various op points and channels very close to model17 | Fs | - |
| model19_check3 | model19 but loss function weighting for data symbols reduced fom 1/18 to 0.5/18, which reduced vocoder feature loss with just a small impact on BER. Loss at various op points and channels very close to model17 | Fs | - |
| model20 | model19_check3 but loss function weighting for pitch and corr doubled, attempt to improve rick samples. Didn't help. | Fs | - |
| model21 | very based fixed EbNodB model like model02 but at 20dB at epoch 30, produced good quality speech on rick, loss 0.02, but not a practical solution | Rs | - |
| model22 | very based fixed EbNodB model like model02 but at 10dB at epoch 30, rick sample starting to get tonal/pitch shift artefact, in between, loss 0.045 | Rs | - |
Note the samples are generated with `evaluate.sh`, which runs inference at rate Fs. even if (e.g model 05), trained at rate Rs.
# Specifications
Using model 17 waveform:
Using model19_check3 waveform:
| Parameter | Value | Comment |
| --- | --- | --- |
Expand All @@ -419,7 +450,7 @@ Using model 17 waveform:
| Mean acquisition time | < 1.5s | 0dB SNR MPP channel |
| Acquisition frequency range | +/- 50 Hz | |
| Acquisition co-channel interference tolerence | -3dBC | Interfering sine wave level, <2s mean acquisition time |
| Auxilary text channel | No | |
| Auxilary text channel | 25 bits/s | currently used for sync |
| SNR measurement | No | |
| Tx and Rx sample clock offset | 200ppm | e.g. Tx sample clock 8000 Hz, Rx sample clock 8001 Hz |
Expand Down
63 changes: 58 additions & 5 deletions cmake/BuildOpus.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,76 @@
message(STATUS "Will build opus with FARGAN")

set(CONFIGURE_COMMAND ./autogen.sh && ./configure --enable-dred --disable-shared --disable-doc --disable-extra-programs)

if (CMAKE_CROSSCOMPILING)
set(CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=${CMAKE_C_COMPILER_TARGET} --target=${CMAKE_C_COMPILER_TARGET})
endif (CMAKE_CROSSCOMPILING)

set(OPUS_URL https://gitlab.xiph.org/xiph/opus/-/archive/main/opus-main.tar.gz)

include(ExternalProject)
if(APPLE AND BUILD_OSX_UNIVERSAL)
# Opus ./configure doesn't behave properly when built as a universal binary;
# build it twice and use lipo to create a universal libopus.a instead.
ExternalProject_Add(build_opus_x86
DOWNLOAD_EXTRACT_TIMESTAMP NO
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=x86_64-apple-darwin --target=x86_64-apple-darwin CFLAGS=-arch\ x86_64\ -O2\ -mmacosx-version-min=10.11
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND ""
URL ${OPUS_URL}
)
ExternalProject_Add(build_opus_arm
DOWNLOAD_EXTRACT_TIMESTAMP NO
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ${CONFIGURE_COMMAND} --host=aarch64-apple-darwin --target=aarch64-apple-darwin CFLAGS=-arch\ arm64\ -O2\ -mmacosx-version-min=10.11
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND ""
URL ${OPUS_URL}
)

ExternalProject_Get_Property(build_opus_arm BINARY_DIR)
ExternalProject_Get_Property(build_opus_arm SOURCE_DIR)
set(OPUS_ARM_BINARY_DIR ${BINARY_DIR})
ExternalProject_Get_Property(build_opus_x86 BINARY_DIR)
set(OPUS_X86_BINARY_DIR ${BINARY_DIR})

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}
COMMAND lipo ${OPUS_ARM_BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX} ${OPUS_X86_BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX} -output ${CMAKE_CURRENT_BINARY_DIR}/libopus${CMAKE_STATIC_LIBRARY_SUFFIX} -create
DEPENDS build_opus_arm build_opus_x86)

add_custom_target(
libopus.a
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libopus${CMAKE_STATIC_LIBRARY_SUFFIX})

include_directories(${SOURCE_DIR}/dnn ${SOURCE_DIR}/celt ${SOURCE_DIR}/include)

add_library(opus STATIC IMPORTED)
add_dependencies(opus libopus.a)
set_target_properties(opus PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

else(APPLE AND BUILD_OSX_UNIVERSAL)
ExternalProject_Add(build_opus
GIT_REPOSITORY https://gitlab.xiph.org/xiph/opus.git
GIT_TAG main
DOWNLOAD_EXTRACT_TIMESTAMP NO
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./autogen.sh && ./configure --enable-dred --disable-shared
CONFIGURE_COMMAND ${CONFIGURE_COMMAND}
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND ""
URL ${OPUS_URL}
)

ExternalProject_Get_Property(build_opus BINARY_DIR)
ExternalProject_Get_Property(build_opus SOURCE_DIR)
add_library(opus SHARED IMPORTED)
add_library(opus STATIC IMPORTED)
add_dependencies(opus build_opus)

set_target_properties(opus PROPERTIES
IMPORTED_LOCATION "${BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_IMPLIB "${BINARY_DIR}/.libs/libopus${CMAKE_IMPORT_LIBRARY_SUFFIX}"
IMPORTED_IMPLIB "${BINARY_DIR}/.libs/libopus${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

include_directories(${SOURCE_DIR}/dnn ${SOURCE_DIR}/celt ${SOURCE_DIR}/include)
endif(APPLE AND BUILD_OSX_UNIVERSAL)
26 changes: 26 additions & 0 deletions cross-compile/mingw-llvm-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
28 changes: 28 additions & 0 deletions cross-compile/mingw-llvm-i686.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
28 changes: 28 additions & 0 deletions cross-compile/mingw-llvm-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

set(CMAKE_C_COMPILER ${triple}-clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${triple}-clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_AR ${triple}-ar)
set(CMAKE_RANLIB ${triple}-ranlib)
set(CMAKE_RC_COMPILER ${triple}-windres)

set(CMAKE_C_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_CXX_FLAGS "-Wno-unused-command-line-argument -gcodeview")
set(CMAKE_EXE_LINKER_FLAGS -Wl,--pdb=)

# For make package use.
set(CMAKE_OBJDUMP ${triple}-objdump)
set(FREEDV_USING_LLVM_MINGW 1)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Loading

0 comments on commit 2051de6

Please sign in to comment.