From 2ab62533e63cdf4e4be94a21a80296123bdbaa64 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Wed, 24 Apr 2019 20:04:52 -0400 Subject: [PATCH] Added input of model file to the demo. --- README | 2 +- examples/rnnoise_demo.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README b/README index 88fc79cd..03697801 100644 --- a/README +++ b/README @@ -12,6 +12,6 @@ While it is meant to be used as a library, a simple command-line tool is provided as an example. It operates on RAW 16-bit (machine endian) mono PCM files sampled at 48 kHz. It can be used as: -./examples/rnnoise_demo < input.raw > output.raw +./examples/rnnoise_demo [model file] < input.raw > output.raw The output is also a 16-bit raw PCM file. diff --git a/examples/rnnoise_demo.c b/examples/rnnoise_demo.c index 9c398ba5..95c2be45 100644 --- a/examples/rnnoise_demo.c +++ b/examples/rnnoise_demo.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) { DenoiseState **sts; float max_attenuation; if (argc < 3) { - fprintf(stderr, "usage: %s \n", argv[0]); + fprintf(stderr, "usage: %s [model file]\n", argv[0]); return 1; } @@ -52,6 +52,21 @@ int main(int argc, char **argv) { if (channels < 1) channels = 1; max_attenuation = pow(10, -atof(argv[2])/10); + if (argc >= 4) { + FILE *model_file = fopen(argv[3], "r"); + if (!model_file) { + perror(argv[3]); + return 1; + } + model = rnnoise_model_from_file(model_file); + fprintf(stderr, "\n\n\n%p\n\n\n", model); + if (!model) { + perror(argv[3]); + return 1; + } + fclose(model_file); + } + sts = malloc(channels * sizeof(DenoiseState *)); if (!sts) { perror("malloc"); @@ -85,5 +100,7 @@ int main(int argc, char **argv) { rnnoise_destroy(sts[i]); free(tmp); free(sts); + if (model) + rnnoise_model_free(model); return 0; }