OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 int16_t decoded[MAX_FRAMESAMPLES]; | 117 int16_t decoded[MAX_FRAMESAMPLES]; |
118 uint16_t streamdata[500]; | 118 uint16_t streamdata[500]; |
119 int16_t speechType[1]; | 119 int16_t speechType[1]; |
120 size_t prevFrameSize = 1; | 120 size_t prevFrameSize = 1; |
121 int16_t rateBPS = 0; | 121 int16_t rateBPS = 0; |
122 int16_t fixedFL = 0; | 122 int16_t fixedFL = 0; |
123 int16_t payloadSize = 0; | 123 int16_t payloadSize = 0; |
124 int32_t payloadRate = 0; | 124 int32_t payloadRate = 0; |
125 int setControlBWE = 0; | 125 int setControlBWE = 0; |
126 int readLoss; | 126 int readLoss; |
127 FILE *plFile = NULL; | 127 FILE* plFile = nullptr; |
128 | 128 |
129 char version_number[20]; | 129 char version_number[20]; |
130 char tmpBit[5] = ".bit"; | 130 char tmpBit[5] = ".bit"; |
131 | 131 |
132 int totalbits =0; | 132 int totalbits =0; |
133 int totalsmpls =0; | 133 int totalsmpls =0; |
134 int16_t testNum, testCE; | 134 int16_t testNum, testCE; |
135 | 135 |
136 FILE *fp_gns = NULL; | 136 FILE* fp_gns = nullptr; |
137 int gns = 0; | 137 int gns = 0; |
138 int cur_delay = 0; | 138 int cur_delay = 0; |
139 char gns_file[100]; | 139 char gns_file[100]; |
140 | 140 |
141 int nbTest = 0; | 141 int nbTest = 0; |
142 int16_t lostFrame; | 142 int16_t lostFrame; |
143 float scale = (float)0.7; | 143 float scale = (float)0.7; |
144 /* only one structure used for ISAC encoder */ | 144 /* only one structure used for ISAC encoder */ |
145 ISACFIX_MainStruct *ISAC_main_inst = NULL; | 145 ISACFIX_MainStruct* ISAC_main_inst = nullptr; |
146 | 146 |
147 /* For fault test 10, garbage data */ | 147 /* For fault test 10, garbage data */ |
148 FILE *seedfile; | 148 FILE *seedfile; |
149 unsigned int random_seed = (unsigned int) time(NULL);//1196764538 | 149 unsigned int random_seed = (unsigned int)time(nullptr); // 1196764538 |
150 | 150 |
151 BottleNeckModel BN_data; | 151 BottleNeckModel BN_data; |
152 f_bn = NULL; | 152 f_bn = nullptr; |
153 | 153 |
154 readLoss = 0; | 154 readLoss = 0; |
155 packetLossPercent = 0; | 155 packetLossPercent = 0; |
156 | 156 |
157 /* Handling wrong input arguments in the command line */ | 157 /* Handling wrong input arguments in the command line */ |
158 if ((argc<3) || (argc>21)) { | 158 if ((argc<3) || (argc>21)) { |
159 printf("\n\nWrong number of arguments or flag values.\n\n"); | 159 printf("\n\nWrong number of arguments or flag values.\n\n"); |
160 | 160 |
161 printf("\n"); | 161 printf("\n"); |
162 WebRtcIsacfix_version(version_number); | 162 WebRtcIsacfix_version(version_number); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if( packetLossPercent > 0 ) { | 311 if( packetLossPercent > 0 ) { |
312 printf( "\nSimulating %d %% of independent packet loss\n", | 312 printf( "\nSimulating %d %% of independent packet loss\n", |
313 packetLossPercent ); | 313 packetLossPercent ); |
314 } else { | 314 } else { |
315 printf( "\nNo Packet Loss Is Simulated \n" ); | 315 printf( "\nNo Packet Loss Is Simulated \n" ); |
316 } | 316 } |
317 readLoss = 0; | 317 readLoss = 0; |
318 } else { | 318 } else { |
319 readLoss = 1; | 319 readLoss = 1; |
320 plFile = fopen( argv[i+1], "rb" ); | 320 plFile = fopen( argv[i+1], "rb" ); |
321 if( plFile == NULL ) { | 321 if (plFile == nullptr) { |
322 printf( "\n couldn't open the frameloss file: %s\n", argv[i+1] ); | 322 printf( "\n couldn't open the frameloss file: %s\n", argv[i+1] ); |
323 exit( 0 ); | 323 exit( 0 ); |
324 } | 324 } |
325 printf( "\nSimulating packet loss through the given " | 325 printf( "\nSimulating packet loss through the given " |
326 "channel file: %s\n", argv[i+1] ); | 326 "channel file: %s\n", argv[i+1] ); |
327 } | 327 } |
328 i++; | 328 i++; |
329 } | 329 } |
330 | 330 |
331 /* Random packetlosses */ | 331 /* Random packetlosses */ |
332 if (!strcmp ("-rnd", argv[i])) { | 332 if (!strcmp ("-rnd", argv[i])) { |
333 srand(time(NULL) ); | 333 srand(time(nullptr)); |
334 printf( "\n Random pattern in lossed packets \n" ); | 334 printf( "\n Random pattern in lossed packets \n" ); |
335 } | 335 } |
336 | 336 |
337 /* Use gns file */ | 337 /* Use gns file */ |
338 if (!strcmp ("-G", argv[i])) { | 338 if (!strcmp ("-G", argv[i])) { |
339 sscanf(argv[i + 1], "%s", gns_file); | 339 sscanf(argv[i + 1], "%s", gns_file); |
340 fp_gns = fopen(gns_file, "rb"); | 340 fp_gns = fopen(gns_file, "rb"); |
341 if (fp_gns == NULL) { | 341 if (fp_gns == nullptr) { |
342 printf("Cannot read file %s.\n", gns_file); | 342 printf("Cannot read file %s.\n", gns_file); |
343 exit(0); | 343 exit(0); |
344 } | 344 } |
345 gns = 1; | 345 gns = 1; |
346 i++; | 346 i++; |
347 } | 347 } |
348 | 348 |
349 /* Run Narrowband interfaces (either encoder or decoder) */ | 349 /* Run Narrowband interfaces (either encoder or decoder) */ |
350 if (!strcmp ("-NB", argv[i])) { | 350 if (!strcmp ("-NB", argv[i])) { |
351 nbTest = atoi(argv[i + 1]); | 351 nbTest = atoi(argv[i + 1]); |
(...skipping 19 matching lines...) Expand all Loading... |
371 i++; | 371 i++; |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 /* Get Bottleneck value */ | 375 /* Get Bottleneck value */ |
376 /* Gns files and bottleneck should not and can not be used simultaneously */ | 376 /* Gns files and bottleneck should not and can not be used simultaneously */ |
377 bottleneck = atoi(argv[CodingMode+1]); | 377 bottleneck = atoi(argv[CodingMode+1]); |
378 if (bottleneck == 0 && gns == 0) { | 378 if (bottleneck == 0 && gns == 0) { |
379 sscanf(argv[CodingMode+1], "%s", bottleneck_file); | 379 sscanf(argv[CodingMode+1], "%s", bottleneck_file); |
380 f_bn = fopen(bottleneck_file, "rb"); | 380 f_bn = fopen(bottleneck_file, "rb"); |
381 if (f_bn == NULL) { | 381 if (f_bn == nullptr) { |
382 printf("No value provided for BottleNeck and cannot read file %s\n", | 382 printf("No value provided for BottleNeck and cannot read file %s\n", |
383 bottleneck_file); | 383 bottleneck_file); |
384 exit(0); | 384 exit(0); |
385 } else { | 385 } else { |
386 int aux_var; | 386 int aux_var; |
387 printf("reading bottleneck rates from file %s\n\n",bottleneck_file); | 387 printf("reading bottleneck rates from file %s\n\n",bottleneck_file); |
388 if (fscanf(f_bn, "%d", &aux_var) == EOF) { | 388 if (fscanf(f_bn, "%d", &aux_var) == EOF) { |
389 /* Set pointer to beginning of file */ | 389 /* Set pointer to beginning of file */ |
390 fseek(f_bn, 0L, SEEK_SET); | 390 fseek(f_bn, 0L, SEEK_SET); |
391 if (fscanf(f_bn, "%d", &aux_var) == EOF) { | 391 if (fscanf(f_bn, "%d", &aux_var) == EOF) { |
392 exit(0); | 392 exit(0); |
393 } | 393 } |
394 } | 394 } |
395 bottleneck = (int16_t)aux_var; | 395 bottleneck = (int16_t)aux_var; |
396 /* Bottleneck is a cosine function | 396 /* Bottleneck is a cosine function |
397 * Matlab code for writing the bottleneck file: | 397 * Matlab code for writing the bottleneck file: |
398 * BottleNeck_10ms = 20e3 + 10e3 * cos((0:5999)/5999*2*pi); | 398 * BottleNeck_10ms = 20e3 + 10e3 * cos((0:5999)/5999*2*pi); |
399 * fid = fopen('bottleneck.txt', 'wb'); | 399 * fid = fopen('bottleneck.txt', 'wb'); |
400 * fprintf(fid, '%d\n', BottleNeck_10ms); fclose(fid); | 400 * fprintf(fid, '%d\n', BottleNeck_10ms); fclose(fid); |
401 */ | 401 */ |
402 } | 402 } |
403 } else { | 403 } else { |
404 f_bn = NULL; | 404 f_bn = nullptr; |
405 printf("\nfixed bottleneck rate of %d bits/s\n\n", bottleneck); | 405 printf("\nfixed bottleneck rate of %d bits/s\n\n", bottleneck); |
406 } | 406 } |
407 | 407 |
408 if (CodingMode == 0) { | 408 if (CodingMode == 0) { |
409 printf("\nAdaptive BottleNeck\n"); | 409 printf("\nAdaptive BottleNeck\n"); |
410 } | 410 } |
411 | 411 |
412 /* Get Input and Output files */ | 412 /* Get Input and Output files */ |
413 sscanf(argv[argc-2], "%s", inname); | 413 sscanf(argv[argc-2], "%s", inname); |
414 sscanf(argv[argc-1], "%s", outname); | 414 sscanf(argv[argc-1], "%s", outname); |
415 | 415 |
416 /* Add '.bit' to output bitstream file */ | 416 /* Add '.bit' to output bitstream file */ |
417 while ((int)outname[h] != 0) { | 417 while ((int)outname[h] != 0) { |
418 outbitsname[h] = outname[h]; | 418 outbitsname[h] = outname[h]; |
419 h++; | 419 h++; |
420 } | 420 } |
421 for (k=0; k<5; k++) { | 421 for (k=0; k<5; k++) { |
422 outbitsname[h] = tmpBit[k]; | 422 outbitsname[h] = tmpBit[k]; |
423 h++; | 423 h++; |
424 } | 424 } |
425 if ((inp = fopen(inname,"rb")) == NULL) { | 425 if ((inp = fopen(inname, "rb")) == nullptr) { |
426 printf(" iSAC: Cannot read file %s\n", inname); | 426 printf(" iSAC: Cannot read file %s\n", inname); |
427 exit(1); | 427 exit(1); |
428 } | 428 } |
429 if ((outp = fopen(outname,"wb")) == NULL) { | 429 if ((outp = fopen(outname, "wb")) == nullptr) { |
430 printf(" iSAC: Cannot write file %s\n", outname); | 430 printf(" iSAC: Cannot write file %s\n", outname); |
431 exit(1); | 431 exit(1); |
432 } | 432 } |
433 | 433 |
434 if ((outbits = fopen(outbitsname,"wb")) == NULL) { | 434 if ((outbits = fopen(outbitsname, "wb")) == nullptr) { |
435 printf(" iSAC: Cannot write file %s\n", outbitsname); | 435 printf(" iSAC: Cannot write file %s\n", outbitsname); |
436 exit(1); | 436 exit(1); |
437 } | 437 } |
438 printf("\nInput:%s\nOutput:%s\n\n", inname, outname); | 438 printf("\nInput:%s\nOutput:%s\n\n", inname, outname); |
439 | 439 |
440 /* Error test number 10, garbage data */ | 440 /* Error test number 10, garbage data */ |
441 if (testNum == 10) { | 441 if (testNum == 10) { |
442 /* Test to run decoder with garbage data */ | 442 /* Test to run decoder with garbage data */ |
443 srand(random_seed); | 443 srand(random_seed); |
444 | 444 |
445 if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { | 445 if ((seedfile = fopen(SEED_FILE, "a+t")) == nullptr) { |
446 printf("Error: Could not open file %s\n", SEED_FILE); | 446 printf("Error: Could not open file %s\n", SEED_FILE); |
447 } | 447 } |
448 else { | 448 else { |
449 fprintf(seedfile, "%u\n", random_seed); | 449 fprintf(seedfile, "%u\n", random_seed); |
450 fclose(seedfile); | 450 fclose(seedfile); |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 /* Runtime statistics */ | 454 /* Runtime statistics */ |
455 starttime = clock()/(double)CLOCKS_PER_SEC; | 455 starttime = clock()/(double)CLOCKS_PER_SEC; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 cur_framesmpls = 0; | 546 cur_framesmpls = 0; |
547 while (1) { | 547 while (1) { |
548 /* Read 10 ms speech block */ | 548 /* Read 10 ms speech block */ |
549 if (nbTest != 1) { | 549 if (nbTest != 1) { |
550 endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms); | 550 endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms); |
551 } else { | 551 } else { |
552 endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms/2)); | 552 endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms/2)); |
553 } | 553 } |
554 | 554 |
555 if (testNum == 7) { | 555 if (testNum == 7) { |
556 srand(time(NULL)); | 556 srand(time(nullptr)); |
557 } | 557 } |
558 | 558 |
559 /* iSAC encoding */ | 559 /* iSAC encoding */ |
560 if (!(testNum == 3 && framecnt == 0)) { | 560 if (!(testNum == 3 && framecnt == 0)) { |
561 if (nbTest != 1) { | 561 if (nbTest != 1) { |
562 short bwe; | 562 short bwe; |
563 | 563 |
564 /* Encode */ | 564 /* Encode */ |
565 stream_len_int = WebRtcIsacfix_Encode(ISAC_main_inst, | 565 stream_len_int = WebRtcIsacfix_Encode(ISAC_main_inst, |
566 shortdata, | 566 shortdata, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 stream_len = static_cast<size_t>(stream_len_int); | 624 stream_len = static_cast<size_t>(stream_len_int); |
625 if (fwrite(streamdata, sizeof(char), stream_len, outbits) != | 625 if (fwrite(streamdata, sizeof(char), stream_len, outbits) != |
626 stream_len) { | 626 stream_len) { |
627 return -1; | 627 return -1; |
628 } | 628 } |
629 } | 629 } |
630 | 630 |
631 cur_framesmpls += FRAMESAMPLES_10ms; | 631 cur_framesmpls += FRAMESAMPLES_10ms; |
632 | 632 |
633 /* read next bottleneck rate */ | 633 /* read next bottleneck rate */ |
634 if (f_bn != NULL) { | 634 if (f_bn != nullptr) { |
635 int aux_var; | 635 int aux_var; |
636 if (fscanf(f_bn, "%d", &aux_var) == EOF) { | 636 if (fscanf(f_bn, "%d", &aux_var) == EOF) { |
637 /* Set pointer to beginning of file */ | 637 /* Set pointer to beginning of file */ |
638 fseek(f_bn, 0L, SEEK_SET); | 638 fseek(f_bn, 0L, SEEK_SET); |
639 if (fscanf(f_bn, "%d", &aux_var) == EOF) { | 639 if (fscanf(f_bn, "%d", &aux_var) == EOF) { |
640 exit(0); | 640 exit(0); |
641 } | 641 } |
642 } | 642 } |
643 bottleneck = (int16_t)aux_var; | 643 bottleneck = (int16_t)aux_var; |
644 if (CodingMode == 1) { | 644 if (CodingMode == 1) { |
(...skipping 11 matching lines...) Expand all Loading... |
656 stream_len += 10; | 656 stream_len += 10; |
657 } | 657 } |
658 | 658 |
659 /* make coded sequence to long be decreasing */ | 659 /* make coded sequence to long be decreasing */ |
660 /* the length the decoder expects */ | 660 /* the length the decoder expects */ |
661 if (testNum == 5) { | 661 if (testNum == 5) { |
662 stream_len -= 10; | 662 stream_len -= 10; |
663 } | 663 } |
664 | 664 |
665 if (testNum == 6) { | 665 if (testNum == 6) { |
666 srand(time(NULL)); | 666 srand(time(nullptr)); |
667 for (i = 0; i < stream_len; i++ ) { | 667 for (i = 0; i < stream_len; i++ ) { |
668 streamdata[i] = rand(); | 668 streamdata[i] = rand(); |
669 } | 669 } |
670 } | 670 } |
671 | 671 |
672 /* set pointer to beginning of file */ | 672 /* set pointer to beginning of file */ |
673 if (fp_gns != NULL) { | 673 if (fp_gns != nullptr) { |
674 if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { | 674 if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { |
675 fseek(fp_gns, 0L, SEEK_SET); | 675 fseek(fp_gns, 0L, SEEK_SET); |
676 if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { | 676 if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { |
677 exit(0); | 677 exit(0); |
678 } | 678 } |
679 } | 679 } |
680 } | 680 } |
681 | 681 |
682 /* simulate packet handling through NetEq and the modem */ | 682 /* simulate packet handling through NetEq and the modem */ |
683 if (!(testNum == 3 && framecnt == 0)) { | 683 if (!(testNum == 3 && framecnt == 0)) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 } else { | 786 } else { |
787 lostPackets++; | 787 lostPackets++; |
788 } | 788 } |
789 framecnt++; | 789 framecnt++; |
790 | 790 |
791 totalsmpls += declen; | 791 totalsmpls += declen; |
792 totalbits += static_cast<int>(8 * stream_len); | 792 totalbits += static_cast<int>(8 * stream_len); |
793 | 793 |
794 /* Error test number 10, garbage data */ | 794 /* Error test number 10, garbage data */ |
795 if (testNum == 10) { | 795 if (testNum == 10) { |
796 if ( (seedfile = fopen(SEED_FILE, "a+t") ) == NULL ) { | 796 if ((seedfile = fopen(SEED_FILE, "a+t")) == nullptr) { |
797 printf( "Error: Could not open file %s\n", SEED_FILE); | 797 printf( "Error: Could not open file %s\n", SEED_FILE); |
798 } | 798 } |
799 else { | 799 else { |
800 fprintf(seedfile, "ok\n\n"); | 800 fprintf(seedfile, "ok\n\n"); |
801 fclose(seedfile); | 801 fclose(seedfile); |
802 } | 802 } |
803 } | 803 } |
804 } | 804 } |
805 printf("\nLost Frames %d ~ %4.1f%%\n", lostPackets, | 805 printf("\nLost Frames %d ~ %4.1f%%\n", lostPackets, |
806 (double)lostPackets/(double)framecnt*100.0 ); | 806 (double)lostPackets/(double)framecnt*100.0 ); |
(...skipping 19 matching lines...) Expand all Loading... |
826 fclose(inp); | 826 fclose(inp); |
827 fclose(outp); | 827 fclose(outp); |
828 fclose(outbits); | 828 fclose(outbits); |
829 | 829 |
830 if ( testCE == 1) { | 830 if ( testCE == 1) { |
831 WebRtcIsacfix_FreeInternal(ISAC_main_inst); | 831 WebRtcIsacfix_FreeInternal(ISAC_main_inst); |
832 } | 832 } |
833 WebRtcIsacfix_Free(ISAC_main_inst); | 833 WebRtcIsacfix_Free(ISAC_main_inst); |
834 return 0; | 834 return 0; |
835 } | 835 } |
OLD | NEW |