1 /*
2  * Copyright (c) 2011-2019 Belledonne Communications SARL.
3  *
4  * This file is part of bcg729.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 /*****************************************************************************/
20 /*                                                                           */
21 /* Test Program for preProcessing Bloc                                       */
22 /*    Input: a CSV text with frame of 80 values of 16 bits PCM on each row   */
23 /*    Ouput: the filtered input, same format                                 */
24 /*                                                                           */
25 /*****************************************************************************/
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 
32 #include "typedef.h"
33 #include "codecParameters.h"
34 
35 #include "testUtils.h"
36 
37 #include "preProcessing.h"
38 
main(int argc,char * argv[])39 int main(int argc, char *argv[] )
40 {
41 	/*** get calling argument ***/
42   	char *filePrefix;
43 	getArgument(argc, argv, &filePrefix); /* check argument and set filePrefix if needed */
44 
45 	/*** input and output file pointers ***/
46 	FILE *fpInput;
47 	FILE *fpOutput;
48 
49 	/*** input and output buffers ***/
50 	word16_t inputBuffer[L_FRAME];
51 	word16_t outputBuffer[L_FRAME];
52 
53 	/*** inits ***/
54 	/* open the input file */
55 	if ( (fpInput = fopen(argv[1], "rb")) == NULL) {
56 		printf("%s - Error: can't open file  %s\n", argv[0], argv[1]);
57 		exit(-1);
58 	}
59 
60 	/* create the output file(filename is the same than input file with the .out extension) */
61 	char *outputFile = malloc((strlen(filePrefix)+5)*sizeof(char));
62 	sprintf(outputFile, "%s.out",filePrefix);
63 	if ( (fpOutput = fopen(outputFile, "wb")) == NULL) {
64 		printf("%s - Error: can't create file  %s\n", argv[0], outputFile);
65 		exit(-1);
66 	}
67 
68 	/*** init of the tested bloc ***/
69 	/* create the context structure */
70 	bcg729EncoderChannelContextStruct *encoderChannelContext = malloc(sizeof(bcg729EncoderChannelContextStruct));
71 
72 	initPreProcessing(encoderChannelContext);
73 
74 	/*** initialisation complete ***/
75 
76 
77 	/*** loop over input file ***/
78 	while(1) /* infinite loop, escape condition is in the reading of data */
79 	{
80 		int i;
81 		/* read the input data until we have some */
82 		if (fscanf(fpInput,"%hd",&(inputBuffer[0])) != 1) break;
83 		for (i=1; i<L_FRAME; i++) {
84 			if (fscanf(fpInput,",%hd",&(inputBuffer[i])) != 1) break;
85 		}
86 
87 		/* call the preProcessing function: output will replace the input in the buffer */
88 		preProcessing(encoderChannelContext, inputBuffer, outputBuffer);
89 
90 		/* write the output to the output file */
91 		fprintf(fpOutput,"%d", outputBuffer[0]);
92 		for (i=1; i<L_FRAME; i++) {
93 			fprintf(fpOutput,",%d", outputBuffer[i]);
94 		}
95 		fprintf(fpOutput,"\n");
96 	}
97 	exit (0);
98 }
99 
100