diff options
author | Jean-Marc Valin <jmvalin@amazon.com> | 2023-07-31 09:06:48 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2023-07-31 09:06:48 +0300 |
commit | 5f9c722c1f6b02191152c83ec0207231d500b6b0 (patch) | |
tree | 3c24e2a0e438667ac20b035ee08dfa260951b820 | |
parent | 1f65af6195d30199ddce385bf42f72dc645bf7e9 (diff) |
Add FWGAN to lpcnet_demo
-rw-r--r-- | dnn/lpcnet_demo.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/dnn/lpcnet_demo.c b/dnn/lpcnet_demo.c index f0688740..b486e09e 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 <input.pcm> <features.f32>\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,26 @@ 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; + fwgan_init(&fwgan); +#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<LPCNET_FRAME_SIZE;i++) pcm[i] = (int)floor(.5 + fpcm[i]); + fwrite(pcm, sizeof(pcm[0]), LPCNET_FRAME_SIZE, fout); + } } else if (mode == MODE_PLC) { opus_int16 pcm[FRAME_SIZE]; int count=0; |