From 8094db614de1d2867527f3fb6ffb08146e337c28 Mon Sep 17 00:00:00 2001 From: drowe67 <45574645+drowe67@users.noreply.github.com> Date: Sat, 28 Sep 2024 04:18:02 +0930 Subject: [PATCH 1/4] Update src/rade_api.h Co-authored-by: Mooneer Salem --- src/rade_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rade_api.h b/src/rade_api.h index b4fcb95..8c3072a 100644 --- a/src/rade_api.h +++ b/src/rade_api.h @@ -54,8 +54,8 @@ extern "C" { #endif // Sample rates used -#define RADE_FS_8000 8000 // modem waveform sample rate -#define RADE_FS_16000 16000 // speech sample rate +#define RADE_MODEM_SAMPLE_RATE 8000 // modem waveform sample rate +#define RADE_SPEECH_SAMPLE_RATE 16000 // speech sample rate // note single context only in this version, one context has one Tx, and one Rx struct rade *rade_open(char model_file[]); From 9ac934d64e6c0343d974f15d013e2b399176e6ac Mon Sep 17 00:00:00 2001 From: David Date: Sat, 28 Sep 2024 15:48:19 +0930 Subject: [PATCH 2/4] rade_tx, rade_tx_eoo, and rade_rx, retunr the number of samples written --- src/radae_rx.c | 4 ++-- src/radae_tx.c | 4 ++-- src/rade_api.c | 14 +++++++++++--- src/rade_api.h | 9 ++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/radae_rx.c b/src/radae_rx.c index 715e784..2ed2000 100644 --- a/src/radae_rx.c +++ b/src/radae_rx.c @@ -26,8 +26,8 @@ int main(void) #endif // _WIN32 while((size_t)nin == fread(rx_in, sizeof(RADE_COMP), nin, stdin)) { - int valid_out = rade_rx(r,features_out,rx_in); - if (valid_out) { + int n_out = rade_rx(r,features_out,rx_in); + if (n_out) { fwrite(features_out, sizeof(float), n_features_out, stdout); fflush(stdout); } diff --git a/src/radae_tx.c b/src/radae_tx.c index 8053bf2..a361ef7 100644 --- a/src/radae_tx.c +++ b/src/radae_tx.c @@ -31,8 +31,8 @@ int main(void) fwrite(tx_out, sizeof(RADE_COMP), n_tx_out, stdout); fflush(stdout); } - //rade_tx_eoo(r,tx_eoo_out); - //fwrite(tx_eoo_out, sizeof(RADE_COMP), n_tx_eoo_out, stdout); + rade_tx_eoo(r,tx_eoo_out); + fwrite(tx_eoo_out, sizeof(RADE_COMP), n_tx_eoo_out, stdout); rade_close(r); return 0; diff --git a/src/rade_api.c b/src/rade_api.c index 1036eba..578e4f6 100644 --- a/src/rade_api.c +++ b/src/rade_api.c @@ -236,6 +236,8 @@ struct rade *rade_open(char model_file[]) { struct rade *r = (struct rade*)malloc(sizeof(struct rade)); assert(r != NULL); + // TODO: implement me + fprintf(stderr, "model file: %s", model_file); Py_Initialize(); // need import array for numpy @@ -270,7 +272,7 @@ int rade_n_features_in_out(struct rade *r) { return (int)r->n_features_in; } -void rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]) { +int rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]) { assert(r != NULL); assert(features_in != NULL); assert(tx_out != NULL); @@ -278,13 +280,15 @@ void rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]) { memcpy(r->features_in, features_in, sizeof(float)*(r->n_features_in)); PyObject_CallObject(r->pFunc_radae_tx, r->pArgs_radae_tx); memcpy(tx_out, r->tx_out, sizeof(RADE_COMP)*(r->Nmf)); + return r->Nmf; } -void rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]) { +int rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]) { assert(r != NULL); assert(tx_eoo_out != NULL); PyObject_CallObject(r->pFunc_radae_tx_eoo, r->pArgs_radae_tx_eoo); memcpy(tx_eoo_out, r->tx_eoo_out, sizeof(RADE_COMP)*(r->Neoo)); + return r->Neoo; } int rade_rx(struct rade *r, float features_out[], RADE_COMP rx_in[]) { @@ -298,8 +302,12 @@ int rade_rx(struct rade *r, float features_out[], RADE_COMP rx_in[]) { check_error(pValue, "return value", "from do_rx_radae"); long valid_out = PyLong_AsLong(pValue); memcpy(features_out, r->features_out, sizeof(float)*(r->n_features_out)); + // sample nin so we have an updated copy r->nin = (int)call_getter(r->pInst_radae_rx, "get_nin"); - return (int)valid_out; + if (valid_out) + return r->n_features_out; + else + return 0; } int rade_sync(struct rade *r) { diff --git a/src/rade_api.h b/src/rade_api.h index 8c3072a..9902eaf 100644 --- a/src/rade_api.h +++ b/src/rade_api.h @@ -71,15 +71,18 @@ int rade_nin_max(struct rade *r); int rade_n_features_in_out(struct rade *r); // Note vocoder is not encapsulated in API in this version -void rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]); +// returns number of RADE_COMP samples written to tx_out[] +int rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]); // call this for the final frame at the end of over -void rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]); +// returns the number of RADE_COMP samples written to tx_eoo_out[] +int rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]); // call me before each call to rade_rx(), provide nin samples to rx_in[] int rade_nin(struct rade *r); -// returns non-zero if features_out[] contains valid output +// returns non-zero if features_out[] contains valid output. The number +// returned is the number of samples written to features_out[] int rade_rx(struct rade *r, float features_out[], RADE_COMP rx_in[]); // returns non-zero if Rx is currently in sync From cb3518a895969fdc1631363cde5b529509730f84 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 28 Sep 2024 16:27:36 +0930 Subject: [PATCH 3/4] add model arg as input - but need major refactor to use aux data as input (sigh) --- embed/radae_rx.py | 6 +++++- src/rade_api.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/embed/radae_rx.py b/embed/radae_rx.py index 3751c0e..d13b82f 100644 --- a/embed/radae_rx.py +++ b/embed/radae_rx.py @@ -37,7 +37,7 @@ */ """ -import os, sys, struct +import os, sys, struct,argparse import numpy as np from matplotlib import pyplot as plt import torch @@ -257,6 +257,10 @@ def do_radae_rx(self, buffer_complex, features_out): return valid_output if __name__ == '__main__': + parser = argparse.ArgumentParser(description='RADAE streaming receiver, IQ.f32 on stdin to features.f32 on stdout') + parser.add_argument('model_name', type=str, help='path to model in .pth format', + default="../model19_check3/checkpoints/checkpoint_epoch_100.pth") + rx = radae_rx(model_name = "../model19_check3/checkpoints/checkpoint_epoch_100.pth") # allocate storage for output features diff --git a/src/rade_api.h b/src/rade_api.h index 9902eaf..7dd6694 100644 --- a/src/rade_api.h +++ b/src/rade_api.h @@ -70,7 +70,7 @@ int rade_n_tx_eoo_out(struct rade *r); int rade_nin_max(struct rade *r); int rade_n_features_in_out(struct rade *r); -// Note vocoder is not encapsulated in API in this version +// note vocoder is not encapsulated in API in this version // returns number of RADE_COMP samples written to tx_out[] int rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]); From 6b6257552737b8bed1c83fca0c434d452aa3c821 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sat, 28 Sep 2024 10:07:32 -0700 Subject: [PATCH 4/4] Use URL download method for Opus to prevent constant rebuilds. --- cmake/BuildOpus.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/BuildOpus.cmake b/cmake/BuildOpus.cmake index dbec590..24667b3 100644 --- a/cmake/BuildOpus.cmake +++ b/cmake/BuildOpus.cmake @@ -2,8 +2,8 @@ message(STATUS "Will build opus with FARGAN") include(ExternalProject) ExternalProject_Add(build_opus - GIT_REPOSITORY https://gitlab.xiph.org/xiph/opus.git - GIT_TAG main + URL https://gitlab.xiph.org/xiph/opus/-/archive/main/opus-main.tar.gz + DOWNLOAD_EXTRACT_TIMESTAMP NO BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ./autogen.sh && ./configure --enable-dred --disable-shared BUILD_COMMAND $(MAKE)