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 computeAdaptativeCodebookGainTest bloc                   */
22 /*    Input: - targetSignal : 40 values                                      */
23 /*           - filtered adaptative codebook vector : 40 values               */
24 /*                                                                           */
25 /*    Ouput: - adaptative codebook gain in Q14                               */
26 /*                                                                           */
27 /*****************************************************************************/
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 
34 #include "typedef.h"
35 #include "codecParameters.h"
36 
37 #include "testUtils.h"
38 
39 #include "computeAdaptativeCodebookGain.h"
40 
main(int argc,char * argv[])41 int main(int argc, char *argv[] )
42 {
43 	/*** get calling argument ***/
44   	char *filePrefix;
45 	getArgument(argc, argv, &filePrefix); /* check argument and set filePrefix if needed */
46 
47 	/*** input and output file pointers ***/
48 	FILE *fpInput;
49 	FILE *fpOutput;
50 
51 	/*** input and output buffers ***/
52 	word16_t targetSignal[L_SUBFRAME];
53 	word16_t filteredAdaptativeCodebookVector[L_SUBFRAME];
54 	/* outputs :   */
55 	word16_t adaptativeCodebookGain;
56 
57 	/* these buffers are part of the output but not of the pattern as they aren't scaled the same way the ITU code does. */
58 	word64_t gainQuantizationXy, gainQuantizationYy; /* used to store in Q0 values reused in gain quantization */
59 
60 	/*** inits ***/
61 	/* open the input file */
62 	if ( (fpInput = fopen(argv[1], "r")) == NULL) {
63 		printf("%s - Error: can't open file  %s\n", argv[0], argv[1]);
64 		exit(-1);
65 	}
66 
67 	/* create the output file(filename is the same than input file with the .out extension) */
68 	char *outputFile = malloc((strlen(filePrefix)+5)*sizeof(char));
69 	sprintf(outputFile, "%s.out",filePrefix);
70 	if ( (fpOutput = fopen(outputFile, "w")) == NULL) {
71 		printf("%s - Error: can't create file  %s\n", argv[0], outputFile);
72 		exit(-1);
73 	}
74 
75 	/*** init of the tested bloc ***/
76 
77 	/* initialise buffers */
78 
79 	/*** initialisation complete ***/
80 
81 
82 	/*** loop over input file ***/
83 	while(1) /* infinite loop, escape condition is in the reading of data */
84 	{
85 		int i;
86 		/* read the input data until we have some */
87 		if (fscanf(fpInput,"%hd",&(filteredAdaptativeCodebookVector[0])) != 1) break;
88 		for (i=1; i<L_SUBFRAME; i++) {
89 			if (fscanf(fpInput,",%hd",&(filteredAdaptativeCodebookVector[i])) != 1) break;
90 		}
91 		for (i=0; i<L_SUBFRAME; i++) {
92 			if (fscanf(fpInput,",%hd",&(targetSignal[i])) != 1) break;
93 		}
94 
95 		/* call the tested funtion */
96 		adaptativeCodebookGain = computeAdaptativeCodebookGain(targetSignal, filteredAdaptativeCodebookVector, &gainQuantizationXy, &gainQuantizationYy);
97 
98 		/* write the output to the output file : adaptativeCodebookGain */
99 		fprintf(fpOutput,"%d\n", adaptativeCodebookGain);
100 	}
101 	exit (0);
102 }
103 
104