| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 |
| 11 /* | 11 /* |
| 12 * test_iSACfixfloat.c | 12 * test_iSACfixfloat.c |
| 13 * | 13 * |
| 14 * Test compatibility and quality between floating- and fixed-point code | 14 * Test compatibility and quality between floating- and fixed-point code |
| 15 * */ | 15 * */ |
| 16 | 16 |
| 17 #include <stdio.h> | 17 #include <stdio.h> |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #include <string.h> | 19 #include <string.h> |
| 20 | 20 |
| 21 /* include API */ | 21 /* include API */ |
| 22 #include "isac.h" | 22 #include "isac.h" |
| 23 #include "isacfix.h" | 23 #include "isacfix.h" |
| 24 #include "webrtc/base/format_macros.h" |
| 24 | 25 |
| 25 /* max number of samples per frame (= 60 ms frame) */ | 26 /* max number of samples per frame (= 60 ms frame) */ |
| 26 #define MAX_FRAMESAMPLES 960 | 27 #define MAX_FRAMESAMPLES 960 |
| 27 /* number of samples per 10ms frame */ | 28 /* number of samples per 10ms frame */ |
| 28 #define FRAMESAMPLES_10ms 160 | 29 #define FRAMESAMPLES_10ms 160 |
| 29 /* sampling frequency (Hz) */ | 30 /* sampling frequency (Hz) */ |
| 30 #define FS 16000 | 31 #define FS 16000 |
| 31 | 32 |
| 32 /* Runtime statistics */ | 33 /* Runtime statistics */ |
| 33 #include <time.h> | 34 #include <time.h> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 } | 51 } |
| 51 | 52 |
| 52 typedef struct { | 53 typedef struct { |
| 53 uint32_t send_time; /* samples */ | 54 uint32_t send_time; /* samples */ |
| 54 uint32_t arrival_time; /* samples */ | 55 uint32_t arrival_time; /* samples */ |
| 55 uint32_t sample_count; /* samples */ | 56 uint32_t sample_count; /* samples */ |
| 56 uint16_t rtp_number; | 57 uint16_t rtp_number; |
| 57 } BottleNeckModel; | 58 } BottleNeckModel; |
| 58 | 59 |
| 59 void get_arrival_time(int current_framesamples, /* samples */ | 60 void get_arrival_time(int current_framesamples, /* samples */ |
| 60 int packet_size, /* bytes */ | 61 size_t packet_size, /* bytes */ |
| 61 int bottleneck, /* excluding headers; bits/s */ | 62 int bottleneck, /* excluding headers; bits/s */ |
| 62 BottleNeckModel* BN_data) { | 63 BottleNeckModel* BN_data) { |
| 63 const int HeaderSize = 35; | 64 const int HeaderSize = 35; |
| 64 int HeaderRate; | 65 int HeaderRate; |
| 65 | 66 |
| 66 HeaderRate = HeaderSize * 8 * FS / current_framesamples; /* bits/s */ | 67 HeaderRate = HeaderSize * 8 * FS / current_framesamples; /* bits/s */ |
| 67 | 68 |
| 68 /* everything in samples */ | 69 /* everything in samples */ |
| 69 BN_data->sample_count = BN_data->sample_count + current_framesamples; | 70 BN_data->sample_count = BN_data->sample_count + current_framesamples; |
| 70 | 71 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 int framesize = 30; /* ms */ | 92 int framesize = 30; /* ms */ |
| 92 // int framesize = 60; /* To invoke cisco complexity case at frame 2252 */ | 93 // int framesize = 60; /* To invoke cisco complexity case at frame 2252 */ |
| 93 | 94 |
| 94 int cur_framesmpls, err; | 95 int cur_framesmpls, err; |
| 95 | 96 |
| 96 /* Runtime statistics */ | 97 /* Runtime statistics */ |
| 97 double starttime; | 98 double starttime; |
| 98 double runtime; | 99 double runtime; |
| 99 double length_file; | 100 double length_file; |
| 100 | 101 |
| 101 int16_t stream_len = 0; | 102 size_t stream_len = 0; |
| 102 int declen; | 103 int declen; |
| 103 | 104 |
| 104 int16_t shortdata[FRAMESAMPLES_10ms]; | 105 int16_t shortdata[FRAMESAMPLES_10ms]; |
| 105 int16_t decoded[MAX_FRAMESAMPLES]; | 106 int16_t decoded[MAX_FRAMESAMPLES]; |
| 106 uint16_t streamdata[600]; | 107 uint16_t streamdata[600]; |
| 107 int16_t speechType[1]; | 108 int16_t speechType[1]; |
| 108 | 109 |
| 109 // int16_t* iSACstruct; | 110 // int16_t* iSACstruct; |
| 110 | 111 |
| 111 char version_number[20]; | 112 char version_number[20]; |
| 112 int mode = -1, tmp, nbTest = 0; /*,sss;*/ | 113 int mode = -1, tmp, nbTest = 0; /*,sss;*/ |
| 113 | 114 |
| 114 #ifdef _DEBUG | 115 #ifdef _DEBUG |
| 115 FILE* fy; | 116 FILE* fy; |
| 116 double kbps; | 117 double kbps; |
| 117 int totalbits = 0; | 118 size_t totalbits = 0; |
| 118 int totalsmpls = 0; | 119 int totalsmpls = 0; |
| 119 #endif /* _DEBUG */ | 120 #endif /* _DEBUG */ |
| 120 | 121 |
| 121 /* only one structure used for ISAC encoder */ | 122 /* only one structure used for ISAC encoder */ |
| 122 ISAC_MainStruct* ISAC_main_inst; | 123 ISAC_MainStruct* ISAC_main_inst; |
| 123 ISACFIX_MainStruct* ISACFIX_main_inst; | 124 ISACFIX_MainStruct* ISACFIX_main_inst; |
| 124 | 125 |
| 125 BottleNeckModel BN_data; | 126 BottleNeckModel BN_data; |
| 126 f_bn = NULL; | 127 f_bn = NULL; |
| 127 | 128 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 fclose(inp); | 386 fclose(inp); |
| 386 fclose(outp); | 387 fclose(outp); |
| 387 fclose(bitsp); | 388 fclose(bitsp); |
| 388 return (EXIT_FAILURE); | 389 return (EXIT_FAILURE); |
| 389 } | 390 } |
| 390 #endif | 391 #endif |
| 391 | 392 |
| 392 while (endfile == 0) { | 393 while (endfile == 0) { |
| 393 cur_framesmpls = 0; | 394 cur_framesmpls = 0; |
| 394 while (1) { | 395 while (1) { |
| 396 int stream_len_int; |
| 397 |
| 395 /* Read 10 ms speech block */ | 398 /* Read 10 ms speech block */ |
| 396 if (nbTest != 1) | 399 if (nbTest != 1) |
| 397 endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms); | 400 endfile = readframe(shortdata, inp, FRAMESAMPLES_10ms); |
| 398 else | 401 else |
| 399 endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms / 2)); | 402 endfile = readframe(shortdata, inp, (FRAMESAMPLES_10ms / 2)); |
| 400 | 403 |
| 401 /* iSAC encoding */ | 404 /* iSAC encoding */ |
| 402 | 405 |
| 403 if (mode == 0 || mode == 1) { | 406 if (mode == 0 || mode == 1) { |
| 404 stream_len = | 407 stream_len_int = |
| 405 WebRtcIsac_Encode(ISAC_main_inst, shortdata, (uint8_t*)streamdata); | 408 WebRtcIsac_Encode(ISAC_main_inst, shortdata, (uint8_t*)streamdata); |
| 406 if (stream_len < 0) { | 409 if (stream_len_int < 0) { |
| 407 /* exit if returned with error */ | 410 /* exit if returned with error */ |
| 408 errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst); | 411 errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst); |
| 409 printf("\n\nError in encoder: %d.\n\n", errtype); | 412 printf("\n\nError in encoder: %d.\n\n", errtype); |
| 410 // exit(EXIT_FAILURE); | 413 // exit(EXIT_FAILURE); |
| 411 } | 414 } |
| 412 } else if (mode == 2 || mode == 3) { | 415 } else if (mode == 2 || mode == 3) { |
| 413 /* iSAC encoding */ | 416 /* iSAC encoding */ |
| 414 if (nbTest != 1) { | 417 if (nbTest != 1) { |
| 415 stream_len = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata, | 418 stream_len_int = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata, |
| 416 (uint8_t*)streamdata); | 419 (uint8_t*)streamdata); |
| 417 } else { | 420 } else { |
| 418 stream_len = | 421 stream_len_int = |
| 419 WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata); | 422 WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata); |
| 420 } | 423 } |
| 421 | 424 |
| 422 if (stream_len < 0) { | 425 if (stream_len_int < 0) { |
| 423 /* exit if returned with error */ | 426 /* exit if returned with error */ |
| 424 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); | 427 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); |
| 425 printf("\n\nError in encoder: %d.\n\n", errtype); | 428 printf("\n\nError in encoder: %d.\n\n", errtype); |
| 426 // exit(EXIT_FAILURE); | 429 // exit(EXIT_FAILURE); |
| 427 } | 430 } |
| 428 } | 431 } |
| 432 stream_len = (size_t)stream_len_int; |
| 429 | 433 |
| 430 cur_framesmpls += FRAMESAMPLES_10ms; | 434 cur_framesmpls += FRAMESAMPLES_10ms; |
| 431 | 435 |
| 432 /* read next bottleneck rate */ | 436 /* read next bottleneck rate */ |
| 433 if (f_bn != NULL) { | 437 if (f_bn != NULL) { |
| 434 if (fscanf(f_bn, "%d", &bottleneck) == EOF) { | 438 if (fscanf(f_bn, "%d", &bottleneck) == EOF) { |
| 435 /* Set pointer to beginning of file */ | 439 /* Set pointer to beginning of file */ |
| 436 fseek(f_bn, 0L, SEEK_SET); | 440 fseek(f_bn, 0L, SEEK_SET); |
| 437 fscanf(f_bn, "%d", &bottleneck); | 441 fscanf(f_bn, "%d", &bottleneck); |
| 438 } | 442 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); | 491 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); |
| 488 printf("\n\nError in decoder: %d.\n\n", errtype); | 492 printf("\n\nError in decoder: %d.\n\n", errtype); |
| 489 // exit(EXIT_FAILURE); | 493 // exit(EXIT_FAILURE); |
| 490 } | 494 } |
| 491 | 495 |
| 492 declen = WebRtcIsac_Decode(ISAC_main_inst, streamdata, stream_len, | 496 declen = WebRtcIsac_Decode(ISAC_main_inst, streamdata, stream_len, |
| 493 decoded, speechType); | 497 decoded, speechType); |
| 494 | 498 |
| 495 /* iSAC decoding */ | 499 /* iSAC decoding */ |
| 496 if (plc && (framecnt + 1) % 10 == 0) { | 500 if (plc && (framecnt + 1) % 10 == 0) { |
| 497 if (nbTest != 2) | 501 if (nbTest != 2) { |
| 498 declen = WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1); | 502 declen = |
| 499 else | 503 (int)WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1); |
| 500 declen = WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1); | 504 } else { |
| 505 declen = |
| 506 (int)WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1); |
| 507 } |
| 501 } else { | 508 } else { |
| 502 if (nbTest != 2) | 509 if (nbTest != 2) |
| 503 declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata, | 510 declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata, |
| 504 stream_len, decoded, speechType); | 511 stream_len, decoded, speechType); |
| 505 else | 512 else |
| 506 declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata, | 513 declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata, |
| 507 stream_len, decoded, speechType); | 514 stream_len, decoded, speechType); |
| 508 } | 515 } |
| 509 | 516 |
| 510 if (declen <= 0) { | 517 if (declen <= 0) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 551 |
| 545 if (err < 0) { | 552 if (err < 0) { |
| 546 /* exit if returned with error */ | 553 /* exit if returned with error */ |
| 547 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); | 554 errtype = WebRtcIsacfix_GetErrorCode(ISACFIX_main_inst); |
| 548 printf("\n\nError in decoder: %d.\n\n", errtype); | 555 printf("\n\nError in decoder: %d.\n\n", errtype); |
| 549 // exit(EXIT_FAILURE); | 556 // exit(EXIT_FAILURE); |
| 550 } | 557 } |
| 551 /* iSAC decoding */ | 558 /* iSAC decoding */ |
| 552 | 559 |
| 553 if (plc && (framecnt + 1) % 10 == 0) { | 560 if (plc && (framecnt + 1) % 10 == 0) { |
| 554 if (nbTest != 2) | 561 if (nbTest != 2) { |
| 555 declen = WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1); | 562 declen = |
| 556 else | 563 (int)WebRtcIsacfix_DecodePlc(ISACFIX_main_inst, decoded, 1); |
| 557 declen = WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1); | 564 } else { |
| 565 declen = |
| 566 (int)WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1); |
| 567 } |
| 558 } else { | 568 } else { |
| 559 if (nbTest != 2) { | 569 if (nbTest != 2) { |
| 560 declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata, | 570 declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata, |
| 561 stream_len, decoded, speechType); | 571 stream_len, decoded, speechType); |
| 562 } else { | 572 } else { |
| 563 declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata, | 573 declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata, |
| 564 stream_len, decoded, speechType); | 574 stream_len, decoded, speechType); |
| 565 } | 575 } |
| 566 } | 576 } |
| 567 if (declen <= 0) { | 577 if (declen <= 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 585 totalbits += 8 * stream_len; | 595 totalbits += 8 * stream_len; |
| 586 kbps = (double)FS / (double)cur_framesmpls * 8.0 * stream_len / 1000.0; | 596 kbps = (double)FS / (double)cur_framesmpls * 8.0 * stream_len / 1000.0; |
| 587 fy = fopen("bit_rate.dat", "a"); | 597 fy = fopen("bit_rate.dat", "a"); |
| 588 fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps); | 598 fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps); |
| 589 fclose(fy); | 599 fclose(fy); |
| 590 | 600 |
| 591 #endif /* _DEBUG */ | 601 #endif /* _DEBUG */ |
| 592 } | 602 } |
| 593 | 603 |
| 594 #ifdef _DEBUG | 604 #ifdef _DEBUG |
| 595 printf("\n\ntotal bits = %d bits", totalbits); | 605 printf("\n\ntotal bits = %" PRIuS " bits", totalbits); |
| 596 printf("\nmeasured average bitrate = %0.3f kbits/s", | 606 printf("\nmeasured average bitrate = %0.3f kbits/s", |
| 597 (double)totalbits * (FS / 1000) / totalsmpls); | 607 (double)totalbits * (FS / 1000) / totalsmpls); |
| 598 printf("\n"); | 608 printf("\n"); |
| 599 #endif /* _DEBUG */ | 609 #endif /* _DEBUG */ |
| 600 | 610 |
| 601 /* Runtime statistics */ | 611 /* Runtime statistics */ |
| 602 runtime = (double)(clock() / (double)CLOCKS_PER_SEC - starttime); | 612 runtime = (double)(clock() / (double)CLOCKS_PER_SEC - starttime); |
| 603 length_file = ((double)framecnt * (double)declen / FS); | 613 length_file = ((double)framecnt * (double)declen / FS); |
| 604 printf("\n\nLength of speech file: %.1f s\n", length_file); | 614 printf("\n\nLength of speech file: %.1f s\n", length_file); |
| 605 printf("Time to run iSAC: %.2f s (%.2f %% of realtime)\n\n", runtime, | 615 printf("Time to run iSAC: %.2f s (%.2f %% of realtime)\n\n", runtime, |
| 606 (100 * runtime / length_file)); | 616 (100 * runtime / length_file)); |
| 607 printf("---------------------END----------------------\n"); | 617 printf("---------------------END----------------------\n"); |
| 608 | 618 |
| 609 fclose(inp); | 619 fclose(inp); |
| 610 fclose(outp); | 620 fclose(outp); |
| 611 | 621 |
| 612 WebRtcIsac_Free(ISAC_main_inst); | 622 WebRtcIsac_Free(ISAC_main_inst); |
| 613 WebRtcIsacfix_Free(ISACFIX_main_inst); | 623 WebRtcIsacfix_Free(ISACFIX_main_inst); |
| 614 | 624 |
| 615 // fclose(histfile); | 625 // fclose(histfile); |
| 616 // fclose(ratefile); | 626 // fclose(ratefile); |
| 617 | 627 |
| 618 return 0; | 628 return 0; |
| 619 } | 629 } |
| OLD | NEW |