test_iSACfixfloat.c revision a6451827d543eb00824bc95097e47d0aac51ae93
1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11/*
12 * test_iSACfixfloat.c
13 *
14 * Test compatibility and quality between floating- and fixed-point code
15 * */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21/* include API */
22#include "isac.h"
23#include "isacfix.h"
24
25
26/* max number of samples per frame (= 60 ms frame) */
27#define MAX_FRAMESAMPLES				960
28/* number of samples per 10ms frame */
29#define FRAMESAMPLES_10ms				160
30/* sampling frequency (Hz) */
31#define FS								16000
32
33
34
35/* Runtime statistics */
36#include <time.h>
37#define CLOCKS_PER_SEC  1000
38
39
40
41//	FILE *histfile, *ratefile;
42
43
44/* function for reading audio data from PCM file */
45int readframe(WebRtc_Word16 *data, FILE *inp, int length) {
46
47	short k, rlen, status = 0;
48
49	rlen = fread(data, sizeof(WebRtc_Word16), length, inp);
50	if (rlen < length) {
51		for (k = rlen; k < length; k++)
52			data[k] = 0;
53		status = 1;
54	}
55
56	return status;
57}
58
59typedef struct {
60	WebRtc_UWord32 send_time;            /* samples */
61	WebRtc_UWord32 arrival_time;            /* samples */
62	WebRtc_UWord32 sample_count;            /* samples */
63	WebRtc_UWord16 rtp_number;
64} BottleNeckModel;
65
66void get_arrival_time(int current_framesamples,   /* samples */
67					  int packet_size,            /* bytes */
68					  int bottleneck,             /* excluding headers; bits/s */
69					  BottleNeckModel *BN_data)
70{
71	const int HeaderSize = 35;
72	int HeaderRate;
73
74	HeaderRate = HeaderSize * 8 * FS / current_framesamples;     /* bits/s */
75
76	/* everything in samples */
77	BN_data->sample_count = BN_data->sample_count + current_framesamples;
78
79	BN_data->arrival_time += ((packet_size + HeaderSize) * 8 * FS) / (bottleneck + HeaderRate);
80	BN_data->send_time += current_framesamples;
81
82	if (BN_data->arrival_time < BN_data->sample_count)
83		BN_data->arrival_time = BN_data->sample_count;
84
85	BN_data->rtp_number++;
86}
87
88
89
90int main(int argc, char* argv[])
91{
92
93	char inname[50], outname[50], bottleneck_file[50], bitfilename[60], bitending[10]="_bits.pcm";
94	FILE *inp, *outp, *f_bn, *bitsp;
95	int framecnt, endfile;
96
97
98	int i,j,errtype, plc=0;
99	WebRtc_Word16 CodingMode;
100	WebRtc_Word16 bottleneck;
101
102	WebRtc_Word16 framesize = 30;           /* ms */
103    //WebRtc_Word16 framesize = 60; /* To invoke cisco complexity case at frame 2252 */
104
105	int cur_framesmpls, err;
106
107	/* Runtime statistics */
108	double starttime;
109	double runtime;
110	double length_file;
111
112	WebRtc_Word16 stream_len = 0;
113	WebRtc_Word16 declen;
114
115	WebRtc_Word16 shortdata[FRAMESAMPLES_10ms];
116	WebRtc_Word16 decoded[MAX_FRAMESAMPLES];
117	WebRtc_UWord16 streamdata[600];
118	WebRtc_Word16	speechType[1];
119
120//	WebRtc_Word16	*iSACstruct;
121
122	char version_number[20];
123	int mode=-1, tmp, nbTest=0; /*,sss;*/
124
125#ifdef _DEBUG
126	FILE *fy;
127	double kbps;
128	int totalbits =0;
129	int totalsmpls =0;
130#endif /* _DEBUG */
131
132
133
134
135	/* only one structure used for ISAC encoder */
136	ISAC_MainStruct *ISAC_main_inst;
137	ISACFIX_MainStruct *ISACFIX_main_inst;
138
139	BottleNeckModel       BN_data;
140	f_bn  = NULL;
141
142#ifdef _DEBUG
143	fy = fopen("bit_rate.dat", "w");
144	fclose(fy);
145	fy = fopen("bytes_frames.dat", "w");
146	fclose(fy);
147#endif /* _DEBUG */
148
149
150//histfile = fopen("histo.dat", "ab");
151//ratefile = fopen("rates.dat", "ab");
152
153	/* handling wrong input arguments in the command line */
154	if ((argc<6) || (argc>10))  {
155		printf("\n\nWrong number of arguments or flag values.\n\n");
156
157		printf("\n");
158		WebRtcIsacfix_version(version_number);
159		printf("iSAC version %s \n\n", version_number);
160
161		printf("Usage:\n\n");
162		printf("./kenny.exe [-I] bottleneck_value infile outfile \n\n");
163		printf("with:\n");
164
165		printf("[-I]			:	if -I option is specified, the coder will use\n");
166		printf("				an instantaneous Bottleneck value. If not, it\n");
167		printf("				will be an adaptive Bottleneck value.\n\n");
168		printf("bottleneck_value	:	the value of the bottleneck provided either\n");
169		printf("				as a fixed value (e.g. 25000) or\n");
170		printf("				read from a file (e.g. bottleneck.txt)\n\n");
171		printf("[-m] mode		: Mode (encoder - decoder):\n");
172		printf("				:		0 - float - float \n");
173		printf("				:		1 - float - fix \n");
174		printf("				:		2 - fix - float \n");
175		printf("				:		3 - fix - fix \n");
176		printf("[-PLC]	 		:	Test PLC packetlosses\n");
177		printf("[-NB] num		:	Test NB interfaces, num=1 encNB, num=2 decNB\n");
178		printf("infile			:	Normal speech input file\n\n");
179		printf("outfile			:	Speech output file\n\n");
180		printf("Example usage:\n\n");
181		printf("./kenny.exe -I bottleneck.txt -m 1 speechIn.pcm speechOut.pcm\n\n");
182		exit(0);
183
184	}
185
186
187	printf("--------------------START---------------------\n\n");
188	WebRtcIsac_version(version_number);
189	printf("iSAC FLOAT version %s \n", version_number);
190	WebRtcIsacfix_version(version_number);
191	printf("iSAC FIX version   %s \n\n", version_number);
192
193	CodingMode = 0;
194	tmp=1;
195	for (i = 1; i < argc;i++)
196	{
197		if (!strcmp ("-I", argv[i]))
198		{
199			printf("\nInstantaneous BottleNeck\n");
200			CodingMode = 1;
201			i++;
202			tmp=0;
203		}
204
205		if (!strcmp ("-m", argv[i])) {
206			mode=atoi(argv[i+1]);
207			i++;
208		}
209
210		if (!strcmp ("-PLC", argv[i]))
211		{
212			plc=1;
213		}
214
215		if (!strcmp ("-NB", argv[i]))
216		{
217			nbTest = atoi(argv[i + 1]);
218			i++;
219		}
220
221	}
222
223	if(mode<0) {
224		printf("\nError! Mode must be set: -m 0 \n");
225		exit(0);
226	}
227
228	if (CodingMode == 0)
229	{
230		printf("\nAdaptive BottleNeck\n");
231	}
232
233
234
235	/* Get Bottleneck value */
236	bottleneck = atoi(argv[2-tmp]);
237	if (bottleneck == 0)
238	{
239		sscanf(argv[2-tmp], "%s", bottleneck_file);
240		f_bn = fopen(bottleneck_file, "rb");
241		if (f_bn  == NULL)
242		{
243			printf("No value provided for BottleNeck and cannot read file %s.\n", bottleneck_file);
244			exit(0);
245		}
246		else {
247			printf("reading bottleneck rates from file %s\n\n",bottleneck_file);
248			if (fscanf(f_bn, "%d", &bottleneck) == EOF) {
249					/* Set pointer to beginning of file */
250					fseek(f_bn, 0L, SEEK_SET);
251					fscanf(f_bn, "%d", &bottleneck);
252			}
253
254			/*	Bottleneck is a cosine function
255			*	Matlab code for writing the bottleneck file:
256			*	BottleNeck_10ms = 20e3 + 10e3 * cos((0:5999)/5999*2*pi);
257			*	fid = fopen('bottleneck.txt', 'wb');
258			*	fprintf(fid, '%d\n', BottleNeck_10ms); fclose(fid);
259			*/
260		}
261	}
262	else
263	{
264		printf("\nfixed bottleneck rate of %d bits/s\n\n", bottleneck);
265	}
266
267
268
269	/* Get Input and Output files */
270	sscanf(argv[argc-2], "%s", inname);
271	sscanf(argv[argc-1], "%s", outname);
272
273	if ((inp = fopen(inname,"rb")) == NULL) {
274		printf("  iSAC: Cannot read file %s.\n", inname);
275		exit(1);
276	}
277	if ((outp = fopen(outname,"wb")) == NULL) {
278		printf("  iSAC: Cannot write file %s.\n", outname);
279		exit(1);
280	}
281	printf("\nInput:%s\nOutput:%s\n", inname, outname);
282
283	i=0;
284	while (outname[i]!='\0') {
285		bitfilename[i]=outname[i];
286		i++;
287	}
288	i-=4;
289	for (j=0;j<9;j++, i++)
290		bitfilename[i]=bitending[j];
291	bitfilename[i]='\0';
292	if ((bitsp = fopen(bitfilename,"wb")) == NULL) {
293		printf("  iSAC: Cannot read file %s.\n", bitfilename);
294		exit(1);
295	}
296	printf("Bitstream:%s\n\n", bitfilename);
297
298
299
300	starttime = clock()/(double)CLOCKS_PER_SEC; /* Runtime statistics */
301
302
303	/* Initialize the ISAC and BN structs */
304	WebRtcIsac_create(&ISAC_main_inst);
305/*	WebRtcIsacfix_AssignSize(&sss);
306	iSACstruct=malloc(sss);
307	WebRtcIsacfix_Assign(&ISACFIX_main_inst,iSACstruct);*/
308	WebRtcIsacfix_Create(&ISACFIX_main_inst);
309
310	BN_data.send_time	  = 0;
311	BN_data.arrival_time  = 0;
312	BN_data.sample_count  = 0;
313	BN_data.rtp_number    = 0;
314
315	/* Initialize encoder and decoder */
316    framecnt= 0;
317    endfile	= 0;
318
319	if (mode==0) { /* Encode using FLOAT, decode using FLOAT */
320
321		printf("Coding mode: Encode using FLOAT, decode using FLOAT \n\n");
322
323		/* Init iSAC FLOAT */
324		WebRtcIsac_EncoderInit(ISAC_main_inst, CodingMode);
325		WebRtcIsac_DecoderInit(ISAC_main_inst);
326		if (CodingMode == 1) {
327			err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
328			if (err < 0) {
329				/* exit if returned with error */
330				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
331				printf("\n\n Error in initialization: %d.\n\n", errtype);
332			//	exit(EXIT_FAILURE);
333			}
334		}
335
336	} else if (mode==1) { /* Encode using FLOAT, decode using FIX */
337
338		printf("Coding mode: Encode using FLOAT, decode using FIX \n\n");
339
340		/* Init iSAC FLOAT */
341		WebRtcIsac_EncoderInit(ISAC_main_inst, CodingMode);
342		WebRtcIsac_DecoderInit(ISAC_main_inst);
343		if (CodingMode == 1) {
344			err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
345			if (err < 0) {
346				/* exit if returned with error */
347				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
348				printf("\n\n Error in initialization: %d.\n\n", errtype);
349			//	exit(EXIT_FAILURE);
350			}
351		}
352
353		/* Init iSAC FIX */
354		WebRtcIsacfix_EncoderInit(ISACFIX_main_inst, CodingMode);
355		WebRtcIsacfix_DecoderInit(ISACFIX_main_inst);
356		if (CodingMode == 1) {
357			err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
358			if (err < 0) {
359				/* exit if returned with error */
360				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
361				printf("\n\n Error in initialization: %d.\n\n", errtype);
362				//exit(EXIT_FAILURE);
363			}
364		}
365	} else if (mode==2) { /* Encode using FIX, decode using FLOAT */
366
367		printf("Coding mode: Encode using FIX, decode using FLOAT \n\n");
368
369		/* Init iSAC FLOAT */
370		WebRtcIsac_EncoderInit(ISAC_main_inst, CodingMode);
371		WebRtcIsac_DecoderInit(ISAC_main_inst);
372		if (CodingMode == 1) {
373			err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
374			if (err < 0) {
375				/* exit if returned with error */
376				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
377				printf("\n\n Error in initialization: %d.\n\n", errtype);
378				//exit(EXIT_FAILURE);
379			}
380		}
381
382		/* Init iSAC FIX */
383		WebRtcIsacfix_EncoderInit(ISACFIX_main_inst, CodingMode);
384		WebRtcIsacfix_DecoderInit(ISACFIX_main_inst);
385		if (CodingMode == 1) {
386			err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
387			if (err < 0) {
388				/* exit if returned with error */
389				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
390				printf("\n\n Error in initialization: %d.\n\n", errtype);
391				//exit(EXIT_FAILURE);
392			}
393		}
394	} else if (mode==3) {
395
396		printf("Coding mode: Encode using FIX, decode using FIX \n\n");
397
398		WebRtcIsacfix_EncoderInit(ISACFIX_main_inst, CodingMode);
399		WebRtcIsacfix_DecoderInit(ISACFIX_main_inst);
400		if (CodingMode == 1) {
401			err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
402			if (err < 0) {
403				/* exit if returned with error */
404				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
405				printf("\n\n Error in initialization: %d.\n\n", errtype);
406				//exit(EXIT_FAILURE);
407			}
408		}
409
410	} else
411		printf("Mode must be value between 0 and 3\n");
412	*speechType = 1;
413
414//#define BI_TEST 1
415#ifdef BI_TEST
416    err = WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_main_inst, 300);
417    if (err < 0) {
418            /* exit if returned with error */
419            errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
420            printf("\n\n Error in setMaxPayloadSize: %d.\n\n", errtype);
421            fclose(inp);
422            fclose(outp);
423            fclose(bitsp);
424            return(EXIT_FAILURE);
425    }
426#endif
427
428
429    while (endfile == 0) {
430
431		cur_framesmpls = 0;
432		while (1) {
433			/* Read 10 ms speech block */
434			if (nbTest != 1)
435				endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms);
436			else
437				endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms/2));
438
439			/* iSAC encoding */
440
441			if (mode==0 || mode ==1) {
442				stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata,	streamdata);
443				if (stream_len < 0) {
444					/* exit if returned with error */
445					errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
446					printf("\n\nError in encoder: %d.\n\n", errtype);
447				//	exit(EXIT_FAILURE);
448				}
449			} else if (mode==2 || mode==3) {
450				/* iSAC encoding */
451				if (nbTest != 1)
452					stream_len = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata,	streamdata);
453				else
454					stream_len = WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata);
455
456				if (stream_len < 0) {
457					/* exit if returned with error */
458					errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
459					printf("\n\nError in encoder: %d.\n\n", errtype);
460				//	exit(EXIT_FAILURE);
461				}
462			}
463
464			cur_framesmpls += FRAMESAMPLES_10ms;
465
466			/* read next bottleneck rate */
467			if (f_bn != NULL) {
468				if (fscanf(f_bn, "%d", &bottleneck) == EOF) {
469					/* Set pointer to beginning of file */
470					fseek(f_bn, 0L, SEEK_SET);
471					fscanf(f_bn, "%d", &bottleneck);
472				}
473				if (CodingMode == 1) {
474					if (mode==0 || mode==1)
475					  WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
476					else if	(mode==2 || mode==3)
477						WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
478				}
479			}
480
481			/* exit encoder loop if the encoder returned a bitstream */
482			if (stream_len != 0) break;
483		}
484
485		fwrite(streamdata, 1, stream_len, bitsp); /* NOTE! Writes bytes to file */
486
487		/* simulate packet handling through NetEq and the modem */
488		get_arrival_time(cur_framesmpls, stream_len, bottleneck,
489						 &BN_data);
490//*****************************
491		if (1){
492		if (mode==0) {
493			err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst,
494									  streamdata,
495									  stream_len,
496									  BN_data.rtp_number,
497									  BN_data.arrival_time);
498
499			if (err < 0) {
500				/* exit if returned with error */
501				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
502				printf("\n\nError in decoder: %d.\n\n", errtype);
503				//exit(EXIT_FAILURE);
504			}
505			/* iSAC decoding */
506			declen = WebRtcIsac_Decode(ISAC_main_inst,
507										  streamdata,
508									  	  stream_len,
509										  decoded,
510										  speechType);
511			if (declen <= 0) {
512				/* exit if returned with error */
513				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
514				printf("\n\nError in decoder: %d.\n\n", errtype);
515				//exit(EXIT_FAILURE);
516			}
517		} else if (mode==1) {
518
519			err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst,
520									  streamdata,
521									  stream_len,
522									  BN_data.rtp_number,
523									  BN_data.arrival_time);
524			err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst,
525									  streamdata,
526									  stream_len,
527									  BN_data.rtp_number,
528									  BN_data.arrival_time);
529			if (err < 0) {
530				/* exit if returned with error */
531				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
532				printf("\n\nError in decoder: %d.\n\n", errtype);
533				//exit(EXIT_FAILURE);
534			}
535
536			declen = WebRtcIsac_Decode(ISAC_main_inst,
537										  streamdata,
538									  	  stream_len,
539										  decoded,
540										  speechType);
541
542			/* iSAC decoding */
543			if (plc && (framecnt+1)%10 == 0) {
544				if (nbTest !=2 )
545					declen = WebRtcIsacfix_DecodePlc( ISACFIX_main_inst, decoded, 1 );
546				else
547					declen = WebRtcIsacfix_DecodePlcNb( ISACFIX_main_inst, decoded, 1 );
548			} else {
549				if (nbTest !=2 )
550					declen = WebRtcIsacfix_Decode(ISACFIX_main_inst,
551												  streamdata,
552											  	  stream_len,
553												  decoded,
554												  speechType);
555				else
556					declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst,
557												  streamdata,
558											  	  stream_len,
559												  decoded,
560												  speechType);
561			}
562
563			if (declen <= 0) {
564				/* exit if returned with error */
565				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
566				printf("\n\nError in decoder: %d.\n\n", errtype);
567				//exit(EXIT_FAILURE);
568			}
569		} else if (mode==2) {
570			err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst,
571									  streamdata,
572									  stream_len,
573									  BN_data.rtp_number,
574									  BN_data.arrival_time);
575
576			err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst,
577									  streamdata,
578									  stream_len,
579									  BN_data.rtp_number,
580									  BN_data.arrival_time);
581
582			if (err < 0) {
583				/* exit if returned with error */
584				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
585				printf("\n\nError in decoder: %d.\n\n", errtype);
586				//exit(EXIT_FAILURE);
587			}
588			/* iSAC decoding */
589			declen = WebRtcIsac_Decode(ISAC_main_inst,
590										  streamdata,
591									  	  stream_len,
592										  decoded,
593										  speechType);
594			if (declen <= 0) {
595				/* exit if returned with error */
596				errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
597				printf("\n\nError in decoder: %d.\n\n", errtype);
598				//exit(EXIT_FAILURE);
599			}
600		}  else if (mode==3) {
601			err = WebRtcIsacfix_UpdateBwEstimate(ISACFIX_main_inst,
602									  streamdata,
603									  stream_len,
604									  BN_data.rtp_number,
605									  BN_data.send_time,
606									  BN_data.arrival_time);
607
608			if (err < 0) {
609				/* exit if returned with error */
610				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
611				printf("\n\nError in decoder: %d.\n\n", errtype);
612				//exit(EXIT_FAILURE);
613			}
614			/* iSAC decoding */
615
616			if (plc && (framecnt+1)%10 == 0) {
617				if (nbTest !=2 )
618					declen = WebRtcIsacfix_DecodePlc( ISACFIX_main_inst, decoded, 1 );
619				else
620					declen = WebRtcIsacfix_DecodePlcNb( ISACFIX_main_inst, decoded, 1 );
621			} else {
622				if (nbTest !=2 )
623					declen = WebRtcIsacfix_Decode(ISACFIX_main_inst,
624												  streamdata,
625											  	  stream_len,
626												  decoded,
627												  speechType);
628				else
629					declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst,
630												  streamdata,
631											  	  stream_len,
632												  decoded,
633												  speechType);
634			}
635			if (declen <= 0) {
636				/* exit if returned with error */
637				errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
638				printf("\n\nError in decoder: %d.\n\n", errtype);
639				//exit(EXIT_FAILURE);
640			}
641		}
642
643		/* Write decoded speech frame to file */
644		fwrite(decoded, sizeof(WebRtc_Word16), declen, outp);
645		}
646
647		fprintf(stderr,"  \rframe = %d", framecnt);
648		framecnt++;
649
650
651
652#ifdef _DEBUG
653
654		totalsmpls += declen;
655		totalbits += 8 * stream_len;
656		kbps = ((double) FS) / ((double) cur_framesmpls) * 8.0 * stream_len / 1000.0;// kbits/s
657		fy = fopen("bit_rate.dat", "a");
658		fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps);
659		fclose(fy);
660
661#endif /* _DEBUG */
662
663	}
664
665#ifdef _DEBUG
666	printf("\n\ntotal bits				= %d bits", totalbits);
667	printf("\nmeasured average bitrate		= %0.3f kbits/s", (double)totalbits *(FS/1000) / totalsmpls);
668	printf("\n");
669#endif /* _DEBUG */
670
671	/* Runtime statistics */
672	runtime = (double)(clock()/(double)CLOCKS_PER_SEC-starttime);
673	length_file = ((double)framecnt*(double)declen/FS);
674	printf("\n\nLength of speech file: %.1f s\n", length_file);
675	printf("Time to run iSAC:      %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file));
676	printf("---------------------END----------------------\n");
677
678	fclose(inp);
679	fclose(outp);
680
681	WebRtcIsac_Free(ISAC_main_inst);
682	WebRtcIsacfix_Free(ISACFIX_main_inst);
683
684
685
686//	fclose(histfile);
687//	fclose(ratefile);
688
689	return 0;
690
691}
692
693
694