diff --git a/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c b/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c index 3aaaf2e7d..1b9c44ca2 100644 --- a/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c +++ b/src/modules/audio_coding/codecs/iSAC/fix/test/kenny.c @@ -137,8 +137,6 @@ int main(int argc, char* argv[]) int cur_delay = 0; char gns_file[100]; - WebRtc_UWord16 rtp_num_init = 0; - int nbTest = 0; WebRtc_Word16 lostFrame; float scale = (float)0.7; @@ -376,7 +374,6 @@ int main(int argc, char* argv[]) /* Set initial RTP number */ if (!strcmp ("-RTP_INIT", argv[i])) { - rtp_num_init = atoi(argv[i + 1]); i++; } } diff --git a/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c b/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c index 0d50f7735..d92ab89f2 100644 --- a/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c +++ b/src/modules/audio_coding/codecs/iSAC/main/test/simpleKenny.c @@ -38,7 +38,6 @@ #define FS_SWB 32000 #define FS_WB 16000 - //#define CHANGE_OUTPUT_NAME #ifdef HAVE_DEBUG_INFO @@ -48,41 +47,36 @@ unsigned long framecnt = 0; - - int main(int argc, char* argv[]) { //--- File IO ---- - FILE* inp; + FILE* inp; FILE* outp; char inname[500]; char outname[500]; /* Runtime statistics */ - double starttime; double rate; double rateRCU; - double rateLB; - double rateUB; unsigned long totalbits = 0; unsigned long totalBitsRCU = 0; unsigned long totalsmpls =0; - + WebRtc_Word32 bottleneck = 39; WebRtc_Word16 frameSize = 30; /* ms */ - WebRtc_Word16 codingMode = 1; + WebRtc_Word16 codingMode = 1; WebRtc_Word16 shortdata[FRAMESAMPLES_SWB_10ms]; WebRtc_Word16 decoded[MAX_FRAMESAMPLES_SWB]; - //WebRtc_UWord16 streamdata[1000]; + //WebRtc_UWord16 streamdata[1000]; WebRtc_Word16 speechType[1]; WebRtc_Word16 payloadLimit; WebRtc_Word32 rateLimit; ISACStruct* ISAC_main_inst; - + WebRtc_Word16 stream_len = 0; WebRtc_Word16 declen; WebRtc_Word16 err; - WebRtc_Word16 cur_framesmpls; + WebRtc_Word16 cur_framesmpls; int endfile; #ifdef WIN32 double length_file; @@ -93,6 +87,9 @@ int main(int argc, char* argv[]) char outSuffix[500]; char bitrateFileName[500]; FILE* bitrateFile; + double starttime; + double rateLB = 0; + double rateUB = 0; #endif FILE* histFile; FILE* averageFile; @@ -120,13 +117,13 @@ int main(int argc, char* argv[]) memset(hist, 0, sizeof(hist)); /* handling wrong input arguments in the command line */ - if(argc < 5) + if(argc < 5) { int size; WebRtcIsac_AssignSize(&size); printf("\n\nWrong number of arguments or flag values.\n\n"); - + printf("Usage:\n\n"); printf("%s infile outfile -bn bottelneck [options] \n\n", argv[0]); printf("with:\n"); @@ -138,7 +135,7 @@ int main(int argc, char* argv[]) printf("OPTIONS\n"); printf("-------\n"); printf("-fs sampFreq......... sampling frequency of codec 16 or 32 (default) kHz.\n"); - printf("-plim payloadLim..... payload limit in bytes,\n"); + printf("-plim payloadLim..... payload limit in bytes,\n"); printf(" default is the maximum possible.\n"); printf("-rlim rateLim........ rate limit in bits/sec, \n"); printf(" default is the maimum possible.\n"); @@ -155,18 +152,18 @@ int main(int argc, char* argv[]) printf("structure size %d bytes\n", size); exit(0); - } - - - + } + + + /* Get Bottleneck value */ bottleneck = readParamInt(argc, argv, "-bn", 50000); fprintf(stderr,"\nfixed bottleneck rate of %d bits/s\n\n", bottleneck); - + /* Get Input and Output files */ sscanf(argv[1], "%s", inname); sscanf(argv[2], "%s", outname); - codingMode = readSwitch(argc, argv, "-I"); + codingMode = readSwitch(argc, argv, "-I"); sampFreqKHz = (WebRtc_Word16)readParamInt(argc, argv, "-fs", 32); if(readParamString(argc, argv, "-h", histFileName, 500) > 0) { @@ -182,7 +179,7 @@ int main(int argc, char* argv[]) // NO recording of hitstogram histFile = NULL; } - + packetLossPercent = readParamInt(argc, argv, "-ploss", 0); @@ -199,7 +196,7 @@ int main(int argc, char* argv[]) { averageFile = NULL; } - + onlyEncode = readSwitch(argc, argv, "-enc"); onlyDecode = readSwitch(argc, argv, "-dec"); @@ -233,7 +230,7 @@ valid values are 8 and 16.\n", sampFreqKHz); exit(1); } -#ifdef WIN32 +#ifdef WIN32 _splitpath(outname, outDrive, outPath, outPrefix, outSuffix); _makepath(bitrateFileName, outDrive, outPath, "bitrate", ".txt"); @@ -244,28 +241,30 @@ valid values are 8 and 16.\n", sampFreqKHz); printf("\n"); printf("Input.................... %s\n", inname); printf("Output................... %s\n", outname); - printf("Encoding Mode............ %s\n", + printf("Encoding Mode............ %s\n", (codingMode == 1)? "Channel-Independent":"Channel-Adaptive"); printf("Bottleneck............... %d bits/sec\n", bottleneck); printf("Packet-loss Percentage... %d\n", packetLossPercent); printf("\n"); - + +#ifdef WIN32 starttime = clock()/(double)CLOCKS_PER_SEC; /* Runtime statistics */ - +#endif + /* Initialize the ISAC and BN structs */ err = WebRtcIsac_Create(&ISAC_main_inst); - WebRtcIsac_SetEncSampRate(ISAC_main_inst, (sampFreqKHz == 16)? kIsacWideband: kIsacSuperWideband); + WebRtcIsac_SetEncSampRate(ISAC_main_inst, (sampFreqKHz == 16)? kIsacWideband: kIsacSuperWideband); WebRtcIsac_SetDecSampRate(ISAC_main_inst, (sampFreqKHz == 16)? kIsacWideband: kIsacSuperWideband); /* Error check */ if (err < 0) { fprintf(stderr,"\n\n Error in create.\n\n"); exit(EXIT_FAILURE); } - + framecnt = 0; endfile = 0; - + /* Initialize encoder and decoder */ if(WebRtcIsac_EncoderInit(ISAC_main_inst, codingMode) < 0) { @@ -277,7 +276,7 @@ valid values are 8 and 16.\n", sampFreqKHz); printf("cannot initialize decoder\n"); return -1; } - + //{ // WebRtc_Word32 b1, b2; // FILE* fileID = fopen("GetBNTest.txt", "w"); @@ -330,10 +329,10 @@ valid values are 8 and 16.\n", sampFreqKHz); // } //#endif - while (endfile == 0) - { + while (endfile == 0) + { fprintf(stderr," \rframe = %7li", framecnt); - + //============== Readind from the file and encoding ================= cur_framesmpls = 0; stream_len = 0; @@ -364,26 +363,26 @@ valid values are 8 and 16.\n", sampFreqKHz); { while(stream_len == 0) { - // Read 10 ms speech block + // Read 10 ms speech block endfile = readframe(shortdata, inp, samplesIn10Ms); if(endfile) { break; } cur_framesmpls += samplesIn10Ms; - + //-------- iSAC encoding --------- - stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata, + stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata, (WebRtc_Word16*)payload); - - if(stream_len < 0) + + if(stream_len < 0) { // exit if returned with error //errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); fprintf(stderr,"\nError in encoder\n"); getchar(); exit(EXIT_FAILURE); - } + } } @@ -397,8 +396,8 @@ valid values are 8 and 16.\n", sampFreqKHz); get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData, sampFreqKHz * 1000, sampFreqKHz * 1000); - if(WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, - payload, stream_len, packetData.rtp_number, + if(WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, + payload, stream_len, packetData.rtp_number, packetData.sample_count, packetData.arrival_time) < 0) { @@ -414,7 +413,7 @@ valid values are 8 and 16.\n", sampFreqKHz); maxStreamLen = (stream_len > maxStreamLen)? stream_len:maxStreamLen; packetCntr++; - + hist[stream_len]++; if(averageFile != NULL) { @@ -433,7 +432,7 @@ valid values are 8 and 16.\n", sampFreqKHz); WebRtc_UWord8 auxUW8; auxUW8 = (WebRtc_UWord8)(((stream_len & 0x7F00) >> 8) & 0xFF); fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp); - + auxUW8 = (WebRtc_UWord8)(stream_len & 0xFF); fwrite(&auxUW8, sizeof(WebRtc_UWord8), 1, outp); fwrite(payload, 1, stream_len, outp); @@ -451,23 +450,23 @@ valid values are 8 and 16.\n", sampFreqKHz); } else { - declen = WebRtcIsac_Decode(ISAC_main_inst, payload, + declen = WebRtcIsac_Decode(ISAC_main_inst, payload, stream_len, decoded, speechType); } - if(declen <= 0) + if(declen <= 0) { //errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); fprintf(stderr,"\nError in decoder.\n"); getchar(); exit(1); } - + // Write decoded speech frame to file fwrite(decoded, sizeof(WebRtc_Word16), declen, outp); cur_framesmpls = declen; } // Update Statistics - framecnt++; + framecnt++; totalsmpls += cur_framesmpls; if(stream_len > 0) { @@ -481,19 +480,20 @@ valid values are 8 and 16.\n", sampFreqKHz); rate = ((double)totalbits * (sampFreqKHz)) / (double)totalsmpls; rateRCU = ((double)totalBitsRCU * (sampFreqKHz)) / (double)totalsmpls; - rateLB = 0; - rateUB = 0; printf("\n\n"); printf("Sampling Rate......................... %d kHz\n", sampFreqKHz); printf("Payload Limit......................... %d bytes \n", payloadLimit); printf("Rate Limit............................ %d bits/sec \n", rateLimit); -#ifdef HAVE_DEBUG_INFO - rateLB = ((double)debugInfo.lbBytes * 8. * (sampFreqKHz)) / (double)totalsmpls; - rateUB = ((double)debugInfo.ubBytes * 8. * (sampFreqKHz)) / (double)totalsmpls; -#endif #ifdef WIN32 +#ifdef HAVE_DEBUG_INFO + rateLB = ((double)debugInfo.lbBytes * 8. * + (sampFreqKHz)) / (double)totalsmpls; + rateUB = ((double)debugInfo.ubBytes * 8. * + (sampFreqKHz)) / (double)totalsmpls; +#endif + fprintf(bitrateFile, "%d %10u %d %6.3f %6.3f %6.3f\n", sampFreqKHz, framecnt, @@ -502,20 +502,20 @@ valid values are 8 and 16.\n", sampFreqKHz); rateUB, rate); fclose(bitrateFile); -#endif +#endif // WIN32 printf("\n"); printf("Measured bit-rate..................... %0.3f kbps\n", rate); printf("Measured RCU bit-ratre................ %0.3f kbps\n", rateRCU); - printf("Maximum bit-rate/payloadsize.......... %0.3f / %d\n", + printf("Maximum bit-rate/payloadsize.......... %0.3f / %d\n", maxStreamLen * 8 / 0.03, maxStreamLen); - printf("Measured packet-loss.................. %0.1f%% \n", + printf("Measured packet-loss.................. %0.1f%% \n", 100.0f * (float)lostPacketCntr / (float)packetCntr); //#ifdef HAVE_DEBUG_INFO -// printf("Measured lower-band bit-rate.......... %0.3f kbps (%.0f%%)\n", +// printf("Measured lower-band bit-rate.......... %0.3f kbps (%.0f%%)\n", // rateLB, (double)(rateLB) * 100. /(double)(rate)); -// printf("Measured upper-band bit-rate.......... %0.3f kbps (%.0f%%)\n", +// printf("Measured upper-band bit-rate.......... %0.3f kbps (%.0f%%)\n", // rateUB, (double)(rateUB) * 100. /(double)(rate)); // // printf("Maximum payload lower-band............ %d bytes (%0.3f kbps)\n", @@ -525,17 +525,17 @@ valid values are 8 and 16.\n", sampFreqKHz); //#endif printf("\n"); - + /* Runtime statistics */ #ifdef WIN32 runtime = (double)(clock()/(double)CLOCKS_PER_SEC-starttime); length_file = ((double)framecnt*(double)declen/(sampFreqKHz*1000)); printf("Length of speech file................ %.1f s\n", length_file); - printf("Time to run iSAC..................... %.2f s (%.2f %% of realtime)\n\n", + printf("Time to run iSAC..................... %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file)); #endif printf("\n\n_______________________________________________\n"); - + if(histFile != NULL) { int n; @@ -558,9 +558,9 @@ valid values are 8 and 16.\n", sampFreqKHz); fclose(inp); fclose(outp); - + WebRtcIsac_Free(ISAC_main_inst); - + #ifdef CHANGE_OUTPUT_NAME { @@ -590,7 +590,7 @@ valid values are 8 and 16.\n", sampFreqKHz); } #endif exit(0); -} +} #ifdef HAVE_DEBUG_INFO @@ -598,7 +598,7 @@ int setupDebugStruct(debugStruct* str) { str->prevPacketLost = 0; str->currPacketLost = 0; - + OPEN_FILE_WB(str->res0to4FilePtr, "Res0to4.dat"); OPEN_FILE_WB(str->res4to8FilePtr, "Res4to8.dat"); OPEN_FILE_WB(str->res8to12FilePtr, "Res8to12.dat"); diff --git a/src/modules/audio_coding/codecs/iSAC/main/util/utility.c b/src/modules/audio_coding/codecs/iSAC/main/util/utility.c index 85734827c..0a2256a03 100644 --- a/src/modules/audio_coding/codecs/iSAC/main/util/utility.c +++ b/src/modules/audio_coding/codecs/iSAC/main/util/utility.c @@ -15,36 +15,36 @@ #include "utility.h" /* function for reading audio data from PCM file */ -int +int readframe( - short* data, + short* data, FILE* inp, - int length) + int length) { short k, rlen, status = 0; unsigned char* ptrUChar; ptrUChar = (unsigned char*)data; - + rlen = (short)fread(data, sizeof(short), length, inp); if (rlen < length) { for (k = rlen; k < length; k++) data[k] = 0; status = 1; - } - + } + // Assuming that our PCM files are written in Intel machines for(k = 0; k < length; k++) { data[k] = (short)ptrUChar[k<<1] | ((((short)ptrUChar[(k<<1) + 1]) << 8) & 0xFF00); - } - + } + return status; } -short +short readSwitch( - int argc, - char* argv[], + int argc, + char* argv[], char* strID) { short n; @@ -58,11 +58,11 @@ readSwitch( return 0; } -double +double readParamDouble( - int argc, - char* argv[], - char* strID, + int argc, + char* argv[], + char* strID, double defaultVal) { double returnVal = defaultVal; @@ -82,11 +82,11 @@ readParamDouble( return returnVal; } -int +int readParamInt( - int argc, - char* argv[], - char* strID, + int argc, + char* argv[], + char* strID, int defaultVal) { int returnVal = defaultVal; @@ -106,12 +106,12 @@ readParamInt( return returnVal; } -int +int readParamString( - int argc, - char* argv[], - char* strID, - char* stringParam, + int argc, + char* argv[], + char* strID, + char* stringParam, int maxSize) { int paramLenght = 0; @@ -132,7 +132,7 @@ readParamString( return paramLenght; } -void +void get_arrival_time( int current_framesamples, /* samples */ int packet_size, /* bytes */ @@ -142,8 +142,7 @@ get_arrival_time( short receiverSampFreqHz) { unsigned int travelTimeMs; - const int headerSizeByte = 35; - unsigned int dummy; + const int headerSizeByte = 35; int headerRate; @@ -156,27 +155,22 @@ get_arrival_time( //travelTimeMs = ((packet_size + HeaderSize) * 8 * sampFreqHz) / // (bottleneck + HeaderRate) - travelTimeMs = (unsigned int)floor((double)((packet_size + headerSizeByte) * 8 * 1000) - / (double)(bottleneck + headerRate) + 0.5); - + travelTimeMs = (unsigned int)floor((double)((packet_size + headerSizeByte) * 8 * 1000) + / (double)(bottleneck + headerRate) + 0.5); + if(BN_data->whenPrevPackLeftMs > BN_data->whenPackGeneratedMs) { BN_data->whenPrevPackLeftMs += travelTimeMs; } else { - BN_data->whenPrevPackLeftMs = BN_data->whenPackGeneratedMs + + BN_data->whenPrevPackLeftMs = BN_data->whenPackGeneratedMs + travelTimeMs; } - - dummy = (BN_data->whenPrevPackLeftMs * - (receiverSampFreqHz / 1000)) - BN_data->arrival_time; - BN_data->arrival_time = (BN_data->whenPrevPackLeftMs * + BN_data->arrival_time = (BN_data->whenPrevPackLeftMs * (receiverSampFreqHz / 1000)); - - // if (BN_data->arrival_time < BN_data->sample_count) // BN_data->arrival_time = BN_data->sample_count;