114   int main(
int argc, 
char* argv[])
 
  123       FILE *ifileid,*efileid,*ofileid, *cfileid;
 
  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");
 
  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,
 
  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);