17 #include "iLBC_define.h"
18 #include "iLBC_encode.h"
19 #include "iLBC_decode.h"
24 #define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2)
41 float block[BLOCKL_MAX];
46 for (k=0; k<iLBCenc_inst->blockl; k++)
47 block[k] = (
float)data[k];
51 iLBC_encode((
unsigned char *)encoded_data, block, iLBCenc_inst);
54 return (iLBCenc_inst->no_of_bytes);
68 float decblock[BLOCKL_MAX], dtmp;
72 if (mode<0 || mode>1) {
73 printf(
"\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}
77 iLBC_decode(decblock, (
unsigned char *)encoded_data,
86 for (k=0; k<iLBCdec_inst->blockl; k++){
91 else if (dtmp>MAX_SAMPLE)
93 decoded_data[k] = (short) dtmp;
96 return (iLBCdec_inst->blockl);
114 int main(
int argc,
char* argv[])
123 FILE *ifileid,*efileid,*ofileid, *cfileid;
124 short data[BLOCKL_MAX];
125 short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];
129 int packetlosscount = 0;
141 if ((argc!=5) && (argc!=6)) {
143 "\n*-----------------------------------------------*\n");
145 " %s <20,30> input encoded decoded (channel)\n\n",
148 " mode : Frame size for the encoding/decoding\n");
154 " input : Speech for encoder (16-bit pcm file)\n");
156 " encoded : Encoded bit stream\n");
158 " decoded : Decoded speech (16-bit pcm file)\n");
160 " channel : Packet loss pattern, optional (16-bit)\n");
162 " 1 - Packet received correctly\n");
164 " 0 - Packet Lost\n");
166 "*-----------------------------------------------*\n\n");
170 if (mode != 20 && mode != 30) {
171 fprintf(stderr,
"Wrong mode %s, must be 20, or 30\n",
175 if ( (ifileid=fopen(argv[2],
"rb")) == NULL) {
176 fprintf(stderr,
"Cannot open input file %s\n", argv[2]);
178 if ( (efileid=fopen(argv[3],
"wb")) == NULL) {
179 fprintf(stderr,
"Cannot open encoded file %s\n",
181 if ( (ofileid=fopen(argv[4],
"wb")) == NULL) {
182 fprintf(stderr,
"Cannot open decoded file %s\n",
185 if( (cfileid=fopen(argv[5],
"rb")) == NULL) {
186 fprintf(stderr,
"Cannot open channel file %s\n",
201 fprintf(stderr,
"\n");
203 "*---------------------------------------------------*\n");
207 "* iLBC test program *\n");
213 "*---------------------------------------------------*\n");
214 fprintf(stderr,
"\nMode : %2d ms\n", mode);
215 fprintf(stderr,
"Input file : %s\n", argv[2]);
216 fprintf(stderr,
"Encoded file : %s\n", argv[3]);
217 fprintf(stderr,
"Output file : %s\n", argv[4]);
219 fprintf(stderr,
"Channel file : %s\n", argv[5]);
221 fprintf(stderr,
"\n");
225 initEncode(&Enc_Inst, mode);
226 initDecode(&Dec_Inst, mode, 1);
230 starttime=clock()/(float)CLOCKS_PER_SEC;
234 while (fread(data,
sizeof(
short),Enc_Inst.blockl,ifileid)==
245 fprintf(stderr,
"--- Encoding block %i --- ",blockcount);
246 len=encode(&Enc_Inst, encoded_data, data);
247 fprintf(stderr,
"\r");
251 if (fwrite(encoded_data,
sizeof(
unsigned char), len, efileid) != len) {
252 fprintf(stderr,
"Failure in fwritef\n");
257 if (fread(&pli,
sizeof(
short), 1, cfileid)) {
258 if ((pli!=0)&&(pli!=1)) {
259 fprintf(stderr,
"Error in channel file\n");
264 memset(encoded_data, 0,
265 sizeof(
short)*ILBCNOOFWORDS_MAX);
269 fprintf(stderr,
"Error. Channel file too short\n");
278 fprintf(stderr,
"--- Decoding block %i --- ",blockcount);
280 len=decode(&Dec_Inst, decoded_data, encoded_data, pli);
281 fprintf(stderr,
"\r");
285 if (fwrite(decoded_data,
sizeof(
short),len,ofileid) != len) {
286 fprintf(stderr,
"Failure in fwritef\n");
292 runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime);
293 outtime = (float)((
float)blockcount*(float)mode/1000.0);
294 printf(
"\n\nLength of speech file: %.1f s\n", outtime);
295 printf(
"Packet loss : %.1f%%\n",
296 100.0*(
float)packetlosscount/(
float)blockcount);
302 printf(
"Time to run iLBC :");
303 printf(
" %.1f s (%.1f %% of realtime)\n\n", runtime,
304 (100*runtime/outtime));
308 fclose(ifileid); fclose(efileid); fclose(ofileid);
Time-related functions and macros.
int main(int argc, char *argv[])