gainQuantizationTest.c 5.07 KB
Newer Older
johan's avatar
johan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/*
 gainQuantizationTest.c

 Copyright (C) 2011 Belledonne Communications, Grenoble, France
 Author : Johan Pascal
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
/*****************************************************************************/
/*                                                                           */
/* Test Program for gainQuantization bloc                                    */
/*    Input:                                                                 */
/*       -(i) targetSignal: 40 values in Q0, x in eq63                       */
/*       -(i) filteredAdaptativeCodebookVector: 40 values in Q0, y in eq63   */
/*       -(i) convolvedFixedCodebookVector: 40 values in Q12, z in eq63      */
/*       -(i) fixedCodebookVector: 40 values in Q13                          */
/*       -(i) xy in Q0 on 64 bits term of eq63 computed previously           */
/*       -(i) yy in Q0 on 64 bits term of eq63 computed previously           */
/*                                                                           */
/*    Ouput:                                                                 */
/*       -(o) quantizedAdaptativeCodebookGain : in Q14                       */
/*       -(o) quantizedFixedCodebookGain : in Q1                             */
/*       -(o) gainCodebookStage1 : GA parameter value (3 bits)               */
/*       -(o) gainCodebookStage2 : GB parameter value (4 bits)               */
/*                                                                           */
/*****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "typedef.h"
#include "codecParameters.h"

#include "testUtils.h"

#include "gainQuantization.h"

int main(int argc, char *argv[] )
{
	/*** get calling argument ***/
  	char *filePrefix;
	getArgument(argc, argv, &filePrefix); /* check argument and set filePrefix if needed */

	/*** input and output file pointers ***/
	FILE *fpInput;
	FILE *fpOutput;

	/*** input and output buffers ***/
	/* inputs : */
	word16_t targetSignal[L_SUBFRAME]; /* Q0 */
	word16_t filteredAdaptativeCodebookVector[L_SUBFRAME]; /* Q0 */
	word16_t convolvedFixedCodebookVector[L_SUBFRAME]; /* Q12 */
	word16_t fixedCodebookVector[L_SUBFRAME]; /* Q13 */
	word64_t xy, yy; /* Q0 */
	/* outputs :   */
	word16_t quantizedAdaptativeCodebookGain, quantizedFixedCodebookGain; /* Q14 */
	uint16_t gainCodebookStage1, gainCodebookStage2;

	/*** inits ***/
	/* open the input file */
	if ( (fpInput = fopen(argv[1], "r")) == NULL) {
		printf("%s - Error: can't open file  %s\n", argv[0], argv[1]);
		exit(-1);
	}

	/* create the output file(filename is the same than input file with the .out extension) */
	char *outputFile = malloc((strlen(filePrefix)+5)*sizeof(char));
	sprintf(outputFile, "%s.out",filePrefix);
	if ( (fpOutput = fopen(outputFile, "w")) == NULL) {
		printf("%s - Error: can't create file  %s\n", argv[0], outputFile);
		exit(-1);
	}
	
	/*** init of the tested bloc ***/
	/* create the context structure */
	bcg729EncoderChannelContextStruct *encoderChannelContext = malloc(sizeof(bcg729EncoderChannelContextStruct));

	initGainQuantization(encoderChannelContext);

	/* initialise buffers */

	/*** initialisation complete ***/


	/*** loop over input file ***/
	while(1) /* infinite loop, escape condition is in the reading of data */
	{
		int i;
		/* read the input data until we have some */
		if (fscanf(fpInput,"%lld,%lld",(long long*)&xy,(long long*) &yy) != 2) break;
		for (i=0; i<L_SUBFRAME; i++) {
			if (fscanf(fpInput,",%hd",&(targetSignal[i])) != 1) break;
		}
		for (i=0; i<L_SUBFRAME; i++) {
			if (fscanf(fpInput,",%hd",&(filteredAdaptativeCodebookVector[i])) != 1) break;
		}
		for (i=0; i<L_SUBFRAME; i++) {
			if (fscanf(fpInput,",%hd",&(convolvedFixedCodebookVector[i])) != 1) break;
		}
		for (i=0; i<L_SUBFRAME; i++) {
			if (fscanf(fpInput,",%hd",&(fixedCodebookVector[i])) != 1) break;
		}
		
		
		/* call the tested funtion */
		gainQuantization(encoderChannelContext, targetSignal, filteredAdaptativeCodebookVector, convolvedFixedCodebookVector, fixedCodebookVector, xy, yy,
			&quantizedAdaptativeCodebookGain, &quantizedFixedCodebookGain, &gainCodebookStage1, &gainCodebookStage2);


		/* write the output to the output file : fixedCodebookParameter, fixedCodebookPulsesSigns, fixedCodebookVector */
		fprintf(fpOutput, "%d,%d,%d,%d\n", quantizedAdaptativeCodebookGain, quantizedFixedCodebookGain, gainCodebookStage1, gainCodebookStage2);
	}
	exit (0);
}