From bf5eb5bf8d7bc6ede8dd8db27a04d5f9e78ed6cc Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 31 Jul 2023 02:06:48 -0400 Subject: Add FWGAN to lpcnet_demo --- dnn/fwgan.c | 3 +++ dnn/fwgan.h | 1 + dnn/lpcnet_demo.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/dnn/fwgan.c b/dnn/fwgan.c index ea4f0e07..4c22b34c 100644 --- a/dnn/fwgan.c +++ b/dnn/fwgan.c @@ -109,6 +109,8 @@ void fwgan_cont(FWGANState *st, const float *pcm0, const float *features0) compute_generic_dense(&model->fwc7_cont_fc_0, st->fwc7_state, cont_inputs, ACTIVATION_TANH); /* FIXME: Do we need to handle initial features? How? */ + + st->cont_initialized = 1; } static void apply_gain(float *pcm, float c0, float *last_gain) { @@ -213,6 +215,7 @@ void fwgan_synthesize(FWGANState *st, float *pcm, const float *features) float lpc_weight; float fwgan_features[NB_FEATURES-1]; int i; + celt_assert(st->cont_initialized); OPUS_COPY(fwgan_features, features, NB_FEATURES-2); fwgan_features[NB_FEATURES-2] = features[NB_FEATURES-1]+.5; diff --git a/dnn/fwgan.h b/dnn/fwgan.h index 7da11b8f..3af76cda 100644 --- a/dnn/fwgan.h +++ b/dnn/fwgan.h @@ -44,6 +44,7 @@ typedef struct { FWGAN model; int arch; + int cont_initialized; double embed_phase; float last_gain; float last_lpc[LPC_ORDER]; diff --git a/dnn/lpcnet_demo.c b/dnn/lpcnet_demo.c index f0688740..2ee385c2 100644 --- a/dnn/lpcnet_demo.c +++ b/dnn/lpcnet_demo.c @@ -36,6 +36,7 @@ #include "lpcnet.h" #include "freq.h" #include "os_support.h" +#include "fwgan.h" #ifdef USE_WEIGHTS_FILE # if __unix__ @@ -84,6 +85,7 @@ void free_blob(unsigned char *blob, int len) { #define MODE_SYNTHESIS 3 #define MODE_PLC 4 #define MODE_ADDLPC 5 +#define MODE_FWGAN_SYNTHESIS 6 void usage(void) { fprintf(stderr, "usage: lpcnet_demo -features \n"); @@ -112,6 +114,7 @@ int main(int argc, char **argv) { if (argc < 4) usage(); if (strcmp(argv[1], "-features") == 0) mode=MODE_FEATURES; else if (strcmp(argv[1], "-synthesis") == 0) mode=MODE_SYNTHESIS; + else if (strcmp(argv[1], "-fwgan-synthesis") == 0) mode=MODE_FWGAN_SYNTHESIS; else if (strcmp(argv[1], "-plc") == 0) { mode=MODE_PLC; plc_options = argv[2]; @@ -184,6 +187,28 @@ int main(int argc, char **argv) { fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout); } lpcnet_destroy(net); + } else if (mode == MODE_FWGAN_SYNTHESIS) { + FWGANState fwgan; + float zeros[320] = {0}; + fwgan_init(&fwgan); + fwgan_cont(&fwgan, zeros, NULL); +#ifdef USE_WEIGHTS_FILE + fwgan_load_model(fwgan, data, len); +#endif + while (1) { + int i; + float in_features[NB_TOTAL_FEATURES]; + float features[NB_FEATURES]; + float fpcm[LPCNET_FRAME_SIZE]; + opus_int16 pcm[LPCNET_FRAME_SIZE]; + size_t ret; + ret = fread(in_features, sizeof(features[0]), NB_TOTAL_FEATURES, fin); + if (feof(fin) || ret != NB_TOTAL_FEATURES) break; + OPUS_COPY(features, in_features, NB_FEATURES); + fwgan_synthesize(&fwgan, fpcm, features); + for (i=0;i