Run clang-format --style=Chromium on four files I'm otherwise touching.

The existing style in these files is pretty inconsistent and wildly divergent
from most of WebRTC/Chromium; clang-formatting them not only makes them easier
to read, it makes me see fewer presubmit errors when I try to touch the files to
make other changes.

BUG=none
R=kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/52019004

Cr-Commit-Position: refs/heads/master@{#9364}
This commit is contained in:
Peter Kasting 2015-06-03 12:32:41 -07:00
parent a9952cdd0e
commit 248b0b0790
4 changed files with 3165 additions and 3357 deletions

View File

@ -22,7 +22,6 @@
#include "isac.h" #include "isac.h"
#include "isacfix.h" #include "isacfix.h"
/* max number of samples per frame (= 60 ms frame) */ /* max number of samples per frame (= 60 ms frame) */
#define MAX_FRAMESAMPLES 960 #define MAX_FRAMESAMPLES 960
/* number of samples per 10ms frame */ /* number of samples per 10ms frame */
@ -30,20 +29,14 @@
/* sampling frequency (Hz) */ /* sampling frequency (Hz) */
#define FS 16000 #define FS 16000
/* Runtime statistics */ /* Runtime statistics */
#include <time.h> #include <time.h>
#define CLOCKS_PER_SEC 1000 #define CLOCKS_PER_SEC 1000
// FILE *histfile, *ratefile; // FILE *histfile, *ratefile;
/* function for reading audio data from PCM file */ /* function for reading audio data from PCM file */
int readframe(int16_t *data, FILE *inp, int length) { int readframe(int16_t* data, FILE* inp, int length) {
short k, rlen, status = 0; short k, rlen, status = 0;
rlen = fread(data, sizeof(int16_t), length, inp); rlen = fread(data, sizeof(int16_t), length, inp);
@ -66,8 +59,7 @@ typedef struct {
void get_arrival_time(int current_framesamples, /* samples */ void get_arrival_time(int current_framesamples, /* samples */
int packet_size, /* bytes */ int packet_size, /* bytes */
int bottleneck, /* excluding headers; bits/s */ int bottleneck, /* excluding headers; bits/s */
BottleNeckModel *BN_data) BottleNeckModel* BN_data) {
{
const int HeaderSize = 35; const int HeaderSize = 35;
int HeaderRate; int HeaderRate;
@ -76,7 +68,8 @@ void get_arrival_time(int current_framesamples, /* samples */
/* everything in samples */ /* everything in samples */
BN_data->sample_count = BN_data->sample_count + current_framesamples; BN_data->sample_count = BN_data->sample_count + current_framesamples;
BN_data->arrival_time += ((packet_size + HeaderSize) * 8 * FS) / (bottleneck + HeaderRate); BN_data->arrival_time +=
((packet_size + HeaderSize) * 8 * FS) / (bottleneck + HeaderRate);
BN_data->send_time += current_framesamples; BN_data->send_time += current_framesamples;
if (BN_data->arrival_time < BN_data->sample_count) if (BN_data->arrival_time < BN_data->sample_count)
@ -85,22 +78,18 @@ void get_arrival_time(int current_framesamples, /* samples */
BN_data->rtp_number++; BN_data->rtp_number++;
} }
int main(int argc, char* argv[]) {
char inname[50], outname[50], bottleneck_file[50], bitfilename[60],
int main(int argc, char* argv[]) bitending[10] = "_bits.pcm";
{ FILE* inp, *outp, *f_bn, *bitsp;
char inname[50], outname[50], bottleneck_file[50], bitfilename[60], bitending[10]="_bits.pcm";
FILE *inp, *outp, *f_bn, *bitsp;
int framecnt, endfile; int framecnt, endfile;
int i, j, errtype, plc = 0;
int i,j,errtype, plc=0;
int16_t CodingMode; int16_t CodingMode;
int16_t bottleneck; int16_t bottleneck;
int16_t framesize = 30; /* ms */ int16_t framesize = 30; /* ms */
//int16_t framesize = 60; /* To invoke cisco complexity case at frame 2252 */ // int16_t framesize = 60; /* To invoke cisco complexity case at frame 2252 */
int cur_framesmpls, err; int cur_framesmpls, err;
@ -117,24 +106,21 @@ int main(int argc, char* argv[])
uint16_t streamdata[600]; uint16_t streamdata[600];
int16_t speechType[1]; int16_t speechType[1];
// int16_t *iSACstruct; // int16_t *iSACstruct;
char version_number[20]; char version_number[20];
int mode=-1, tmp, nbTest=0; /*,sss;*/ int mode = -1, tmp, nbTest = 0; /*,sss;*/
#ifdef _DEBUG #ifdef _DEBUG
FILE *fy; FILE* fy;
double kbps; double kbps;
int totalbits =0; int totalbits = 0;
int totalsmpls =0; int totalsmpls = 0;
#endif /* _DEBUG */ #endif /* _DEBUG */
/* only one structure used for ISAC encoder */ /* only one structure used for ISAC encoder */
ISAC_MainStruct *ISAC_main_inst; ISAC_MainStruct* ISAC_main_inst;
ISACFIX_MainStruct *ISACFIX_main_inst; ISACFIX_MainStruct* ISACFIX_main_inst;
BottleNeckModel BN_data; BottleNeckModel BN_data;
f_bn = NULL; f_bn = NULL;
@ -146,12 +132,11 @@ int main(int argc, char* argv[])
fclose(fy); fclose(fy);
#endif /* _DEBUG */ #endif /* _DEBUG */
// histfile = fopen("histo.dat", "ab");
//histfile = fopen("histo.dat", "ab"); // ratefile = fopen("rates.dat", "ab");
//ratefile = fopen("rates.dat", "ab");
/* handling wrong input arguments in the command line */ /* handling wrong input arguments in the command line */
if ((argc<6) || (argc>10)) { if ((argc < 6) || (argc > 10)) {
printf("\n\nWrong number of arguments or flag values.\n\n"); printf("\n\nWrong number of arguments or flag values.\n\n");
printf("\n"); printf("\n");
@ -162,28 +147,42 @@ int main(int argc, char* argv[])
printf("./kenny.exe [-I] bottleneck_value infile outfile \n\n"); printf("./kenny.exe [-I] bottleneck_value infile outfile \n\n");
printf("with:\n"); printf("with:\n");
printf("[-I] : if -I option is specified, the coder will use\n"); printf(
printf(" an instantaneous Bottleneck value. If not, it\n"); "[-I] : if -I option is specified, the coder "
printf(" will be an adaptive Bottleneck value.\n\n"); "will use\n");
printf("bottleneck_value : the value of the bottleneck provided either\n"); printf(
printf(" as a fixed value (e.g. 25000) or\n"); " an instantaneous Bottleneck value. If "
printf(" read from a file (e.g. bottleneck.txt)\n\n"); "not, it\n");
printf(
" will be an adaptive Bottleneck "
"value.\n\n");
printf(
"bottleneck_value : the value of the bottleneck provided "
"either\n");
printf(
" as a fixed value (e.g. 25000) or\n");
printf(
" read from a file (e.g. "
"bottleneck.txt)\n\n");
printf("[-m] mode : Mode (encoder - decoder):\n"); printf("[-m] mode : Mode (encoder - decoder):\n");
printf(" : 0 - float - float \n"); printf(
printf(" : 1 - float - fix \n"); " : 0 - float - float \n");
printf(" : 2 - fix - float \n"); printf(
" : 1 - float - fix \n");
printf(
" : 2 - fix - float \n");
printf(" : 3 - fix - fix \n"); printf(" : 3 - fix - fix \n");
printf("[-PLC] : Test PLC packetlosses\n"); printf("[-PLC] : Test PLC packetlosses\n");
printf("[-NB] num : Test NB interfaces, num=1 encNB, num=2 decNB\n"); printf(
"[-NB] num : Test NB interfaces, num=1 encNB, num=2 "
"decNB\n");
printf("infile : Normal speech input file\n\n"); printf("infile : Normal speech input file\n\n");
printf("outfile : Speech output file\n\n"); printf("outfile : Speech output file\n\n");
printf("Example usage:\n\n"); printf("Example usage:\n\n");
printf("./kenny.exe -I bottleneck.txt -m 1 speechIn.pcm speechOut.pcm\n\n"); printf("./kenny.exe -I bottleneck.txt -m 1 speechIn.pcm speechOut.pcm\n\n");
exit(0); exit(0);
} }
printf("--------------------START---------------------\n\n"); printf("--------------------START---------------------\n\n");
WebRtcIsac_version(version_number); WebRtcIsac_version(version_number);
printf("iSAC FLOAT version %s \n", version_number); printf("iSAC FLOAT version %s \n", version_number);
@ -191,60 +190,50 @@ int main(int argc, char* argv[])
printf("iSAC FIX version %s \n\n", version_number); printf("iSAC FIX version %s \n\n", version_number);
CodingMode = 0; CodingMode = 0;
tmp=1; tmp = 1;
for (i = 1; i < argc;i++) for (i = 1; i < argc; i++) {
{ if (!strcmp("-I", argv[i])) {
if (!strcmp ("-I", argv[i]))
{
printf("\nInstantaneous BottleNeck\n"); printf("\nInstantaneous BottleNeck\n");
CodingMode = 1; CodingMode = 1;
i++; i++;
tmp=0; tmp = 0;
} }
if (!strcmp ("-m", argv[i])) { if (!strcmp("-m", argv[i])) {
mode=atoi(argv[i+1]); mode = atoi(argv[i + 1]);
i++; i++;
} }
if (!strcmp ("-PLC", argv[i])) if (!strcmp("-PLC", argv[i])) {
{ plc = 1;
plc=1;
} }
if (!strcmp ("-NB", argv[i])) if (!strcmp("-NB", argv[i])) {
{
nbTest = atoi(argv[i + 1]); nbTest = atoi(argv[i + 1]);
i++; i++;
} }
} }
if(mode<0) { if (mode < 0) {
printf("\nError! Mode must be set: -m 0 \n"); printf("\nError! Mode must be set: -m 0 \n");
exit(0); exit(0);
} }
if (CodingMode == 0) if (CodingMode == 0) {
{
printf("\nAdaptive BottleNeck\n"); printf("\nAdaptive BottleNeck\n");
} }
/* Get Bottleneck value */ /* Get Bottleneck value */
bottleneck = atoi(argv[2-tmp]); bottleneck = atoi(argv[2 - tmp]);
if (bottleneck == 0) if (bottleneck == 0) {
{ sscanf(argv[2 - tmp], "%s", bottleneck_file);
sscanf(argv[2-tmp], "%s", bottleneck_file);
f_bn = fopen(bottleneck_file, "rb"); f_bn = fopen(bottleneck_file, "rb");
if (f_bn == NULL) if (f_bn == NULL) {
{ printf("No value provided for BottleNeck and cannot read file %s.\n",
printf("No value provided for BottleNeck and cannot read file %s.\n", bottleneck_file); bottleneck_file);
exit(0); exit(0);
} } else {
else { printf("reading bottleneck rates from file %s\n\n", bottleneck_file);
printf("reading bottleneck rates from file %s\n\n",bottleneck_file);
if (fscanf(f_bn, "%d", &bottleneck) == EOF) { if (fscanf(f_bn, "%d", &bottleneck) == EOF) {
/* Set pointer to beginning of file */ /* Set pointer to beginning of file */
fseek(f_bn, 0L, SEEK_SET); fseek(f_bn, 0L, SEEK_SET);
@ -258,51 +247,44 @@ int main(int argc, char* argv[])
* fprintf(fid, '%d\n', BottleNeck_10ms); fclose(fid); * fprintf(fid, '%d\n', BottleNeck_10ms); fclose(fid);
*/ */
} }
} } else {
else
{
printf("\nfixed bottleneck rate of %d bits/s\n\n", bottleneck); printf("\nfixed bottleneck rate of %d bits/s\n\n", bottleneck);
} }
/* Get Input and Output files */ /* Get Input and Output files */
sscanf(argv[argc-2], "%s", inname); sscanf(argv[argc - 2], "%s", inname);
sscanf(argv[argc-1], "%s", outname); sscanf(argv[argc - 1], "%s", outname);
if ((inp = fopen(inname,"rb")) == NULL) { if ((inp = fopen(inname, "rb")) == NULL) {
printf(" iSAC: Cannot read file %s.\n", inname); printf(" iSAC: Cannot read file %s.\n", inname);
exit(1); exit(1);
} }
if ((outp = fopen(outname,"wb")) == NULL) { if ((outp = fopen(outname, "wb")) == NULL) {
printf(" iSAC: Cannot write file %s.\n", outname); printf(" iSAC: Cannot write file %s.\n", outname);
exit(1); exit(1);
} }
printf("\nInput:%s\nOutput:%s\n", inname, outname); printf("\nInput:%s\nOutput:%s\n", inname, outname);
i=0; i = 0;
while (outname[i]!='\0') { while (outname[i] != '\0') {
bitfilename[i]=outname[i]; bitfilename[i] = outname[i];
i++; i++;
} }
i-=4; i -= 4;
for (j=0;j<9;j++, i++) for (j = 0; j < 9; j++, i++)
bitfilename[i]=bitending[j]; bitfilename[i] = bitending[j];
bitfilename[i]='\0'; bitfilename[i] = '\0';
if ((bitsp = fopen(bitfilename,"wb")) == NULL) { if ((bitsp = fopen(bitfilename, "wb")) == NULL) {
printf(" iSAC: Cannot read file %s.\n", bitfilename); printf(" iSAC: Cannot read file %s.\n", bitfilename);
exit(1); exit(1);
} }
printf("Bitstream:%s\n\n", bitfilename); printf("Bitstream:%s\n\n", bitfilename);
starttime = clock() / (double)CLOCKS_PER_SEC; /* Runtime statistics */
starttime = clock()/(double)CLOCKS_PER_SEC; /* Runtime statistics */
/* Initialize the ISAC and BN structs */ /* Initialize the ISAC and BN structs */
WebRtcIsac_create(&ISAC_main_inst); WebRtcIsac_create(&ISAC_main_inst);
/* WebRtcIsacfix_AssignSize(&sss); /* WebRtcIsacfix_AssignSize(&sss);
iSACstruct=malloc(sss); iSACstruct=malloc(sss);
WebRtcIsacfix_Assign(&ISACFIX_main_inst,iSACstruct);*/ WebRtcIsacfix_Assign(&ISACFIX_main_inst,iSACstruct);*/
WebRtcIsacfix_Create(&ISACFIX_main_inst); WebRtcIsacfix_Create(&ISACFIX_main_inst);
@ -313,10 +295,10 @@ int main(int argc, char* argv[])
BN_data.rtp_number = 0; BN_data.rtp_number = 0;
/* Initialize encoder and decoder */ /* Initialize encoder and decoder */
framecnt= 0; framecnt = 0;
endfile = 0; endfile = 0;
if (mode==0) { /* Encode using FLOAT, decode using FLOAT */ if (mode == 0) { /* Encode using FLOAT, decode using FLOAT */
printf("Coding mode: Encode using FLOAT, decode using FLOAT \n\n"); printf("Coding mode: Encode using FLOAT, decode using FLOAT \n\n");
@ -327,13 +309,13 @@ int main(int argc, char* argv[])
err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize); err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
// exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
} else if (mode==1) { /* Encode using FLOAT, decode using FIX */ } else if (mode == 1) { /* Encode using FLOAT, decode using FIX */
printf("Coding mode: Encode using FLOAT, decode using FIX \n\n"); printf("Coding mode: Encode using FLOAT, decode using FIX \n\n");
@ -344,7 +326,7 @@ int main(int argc, char* argv[])
err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize); err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
// exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
@ -357,12 +339,12 @@ int main(int argc, char* argv[])
err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize); err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
} else if (mode==2) { /* Encode using FIX, decode using FLOAT */ } else if (mode == 2) { /* Encode using FIX, decode using FLOAT */
printf("Coding mode: Encode using FIX, decode using FLOAT \n\n"); printf("Coding mode: Encode using FIX, decode using FLOAT \n\n");
@ -373,9 +355,9 @@ int main(int argc, char* argv[])
err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize); err = WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
@ -386,13 +368,12 @@ int main(int argc, char* argv[])
err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize); err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
} else if (mode==3) { } else if (mode == 3) {
printf("Coding mode: Encode using FIX, decode using FIX \n\n"); printf("Coding mode: Encode using FIX, decode using FIX \n\n");
WebRtcIsacfix_EncoderInit(ISACFIX_main_inst, CodingMode); WebRtcIsacfix_EncoderInit(ISACFIX_main_inst, CodingMode);
@ -401,9 +382,9 @@ int main(int argc, char* argv[])
err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize); err = WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\n Error in initialization: %d.\n\n", errtype); printf("\n\n Error in initialization: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
@ -416,51 +397,47 @@ int main(int argc, char* argv[])
err = WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_main_inst, 300); err = WebRtcIsacfix_SetMaxPayloadSize(ISACFIX_main_inst, 300);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\n Error in setMaxPayloadSize: %d.\n\n", errtype); printf("\n\n Error in setMaxPayloadSize: %d.\n\n", errtype);
fclose(inp); fclose(inp);
fclose(outp); fclose(outp);
fclose(bitsp); fclose(bitsp);
return(EXIT_FAILURE); return (EXIT_FAILURE);
} }
#endif #endif
while (endfile == 0) { while (endfile == 0) {
cur_framesmpls = 0; cur_framesmpls = 0;
while (1) { while (1) {
/* Read 10 ms speech block */ /* Read 10 ms speech block */
if (nbTest != 1) if (nbTest != 1)
endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms); endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms);
else else
endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms/2)); endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms / 2));
/* iSAC encoding */ /* iSAC encoding */
if (mode==0 || mode ==1) { if (mode == 0 || mode == 1) {
stream_len = WebRtcIsac_Encode(ISAC_main_inst, stream_len =
shortdata, WebRtcIsac_Encode(ISAC_main_inst, shortdata, (uint8_t*)streamdata);
(uint8_t*)streamdata);
if (stream_len < 0) { if (stream_len < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\nError in encoder: %d.\n\n", errtype); printf("\n\nError in encoder: %d.\n\n", errtype);
// exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} else if (mode==2 || mode==3) { } else if (mode == 2 || mode == 3) {
/* iSAC encoding */ /* iSAC encoding */
if (nbTest != 1) if (nbTest != 1)
stream_len = WebRtcIsacfix_Encode( stream_len = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata,
ISACFIX_main_inst,
shortdata,
(uint8_t*)streamdata); (uint8_t*)streamdata);
else else
stream_len = WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata); stream_len =
WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata);
if (stream_len < 0) { if (stream_len < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\nError in encoder: %d.\n\n", errtype); printf("\n\nError in encoder: %d.\n\n", errtype);
// exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
@ -476,172 +453,137 @@ int main(int argc, char* argv[])
fscanf(f_bn, "%d", &bottleneck); fscanf(f_bn, "%d", &bottleneck);
} }
if (CodingMode == 1) { if (CodingMode == 1) {
if (mode==0 || mode==1) if (mode == 0 || mode == 1)
WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize); WebRtcIsac_Control(ISAC_main_inst, bottleneck, framesize);
else if (mode==2 || mode==3) else if (mode == 2 || mode == 3)
WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize); WebRtcIsacfix_Control(ISACFIX_main_inst, bottleneck, framesize);
} }
} }
/* exit encoder loop if the encoder returned a bitstream */ /* exit encoder loop if the encoder returned a bitstream */
if (stream_len != 0) break; if (stream_len != 0)
break;
} }
fwrite(streamdata, 1, stream_len, bitsp); /* NOTE! Writes bytes to file */ fwrite(streamdata, 1, stream_len, bitsp); /* NOTE! Writes bytes to file */
/* simulate packet handling through NetEq and the modem */ /* simulate packet handling through NetEq and the modem */
get_arrival_time(cur_framesmpls, stream_len, bottleneck, get_arrival_time(cur_framesmpls, stream_len, bottleneck, &BN_data);
&BN_data); //*****************************
//***************************** if (1) {
if (1){ if (mode == 0) {
if (mode==0) { err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, streamdata,
err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, stream_len, BN_data.rtp_number,
streamdata,
stream_len,
BN_data.rtp_number,
BN_data.arrival_time); BN_data.arrival_time);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
/* iSAC decoding */ /* iSAC decoding */
declen = WebRtcIsac_Decode(ISAC_main_inst, declen = WebRtcIsac_Decode(ISAC_main_inst, streamdata, stream_len,
streamdata, decoded, speechType);
stream_len,
decoded,
speechType);
if (declen <= 0) { if (declen <= 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} else if (mode==1) { } else if (mode == 1) {
err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, streamdata,
err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, stream_len, BN_data.rtp_number,
streamdata,
stream_len,
BN_data.rtp_number,
BN_data.arrival_time); BN_data.arrival_time);
err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst, err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst, streamdata,
streamdata, stream_len, BN_data.rtp_number,
stream_len,
BN_data.rtp_number,
BN_data.arrival_time); BN_data.arrival_time);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
declen = WebRtcIsac_Decode(ISAC_main_inst, declen = WebRtcIsac_Decode(ISAC_main_inst, streamdata, stream_len,
streamdata, decoded, speechType);
stream_len,
decoded,
speechType);
/* iSAC decoding */ /* iSAC decoding */
if (plc && (framecnt+1)%10 == 0) { if (plc && (framecnt + 1) % 10 == 0) {
if (nbTest !=2 ) if (nbTest != 2)
declen = WebRtcIsacfix_DecodePlc( ISACFIX_main_inst, decoded, 1 ); declen = WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1);
else else
declen = WebRtcIsacfix_DecodePlcNb( ISACFIX_main_inst, decoded, 1 ); declen = WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1);
} else { } else {
if (nbTest !=2 ) if (nbTest != 2)
declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata,
streamdata, stream_len, decoded, speechType);
stream_len,
decoded,
speechType);
else else
declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata,
streamdata, stream_len, decoded, speechType);
stream_len,
decoded,
speechType);
} }
if (declen <= 0) { if (declen <= 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} else if (mode==2) { } else if (mode == 2) {
err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst, err = WebRtcIsacfix_UpdateBwEstimate1(ISACFIX_main_inst, streamdata,
streamdata, stream_len, BN_data.rtp_number,
stream_len,
BN_data.rtp_number,
BN_data.arrival_time); BN_data.arrival_time);
err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, err = WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, streamdata,
streamdata, stream_len, BN_data.rtp_number,
stream_len,
BN_data.rtp_number,
BN_data.arrival_time); BN_data.arrival_time);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
/* iSAC decoding */ /* iSAC decoding */
declen = WebRtcIsac_Decode(ISAC_main_inst, declen = WebRtcIsac_Decode(ISAC_main_inst, streamdata, stream_len,
streamdata, decoded, speechType);
stream_len,
decoded,
speechType);
if (declen <= 0) { if (declen <= 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst); errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} else if (mode==3) { } else if (mode == 3) {
err = WebRtcIsacfix_UpdateBwEstimate(ISACFIX_main_inst, err = WebRtcIsacfix_UpdateBwEstimate(
streamdata, ISACFIX_main_inst, streamdata, stream_len, BN_data.rtp_number,
stream_len, BN_data.send_time, BN_data.arrival_time);
BN_data.rtp_number,
BN_data.send_time,
BN_data.arrival_time);
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
/* iSAC decoding */ /* iSAC decoding */
if (plc && (framecnt+1)%10 == 0) { if (plc && (framecnt + 1) % 10 == 0) {
if (nbTest !=2 ) if (nbTest != 2)
declen = WebRtcIsacfix_DecodePlc( ISACFIX_main_inst, decoded, 1 ); declen = WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1);
else else
declen = WebRtcIsacfix_DecodePlcNb( ISACFIX_main_inst, decoded, 1 ); declen = WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1);
} else { } else {
if (nbTest !=2 ) if (nbTest != 2)
declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata,
streamdata, stream_len, decoded, speechType);
stream_len,
decoded,
speechType);
else else
declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata,
streamdata, stream_len, decoded, speechType);
stream_len,
decoded,
speechType);
} }
if (declen <= 0) { if (declen <= 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst);
printf("\n\nError in decoder: %d.\n\n", errtype); printf("\n\nError in decoder: %d.\n\n", errtype);
//exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
} }
} }
@ -649,35 +591,35 @@ int main(int argc, char* argv[])
fwrite(decoded, sizeof(int16_t), declen, outp); fwrite(decoded, sizeof(int16_t), declen, outp);
} }
fprintf(stderr," \rframe = %d", framecnt); fprintf(stderr, " \rframe = %d", framecnt);
framecnt++; framecnt++;
#ifdef _DEBUG #ifdef _DEBUG
totalsmpls += declen; totalsmpls += declen;
totalbits += 8 * stream_len; totalbits += 8 * stream_len;
kbps = ((double) FS) / ((double) cur_framesmpls) * 8.0 * stream_len / 1000.0;// kbits/s kbps = ((double)FS) / ((double)cur_framesmpls) * 8.0 * stream_len /
1000.0; // kbits/s
fy = fopen("bit_rate.dat", "a"); fy = fopen("bit_rate.dat", "a");
fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps); fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps);
fclose(fy); fclose(fy);
#endif /* _DEBUG */ #endif /* _DEBUG */
} }
#ifdef _DEBUG #ifdef _DEBUG
printf("\n\ntotal bits = %d bits", totalbits); printf("\n\ntotal bits = %d bits", totalbits);
printf("\nmeasured average bitrate = %0.3f kbits/s", (double)totalbits *(FS/1000) / totalsmpls); printf("\nmeasured average bitrate = %0.3f kbits/s",
(double)totalbits * (FS / 1000) / totalsmpls);
printf("\n"); printf("\n");
#endif /* _DEBUG */ #endif /* _DEBUG */
/* Runtime statistics */ /* Runtime statistics */
runtime = (double)(clock()/(double)CLOCKS_PER_SEC-starttime); runtime = (double)(clock() / (double)CLOCKS_PER_SEC - starttime);
length_file = ((double)framecnt*(double)declen/FS); length_file = ((double)framecnt * (double)declen / FS);
printf("\n\nLength of speech file: %.1f s\n", length_file); printf("\n\nLength of speech file: %.1f s\n", length_file);
printf("Time to run iSAC: %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file)); printf("Time to run iSAC: %.2f s (%.2f %% of realtime)\n\n", runtime,
(100 * runtime / length_file));
printf("---------------------END----------------------\n"); printf("---------------------END----------------------\n");
fclose(inp); fclose(inp);
@ -686,13 +628,8 @@ int main(int argc, char* argv[])
WebRtcIsac_Free(ISAC_main_inst); WebRtcIsac_Free(ISAC_main_inst);
WebRtcIsacfix_Free(ISACFIX_main_inst); WebRtcIsacfix_Free(ISACFIX_main_inst);
// fclose(histfile);
// fclose(ratefile);
// fclose(histfile);
// fclose(ratefile);
return 0; return 0;
} }

View File

@ -41,14 +41,13 @@
//#define CHANGE_OUTPUT_NAME //#define CHANGE_OUTPUT_NAME
#ifdef HAVE_DEBUG_INFO #ifdef HAVE_DEBUG_INFO
#include "debugUtility.h" #include "debugUtility.h"
debugStruct debugInfo; debugStruct debugInfo;
#endif #endif
unsigned long framecnt = 0; unsigned long framecnt = 0;
int main(int argc, char* argv[]) int main(int argc, char* argv[]) {
{
//--- File IO ---- //--- File IO ----
FILE* inp; FILE* inp;
FILE* outp; FILE* outp;
@ -60,14 +59,14 @@ int main(int argc, char* argv[])
double rateRCU; double rateRCU;
unsigned long totalbits = 0; unsigned long totalbits = 0;
unsigned long totalBitsRCU = 0; unsigned long totalBitsRCU = 0;
unsigned long totalsmpls =0; unsigned long totalsmpls = 0;
int32_t bottleneck = 39; int32_t bottleneck = 39;
int16_t frameSize = 30; /* ms */ int16_t frameSize = 30; /* ms */
int16_t codingMode = 1; int16_t codingMode = 1;
int16_t shortdata[FRAMESAMPLES_SWB_10ms]; int16_t shortdata[FRAMESAMPLES_SWB_10ms];
int16_t decoded[MAX_FRAMESAMPLES_SWB]; int16_t decoded[MAX_FRAMESAMPLES_SWB];
//uint16_t streamdata[1000]; // uint16_t streamdata[1000];
int16_t speechType[1]; int16_t speechType[1];
int16_t payloadLimit; int16_t payloadLimit;
int32_t rateLimit; int32_t rateLimit;
@ -109,7 +108,6 @@ int main(int argc, char* argv[])
int onlyEncode; int onlyEncode;
int onlyDecode; int onlyDecode;
BottleNeckModel packetData; BottleNeckModel packetData;
packetData.arrival_time = 0; packetData.arrival_time = 0;
packetData.sample_count = 0; packetData.sample_count = 0;
@ -117,8 +115,7 @@ int main(int argc, char* argv[])
memset(hist, 0, sizeof(hist)); memset(hist, 0, sizeof(hist));
/* handling wrong input arguments in the command line */ /* handling wrong input arguments in the command line */
if(argc < 5) if (argc < 5) {
{
int size; int size;
WebRtcIsac_AssignSize(&size); WebRtcIsac_AssignSize(&size);
@ -128,22 +125,31 @@ int main(int argc, char* argv[])
printf("%s infile outfile -bn bottelneck [options] \n\n", argv[0]); printf("%s infile outfile -bn bottelneck [options] \n\n", argv[0]);
printf("with:\n"); printf("with:\n");
printf("-I................... indicates encoding in instantaneous mode.\n"); printf("-I................... indicates encoding in instantaneous mode.\n");
printf("-bn bottleneck....... the value of the bottleneck in bit/sec, e.g. 39742,\n"); printf(
printf(" in instantaneous (channel-independent) mode.\n\n"); "-bn bottleneck....... the value of the bottleneck in bit/sec, e.g. "
"39742,\n");
printf(
" in instantaneous (channel-independent) "
"mode.\n\n");
printf("infile............... Normal speech input file\n\n"); printf("infile............... Normal speech input file\n\n");
printf("outfile.............. Speech output file\n\n"); printf("outfile.............. Speech output file\n\n");
printf("OPTIONS\n"); printf("OPTIONS\n");
printf("-------\n"); printf("-------\n");
printf("-fs sampFreq......... sampling frequency of codec 16 or 32 (default) kHz.\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(" default is the maximum possible.\n");
printf("-rlim rateLim........ rate limit in bits/sec, \n"); printf("-rlim rateLim........ rate limit in bits/sec, \n");
printf(" default is the maimum possible.\n"); printf(" default is the maimum possible.\n");
printf("-h file.............. record histogram and *append* to 'file'.\n"); printf("-h file.............. record histogram and *append* to 'file'.\n");
printf("-ave file............ record average rate of 3 sec intervales and *append* to 'file'.\n"); printf(
"-ave file............ record average rate of 3 sec intervales and "
"*append* to 'file'.\n");
printf("-ploss............... packet-loss percentage.\n"); printf("-ploss............... packet-loss percentage.\n");
printf("-enc................. do only encoding and store the bit-stream\n"); printf("-enc................. do only encoding and store the bit-stream\n");
printf("-dec................. the input file is a bit-stream, decode it.\n"); printf(
"-dec................. the input file is a bit-stream, decode it.\n");
printf("\n"); printf("\n");
printf("Example usage:\n\n"); printf("Example usage:\n\n");
@ -154,78 +160,65 @@ int main(int argc, char* argv[])
exit(0); exit(0);
} }
/* Get Bottleneck value */ /* Get Bottleneck value */
bottleneck = readParamInt(argc, argv, "-bn", 50000); bottleneck = readParamInt(argc, argv, "-bn", 50000);
fprintf(stderr,"\nfixed bottleneck rate of %d bits/s\n\n", bottleneck); fprintf(stderr, "\nfixed bottleneck rate of %d bits/s\n\n", bottleneck);
/* Get Input and Output files */ /* Get Input and Output files */
sscanf(argv[1], "%s", inname); sscanf(argv[1], "%s", inname);
sscanf(argv[2], "%s", outname); sscanf(argv[2], "%s", outname);
codingMode = readSwitch(argc, argv, "-I"); codingMode = readSwitch(argc, argv, "-I");
sampFreqKHz = (int16_t)readParamInt(argc, argv, "-fs", 32); sampFreqKHz = (int16_t)readParamInt(argc, argv, "-fs", 32);
if(readParamString(argc, argv, "-h", histFileName, 500) > 0) if (readParamString(argc, argv, "-h", histFileName, 500) > 0) {
{
histFile = fopen(histFileName, "a"); histFile = fopen(histFileName, "a");
if(histFile == NULL) if (histFile == NULL) {
{
printf("cannot open hist file %s", histFileName); printf("cannot open hist file %s", histFileName);
exit(0); exit(0);
} }
} } else {
else
{
// NO recording of hitstogram // NO recording of hitstogram
histFile = NULL; histFile = NULL;
} }
packetLossPercent = readParamInt(argc, argv, "-ploss", 0); packetLossPercent = readParamInt(argc, argv, "-ploss", 0);
if(readParamString(argc, argv, "-ave", averageFileName, 500) > 0) if (readParamString(argc, argv, "-ave", averageFileName, 500) > 0) {
{
averageFile = fopen(averageFileName, "a"); averageFile = fopen(averageFileName, "a");
if(averageFile == NULL) if (averageFile == NULL) {
{
printf("cannot open file to write rate %s", averageFileName); printf("cannot open file to write rate %s", averageFileName);
exit(0); exit(0);
} }
} } else {
else
{
averageFile = NULL; averageFile = NULL;
} }
onlyEncode = readSwitch(argc, argv, "-enc"); onlyEncode = readSwitch(argc, argv, "-enc");
onlyDecode = readSwitch(argc, argv, "-dec"); onlyDecode = readSwitch(argc, argv, "-dec");
switch (sampFreqKHz) {
switch(sampFreqKHz) case 16: {
{
case 16:
{
samplesIn10Ms = 160; samplesIn10Ms = 160;
break; break;
} }
case 32: case 32: {
{
samplesIn10Ms = 320; samplesIn10Ms = 320;
break; break;
} }
default: default:
printf("A sampling frequency of %d kHz is not supported,\ printf(
valid values are 8 and 16.\n", sampFreqKHz); "A sampling frequency of %d kHz is not supported,\
valid values are 8 and 16.\n",
sampFreqKHz);
exit(-1); exit(-1);
} }
payloadLimit = (int16_t)readParamInt(argc, argv, "-plim", 400); payloadLimit = (int16_t)readParamInt(argc, argv, "-plim", 400);
rateLimit = readParamInt(argc, argv, "-rlim", 106800); rateLimit = readParamInt(argc, argv, "-rlim", 106800);
if ((inp = fopen(inname,"rb")) == NULL) { if ((inp = fopen(inname, "rb")) == NULL) {
printf(" iSAC: Cannot read file %s.\n", inname); printf(" iSAC: Cannot read file %s.\n", inname);
exit(1); exit(1);
} }
if ((outp = fopen(outname,"wb")) == NULL) { if ((outp = fopen(outname, "wb")) == NULL) {
printf(" iSAC: Cannot write file %s.\n", outname); printf(" iSAC: Cannot write file %s.\n", outname);
exit(1); exit(1);
} }
@ -242,24 +235,23 @@ valid values are 8 and 16.\n", sampFreqKHz);
printf("Input.................... %s\n", inname); printf("Input.................... %s\n", inname);
printf("Output................... %s\n", outname); printf("Output................... %s\n", outname);
printf("Encoding Mode............ %s\n", printf("Encoding Mode............ %s\n",
(codingMode == 1)? "Channel-Independent":"Channel-Adaptive"); (codingMode == 1) ? "Channel-Independent" : "Channel-Adaptive");
printf("Bottleneck............... %d bits/sec\n", bottleneck); printf("Bottleneck............... %d bits/sec\n", bottleneck);
printf("Packet-loss Percentage... %d\n", packetLossPercent); printf("Packet-loss Percentage... %d\n", packetLossPercent);
printf("\n"); printf("\n");
#ifdef WIN32 #ifdef WIN32
starttime = clock()/(double)CLOCKS_PER_SEC; /* Runtime statistics */ starttime = clock() / (double)CLOCKS_PER_SEC; /* Runtime statistics */
#endif #endif
/* Initialize the ISAC and BN structs */ /* Initialize the ISAC and BN structs */
err = WebRtcIsac_Create(&ISAC_main_inst); err = WebRtcIsac_Create(&ISAC_main_inst);
WebRtcIsac_SetEncSampRate(ISAC_main_inst, sampFreqKHz * 1000); WebRtcIsac_SetEncSampRate(ISAC_main_inst, sampFreqKHz * 1000);
WebRtcIsac_SetDecSampRate(ISAC_main_inst, sampFreqKHz >= 32 ? 32000 : WebRtcIsac_SetDecSampRate(ISAC_main_inst, sampFreqKHz >= 32 ? 32000 : 16000);
16000);
/* Error check */ /* Error check */
if (err < 0) { if (err < 0) {
fprintf(stderr,"\n\n Error in create.\n\n"); fprintf(stderr, "\n\n Error in create.\n\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -267,13 +259,11 @@ valid values are 8 and 16.\n", sampFreqKHz);
endfile = 0; endfile = 0;
/* Initialize encoder and decoder */ /* Initialize encoder and decoder */
if(WebRtcIsac_EncoderInit(ISAC_main_inst, codingMode) < 0) if (WebRtcIsac_EncoderInit(ISAC_main_inst, codingMode) < 0) {
{
printf("cannot initialize encoder\n"); printf("cannot initialize encoder\n");
return -1; return -1;
} }
if(WebRtcIsac_DecoderInit(ISAC_main_inst) < 0) if (WebRtcIsac_DecoderInit(ISAC_main_inst) < 0) {
{
printf("cannot initialize decoder\n"); printf("cannot initialize decoder\n");
return -1; return -1;
} }
@ -291,151 +281,118 @@ valid values are 8 and 16.\n", sampFreqKHz);
// } // }
//} //}
if(codingMode == 1) if (codingMode == 1) {
{ if (WebRtcIsac_Control(ISAC_main_inst, bottleneck, frameSize) < 0) {
if(WebRtcIsac_Control(ISAC_main_inst, bottleneck, frameSize) < 0)
{
printf("cannot set bottleneck\n"); printf("cannot set bottleneck\n");
return -1; return -1;
} }
} } else {
else if (WebRtcIsac_ControlBwe(ISAC_main_inst, 15000, 30, 1) < 0) {
{
if(WebRtcIsac_ControlBwe(ISAC_main_inst, 15000, 30, 1) < 0)
{
printf("cannot configure BWE\n"); printf("cannot configure BWE\n");
return -1; return -1;
} }
} }
if(WebRtcIsac_SetMaxPayloadSize(ISAC_main_inst, payloadLimit) < 0) if (WebRtcIsac_SetMaxPayloadSize(ISAC_main_inst, payloadLimit) < 0) {
{
printf("cannot set maximum payload size %d.\n", payloadLimit); printf("cannot set maximum payload size %d.\n", payloadLimit);
return -1; return -1;
} }
if (rateLimit < 106800) { if (rateLimit < 106800) {
if(WebRtcIsac_SetMaxRate(ISAC_main_inst, rateLimit) < 0) if (WebRtcIsac_SetMaxRate(ISAC_main_inst, rateLimit) < 0) {
{
printf("cannot set the maximum rate %d.\n", rateLimit); printf("cannot set the maximum rate %d.\n", rateLimit);
return -1; return -1;
} }
} }
//===================================== //=====================================
//#ifdef HAVE_DEBUG_INFO //#ifdef HAVE_DEBUG_INFO
// if(setupDebugStruct(&debugInfo) < 0) // if(setupDebugStruct(&debugInfo) < 0)
// { // {
// exit(1); // exit(1);
// } // }
//#endif //#endif
while (endfile == 0) while (endfile == 0) {
{ fprintf(stderr, " \rframe = %7li", framecnt);
fprintf(stderr," \rframe = %7li", framecnt);
//============== Readind from the file and encoding ================= //============== Readind from the file and encoding =================
cur_framesmpls = 0; cur_framesmpls = 0;
stream_len = 0; stream_len = 0;
if (onlyDecode) {
if(onlyDecode)
{
uint8_t auxUW8; uint8_t auxUW8;
size_t auxSizet; size_t auxSizet;
if(fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) {
{
break; break;
} }
stream_len = ((uint8_t)auxUW8) << 8; stream_len = ((uint8_t)auxUW8) << 8;
if(fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) {
{
break; break;
} }
stream_len |= (uint16_t)auxUW8; stream_len |= (uint16_t)auxUW8;
auxSizet = (size_t)stream_len; auxSizet = (size_t)stream_len;
if(fread(payload, 1, auxSizet, inp) < auxSizet) if (fread(payload, 1, auxSizet, inp) < auxSizet) {
{
printf("last payload is corrupted\n"); printf("last payload is corrupted\n");
break; break;
} }
} } else {
else while (stream_len == 0) {
{
while(stream_len == 0)
{
// Read 10 ms speech block // Read 10 ms speech block
endfile = readframe(shortdata, inp, samplesIn10Ms); endfile = readframe(shortdata, inp, samplesIn10Ms);
if(endfile) if (endfile) {
{
break; break;
} }
cur_framesmpls += samplesIn10Ms; cur_framesmpls += samplesIn10Ms;
//-------- iSAC encoding --------- //-------- iSAC encoding ---------
stream_len = WebRtcIsac_Encode( stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata, payload);
ISAC_main_inst,
shortdata,
payload);
if(stream_len < 0) if (stream_len < 0) {
{
// exit if returned with error // exit if returned with error
//errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst);
fprintf(stderr,"\nError in encoder\n"); fprintf(stderr, "\nError in encoder\n");
getc(stdin); getc(stdin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
//=================================================================== //===================================================================
if(endfile) if (endfile) {
{
break; break;
} }
rcuStreamLen = WebRtcIsac_GetRedPayload( rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, payloadRCU);
ISAC_main_inst, payloadRCU);
get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData, get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData,
sampFreqKHz * 1000, sampFreqKHz * 1000); sampFreqKHz * 1000, sampFreqKHz * 1000);
if(WebRtcIsac_UpdateBwEstimate(ISAC_main_inst, if (WebRtcIsac_UpdateBwEstimate(
payload, ISAC_main_inst, payload, stream_len, packetData.rtp_number,
stream_len, packetData.sample_count, packetData.arrival_time) < 0) {
packetData.rtp_number,
packetData.sample_count,
packetData.arrival_time)
< 0)
{
printf(" BWE Error at client\n"); printf(" BWE Error at client\n");
return -1; return -1;
} }
} }
if(endfile) if (endfile) {
{
break; break;
} }
maxStreamLen = (stream_len > maxStreamLen)? stream_len:maxStreamLen; maxStreamLen = (stream_len > maxStreamLen) ? stream_len : maxStreamLen;
packetCntr++; packetCntr++;
hist[stream_len]++; hist[stream_len]++;
if(averageFile != NULL) if (averageFile != NULL) {
{
tmpSumStreamLen += stream_len; tmpSumStreamLen += stream_len;
if(packetCntr == 100) if (packetCntr == 100) {
{
// kbps // kbps
fprintf(averageFile, "%8.3f ", (double)tmpSumStreamLen * 8.0 / (30.0 * packetCntr)); fprintf(averageFile, "%8.3f ",
(double)tmpSumStreamLen * 8.0 / (30.0 * packetCntr));
packetCntr = 0; packetCntr = 0;
tmpSumStreamLen = 0; tmpSumStreamLen = 0;
} }
} }
if(onlyEncode) if (onlyEncode) {
{
uint8_t auxUW8; uint8_t auxUW8;
auxUW8 = (uint8_t)(((stream_len & 0x7F00) >> 8) & 0xFF); auxUW8 = (uint8_t)(((stream_len & 0x7F00) >> 8) & 0xFF);
if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) {
@ -446,46 +403,29 @@ valid values are 8 and 16.\n", sampFreqKHz);
if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) {
return -1; return -1;
} }
if (fwrite(payload, 1, stream_len, if (fwrite(payload, 1, stream_len, outp) != (size_t)stream_len) {
outp) != (size_t)stream_len) {
return -1; return -1;
} }
} } else {
else
{
//======================= iSAC decoding =========================== //======================= iSAC decoding ===========================
if((rand() % 100) < packetLossPercent) if ((rand() % 100) < packetLossPercent) {
{ declen = WebRtcIsac_DecodeRcu(ISAC_main_inst, payloadRCU, rcuStreamLen,
declen = WebRtcIsac_DecodeRcu( decoded, speechType);
ISAC_main_inst,
payloadRCU,
rcuStreamLen,
decoded,
speechType);
lostPacketCntr++; lostPacketCntr++;
} } else {
else declen = WebRtcIsac_Decode(ISAC_main_inst, payload, stream_len, decoded,
{
declen = WebRtcIsac_Decode(
ISAC_main_inst,
payload,
stream_len,
decoded,
speechType); speechType);
} }
if(declen <= 0) if (declen <= 0) {
{ // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst);
//errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); fprintf(stderr, "\nError in decoder.\n");
fprintf(stderr,"\nError in decoder.\n");
getc(stdin); getc(stdin);
exit(1); exit(1);
} }
// Write decoded speech frame to file // Write decoded speech frame to file
if (fwrite(decoded, sizeof(int16_t), if (fwrite(decoded, sizeof(int16_t), declen, outp) != (size_t)declen) {
declen, outp) != (size_t)declen) {
return -1; return -1;
} }
cur_framesmpls = declen; cur_framesmpls = declen;
@ -493,12 +433,10 @@ valid values are 8 and 16.\n", sampFreqKHz);
// Update Statistics // Update Statistics
framecnt++; framecnt++;
totalsmpls += cur_framesmpls; totalsmpls += cur_framesmpls;
if(stream_len > 0) if (stream_len > 0) {
{
totalbits += 8 * stream_len; totalbits += 8 * stream_len;
} }
if(rcuStreamLen > 0) if (rcuStreamLen > 0) {
{
totalBitsRCU += 8 * rcuStreamLen; totalBitsRCU += 8 * rcuStreamLen;
} }
} }
@ -513,19 +451,14 @@ valid values are 8 and 16.\n", sampFreqKHz);
#ifdef WIN32 #ifdef WIN32
#ifdef HAVE_DEBUG_INFO #ifdef HAVE_DEBUG_INFO
rateLB = ((double)debugInfo.lbBytes * 8. * rateLB =
(sampFreqKHz)) / (double)totalsmpls; ((double)debugInfo.lbBytes * 8. * (sampFreqKHz)) / (double)totalsmpls;
rateUB = ((double)debugInfo.ubBytes * 8. * rateUB =
(sampFreqKHz)) / (double)totalsmpls; ((double)debugInfo.ubBytes * 8. * (sampFreqKHz)) / (double)totalsmpls;
#endif #endif
fprintf(bitrateFile, "%d %10u %d %6.3f %6.3f %6.3f\n", fprintf(bitrateFile, "%d %10u %d %6.3f %6.3f %6.3f\n",
sampFreqKHz, sampFreqKHz, framecnt, bottleneck, rateLB, rateUB, rate);
framecnt,
bottleneck,
rateLB,
rateUB,
rate);
fclose(bitrateFile); fclose(bitrateFile);
#endif // WIN32 #endif // WIN32
@ -537,45 +470,43 @@ valid values are 8 and 16.\n", sampFreqKHz);
printf("Measured packet-loss.................. %0.1f%% \n", printf("Measured packet-loss.................. %0.1f%% \n",
100.0f * (float)lostPacketCntr / (float)packetCntr); 100.0f * (float)lostPacketCntr / (float)packetCntr);
//#ifdef HAVE_DEBUG_INFO //#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)); // 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)); // rateUB, (double)(rateUB) * 100. /(double)(rate));
// //
// printf("Maximum payload lower-band............ %d bytes (%0.3f kbps)\n", // printf("Maximum payload lower-band............ %d bytes (%0.3f kbps)\n",
// debugInfo.maxPayloadLB, debugInfo.maxPayloadLB * 8.0 / 0.03); // debugInfo.maxPayloadLB, debugInfo.maxPayloadLB * 8.0 / 0.03);
// printf("Maximum payload upper-band............ %d bytes (%0.3f kbps)\n", // printf("Maximum payload upper-band............ %d bytes (%0.3f kbps)\n",
// debugInfo.maxPayloadUB, debugInfo.maxPayloadUB * 8.0 / 0.03); // debugInfo.maxPayloadUB, debugInfo.maxPayloadUB * 8.0 / 0.03);
//#endif //#endif
printf("\n"); printf("\n");
/* Runtime statistics */ /* Runtime statistics */
#ifdef WIN32 #ifdef WIN32
runtime = (double)(clock()/(double)CLOCKS_PER_SEC-starttime); runtime = (double)(clock() / (double)CLOCKS_PER_SEC - starttime);
length_file = ((double)framecnt*(double)declen/(sampFreqKHz*1000)); length_file = ((double)framecnt * (double)declen / (sampFreqKHz * 1000));
printf("Length of speech file................ %.1f s\n", length_file); printf("Length of speech file................ %.1f s\n", length_file);
printf("Time to run iSAC..................... %.2f s (%.2f %% of realtime)\n\n", printf(
runtime, (100*runtime/length_file)); "Time to run iSAC..................... %.2f s (%.2f %% of realtime)\n\n",
runtime, (100 * runtime / length_file));
#endif #endif
printf("\n\n_______________________________________________\n"); printf("\n\n_______________________________________________\n");
if(histFile != NULL) if (histFile != NULL) {
{
int n; int n;
for(n = 0; n < 600; n++) for (n = 0; n < 600; n++) {
{
fprintf(histFile, "%6d ", hist[n]); fprintf(histFile, "%6d ", hist[n]);
} }
fprintf(histFile, "\n"); fprintf(histFile, "\n");
fclose(histFile); fclose(histFile);
} }
if(averageFile != NULL) if (averageFile != NULL) {
{ if (packetCntr > 0) {
if(packetCntr > 0) fprintf(averageFile, "%8.3f ",
{ (double)tmpSumStreamLen * 8.0 / (30.0 * packetCntr));
fprintf(averageFile, "%8.3f ", (double)tmpSumStreamLen * 8.0 / (30.0 * packetCntr));
} }
fprintf(averageFile, "\n"); fprintf(averageFile, "\n");
fclose(averageFile); fclose(averageFile);
@ -586,7 +517,6 @@ valid values are 8 and 16.\n", sampFreqKHz);
WebRtcIsac_Free(ISAC_main_inst); WebRtcIsac_Free(ISAC_main_inst);
#ifdef CHANGE_OUTPUT_NAME #ifdef CHANGE_OUTPUT_NAME
{ {
char* p; char* p;
@ -597,15 +527,12 @@ valid values are 8 and 16.\n", sampFreqKHz);
myExt[0] = '\0'; myExt[0] = '\0';
p = strchr(newOutName, '.'); p = strchr(newOutName, '.');
if(p != NULL) if (p != NULL) {
{
strcpy(myExt, p); strcpy(myExt, p);
*p = '_'; *p = '_';
p++; p++;
*p = '\0'; *p = '\0';
} } else {
else
{
strcat(newOutName, "_"); strcat(newOutName, "_");
} }
sprintf(bitRateStr, "%0.0fkbps", rate); sprintf(bitRateStr, "%0.0fkbps", rate);
@ -617,10 +544,8 @@ valid values are 8 and 16.\n", sampFreqKHz);
exit(0); exit(0);
} }
#ifdef HAVE_DEBUG_INFO #ifdef HAVE_DEBUG_INFO
int setupDebugStruct(debugStruct* str) int setupDebugStruct(debugStruct* str) {
{
str->prevPacketLost = 0; str->prevPacketLost = 0;
str->currPacketLost = 0; str->currPacketLost = 0;
@ -646,7 +571,7 @@ int setupDebugStruct(debugStruct* str)
OPEN_FILE_WB(str->fftFilePtr, "riFFT.dat"); OPEN_FILE_WB(str->fftFilePtr, "riFFT.dat");
OPEN_FILE_WB(str->fftDecFilePtr, "riFFTDec.dat"); OPEN_FILE_WB(str->fftDecFilePtr, "riFFTDec.dat");
OPEN_FILE_WB(str->arrivalTime, NULL/*"ArivalTime.dat"*/); OPEN_FILE_WB(str->arrivalTime, NULL /*"ArivalTime.dat"*/);
str->lastArrivalTime = 0; str->lastArrivalTime = 0;
str->maxPayloadLB = 0; str->maxPayloadLB = 0;

File diff suppressed because it is too large Load Diff