1 /* Copyright (c) 2018 Gregor Richards
2 * Copyright (c) 2017 Mozilla */
3 /*
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <stdio.h>
29 #include "rnnoise.h"
30
31 #define FRAME_SIZE 480
32
main(int argc,char ** argv)33 int main(int argc, char **argv) {
34 int i;
35 int first = 1;
36 float x[FRAME_SIZE];
37 FILE *f1, *fout;
38 DenoiseState *st;
39 st = rnnoise_create(NULL);
40 if (argc!=3) {
41 fprintf(stderr, "usage: %s <noisy speech> <output denoised>\n", argv[0]);
42 return 1;
43 }
44 f1 = fopen(argv[1], "rb");
45 fout = fopen(argv[2], "wb");
46 while (1) {
47 short tmp[FRAME_SIZE];
48 fread(tmp, sizeof(short), FRAME_SIZE, f1);
49 if (feof(f1)) break;
50 for (i=0;i<FRAME_SIZE;i++) x[i] = tmp[i];
51 rnnoise_process_frame(st, x, x);
52 for (i=0;i<FRAME_SIZE;i++) tmp[i] = x[i];
53 if (!first) fwrite(tmp, sizeof(short), FRAME_SIZE, fout);
54 first = 0;
55 }
56 rnnoise_destroy(st);
57 fclose(f1);
58 fclose(fout);
59 return 0;
60 }
61