From 5008a0f480c3399440cd9b221336b91ffb794e02 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Tue, 20 Dec 2022 09:51:07 +0530 Subject: [PATCH] sf_open() should be matched with sf_close() Also the program expects a mono channel input file. --- example/adenoiser_demo.c | 10 +++++++++- example/denoiser_demo.c | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/example/adenoiser_demo.c b/example/adenoiser_demo.c index dfc2eb5..165051c 100644 --- a/example/adenoiser_demo.c +++ b/example/adenoiser_demo.c @@ -44,6 +44,14 @@ int main(int argc, char **argv) { SF_INFO *sfinfo = (SF_INFO *)calloc(1, sizeof(SF_INFO)); SNDFILE *input_file = sf_open(input_file_name, SFM_READ, sfinfo); + + if (sfinfo->channels != 1) { + fprintf(stderr, "input has more than %d channels, please input a mono wav file\n", sfinfo->channels); + sf_close(input_file); + free(sfinfo); + return 1; + } + SNDFILE *output_file = sf_open(output_file_name, SFM_WRITE, sfinfo); // Buffers for input and output to be used by the library @@ -89,4 +97,4 @@ int main(int argc, char **argv) { free(input_library_buffer); free(output_library_buffer); return 0; -} \ No newline at end of file +} diff --git a/example/denoiser_demo.c b/example/denoiser_demo.c index 89725b8..a0c6305 100644 --- a/example/denoiser_demo.c +++ b/example/denoiser_demo.c @@ -47,6 +47,12 @@ int main(int argc, char **argv) { SF_INFO *sfinfo = (SF_INFO *)calloc(1, sizeof(SF_INFO)); SNDFILE *input_file = sf_open(input_file_name, SFM_READ, sfinfo); + if (sfinfo->channels != 1) { + fprintf(stderr, "input has %d channels, please input a mono wav file\n", sfinfo->channels); + sf_close(input_file); + free(sfinfo); + return 1; + } SNDFILE *output_file = sf_open(output_file_name, SFM_WRITE, sfinfo); // Buffers for input and output to be used by the library @@ -115,4 +121,4 @@ int main(int argc, char **argv) { free(input_library_buffer); free(output_library_buffer); return 0; -} \ No newline at end of file +}