To remove all calls involving scratch-memory
Review URL: http://webrtc-codereview.appspot.com/129001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@462 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
ac55f7b33c
commit
7f2bbbbefd
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
iLBC Speech Coder ANSI-C Source Code
|
iLBC Speech Coder ANSI-C Source Code
|
||||||
|
|
||||||
iLBC_test.c
|
iLBC_test.c
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
@ -22,7 +22,7 @@
|
|||||||
#include "ilbc.h"
|
#include "ilbc.h"
|
||||||
|
|
||||||
/*---------------------------------------------------------------*
|
/*---------------------------------------------------------------*
|
||||||
* Main program to test iLBC encoding and decoding
|
* Main program to test iLBC encoding and decoding
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* exefile_name.exe <infile> <bytefile> <outfile> <channel>
|
* exefile_name.exe <infile> <bytefile> <outfile> <channel>
|
||||||
@ -38,202 +38,188 @@
|
|||||||
|
|
||||||
#define BLOCKL_MAX 240
|
#define BLOCKL_MAX 240
|
||||||
#define ILBCNOOFWORDS_MAX 25
|
#define ILBCNOOFWORDS_MAX 25
|
||||||
#define ILBCSCRATCHMEMSIZE 2156
|
|
||||||
|
|
||||||
#ifdef __ILBC_WITH_SCRATCHMEM
|
|
||||||
WebRtc_Word16 iLBC_ScratchMem[ILBCSCRATCHMEMSIZE];
|
|
||||||
WebRtc_Word16 size;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
FILE *ifileid,*efileid,*ofileid, *cfileid;
|
FILE *ifileid,*efileid,*ofileid, *cfileid;
|
||||||
WebRtc_Word16 data[BLOCKL_MAX];
|
WebRtc_Word16 data[BLOCKL_MAX];
|
||||||
WebRtc_Word16 encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];
|
WebRtc_Word16 encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];
|
||||||
int len;
|
int len;
|
||||||
short pli, mode;
|
short pli, mode;
|
||||||
int blockcount = 0;
|
int blockcount = 0;
|
||||||
int packetlosscount = 0;
|
int packetlosscount = 0;
|
||||||
int frameLen;
|
int frameLen;
|
||||||
WebRtc_Word16 speechType;
|
WebRtc_Word16 speechType;
|
||||||
iLBC_encinst_t *Enc_Inst;
|
iLBC_encinst_t *Enc_Inst;
|
||||||
iLBC_decinst_t *Dec_Inst;
|
iLBC_decinst_t *Dec_Inst;
|
||||||
|
|
||||||
#ifdef __ILBC_WITH_40BITACC
|
#ifdef __ILBC_WITH_40BITACC
|
||||||
/* Doublecheck that long long exists */
|
/* Doublecheck that long long exists */
|
||||||
if (sizeof(long)>=sizeof(long long)) {
|
if (sizeof(long)>=sizeof(long long)) {
|
||||||
fprintf(stderr, "40-bit simulation is not be supported on this platform\n");
|
fprintf(stderr, "40-bit simulation is not be supported on this platform\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* get arguments and open files */
|
/* get arguments and open files */
|
||||||
|
|
||||||
if ((argc!=5) && (argc!=6)) {
|
if ((argc!=5) && (argc!=6)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\n*-----------------------------------------------*\n");
|
"\n*-----------------------------------------------*\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" %s <20,30> input encoded decoded (channel)\n\n",
|
" %s <20,30> input encoded decoded (channel)\n\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" mode : Frame size for the encoding/decoding\n");
|
" mode : Frame size for the encoding/decoding\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" 20 - 20 ms\n");
|
" 20 - 20 ms\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" 30 - 30 ms\n");
|
" 30 - 30 ms\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" input : Speech for encoder (16-bit pcm file)\n");
|
" input : Speech for encoder (16-bit pcm file)\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" encoded : Encoded bit stream\n");
|
" encoded : Encoded bit stream\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" decoded : Decoded speech (16-bit pcm file)\n");
|
" decoded : Decoded speech (16-bit pcm file)\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" channel : Packet loss pattern, optional (16-bit)\n");
|
" channel : Packet loss pattern, optional (16-bit)\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" 1 - Packet received correctly\n");
|
" 1 - Packet received correctly\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" 0 - Packet Lost\n");
|
" 0 - Packet Lost\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"*-----------------------------------------------*\n\n");
|
"*-----------------------------------------------*\n\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
mode=atoi(argv[1]);
|
mode=atoi(argv[1]);
|
||||||
if (mode != 20 && mode != 30) {
|
if (mode != 20 && mode != 30) {
|
||||||
fprintf(stderr,"Wrong mode %s, must be 20, or 30\n",
|
fprintf(stderr,"Wrong mode %s, must be 20, or 30\n",
|
||||||
argv[1]);
|
argv[1]);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
|
if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
|
||||||
fprintf(stderr,"Cannot open input file %s\n", argv[2]);
|
fprintf(stderr,"Cannot open input file %s\n", argv[2]);
|
||||||
exit(2);}
|
exit(2);}
|
||||||
if ( (efileid=fopen(argv[3],"wb")) == NULL) {
|
if ( (efileid=fopen(argv[3],"wb")) == NULL) {
|
||||||
fprintf(stderr, "Cannot open encoded file file %s\n",
|
fprintf(stderr, "Cannot open encoded file file %s\n",
|
||||||
argv[3]); exit(1);}
|
argv[3]); exit(1);}
|
||||||
if ( (ofileid=fopen(argv[4],"wb")) == NULL) {
|
if ( (ofileid=fopen(argv[4],"wb")) == NULL) {
|
||||||
fprintf(stderr, "Cannot open decoded file %s\n",
|
fprintf(stderr, "Cannot open decoded file %s\n",
|
||||||
argv[4]); exit(1);}
|
argv[4]); exit(1);}
|
||||||
if (argc==6) {
|
if (argc==6) {
|
||||||
if( (cfileid=fopen(argv[5],"rb")) == NULL) {
|
if( (cfileid=fopen(argv[5],"rb")) == NULL) {
|
||||||
fprintf(stderr, "Cannot open channel file %s\n",
|
fprintf(stderr, "Cannot open channel file %s\n",
|
||||||
argv[5]);
|
argv[5]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cfileid=NULL;
|
cfileid=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print info */
|
/* print info */
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"*---------------------------------------------------*\n");
|
"*---------------------------------------------------*\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* iLBC test program *\n");
|
"* iLBC test program *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"*---------------------------------------------------*\n");
|
"*---------------------------------------------------*\n");
|
||||||
fprintf(stderr,"\nMode : %2d ms\n", mode);
|
fprintf(stderr,"\nMode : %2d ms\n", mode);
|
||||||
fprintf(stderr,"Input file : %s\n", argv[2]);
|
fprintf(stderr,"Input file : %s\n", argv[2]);
|
||||||
fprintf(stderr,"Encoded file : %s\n", argv[3]);
|
fprintf(stderr,"Encoded file : %s\n", argv[3]);
|
||||||
fprintf(stderr,"Output file : %s\n", argv[4]);
|
fprintf(stderr,"Output file : %s\n", argv[4]);
|
||||||
if (argc==6) {
|
if (argc==6) {
|
||||||
fprintf(stderr,"Channel file : %s\n", argv[5]);
|
fprintf(stderr,"Channel file : %s\n", argv[5]);
|
||||||
}
|
}
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
|
|
||||||
/* Create structs */
|
/* Create structs */
|
||||||
WebRtcIlbcfix_EncoderCreate(&Enc_Inst);
|
WebRtcIlbcfix_EncoderCreate(&Enc_Inst);
|
||||||
WebRtcIlbcfix_DecoderCreate(&Dec_Inst);
|
WebRtcIlbcfix_DecoderCreate(&Dec_Inst);
|
||||||
|
|
||||||
#ifdef __ILBC_WITH_SCRATCHMEM
|
|
||||||
/* Assign scratch memory. Note that Enc and Dec can use the same area */
|
|
||||||
WebRtcIlbcfix_EncoderAssignScratchMem(Enc_Inst, iLBC_ScratchMem, &size);
|
|
||||||
if (size>ILBCSCRATCHMEMSIZE) { fprintf(stderr,"Error: Scratch not big enough"); exit(0); }
|
|
||||||
WebRtcIlbcfix_DecoderAssignScratchMem(Dec_Inst, iLBC_ScratchMem, &size);
|
|
||||||
if (size>ILBCSCRATCHMEMSIZE) { fprintf(stderr,"Error: Scratch not big enough"); exit(0); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
|
|
||||||
WebRtcIlbcfix_EncoderInit(Enc_Inst, mode);
|
WebRtcIlbcfix_EncoderInit(Enc_Inst, mode);
|
||||||
WebRtcIlbcfix_DecoderInit(Dec_Inst, mode);
|
WebRtcIlbcfix_DecoderInit(Dec_Inst, mode);
|
||||||
frameLen = mode*8;
|
frameLen = mode*8;
|
||||||
|
|
||||||
/* loop over input blocks */
|
/* loop over input blocks */
|
||||||
|
|
||||||
while (((WebRtc_Word16)fread(data,sizeof(WebRtc_Word16),frameLen,ifileid))==
|
while (((WebRtc_Word16)fread(data,sizeof(WebRtc_Word16),frameLen,ifileid))==
|
||||||
frameLen) {
|
frameLen) {
|
||||||
|
|
||||||
blockcount++;
|
|
||||||
|
|
||||||
/* encoding */
|
|
||||||
|
|
||||||
fprintf(stderr, "--- Encoding block %i --- ",blockcount);
|
blockcount++;
|
||||||
len=WebRtcIlbcfix_Encode(Enc_Inst, data, (WebRtc_Word16)frameLen, encoded_data);
|
|
||||||
fprintf(stderr, "\r");
|
|
||||||
|
|
||||||
/* write byte file */
|
/* encoding */
|
||||||
|
|
||||||
fwrite(encoded_data, sizeof(WebRtc_Word16), ((len+1)/sizeof(WebRtc_Word16)), efileid);
|
fprintf(stderr, "--- Encoding block %i --- ",blockcount);
|
||||||
|
len=WebRtcIlbcfix_Encode(Enc_Inst, data, (WebRtc_Word16)frameLen, encoded_data);
|
||||||
|
fprintf(stderr, "\r");
|
||||||
|
|
||||||
/* get channel data if provided */
|
/* write byte file */
|
||||||
if (argc==6) {
|
|
||||||
if (fread(&pli, sizeof(WebRtc_Word16), 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(WebRtc_Word16)*ILBCNOOFWORDS_MAX);
|
|
||||||
packetlosscount++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Error. Channel file too short\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pli=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* decoding */
|
|
||||||
|
|
||||||
fprintf(stderr, "--- Decoding block %i --- ",blockcount);
|
fwrite(encoded_data, sizeof(WebRtc_Word16), ((len+1)/sizeof(WebRtc_Word16)), efileid);
|
||||||
if (pli==1) {
|
|
||||||
len=WebRtcIlbcfix_Decode(Dec_Inst, encoded_data,
|
|
||||||
(WebRtc_Word16)len, decoded_data,&speechType);
|
|
||||||
} else {
|
|
||||||
len=WebRtcIlbcfix_DecodePlc(Dec_Inst, decoded_data, 1);
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\r");
|
|
||||||
|
|
||||||
/* write output file */
|
/* get channel data if provided */
|
||||||
|
if (argc==6) {
|
||||||
|
if (fread(&pli, sizeof(WebRtc_Word16), 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(WebRtc_Word16)*ILBCNOOFWORDS_MAX);
|
||||||
|
packetlosscount++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Error. Channel file too short\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pli=1;
|
||||||
|
}
|
||||||
|
|
||||||
fwrite(decoded_data,sizeof(WebRtc_Word16),len,ofileid);
|
/* decoding */
|
||||||
}
|
|
||||||
|
|
||||||
/* close files */
|
|
||||||
|
|
||||||
fclose(ifileid); fclose(efileid); fclose(ofileid);
|
fprintf(stderr, "--- Decoding block %i --- ",blockcount);
|
||||||
if (argc==6) {
|
if (pli==1) {
|
||||||
fclose(cfileid);
|
len=WebRtcIlbcfix_Decode(Dec_Inst, encoded_data,
|
||||||
}
|
(WebRtc_Word16)len, decoded_data,&speechType);
|
||||||
|
} else {
|
||||||
|
len=WebRtcIlbcfix_DecodePlc(Dec_Inst, decoded_data, 1);
|
||||||
|
}
|
||||||
|
fprintf(stderr, "\r");
|
||||||
|
|
||||||
/* Free structs */
|
/* write output file */
|
||||||
WebRtcIlbcfix_EncoderFree(Enc_Inst);
|
|
||||||
WebRtcIlbcfix_DecoderFree(Dec_Inst);
|
|
||||||
|
|
||||||
|
fwrite(decoded_data,sizeof(WebRtc_Word16),len,ofileid);
|
||||||
printf("\nDone with simulation\n\n");
|
}
|
||||||
|
|
||||||
return(0);
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
iLBC Speech Coder ANSI-C Source Code
|
iLBC Speech Coder ANSI-C Source Code
|
||||||
|
|
||||||
iLBC_test.c
|
iLBC_test.c
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
@ -36,47 +36,47 @@
|
|||||||
/* #define CLOCKS_PER_SEC 1000 */
|
/* #define CLOCKS_PER_SEC 1000 */
|
||||||
|
|
||||||
/*----------------------------------------------------------------*
|
/*----------------------------------------------------------------*
|
||||||
* Encoder interface function
|
* Encoder interface function
|
||||||
*---------------------------------------------------------------*/
|
*---------------------------------------------------------------*/
|
||||||
|
|
||||||
short encode( /* (o) Number of bytes encoded */
|
short encode( /* (o) Number of bytes encoded */
|
||||||
iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
|
iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
|
||||||
WebRtc_Word16 *encoded_data, /* (o) The encoded bytes */
|
WebRtc_Word16 *encoded_data, /* (o) The encoded bytes */
|
||||||
WebRtc_Word16 *data /* (i) The signal block to encode */
|
WebRtc_Word16 *data /* (i) The signal block to encode */
|
||||||
){
|
){
|
||||||
|
|
||||||
/* do the actual encoding */
|
/* do the actual encoding */
|
||||||
WebRtcIlbcfix_Encode((WebRtc_UWord16 *)encoded_data, data, iLBCenc_inst);
|
WebRtcIlbcfix_Encode((WebRtc_UWord16 *)encoded_data, data, iLBCenc_inst);
|
||||||
|
|
||||||
return (iLBCenc_inst->no_of_bytes);
|
return (iLBCenc_inst->no_of_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------*
|
/*----------------------------------------------------------------*
|
||||||
* Decoder interface function
|
* Decoder interface function
|
||||||
*---------------------------------------------------------------*/
|
*---------------------------------------------------------------*/
|
||||||
|
|
||||||
short decode( /* (o) Number of decoded samples */
|
short decode( /* (o) Number of decoded samples */
|
||||||
iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
|
iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
|
||||||
short *decoded_data, /* (o) Decoded signal block */
|
short *decoded_data, /* (o) Decoded signal block */
|
||||||
short *encoded_data, /* (i) Encoded bytes */
|
short *encoded_data, /* (i) Encoded bytes */
|
||||||
short mode /* (i) 0=PL, 1=Normal */
|
short mode /* (i) 0=PL, 1=Normal */
|
||||||
){
|
){
|
||||||
|
|
||||||
/* check if mode is valid */
|
/* check if mode is valid */
|
||||||
|
|
||||||
if (mode<0 || mode>1) {
|
if (mode<0 || mode>1) {
|
||||||
printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}
|
printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}
|
||||||
|
|
||||||
/* do actual decoding of block */
|
/* do actual decoding of block */
|
||||||
|
|
||||||
WebRtcIlbcfix_Decode(decoded_data, (WebRtc_UWord16 *)encoded_data,
|
WebRtcIlbcfix_Decode(decoded_data, (WebRtc_UWord16 *)encoded_data,
|
||||||
iLBCdec_inst, mode);
|
iLBCdec_inst, mode);
|
||||||
|
|
||||||
return (iLBCdec_inst->blockl);
|
return (iLBCdec_inst->blockl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------*
|
/*----------------------------------------------------------------*
|
||||||
* Main program to test iLBC encoding and decoding
|
* Main program to test iLBC encoding and decoding
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* exefile_name.exe <infile> <bytefile> <outfile> <channelfile>
|
* exefile_name.exe <infile> <bytefile> <outfile> <channelfile>
|
||||||
@ -89,260 +89,255 @@ short decode( /* (o) Number of decoded samples */
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Runtime statistics */
|
/* Runtime statistics */
|
||||||
|
|
||||||
float starttime1, starttime2;
|
float starttime1, starttime2;
|
||||||
float runtime1, runtime2;
|
float runtime1, runtime2;
|
||||||
float outtime;
|
float outtime;
|
||||||
|
|
||||||
FILE *ifileid,*efileid,*ofileid, *chfileid;
|
FILE *ifileid,*efileid,*ofileid, *chfileid;
|
||||||
short *inputdata, *encodeddata, *decodeddata;
|
short *inputdata, *encodeddata, *decodeddata;
|
||||||
short *channeldata;
|
short *channeldata;
|
||||||
int blockcount = 0, noOfBlocks=0, i, noOfLostBlocks=0;
|
int blockcount = 0, noOfBlocks=0, i, noOfLostBlocks=0;
|
||||||
short mode;
|
short mode;
|
||||||
iLBC_Enc_Inst_t Enc_Inst;
|
iLBC_Enc_Inst_t Enc_Inst;
|
||||||
iLBC_Dec_Inst_t Dec_Inst;
|
iLBC_Dec_Inst_t Dec_Inst;
|
||||||
|
|
||||||
short frameLen;
|
short frameLen;
|
||||||
short count;
|
short count;
|
||||||
#ifdef SPLIT_10MS
|
#ifdef SPLIT_10MS
|
||||||
short size;
|
short size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inputdata=(short*) malloc(MAXFILELEN*sizeof(short));
|
inputdata=(short*) malloc(MAXFILELEN*sizeof(short));
|
||||||
if (inputdata==NULL) {
|
if (inputdata==NULL) {
|
||||||
fprintf(stderr,"Could not allocate memory for vector\n");
|
fprintf(stderr,"Could not allocate memory for vector\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
encodeddata=(short*) malloc(ILBCNOOFWORDS_MAX*MAXFRAMES*sizeof(short));
|
encodeddata=(short*) malloc(ILBCNOOFWORDS_MAX*MAXFRAMES*sizeof(short));
|
||||||
if (encodeddata==NULL) {
|
if (encodeddata==NULL) {
|
||||||
fprintf(stderr,"Could not allocate memory for vector\n");
|
fprintf(stderr,"Could not allocate memory for vector\n");
|
||||||
free(inputdata);
|
free(inputdata);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
decodeddata=(short*) malloc(MAXFILELEN*sizeof(short));
|
decodeddata=(short*) malloc(MAXFILELEN*sizeof(short));
|
||||||
if (decodeddata==NULL) {
|
if (decodeddata==NULL) {
|
||||||
fprintf(stderr,"Could not allocate memory for vector\n");
|
fprintf(stderr,"Could not allocate memory for vector\n");
|
||||||
free(inputdata);
|
free(inputdata);
|
||||||
free(encodeddata);
|
free(encodeddata);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
channeldata=(short*) malloc(MAXFRAMES*sizeof(short));
|
channeldata=(short*) malloc(MAXFRAMES*sizeof(short));
|
||||||
if (channeldata==NULL) {
|
if (channeldata==NULL) {
|
||||||
fprintf(stderr,"Could not allocate memory for vector\n");
|
fprintf(stderr,"Could not allocate memory for vector\n");
|
||||||
free(inputdata);
|
free(inputdata);
|
||||||
free(encodeddata);
|
free(encodeddata);
|
||||||
free(decodeddata);
|
free(decodeddata);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get arguments and open files */
|
/* get arguments and open files */
|
||||||
|
|
||||||
if (argc != 6 ) {
|
if (argc != 6 ) {
|
||||||
fprintf(stderr, "%s mode inputfile bytefile outputfile channelfile\n",
|
fprintf(stderr, "%s mode inputfile bytefile outputfile channelfile\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
fprintf(stderr, "Example:\n");
|
fprintf(stderr, "Example:\n");
|
||||||
fprintf(stderr, "%s <30,20> in.pcm byte.dat out.pcm T30.0.dat\n", argv[0]);
|
fprintf(stderr, "%s <30,20> in.pcm byte.dat out.pcm T30.0.dat\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
mode=atoi(argv[1]);
|
mode=atoi(argv[1]);
|
||||||
if (mode != 20 && mode != 30) {
|
if (mode != 20 && mode != 30) {
|
||||||
fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", argv[1]);
|
fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", argv[1]);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
|
if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
|
||||||
fprintf(stderr,"Cannot open input file %s\n", argv[2]);
|
fprintf(stderr,"Cannot open input file %s\n", argv[2]);
|
||||||
exit(2);}
|
exit(2);}
|
||||||
if ( (efileid=fopen(argv[3],"wb")) == NULL) {
|
if ( (efileid=fopen(argv[3],"wb")) == NULL) {
|
||||||
fprintf(stderr, "Cannot open channelfile file %s\n",
|
fprintf(stderr, "Cannot open channelfile file %s\n",
|
||||||
argv[3]); exit(3);}
|
argv[3]); exit(3);}
|
||||||
if( (ofileid=fopen(argv[4],"wb")) == NULL) {
|
if( (ofileid=fopen(argv[4],"wb")) == NULL) {
|
||||||
fprintf(stderr, "Cannot open output file %s\n",
|
fprintf(stderr, "Cannot open output file %s\n",
|
||||||
argv[4]); exit(3);}
|
argv[4]); exit(3);}
|
||||||
if ( (chfileid=fopen(argv[5],"rb")) == NULL) {
|
if ( (chfileid=fopen(argv[5],"rb")) == NULL) {
|
||||||
fprintf(stderr,"Cannot open channel file file %s\n", argv[5]);
|
fprintf(stderr,"Cannot open channel file file %s\n", argv[5]);
|
||||||
exit(2);}
|
exit(2);}
|
||||||
|
|
||||||
|
|
||||||
/* print info */
|
/* print info */
|
||||||
#ifndef PRINT_MIPS
|
#ifndef PRINT_MIPS
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"*---------------------------------------------------*\n");
|
"*---------------------------------------------------*\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* iLBCtest *\n");
|
"* iLBCtest *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"* *\n");
|
"* *\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"*---------------------------------------------------*\n");
|
"*---------------------------------------------------*\n");
|
||||||
#ifdef SPLIT_10MS
|
#ifdef SPLIT_10MS
|
||||||
fprintf(stderr,"\n10ms split with raw mode: %2d ms\n", mode);
|
fprintf(stderr,"\n10ms split with raw mode: %2d ms\n", mode);
|
||||||
#else
|
#else
|
||||||
fprintf(stderr,"\nMode : %2d ms\n", mode);
|
fprintf(stderr,"\nMode : %2d ms\n", mode);
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr,"\nInput file : %s\n", argv[2]);
|
fprintf(stderr,"\nInput file : %s\n", argv[2]);
|
||||||
fprintf(stderr,"Coded file : %s\n", argv[3]);
|
fprintf(stderr,"Coded file : %s\n", argv[3]);
|
||||||
fprintf(stderr,"Output file : %s\n\n", argv[4]);
|
fprintf(stderr,"Output file : %s\n\n", argv[4]);
|
||||||
fprintf(stderr,"Channel file : %s\n\n", argv[5]);
|
fprintf(stderr,"Channel file : %s\n\n", argv[5]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialization */
|
/* Initialization */
|
||||||
|
|
||||||
WebRtcIlbcfix_EncoderInit(&Enc_Inst, mode);
|
WebRtcIlbcfix_EncoderInit(&Enc_Inst, mode);
|
||||||
WebRtcIlbcfix_DecoderInit(&Dec_Inst, mode, 1);
|
WebRtcIlbcfix_DecoderInit(&Dec_Inst, mode, 1);
|
||||||
|
|
||||||
#if __ILBC_WITH_SCRATCHMEM
|
/* extract the input file and channel file */
|
||||||
// we can use the same scratch space for both encoder and decoder.
|
|
||||||
WebRtcIlbcfix_EncoderAssignScratchMem((iLBC_encinst_t*)&Enc_Inst, scratchBlock, &size);
|
|
||||||
WebRtcIlbcfix_DecoderAssignScratchMem((iLBC_decinst_t*)&Dec_Inst, scratchBlock, &size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* extract the input file and channel file */
|
|
||||||
|
|
||||||
#ifdef SPLIT_10MS
|
#ifdef SPLIT_10MS
|
||||||
frameLen = (mode==20)? 80:160;
|
frameLen = (mode==20)? 80:160;
|
||||||
fread(Enc_Inst.past_samples, sizeof(short), frameLen, ifileid);
|
fread(Enc_Inst.past_samples, sizeof(short), frameLen, ifileid);
|
||||||
Enc_Inst.section = 0;
|
Enc_Inst.section = 0;
|
||||||
|
|
||||||
while( fread(&inputdata[noOfBlocks*80], sizeof(short),
|
while( fread(&inputdata[noOfBlocks*80], sizeof(short),
|
||||||
80, ifileid) == 80 ) {
|
80, ifileid) == 80 ) {
|
||||||
noOfBlocks++;
|
noOfBlocks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
noOfBlocks += frameLen/80;
|
noOfBlocks += frameLen/80;
|
||||||
frameLen = 80;
|
frameLen = 80;
|
||||||
#else
|
#else
|
||||||
frameLen = Enc_Inst.blockl;
|
frameLen = Enc_Inst.blockl;
|
||||||
|
|
||||||
while( fread(&inputdata[noOfBlocks*Enc_Inst.blockl],sizeof(short),
|
while( fread(&inputdata[noOfBlocks*Enc_Inst.blockl],sizeof(short),
|
||||||
Enc_Inst.blockl,ifileid)==(WebRtc_UWord16)Enc_Inst.blockl){
|
Enc_Inst.blockl,ifileid)==(WebRtc_UWord16)Enc_Inst.blockl){
|
||||||
noOfBlocks++;
|
noOfBlocks++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
while ( (fread(&channeldata[blockcount],sizeof(short), 1,chfileid)==1)
|
|
||||||
&& ( blockcount < noOfBlocks/(Enc_Inst.blockl/frameLen) ) ) {
|
|
||||||
blockcount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( blockcount < noOfBlocks/(Enc_Inst.blockl/frameLen) ) {
|
while ((fread(&channeldata[blockcount],sizeof(short), 1,chfileid)==1)
|
||||||
fprintf(stderr,"Channel file %s is too short\n", argv[4]);
|
&& ( blockcount < noOfBlocks/(Enc_Inst.blockl/frameLen) )) {
|
||||||
free(inputdata);
|
blockcount++;
|
||||||
free(encodeddata);
|
}
|
||||||
free(decodeddata);
|
|
||||||
free(channeldata);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
count=0;
|
if ( blockcount < noOfBlocks/(Enc_Inst.blockl/frameLen) ) {
|
||||||
|
fprintf(stderr,"Channel file %s is too short\n", argv[4]);
|
||||||
|
free(inputdata);
|
||||||
|
free(encodeddata);
|
||||||
|
free(decodeddata);
|
||||||
|
free(channeldata);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Runtime statistics */
|
count=0;
|
||||||
|
|
||||||
starttime1 = clock()/(float)CLOCKS_PER_SEC;
|
/* Runtime statistics */
|
||||||
|
|
||||||
/* Encoding loop */
|
starttime1 = clock()/(float)CLOCKS_PER_SEC;
|
||||||
#ifdef PRINT_MIPS
|
|
||||||
printf("-1 -1\n");
|
/* Encoding loop */
|
||||||
#endif
|
#ifdef PRINT_MIPS
|
||||||
|
printf("-1 -1\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SPLIT_10MS
|
#ifdef SPLIT_10MS
|
||||||
/* "Enc_Inst.section != 0" is to make sure we run through full
|
/* "Enc_Inst.section != 0" is to make sure we run through full
|
||||||
lengths of all vectors for 10ms split mode.
|
lengths of all vectors for 10ms split mode.
|
||||||
*/
|
*/
|
||||||
// while( (count < noOfBlocks) || (Enc_Inst.section != 0) ) {
|
// while( (count < noOfBlocks) || (Enc_Inst.section != 0) ) {
|
||||||
while( count < blockcount * (Enc_Inst.blockl/frameLen) ) {
|
while( count < blockcount * (Enc_Inst.blockl/frameLen) ) {
|
||||||
|
|
||||||
encode(&Enc_Inst, &encodeddata[Enc_Inst.no_of_words *
|
encode(&Enc_Inst, &encodeddata[Enc_Inst.no_of_words *
|
||||||
(count/(Enc_Inst.nsub/2))], &inputdata[frameLen * count] );
|
(count/(Enc_Inst.nsub/2))],
|
||||||
|
&inputdata[frameLen * count] );
|
||||||
#else
|
#else
|
||||||
while (count < noOfBlocks) {
|
while (count < noOfBlocks) {
|
||||||
encode( &Enc_Inst, &encodeddata[Enc_Inst.no_of_words * count],
|
encode( &Enc_Inst, &encodeddata[Enc_Inst.no_of_words * count],
|
||||||
&inputdata[frameLen * count] );
|
&inputdata[frameLen * count] );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PRINT_MIPS
|
#ifdef PRINT_MIPS
|
||||||
printf("-1 -1\n");
|
printf("-1 -1\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
count=0;
|
count=0;
|
||||||
|
|
||||||
/* Runtime statistics */
|
/* Runtime statistics */
|
||||||
|
|
||||||
starttime2=clock()/(float)CLOCKS_PER_SEC;
|
starttime2=clock()/(float)CLOCKS_PER_SEC;
|
||||||
runtime1 = (float)(starttime2-starttime1);
|
runtime1 = (float)(starttime2-starttime1);
|
||||||
|
|
||||||
/* Decoding loop */
|
/* Decoding loop */
|
||||||
|
|
||||||
while (count < blockcount) {
|
while (count < blockcount) {
|
||||||
if (channeldata[count]==1) {
|
if (channeldata[count]==1) {
|
||||||
/* Normal decoding */
|
/* Normal decoding */
|
||||||
decode(&Dec_Inst, &decodeddata[count * Dec_Inst.blockl],
|
decode(&Dec_Inst, &decodeddata[count * Dec_Inst.blockl],
|
||||||
&encodeddata[Dec_Inst.no_of_words * count], 1);
|
&encodeddata[Dec_Inst.no_of_words * count], 1);
|
||||||
} else if (channeldata[count]==0) {
|
} else if (channeldata[count]==0) {
|
||||||
/* PLC */
|
/* PLC */
|
||||||
short emptydata[ILBCNOOFWORDS_MAX];
|
short emptydata[ILBCNOOFWORDS_MAX];
|
||||||
memset(emptydata, 0, Dec_Inst.no_of_words*sizeof(short));
|
memset(emptydata, 0, Dec_Inst.no_of_words*sizeof(short));
|
||||||
decode(&Dec_Inst, &decodeddata[count*Dec_Inst.blockl],
|
decode(&Dec_Inst, &decodeddata[count*Dec_Inst.blockl],
|
||||||
emptydata, 0);
|
emptydata, 0);
|
||||||
noOfLostBlocks++;
|
noOfLostBlocks++;
|
||||||
} else {
|
} else {
|
||||||
printf("Error in channel file (values have to be either 1 or 0)\n");
|
printf("Error in channel file (values have to be either 1 or 0)\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#ifdef PRINT_MIPS
|
#ifdef PRINT_MIPS
|
||||||
printf("-1 -1\n");
|
printf("-1 -1\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Runtime statistics */
|
/* Runtime statistics */
|
||||||
|
|
||||||
runtime2 = (float)(clock()/(float)CLOCKS_PER_SEC-starttime2);
|
runtime2 = (float)(clock()/(float)CLOCKS_PER_SEC-starttime2);
|
||||||
|
|
||||||
outtime = (float)((float)blockcount*
|
outtime = (float)((float)blockcount*
|
||||||
(float)mode/1000.0);
|
(float)mode/1000.0);
|
||||||
|
|
||||||
#ifndef PRINT_MIPS
|
#ifndef PRINT_MIPS
|
||||||
printf("\nLength of speech file: %.1f s\n", outtime);
|
printf("\nLength of speech file: %.1f s\n", outtime);
|
||||||
printf("Lost frames : %.1f%%\n\n", 100*(float)noOfLostBlocks/(float)blockcount);
|
printf("Lost frames : %.1f%%\n\n", 100*(float)noOfLostBlocks/(float)blockcount);
|
||||||
|
|
||||||
printf("Time to run iLBC_encode+iLBC_decode:");
|
printf("Time to run iLBC_encode+iLBC_decode:");
|
||||||
printf(" %.1f s (%.1f%% of realtime)\n", runtime1+runtime2,
|
printf(" %.1f s (%.1f%% of realtime)\n", runtime1+runtime2,
|
||||||
(100*(runtime1+runtime2)/outtime));
|
(100*(runtime1+runtime2)/outtime));
|
||||||
|
|
||||||
printf("Time in iLBC_encode :");
|
printf("Time in iLBC_encode :");
|
||||||
printf(" %.1f s (%.1f%% of total runtime)\n",
|
printf(" %.1f s (%.1f%% of total runtime)\n",
|
||||||
runtime1, 100.0*runtime1/(runtime1+runtime2));
|
runtime1, 100.0*runtime1/(runtime1+runtime2));
|
||||||
|
|
||||||
printf("Time in iLBC_decode :");
|
printf("Time in iLBC_decode :");
|
||||||
printf(" %.1f s (%.1f%% of total runtime)\n\n",
|
printf(" %.1f s (%.1f%% of total runtime)\n\n",
|
||||||
runtime2, 100.0*runtime2/(runtime1+runtime2));
|
runtime2, 100.0*runtime2/(runtime1+runtime2));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Write data to files */
|
/* Write data to files */
|
||||||
for (i=0; i<blockcount; i++) {
|
for (i=0; i<blockcount; i++) {
|
||||||
fwrite(&encodeddata[i*Enc_Inst.no_of_words], sizeof(short),
|
fwrite(&encodeddata[i*Enc_Inst.no_of_words], sizeof(short),
|
||||||
Enc_Inst.no_of_words, efileid);
|
Enc_Inst.no_of_words, efileid);
|
||||||
}
|
}
|
||||||
for (i=0;i<blockcount;i++) {
|
for (i=0;i<blockcount;i++) {
|
||||||
fwrite(&decodeddata[i*Enc_Inst.blockl],sizeof(short),Enc_Inst.blockl,ofileid);
|
fwrite(&decodeddata[i*Enc_Inst.blockl],sizeof(short),Enc_Inst.blockl,ofileid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return memory and close files */
|
/* return memory and close files */
|
||||||
|
|
||||||
free(inputdata);
|
free(inputdata);
|
||||||
free(encodeddata);
|
free(encodeddata);
|
||||||
free(decodeddata);
|
free(decodeddata);
|
||||||
free(channeldata);
|
free(channeldata);
|
||||||
fclose(ifileid); fclose(efileid); fclose(ofileid);
|
fclose(ifileid); fclose(efileid); fclose(ofileid);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user