static void reset_encoder_impl() { if(!encoding) { WebRtcIlbcfix_EncoderFree(Enc_Inst); Enc_Inst = NULL; WebRtcNsx_Free(nsxInst); nsxInst = NULL; encoderReset = 0; } else { encoderReset = 1; } }
int main(int argc, char* argv[]) { FILE *ifileid,*efileid,*ofileid, *cfileid; int16_t data[BLOCKL_MAX]; int16_t encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX]; int len; short pli, mode; int blockcount = 0; int packetlosscount = 0; int frameLen; int16_t speechType; iLBC_encinst_t *Enc_Inst; iLBC_decinst_t *Dec_Inst; #ifdef __ILBC_WITH_40BITACC /* Doublecheck that long long exists */ if (sizeof(long)>=sizeof(long long)) { fprintf(stderr, "40-bit simulation is not be supported on this platform\n"); exit(0); } #endif /* get arguments and open files */ if ((argc!=5) && (argc!=6)) { fprintf(stderr, "\n*-----------------------------------------------*\n"); fprintf(stderr, " %s <20,30> input encoded decoded (channel)\n\n", argv[0]); fprintf(stderr, " mode : Frame size for the encoding/decoding\n"); fprintf(stderr, " 20 - 20 ms\n"); fprintf(stderr, " 30 - 30 ms\n"); fprintf(stderr, " input : Speech for encoder (16-bit pcm file)\n"); fprintf(stderr, " encoded : Encoded bit stream\n"); fprintf(stderr, " decoded : Decoded speech (16-bit pcm file)\n"); fprintf(stderr, " channel : Packet loss pattern, optional (16-bit)\n"); fprintf(stderr, " 1 - Packet received correctly\n"); fprintf(stderr, " 0 - Packet Lost\n"); fprintf(stderr, "*-----------------------------------------------*\n\n"); exit(1); } mode=atoi(argv[1]); if (mode != 20 && mode != 30) { fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", argv[1]); exit(2); } if ( (ifileid=fopen(argv[2],"rb")) == NULL) { fprintf(stderr,"Cannot open input file %s\n", argv[2]); exit(2);} if ( (efileid=fopen(argv[3],"wb")) == NULL) { fprintf(stderr, "Cannot open encoded file file %s\n", argv[3]); exit(1);} if ( (ofileid=fopen(argv[4],"wb")) == NULL) { fprintf(stderr, "Cannot open decoded file %s\n", argv[4]); exit(1);} if (argc==6) { if( (cfileid=fopen(argv[5],"rb")) == NULL) { fprintf(stderr, "Cannot open channel file %s\n", argv[5]); exit(1); } } else { cfileid=NULL; } /* print info */ fprintf(stderr, "\n"); fprintf(stderr, "*---------------------------------------------------*\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "* iLBC test program *\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "*---------------------------------------------------*\n"); fprintf(stderr,"\nMode : %2d ms\n", mode); fprintf(stderr,"Input file : %s\n", argv[2]); fprintf(stderr,"Encoded file : %s\n", argv[3]); fprintf(stderr,"Output file : %s\n", argv[4]); if (argc==6) { fprintf(stderr,"Channel file : %s\n", argv[5]); } fprintf(stderr,"\n"); /* Create structs */ WebRtcIlbcfix_EncoderCreate(&Enc_Inst); WebRtcIlbcfix_DecoderCreate(&Dec_Inst); /* Initialization */ WebRtcIlbcfix_EncoderInit(Enc_Inst, mode); WebRtcIlbcfix_DecoderInit(Dec_Inst, mode); frameLen = mode*8; /* loop over input blocks */ while (((int16_t)fread(data,sizeof(int16_t),frameLen,ifileid))== frameLen) { blockcount++; /* encoding */ fprintf(stderr, "--- Encoding block %i --- ",blockcount); len=WebRtcIlbcfix_Encode(Enc_Inst, data, (int16_t)frameLen, encoded_data); fprintf(stderr, "\r"); /* write byte file */ if (fwrite(encoded_data, sizeof(int16_t), ((len+1)/sizeof(int16_t)), efileid) != (size_t)(((len+1)/sizeof(int16_t)))) { return -1; } /* get channel data if provided */ if (argc==6) { if (fread(&pli, sizeof(int16_t), 1, cfileid)) { if ((pli!=0)&&(pli!=1)) { fprintf(stderr, "Error in channel file\n"); exit(0); } if (pli==0) { /* Packet loss -> remove info from frame */ memset(encoded_data, 0, sizeof(int16_t)*ILBCNOOFWORDS_MAX); packetlosscount++; } } else { fprintf(stderr, "Error. Channel file too short\n"); exit(0); } } else { pli=1; } /* decoding */ fprintf(stderr, "--- Decoding block %i --- ",blockcount); if (pli==1) { len=WebRtcIlbcfix_Decode(Dec_Inst, encoded_data, (int16_t)len, decoded_data,&speechType); } else { len=WebRtcIlbcfix_DecodePlc(Dec_Inst, decoded_data, 1); } fprintf(stderr, "\r"); /* write output file */ if (fwrite(decoded_data, sizeof(int16_t), len, ofileid) != (size_t)len) { return -1; } } /* close files */ fclose(ifileid); fclose(efileid); fclose(ofileid); if (argc==6) { fclose(cfileid); } /* Free structs */ WebRtcIlbcfix_EncoderFree(Enc_Inst); WebRtcIlbcfix_DecoderFree(Dec_Inst); printf("\nDone with simulation\n\n"); return(0); }
int main(int argc, char* argv[]) { FILE *ifileid,*efileid,*ofileid, *chfileid; short encoded_data[55], data[240], speechType; short len, mode, pli; int blockcount = 0; iLBC_encinst_t *Enc_Inst; iLBC_decinst_t *Dec_Inst; #ifdef JUNK_DATA int i; FILE *seedfile; unsigned int random_seed = (unsigned int) time(NULL);//1196764538 #endif /* Create structs */ WebRtcIlbcfix_EncoderCreate(&Enc_Inst); WebRtcIlbcfix_DecoderCreate(&Dec_Inst); /* get arguments and open files */ if (argc != 6 ) { fprintf(stderr, "%s mode inputfile bytefile outputfile channelfile\n", argv[0]); fprintf(stderr, "Example:\n"); fprintf(stderr, "%s <30,20> in.pcm byte.dat out.pcm T30.0.dat\n", argv[0]); exit(1); } mode=atoi(argv[1]); if (mode != 20 && mode != 30) { fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", argv[1]); exit(2); } if ( (ifileid=fopen(argv[2],"rb")) == NULL) { fprintf(stderr,"Cannot open input file %s\n", argv[2]); exit(2);} if ( (efileid=fopen(argv[3],"wb")) == NULL) { fprintf(stderr, "Cannot open channelfile file %s\n", argv[3]); exit(3);} if( (ofileid=fopen(argv[4],"wb")) == NULL) { fprintf(stderr, "Cannot open output file %s\n", argv[4]); exit(3);} if ( (chfileid=fopen(argv[5],"rb")) == NULL) { fprintf(stderr,"Cannot open channel file file %s\n", argv[5]); exit(2); } /* print info */ fprintf(stderr, "\n"); fprintf(stderr, "*---------------------------------------------------*\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "* iLBCtest *\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "* *\n"); fprintf(stderr, "*---------------------------------------------------*\n"); #ifdef SPLIT_10MS fprintf(stderr,"\n10ms split with raw mode: %2d ms\n", mode); #else fprintf(stderr,"\nMode : %2d ms\n", mode); #endif fprintf(stderr,"\nInput file : %s\n", argv[2]); fprintf(stderr,"Coded file : %s\n", argv[3]); fprintf(stderr,"Output file : %s\n\n", argv[4]); fprintf(stderr,"Channel file : %s\n\n", argv[5]); #ifdef JUNK_DATA srand(random_seed); if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { fprintf(stderr, "Error: Could not open file %s\n", SEED_FILE); } else { fprintf(seedfile, "%u\n", random_seed); fclose(seedfile); } #endif /* Initialization */ WebRtcIlbcfix_EncoderInit(Enc_Inst, mode); WebRtcIlbcfix_DecoderInit(Dec_Inst, mode); /* loop over input blocks */ #ifdef SPLIT_10MS while(fread(data, sizeof(short), 80, ifileid) == 80) { #else while((short)fread(data,sizeof(short),(mode<<3),ifileid)==(mode<<3)) { #endif blockcount++; /* encoding */ fprintf(stderr, "--- Encoding block %i --- ",blockcount); #ifdef SPLIT_10MS len=WebRtcIlbcfix_Encode(Enc_Inst, data, 80, encoded_data); #else len=WebRtcIlbcfix_Encode(Enc_Inst, data, (short)(mode<<3), encoded_data); #endif fprintf(stderr, "\r"); #ifdef JUNK_DATA for ( i = 0; i < len; i++) { encoded_data[i] = (short) (encoded_data[i] + (short) rand()); } #endif /* write byte file */ if(len != 0){ //len may be 0 in 10ms split case fwrite(encoded_data,1,len,efileid); } if(len != 0){ //len may be 0 in 10ms split case /* get channel data if provided */ if (argc==6) { if (fread(&pli, sizeof(WebRtc_Word16), 1, chfileid)) { if ((pli!=0)&&(pli!=1)) { fprintf(stderr, "Error in channel file\n"); exit(0); } if (pli==0) { /* Packet loss -> remove info from frame */ memset(encoded_data, 0, sizeof(WebRtc_Word16)*25); } } else { fprintf(stderr, "Error. Channel file too short\n"); exit(0); } } else { pli=1; } /* decoding */ fprintf(stderr, "--- Decoding block %i --- ",blockcount); if (pli==1) { len=WebRtcIlbcfix_Decode(Dec_Inst, encoded_data, len, data, &speechType); } else { len=WebRtcIlbcfix_DecodePlc(Dec_Inst, data, 1); } fprintf(stderr, "\r"); /* write output file */ fwrite(data,sizeof(short),len,ofileid); } } #ifdef JUNK_DATA if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { fprintf(stderr, "Error: Could not open file %s\n", SEED_FILE); } else { fprintf(seedfile, "ok\n\n"); fclose(seedfile); } #endif /* free structs */ WebRtcIlbcfix_EncoderFree(Enc_Inst); WebRtcIlbcfix_DecoderFree(Dec_Inst); /* close files */ fclose(ifileid); fclose(efileid); fclose(ofileid); return 0; }