Skip to content

Commit

Permalink
rade_tx, rade_tx_eoo, and rade_rx, retunr the number of samples written
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Sep 28, 2024
1 parent 8094db6 commit 9ac934d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
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
9 changes: 6 additions & 3 deletions src/rade_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ac934d

Please sign in to comment.