Skip to content

Commit

Permalink
Merge branch 'dr-embed' of github.com:drowe67/radae into dr-embed
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Sep 30, 2024
2 parents 8a3520c + 6b62575 commit 369b76c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmake/BuildOpus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion embed/radae_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/radae_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/radae_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions src/rade_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -270,21 +272,23 @@ 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);

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[]) {
Expand All @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions src/rade_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand All @@ -70,16 +70,19 @@ 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
void rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]);
// 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[]);

// 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
Expand Down

0 comments on commit 369b76c

Please sign in to comment.