115   {
  116 
  117       
  118 
  119       float starttime;
  120       float runtime;
  121       float outtime;
  122 
  123       FILE *ifileid,*efileid,*ofileid, *cfileid;
  127       short pli, mode;
  128       int blockcount = 0;
  129       int packetlosscount = 0;
  130 
  131       
  134 
  135 
  136 
  137 
  138 
  139       
  140 
  141       if ((argc!=5) && (argc!=6)) {
  142           fprintf(stderr,
  143           "\n*-----------------------------------------------*\n");
  144           fprintf(stderr,
  145           "   %s <20,30> input encoded decoded (channel)\n\n",
  146               argv[0]);
  147           fprintf(stderr,
  148           "   mode    : Frame size for the encoding/decoding\n");
  149           fprintf(stderr,
  150           "                 20 - 20 ms\n");
  151           fprintf(stderr,
  152           "                 30 - 30 ms\n");
  153           fprintf(stderr,
  154           "   input   : Speech for encoder (16-bit pcm file)\n");
  155           fprintf(stderr,
  156           "   encoded : Encoded bit stream\n");
  157           fprintf(stderr,
  158           "   decoded : Decoded speech (16-bit pcm file)\n");
  159           fprintf(stderr,
  160           "   channel : Packet loss pattern, optional (16-bit)\n");
  161           fprintf(stderr,
  162           "                  1 - Packet received correctly\n");
  163           fprintf(stderr,
  164           "                  0 - Packet Lost\n");
  165           fprintf(stderr,
  166           "*-----------------------------------------------*\n\n");
  167           exit(1);
  168       }
  169       mode=atoi(argv[1]);
  170       if (mode != 20 && mode != 30) {
  171           fprintf(stderr,"Wrong mode %s, must be 20, or 30\n",
  172               argv[1]);
  173           exit(2);
  174       }
  175       if ( (ifileid=fopen(argv[2],
"rb")) == 
NULL) {
 
  176           fprintf(stderr,"Cannot open input file %s\n", argv[2]);
  177           exit(2);}
  178       if ( (efileid=fopen(argv[3],
"wb")) == 
NULL) {
 
  179           fprintf(stderr, "Cannot open encoded file %s\n",
  180               argv[3]); exit(1);}
  181       if ( (ofileid=fopen(argv[4],
"wb")) == 
NULL) {
 
  182           fprintf(stderr, "Cannot open decoded file %s\n",
  183               argv[4]); exit(1);}
  184       if (argc==6) {
  185           if( (cfileid=fopen(argv[5],
"rb")) == 
NULL) {
 
  186               fprintf(stderr, "Cannot open channel file %s\n",
  187 
  188 
  189 
  190 
  191 
  192                   argv[5]);
  193               exit(1);
  194           }
  195       } else {
  197       }
  198 
  199       
  200 
  201       fprintf(stderr, "\n");
  202       fprintf(stderr,
  203           "*---------------------------------------------------*\n");
  204       fprintf(stderr,
  205           "*                                                   *\n");
  206       fprintf(stderr,
  207           "*      iLBC test program                            *\n");
  208       fprintf(stderr,
  209           "*                                                   *\n");
  210       fprintf(stderr,
  211           "*                                                   *\n");
  212       fprintf(stderr,
  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]);
  218       if (argc==6) {
  219           fprintf(stderr,"Channel file   : %s\n", argv[5]);
  220       }
  221       fprintf(stderr,"\n");
  222 
  223       
  224 
  227 
  228       
  229 
  230       starttime=clock()/(float)CLOCKS_PER_SEC;
  231 
  232       
  233 
  234       while (fread(data,
sizeof(
short),Enc_Inst.
blockl,ifileid)==
 
  236 
  237           blockcount++;
  238 
  239           
  240 
  241 
  242 
  243 
  244 
  245           fprintf(stderr, "--- Encoding block %i --- ",blockcount);
  246           len=
encode(&Enc_Inst, encoded_data, data);
 
  247           fprintf(stderr, "\r");
  248 
  249           
  250 
  251           if (fwrite(encoded_data, 
sizeof(
unsigned char), 
len, efileid) != 
len) {
 
  252               fprintf(stderr, "Failure in fwritef\n");
  253           }
  254 
  255           
  256           if (argc==6) {
  257               if (fread(&pli, sizeof(short), 1, cfileid)) {
  258                   if ((pli!=0)&&(pli!=1)) {
  259                       fprintf(stderr, "Error in channel file\n");
  260                       exit(0);
  261                   }
  262                   if (pli==0) {
  263                       
  264                       memset(encoded_data, 0,
  266                       packetlosscount++;
  267                   }
  268               } else {
  269                   fprintf(stderr, "Error. Channel file too short\n");
  270                   exit(0);
  271               }
  272           } else {
  273               pli=1;
  274           }
  275 
  276           
  277 
  278           fprintf(stderr, "--- Decoding block %i --- ",blockcount);
  279 
  280           len=
decode(&Dec_Inst, decoded_data, encoded_data, pli);
 
  281           fprintf(stderr, "\r");
  282 
  283           
  284 
  285           if (fwrite(decoded_data,
sizeof(
short),
len,ofileid) != 
len) {
 
  286               fprintf(stderr, "Failure in fwritef\n");
  287           }
  288       }
  289 
  290       
  291 
  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);
  297 
  298 
  299 
  300 
  301 
  302       printf("Time to run iLBC     :");
  303       printf(" %.1f s (%.1f %% of realtime)\n\n", runtime,
  304           (100*runtime/outtime));
  305 
  306       
  307 
  308       fclose(ifileid);  fclose(efileid); fclose(ofileid);
  309       if (argc==6) {
  310           fclose(cfileid);
  311       }
  312       return(0);
  313   }
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
short initDecode(iLBC_Dec_Inst_t *iLBCdec_inst, int mode, int use_enhancer)
short initEncode(iLBC_Enc_Inst_t *iLBCenc_inst, int mode)
short encode(iLBC_Enc_Inst_t *iLBCenc_inst, short *encoded_data, short *data)
#define ILBCNOOFWORDS_MAX
short decode(iLBC_Dec_Inst_t *iLBCdec_inst, short *decoded_data, short *encoded_data, short mode)