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 |
11 /* kenny.c - Main function for the iSAC coder */ | 11 /* kenny.c - Main function for the iSAC coder */ |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <string.h> | 15 #include <string.h> |
16 #include <time.h> | 16 #include <time.h> |
17 | 17 |
18 #ifdef WIN32 | 18 #ifdef WIN32 |
19 #include "windows.h" | 19 #include "windows.h" |
20 #define CLOCKS_PER_SEC 1000 | 20 #define CLOCKS_PER_SEC 1000 |
21 #endif | 21 #endif |
22 | 22 |
23 #include <ctype.h> | 23 #include <ctype.h> |
24 #include <math.h> | 24 #include <math.h> |
25 | 25 |
26 /* include API */ | 26 /* include API */ |
27 #include "isac.h" | 27 #include "isac.h" |
28 #include "utility.h" | 28 #include "utility.h" |
| 29 #include "webrtc/base/format_macros.h" |
29 //#include "commonDefs.h" | 30 //#include "commonDefs.h" |
30 | 31 |
31 /* max number of samples per frame (= 60 ms frame) */ | 32 /* max number of samples per frame (= 60 ms frame) */ |
32 #define MAX_FRAMESAMPLES_SWB 1920 | 33 #define MAX_FRAMESAMPLES_SWB 1920 |
33 /* number of samples per 10ms frame */ | 34 /* number of samples per 10ms frame */ |
34 #define FRAMESAMPLES_SWB_10ms 320 | 35 #define FRAMESAMPLES_SWB_10ms 320 |
35 #define FRAMESAMPLES_WB_10ms 160 | 36 #define FRAMESAMPLES_WB_10ms 160 |
36 | 37 |
37 /* sampling frequency (Hz) */ | 38 /* sampling frequency (Hz) */ |
38 #define FS_SWB 32000 | 39 #define FS_SWB 32000 |
(...skipping 11 matching lines...) Expand all Loading... |
50 int main(int argc, char* argv[]) { | 51 int main(int argc, char* argv[]) { |
51 //--- File IO ---- | 52 //--- File IO ---- |
52 FILE* inp; | 53 FILE* inp; |
53 FILE* outp; | 54 FILE* outp; |
54 char inname[500]; | 55 char inname[500]; |
55 char outname[500]; | 56 char outname[500]; |
56 | 57 |
57 /* Runtime statistics */ | 58 /* Runtime statistics */ |
58 double rate; | 59 double rate; |
59 double rateRCU; | 60 double rateRCU; |
60 unsigned long totalbits = 0; | 61 size_t totalbits = 0; |
61 unsigned long totalBitsRCU = 0; | 62 unsigned long totalBitsRCU = 0; |
62 unsigned long totalsmpls = 0; | 63 unsigned long totalsmpls = 0; |
63 | 64 |
64 int32_t bottleneck = 39; | 65 int32_t bottleneck = 39; |
65 int frameSize = 30; /* ms */ | 66 int frameSize = 30; /* ms */ |
66 int16_t codingMode = 1; | 67 int16_t codingMode = 1; |
67 int16_t shortdata[FRAMESAMPLES_SWB_10ms]; | 68 int16_t shortdata[FRAMESAMPLES_SWB_10ms]; |
68 int16_t decoded[MAX_FRAMESAMPLES_SWB]; | 69 int16_t decoded[MAX_FRAMESAMPLES_SWB]; |
69 // uint16_t streamdata[1000]; | 70 // uint16_t streamdata[1000]; |
70 int16_t speechType[1]; | 71 int16_t speechType[1]; |
71 int16_t payloadLimit; | 72 int16_t payloadLimit; |
72 int32_t rateLimit; | 73 int32_t rateLimit; |
73 ISACStruct* ISAC_main_inst; | 74 ISACStruct* ISAC_main_inst; |
74 | 75 |
75 int16_t stream_len = 0; | 76 size_t stream_len = 0; |
76 int declen = 0; | 77 int declen = 0; |
77 int16_t err; | 78 int16_t err; |
78 int cur_framesmpls; | 79 int cur_framesmpls; |
79 int endfile; | 80 int endfile; |
80 #ifdef WIN32 | 81 #ifdef WIN32 |
81 double length_file; | 82 double length_file; |
82 double runtime; | 83 double runtime; |
83 char outDrive[10]; | 84 char outDrive[10]; |
84 char outPath[500]; | 85 char outPath[500]; |
85 char outPrefix[500]; | 86 char outPrefix[500]; |
86 char outSuffix[500]; | 87 char outSuffix[500]; |
87 char bitrateFileName[500]; | 88 char bitrateFileName[500]; |
88 FILE* bitrateFile; | 89 FILE* bitrateFile; |
89 double starttime; | 90 double starttime; |
90 double rateLB = 0; | 91 double rateLB = 0; |
91 double rateUB = 0; | 92 double rateUB = 0; |
92 #endif | 93 #endif |
93 FILE* histFile; | 94 FILE* histFile; |
94 FILE* averageFile; | 95 FILE* averageFile; |
95 int sampFreqKHz; | 96 int sampFreqKHz; |
96 int samplesIn10Ms; | 97 int samplesIn10Ms; |
97 int16_t maxStreamLen = 0; | 98 size_t maxStreamLen = 0; |
98 char histFileName[500]; | 99 char histFileName[500]; |
99 char averageFileName[500]; | 100 char averageFileName[500]; |
100 unsigned int hist[600]; | 101 unsigned int hist[600]; |
101 double tmpSumStreamLen = 0; | 102 double tmpSumStreamLen = 0; |
102 unsigned int packetCntr = 0; | 103 unsigned int packetCntr = 0; |
103 unsigned int lostPacketCntr = 0; | 104 unsigned int lostPacketCntr = 0; |
104 uint8_t payload[1200]; | 105 uint8_t payload[1200]; |
105 uint8_t payloadRCU[1200]; | 106 uint8_t payloadRCU[1200]; |
106 uint16_t packetLossPercent = 0; | 107 uint16_t packetLossPercent = 0; |
107 int16_t rcuStreamLen = 0; | 108 int16_t rcuStreamLen = 0; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 304 |
304 while (endfile == 0) { | 305 while (endfile == 0) { |
305 fprintf(stderr, " \rframe = %7li", framecnt); | 306 fprintf(stderr, " \rframe = %7li", framecnt); |
306 | 307 |
307 //============== Readind from the file and encoding ================= | 308 //============== Readind from the file and encoding ================= |
308 cur_framesmpls = 0; | 309 cur_framesmpls = 0; |
309 stream_len = 0; | 310 stream_len = 0; |
310 | 311 |
311 if (onlyDecode) { | 312 if (onlyDecode) { |
312 uint8_t auxUW8; | 313 uint8_t auxUW8; |
313 size_t auxSizet; | |
314 if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) { | 314 if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) { |
315 break; | 315 break; |
316 } | 316 } |
317 stream_len = ((uint8_t)auxUW8) << 8; | 317 stream_len = auxUW8 << 8; |
318 if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) { | 318 if (fread(&auxUW8, sizeof(uint8_t), 1, inp) < 1) { |
319 break; | 319 break; |
320 } | 320 } |
321 stream_len |= (uint16_t)auxUW8; | 321 stream_len |= auxUW8; |
322 auxSizet = (size_t)stream_len; | 322 if (fread(payload, 1, stream_len, inp) < stream_len) { |
323 if (fread(payload, 1, auxSizet, inp) < auxSizet) { | |
324 printf("last payload is corrupted\n"); | 323 printf("last payload is corrupted\n"); |
325 break; | 324 break; |
326 } | 325 } |
327 } else { | 326 } else { |
328 while (stream_len == 0) { | 327 while (stream_len == 0) { |
| 328 int stream_len_int; |
| 329 |
329 // Read 10 ms speech block | 330 // Read 10 ms speech block |
330 endfile = readframe(shortdata, inp, samplesIn10Ms); | 331 endfile = readframe(shortdata, inp, samplesIn10Ms); |
331 if (endfile) { | 332 if (endfile) { |
332 break; | 333 break; |
333 } | 334 } |
334 cur_framesmpls += samplesIn10Ms; | 335 cur_framesmpls += samplesIn10Ms; |
335 | 336 |
336 //-------- iSAC encoding --------- | 337 //-------- iSAC encoding --------- |
337 stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata, payload); | 338 stream_len_int = WebRtcIsac_Encode(ISAC_main_inst, shortdata, payload); |
338 | 339 |
339 if (stream_len < 0) { | 340 if (stream_len_int < 0) { |
340 // exit if returned with error | 341 // exit if returned with error |
341 // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); | 342 // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); |
342 fprintf(stderr, "\nError in encoder\n"); | 343 fprintf(stderr, "\nError in encoder\n"); |
343 getc(stdin); | 344 getc(stdin); |
344 exit(EXIT_FAILURE); | 345 exit(EXIT_FAILURE); |
345 } | 346 } |
| 347 stream_len = (size_t)stream_len_int; |
346 } | 348 } |
347 //=================================================================== | 349 //=================================================================== |
348 if (endfile) { | 350 if (endfile) { |
349 break; | 351 break; |
350 } | 352 } |
351 | 353 |
352 rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, payloadRCU); | 354 rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, payloadRCU); |
353 if (rcuStreamLen < 0) { | 355 if (rcuStreamLen < 0) { |
354 fprintf(stderr, "\nError getting RED payload\n"); | 356 fprintf(stderr, "\nError getting RED payload\n"); |
355 getc(stdin); | 357 getc(stdin); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 uint8_t auxUW8; | 391 uint8_t auxUW8; |
390 auxUW8 = (uint8_t)(((stream_len & 0x7F00) >> 8) & 0xFF); | 392 auxUW8 = (uint8_t)(((stream_len & 0x7F00) >> 8) & 0xFF); |
391 if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { | 393 if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { |
392 return -1; | 394 return -1; |
393 } | 395 } |
394 | 396 |
395 auxUW8 = (uint8_t)(stream_len & 0xFF); | 397 auxUW8 = (uint8_t)(stream_len & 0xFF); |
396 if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { | 398 if (fwrite(&auxUW8, sizeof(uint8_t), 1, outp) != 1) { |
397 return -1; | 399 return -1; |
398 } | 400 } |
399 if (fwrite(payload, 1, stream_len, outp) != (size_t)stream_len) { | 401 if (fwrite(payload, 1, stream_len, outp) != stream_len) { |
400 return -1; | 402 return -1; |
401 } | 403 } |
402 } else { | 404 } else { |
403 //======================= iSAC decoding =========================== | 405 //======================= iSAC decoding =========================== |
404 | 406 |
405 if ((rand() % 100) < packetLossPercent) { | 407 if ((rand() % 100) < packetLossPercent) { |
406 declen = WebRtcIsac_DecodeRcu(ISAC_main_inst, payloadRCU, rcuStreamLen, | 408 declen = WebRtcIsac_DecodeRcu(ISAC_main_inst, payloadRCU, |
407 decoded, speechType); | 409 (size_t)rcuStreamLen, decoded, |
| 410 speechType); |
408 lostPacketCntr++; | 411 lostPacketCntr++; |
409 } else { | 412 } else { |
410 declen = WebRtcIsac_Decode(ISAC_main_inst, payload, stream_len, decoded, | 413 declen = WebRtcIsac_Decode(ISAC_main_inst, payload, stream_len, decoded, |
411 speechType); | 414 speechType); |
412 } | 415 } |
413 if (declen <= 0) { | 416 if (declen <= 0) { |
414 // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); | 417 // errType=WebRtcIsac_GetErrorCode(ISAC_main_inst); |
415 fprintf(stderr, "\nError in decoder.\n"); | 418 fprintf(stderr, "\nError in decoder.\n"); |
416 getc(stdin); | 419 getc(stdin); |
417 exit(1); | 420 exit(1); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 #endif | 454 #endif |
452 | 455 |
453 fprintf(bitrateFile, "%d %10u %d %6.3f %6.3f %6.3f\n", | 456 fprintf(bitrateFile, "%d %10u %d %6.3f %6.3f %6.3f\n", |
454 sampFreqKHz, framecnt, bottleneck, rateLB, rateUB, rate); | 457 sampFreqKHz, framecnt, bottleneck, rateLB, rateUB, rate); |
455 fclose(bitrateFile); | 458 fclose(bitrateFile); |
456 #endif // WIN32 | 459 #endif // WIN32 |
457 | 460 |
458 printf("\n"); | 461 printf("\n"); |
459 printf("Measured bit-rate........... %0.3f kbps\n", rate); | 462 printf("Measured bit-rate........... %0.3f kbps\n", rate); |
460 printf("Measured RCU bit-ratre...... %0.3f kbps\n", rateRCU); | 463 printf("Measured RCU bit-ratre...... %0.3f kbps\n", rateRCU); |
461 printf("Maximum bit-rate/payloadsize %0.3f / %d\n", | 464 printf("Maximum bit-rate/payloadsize %0.3f / %" PRIuS "\n", |
462 maxStreamLen * 8 / 0.03, maxStreamLen); | 465 maxStreamLen * 8 / 0.03, maxStreamLen); |
463 printf("Measured packet-loss........ %0.1f%% \n", | 466 printf("Measured packet-loss........ %0.1f%% \n", |
464 100.0f * (float)lostPacketCntr / (float)packetCntr); | 467 100.0f * (float)lostPacketCntr / (float)packetCntr); |
465 | 468 |
466 // #ifdef HAVE_DEBUG_INFO | 469 // #ifdef HAVE_DEBUG_INFO |
467 // printf("Measured lower-band bit-rate %0.3f kbps (%.0f%%)\n", | 470 // printf("Measured lower-band bit-rate %0.3f kbps (%.0f%%)\n", |
468 // rateLB, (double)(rateLB) * 100. /(double)(rate)); | 471 // rateLB, (double)(rateLB) * 100. /(double)(rate)); |
469 // printf("Measured upper-band bit-rate %0.3f kbps (%.0f%%)\n", | 472 // printf("Measured upper-band bit-rate %0.3f kbps (%.0f%%)\n", |
470 // rateUB, (double)(rateUB) * 100. /(double)(rate)); | 473 // rateUB, (double)(rateUB) * 100. /(double)(rate)); |
471 // | 474 // |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 str->lastArrivalTime = 0; | 570 str->lastArrivalTime = 0; |
568 | 571 |
569 str->maxPayloadLB = 0; | 572 str->maxPayloadLB = 0; |
570 str->maxPayloadUB = 0; | 573 str->maxPayloadUB = 0; |
571 str->lbBytes = 0; | 574 str->lbBytes = 0; |
572 str->ubBytes = 0; | 575 str->ubBytes = 0; |
573 | 576 |
574 return 0; | 577 return 0; |
575 }; | 578 }; |
576 #endif | 579 #endif |
OLD | NEW |