OLD | NEW |
---|---|
1 /* | 1 /* |
hlundin-webrtc
2015/08/10 11:30:01
Just FYI: This is very old and hairy code. Here be
| |
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 // TODO(hlundin): Reformat file to meet style guide. | 11 // TODO(hlundin): Reformat file to meet style guide. |
12 | 12 |
13 /* header includes */ | 13 /* header includes */ |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include <stdlib.h> | 15 #include <stdlib.h> |
16 #include <string.h> | 16 #include <string.h> |
17 #ifdef WIN32 | 17 #ifdef WIN32 |
18 #include <winsock2.h> | 18 #include <winsock2.h> |
19 #endif | 19 #endif |
20 #ifdef WEBRTC_LINUX | 20 #ifdef WEBRTC_LINUX |
21 #include <netinet/in.h> | 21 #include <netinet/in.h> |
22 #endif | 22 #endif |
23 | 23 |
24 #include <assert.h> | 24 #include <assert.h> |
25 | 25 |
26 #include <algorithm> | |
27 | |
26 #include "webrtc/typedefs.h" | 28 #include "webrtc/typedefs.h" |
27 // needed for NetEqDecoder | 29 // needed for NetEqDecoder |
28 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" | 30 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" |
29 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" | 31 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h" |
30 | 32 |
31 /************************/ | 33 /************************/ |
32 /* Define payload types */ | 34 /* Define payload types */ |
33 /************************/ | 35 /************************/ |
34 | 36 |
35 #include "PayloadTypes.h" | 37 #include "PayloadTypes.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 #define STEREO_MODE_SAMPLE_1 1 // 1 octet per sample | 71 #define STEREO_MODE_SAMPLE_1 1 // 1 octet per sample |
70 #define STEREO_MODE_SAMPLE_2 2 // 2 octets per sample | 72 #define STEREO_MODE_SAMPLE_2 2 // 2 octets per sample |
71 | 73 |
72 /*************************/ | 74 /*************************/ |
73 /* Function declarations */ | 75 /* Function declarations */ |
74 /*************************/ | 76 /*************************/ |
75 | 77 |
76 void NetEQTest_GetCodec_and_PT(char* name, | 78 void NetEQTest_GetCodec_and_PT(char* name, |
77 webrtc::NetEqDecoder* codec, | 79 webrtc::NetEqDecoder* codec, |
78 int* PT, | 80 int* PT, |
79 int frameLen, | 81 size_t frameLen, |
80 int* fs, | 82 int* fs, |
81 int* bitrate, | 83 int* bitrate, |
82 int* useRed); | 84 int* useRed); |
83 int NetEQTest_init_coders(webrtc::NetEqDecoder coder, | 85 int NetEQTest_init_coders(webrtc::NetEqDecoder coder, |
84 int enc_frameSize, | 86 size_t enc_frameSize, |
85 int bitrate, | 87 int bitrate, |
86 int sampfreq, | 88 int sampfreq, |
87 int vad, | 89 int vad, |
88 int numChannels); | 90 size_t numChannels); |
89 void defineCodecs(webrtc::NetEqDecoder* usedCodec, int* noOfCodecs); | 91 void defineCodecs(webrtc::NetEqDecoder* usedCodec, int* noOfCodecs); |
90 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, int numChannels); | 92 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels); |
91 int NetEQTest_encode(int coder, | 93 size_t NetEQTest_encode(int coder, |
92 int16_t* indata, | 94 int16_t* indata, |
93 int frameLen, | 95 size_t frameLen, |
94 unsigned char* encoded, | 96 unsigned char* encoded, |
95 int sampleRate, | 97 int sampleRate, |
96 int* vad, | 98 int* vad, |
97 int useVAD, | 99 int useVAD, |
98 int bitrate, | 100 int bitrate, |
99 int numChannels); | 101 size_t numChannels); |
100 void makeRTPheader(unsigned char* rtp_data, | 102 void makeRTPheader(unsigned char* rtp_data, |
101 int payloadType, | 103 int payloadType, |
102 int seqNo, | 104 int seqNo, |
103 uint32_t timestamp, | 105 uint32_t timestamp, |
104 uint32_t ssrc); | 106 uint32_t ssrc); |
105 int makeRedundantHeader(unsigned char* rtp_data, | 107 int makeRedundantHeader(unsigned char* rtp_data, |
106 int* payloadType, | 108 int* payloadType, |
107 int numPayloads, | 109 int numPayloads, |
108 uint32_t* timestamp, | 110 uint32_t* timestamp, |
109 uint16_t* blockLen, | 111 uint16_t* blockLen, |
110 int seqNo, | 112 int seqNo, |
111 uint32_t ssrc); | 113 uint32_t ssrc); |
112 int makeDTMFpayload(unsigned char* payload_data, | 114 size_t makeDTMFpayload(unsigned char* payload_data, |
113 int Event, | 115 int Event, |
114 int End, | 116 int End, |
115 int Volume, | 117 int Volume, |
116 int Duration); | 118 int Duration); |
117 void stereoDeInterleave(int16_t* audioSamples, int numSamples); | 119 void stereoDeInterleave(int16_t* audioSamples, size_t numSamples); |
118 void stereoInterleave(unsigned char* data, int dataLen, int stride); | 120 void stereoInterleave(unsigned char* data, size_t dataLen, size_t stride); |
119 | 121 |
120 /*********************/ | 122 /*********************/ |
121 /* Codec definitions */ | 123 /* Codec definitions */ |
122 /*********************/ | 124 /*********************/ |
123 | 125 |
124 #include "webrtc_vad.h" | 126 #include "webrtc_vad.h" |
125 | 127 |
126 #if ((defined CODEC_PCM16B) || (defined NETEQ_ARBITRARY_CODEC)) | 128 #if ((defined CODEC_PCM16B) || (defined NETEQ_ARBITRARY_CODEC)) |
127 #include "pcm16b.h" | 129 #include "pcm16b.h" |
128 #endif | 130 #endif |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 CNG_enc_inst* CNGenc_inst[2]; | 259 CNG_enc_inst* CNGenc_inst[2]; |
258 #endif | 260 #endif |
259 #ifdef CODEC_SPEEX_8 | 261 #ifdef CODEC_SPEEX_8 |
260 SPEEX_encinst_t* SPEEX8enc_inst[2]; | 262 SPEEX_encinst_t* SPEEX8enc_inst[2]; |
261 #endif | 263 #endif |
262 #ifdef CODEC_SPEEX_16 | 264 #ifdef CODEC_SPEEX_16 |
263 SPEEX_encinst_t* SPEEX16enc_inst[2]; | 265 SPEEX_encinst_t* SPEEX16enc_inst[2]; |
264 #endif | 266 #endif |
265 | 267 |
266 int main(int argc, char* argv[]) { | 268 int main(int argc, char* argv[]) { |
267 int packet_size, fs; | 269 size_t packet_size; |
270 int fs; | |
268 webrtc::NetEqDecoder usedCodec; | 271 webrtc::NetEqDecoder usedCodec; |
269 int payloadType; | 272 int payloadType; |
270 int bitrate = 0; | 273 int bitrate = 0; |
271 int useVAD, vad; | 274 int useVAD, vad; |
272 int useRed = 0; | 275 int useRed = 0; |
273 int len, enc_len; | 276 size_t len, enc_len; |
274 int16_t org_data[4000]; | 277 int16_t org_data[4000]; |
275 unsigned char rtp_data[8000]; | 278 unsigned char rtp_data[8000]; |
276 int16_t seqNo = 0xFFF; | 279 int16_t seqNo = 0xFFF; |
277 uint32_t ssrc = 1235412312; | 280 uint32_t ssrc = 1235412312; |
278 uint32_t timestamp = 0xAC1245; | 281 uint32_t timestamp = 0xAC1245; |
279 uint16_t length, plen; | 282 uint16_t length, plen; |
280 uint32_t offset; | 283 uint32_t offset; |
281 double sendtime = 0; | 284 double sendtime = 0; |
282 int red_PT[2] = {0}; | 285 int red_PT[2] = {0}; |
283 uint32_t red_TS[2] = {0}; | 286 uint32_t red_TS[2] = {0}; |
284 uint16_t red_len[2] = {0}; | 287 uint16_t red_len[2] = {0}; |
285 int RTPheaderLen = 12; | 288 size_t RTPheaderLen = 12; |
286 uint8_t red_data[8000]; | 289 uint8_t red_data[8000]; |
287 #ifdef INSERT_OLD_PACKETS | 290 #ifdef INSERT_OLD_PACKETS |
288 uint16_t old_length, old_plen; | 291 uint16_t old_length, old_plen; |
289 int old_enc_len; | 292 size_t old_enc_len; |
290 int first_old_packet = 1; | 293 int first_old_packet = 1; |
291 unsigned char old_rtp_data[8000]; | 294 unsigned char old_rtp_data[8000]; |
292 int packet_age = 0; | 295 size_t packet_age = 0; |
293 #endif | 296 #endif |
294 #ifdef INSERT_DTMF_PACKETS | 297 #ifdef INSERT_DTMF_PACKETS |
295 int NTone = 1; | 298 int NTone = 1; |
296 int DTMFfirst = 1; | 299 int DTMFfirst = 1; |
297 uint32_t DTMFtimestamp; | 300 uint32_t DTMFtimestamp; |
298 bool dtmfSent = false; | 301 bool dtmfSent = false; |
299 #endif | 302 #endif |
300 bool usingStereo = false; | 303 bool usingStereo = false; |
301 int stereoMode = 0; | 304 size_t stereoMode = 0; |
302 int numChannels = 1; | 305 size_t numChannels = 1; |
303 | 306 |
304 /* check number of parameters */ | 307 /* check number of parameters */ |
305 if ((argc != 6) && (argc != 7)) { | 308 if ((argc != 6) && (argc != 7)) { |
306 /* print help text and exit */ | 309 /* print help text and exit */ |
307 printf("Application to encode speech into an RTP stream.\n"); | 310 printf("Application to encode speech into an RTP stream.\n"); |
308 printf("The program reads a PCM file and encodes is using the specified " | 311 printf("The program reads a PCM file and encodes is using the specified " |
309 "codec.\n"); | 312 "codec.\n"); |
310 printf("The coded speech is packetized in RTP packest and written to the " | 313 printf("The coded speech is packetized in RTP packest and written to the " |
311 "output file.\n"); | 314 "output file.\n"); |
312 printf("The format of the RTP stream file is simlilar to that of " | 315 printf("The format of the RTP stream file is simlilar to that of " |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 | 445 |
443 return (0); | 446 return (0); |
444 } | 447 } |
445 | 448 |
446 FILE* in_file = fopen(argv[1], "rb"); | 449 FILE* in_file = fopen(argv[1], "rb"); |
447 CHECK_NOT_NULL(in_file); | 450 CHECK_NOT_NULL(in_file); |
448 printf("Input file: %s\n", argv[1]); | 451 printf("Input file: %s\n", argv[1]); |
449 FILE* out_file = fopen(argv[2], "wb"); | 452 FILE* out_file = fopen(argv[2], "wb"); |
450 CHECK_NOT_NULL(out_file); | 453 CHECK_NOT_NULL(out_file); |
451 printf("Output file: %s\n\n", argv[2]); | 454 printf("Output file: %s\n\n", argv[2]); |
452 packet_size = atoi(argv[3]); | 455 int packet_size_int = atoi(argv[3]); |
453 if (packet_size <= 0) { | 456 if (packet_size_int <= 0) { |
454 printf("Packet size %d must be positive", packet_size); | 457 printf("Packet size %d must be positive", packet_size_int); |
455 return -1; | 458 return -1; |
456 } | 459 } |
457 printf("Packet size: %d\n", packet_size); | 460 printf("Packet size: %d\n", packet_size_int); |
461 packet_size = static_cast<size_t>(packet_size_int); | |
458 | 462 |
459 // check for stereo | 463 // check for stereo |
460 if (argv[4][strlen(argv[4]) - 1] == '*') { | 464 if (argv[4][strlen(argv[4]) - 1] == '*') { |
461 // use stereo | 465 // use stereo |
462 usingStereo = true; | 466 usingStereo = true; |
463 numChannels = 2; | 467 numChannels = 2; |
464 argv[4][strlen(argv[4]) - 1] = '\0'; | 468 argv[4][strlen(argv[4]) - 1] = '\0'; |
465 } | 469 } |
466 | 470 |
467 NetEQTest_GetCodec_and_PT(argv[4], &usedCodec, &payloadType, packet_size, &fs, | 471 NetEQTest_GetCodec_and_PT(argv[4], &usedCodec, &payloadType, packet_size, &fs, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 /* If DTMF is sent, we should not send any speech packets during the same | 650 /* If DTMF is sent, we should not send any speech packets during the same |
647 * time */ | 651 * time */ |
648 if (dtmfSent) { | 652 if (dtmfSent) { |
649 enc_len = 0; | 653 enc_len = 0; |
650 } else { | 654 } else { |
651 #endif | 655 #endif |
652 /* encode frame */ | 656 /* encode frame */ |
653 enc_len = | 657 enc_len = |
654 NetEQTest_encode(usedCodec, org_data, packet_size, &rtp_data[12], fs, | 658 NetEQTest_encode(usedCodec, org_data, packet_size, &rtp_data[12], fs, |
655 &vad, useVAD, bitrate, numChannels); | 659 &vad, useVAD, bitrate, numChannels); |
656 if (enc_len == -1) { | |
657 printf("Error encoding frame\n"); | |
658 exit(0); | |
659 } | |
660 | 660 |
661 if (usingStereo && stereoMode != STEREO_MODE_FRAME && vad == 1) { | 661 if (usingStereo && stereoMode != STEREO_MODE_FRAME && vad == 1) { |
662 // interleave the encoded payload for sample-based codecs (not for CNG) | 662 // interleave the encoded payload for sample-based codecs (not for CNG) |
663 stereoInterleave(&rtp_data[12], enc_len, stereoMode); | 663 stereoInterleave(&rtp_data[12], enc_len, stereoMode); |
664 } | 664 } |
665 #ifdef NO_DTMF_OVERDUB | 665 #ifdef NO_DTMF_OVERDUB |
666 } | 666 } |
667 #endif | 667 #endif |
668 | 668 |
669 if (enc_len > 0 && | 669 if (enc_len > 0 && |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 if (fwrite(&length, 2, 1, out_file) != 1) { | 722 if (fwrite(&length, 2, 1, out_file) != 1) { |
723 return -1; | 723 return -1; |
724 } | 724 } |
725 if (fwrite(&plen, 2, 1, out_file) != 1) { | 725 if (fwrite(&plen, 2, 1, out_file) != 1) { |
726 return -1; | 726 return -1; |
727 } | 727 } |
728 if (fwrite(&offset, 4, 1, out_file) != 1) { | 728 if (fwrite(&offset, 4, 1, out_file) != 1) { |
729 return -1; | 729 return -1; |
730 } | 730 } |
731 #ifdef RANDOM_DATA | 731 #ifdef RANDOM_DATA |
732 for (int k = 0; k < 12 + enc_len; k++) { | 732 for (size_t k = 0; k < 12 + enc_len; k++) { |
733 rtp_data[k] = rand() + rand(); | 733 rtp_data[k] = rand() + rand(); |
734 } | 734 } |
735 #endif | 735 #endif |
736 #ifdef RANDOM_PAYLOAD_DATA | 736 #ifdef RANDOM_PAYLOAD_DATA |
737 for (int k = 12; k < 12 + enc_len; k++) { | 737 for (size_t k = 12; k < 12 + enc_len; k++) { |
738 rtp_data[k] = rand() + rand(); | 738 rtp_data[k] = rand() + rand(); |
739 } | 739 } |
740 #endif | 740 #endif |
741 if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) { | 741 if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) { |
742 return -1; | 742 return -1; |
743 } | 743 } |
744 #ifdef MULTIPLE_SAME_TIMESTAMP | 744 #ifdef MULTIPLE_SAME_TIMESTAMP |
745 } while ((seqNo % REPEAT_PACKET_DISTANCE == 0) && | 745 } while ((seqNo % REPEAT_PACKET_DISTANCE == 0) && |
746 (mult_pack++ < REPEAT_PACKET_COUNT)); | 746 (mult_pack++ < REPEAT_PACKET_COUNT)); |
747 #endif // MULTIPLE_SAME_TIMESTAMP | 747 #endif // MULTIPLE_SAME_TIMESTAMP |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 return (0); | 815 return (0); |
816 } | 816 } |
817 | 817 |
818 /****************/ | 818 /****************/ |
819 /* Subfunctions */ | 819 /* Subfunctions */ |
820 /****************/ | 820 /****************/ |
821 | 821 |
822 void NetEQTest_GetCodec_and_PT(char* name, | 822 void NetEQTest_GetCodec_and_PT(char* name, |
823 webrtc::NetEqDecoder* codec, | 823 webrtc::NetEqDecoder* codec, |
824 int* PT, | 824 int* PT, |
825 int frameLen, | 825 size_t frameLen, |
826 int* fs, | 826 int* fs, |
827 int* bitrate, | 827 int* bitrate, |
828 int* useRed) { | 828 int* useRed) { |
829 *bitrate = 0; /* Default bitrate setting */ | 829 *bitrate = 0; /* Default bitrate setting */ |
830 *useRed = 0; /* Default no redundancy */ | 830 *useRed = 0; /* Default no redundancy */ |
831 | 831 |
832 if (!strcmp(name, "pcmu")) { | 832 if (!strcmp(name, "pcmu")) { |
833 *codec = webrtc::kDecoderPCMu; | 833 *codec = webrtc::kDecoderPCMu; |
834 *PT = NETEQ_CODEC_PCMU_PT; | 834 *PT = NETEQ_CODEC_PCMU_PT; |
835 *fs = 8000; | 835 *fs = 8000; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 *PT = NETEQ_CODEC_ISAC_PT; /* this will be the PT for the sub-headers */ | 880 *PT = NETEQ_CODEC_ISAC_PT; /* this will be the PT for the sub-headers */ |
881 *fs = 16000; | 881 *fs = 16000; |
882 *useRed = 1; | 882 *useRed = 1; |
883 } else { | 883 } else { |
884 printf("Error: Not a supported codec (%s)\n", name); | 884 printf("Error: Not a supported codec (%s)\n", name); |
885 exit(0); | 885 exit(0); |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 int NetEQTest_init_coders(webrtc::NetEqDecoder coder, | 889 int NetEQTest_init_coders(webrtc::NetEqDecoder coder, |
890 int enc_frameSize, | 890 size_t enc_frameSize, |
891 int bitrate, | 891 int bitrate, |
892 int sampfreq, | 892 int sampfreq, |
893 int vad, | 893 int vad, |
894 int numChannels) { | 894 size_t numChannels) { |
895 int ok = 0; | 895 int ok = 0; |
896 | 896 |
897 for (int k = 0; k < numChannels; k++) { | 897 for (size_t k = 0; k < numChannels; k++) { |
898 VAD_inst[k] = WebRtcVad_Create(); | 898 VAD_inst[k] = WebRtcVad_Create(); |
899 if (!VAD_inst[k]) { | 899 if (!VAD_inst[k]) { |
900 printf("Error: Couldn't allocate memory for VAD instance\n"); | 900 printf("Error: Couldn't allocate memory for VAD instance\n"); |
901 exit(0); | 901 exit(0); |
902 } | 902 } |
903 ok = WebRtcVad_Init(VAD_inst[k]); | 903 ok = WebRtcVad_Init(VAD_inst[k]); |
904 if (ok == -1) { | 904 if (ok == -1) { |
905 printf("Error: Initialization of VAD struct failed\n"); | 905 printf("Error: Initialization of VAD struct failed\n"); |
906 exit(0); | 906 exit(0); |
907 } | 907 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 exit(0); | 955 exit(0); |
956 } | 956 } |
957 } else { | 957 } else { |
958 printf("\nError: g729 only supports 10, 20, 30, 40, 50 or 60 " | 958 printf("\nError: g729 only supports 10, 20, 30, 40, 50 or 60 " |
959 "ms!!\n\n"); | 959 "ms!!\n\n"); |
960 exit(0); | 960 exit(0); |
961 } | 961 } |
962 WebRtcG729_EncoderInit(G729enc_inst[k], vad); | 962 WebRtcG729_EncoderInit(G729enc_inst[k], vad); |
963 if ((vad == 1) && (enc_frameSize != 80)) { | 963 if ((vad == 1) && (enc_frameSize != 80)) { |
964 printf("\nError - This simulation only supports VAD for G729 at " | 964 printf("\nError - This simulation only supports VAD for G729 at " |
965 "10ms packets (not %dms)\n", (enc_frameSize >> 3)); | 965 "10ms packets (not %" PRIuS "ms)\n", (enc_frameSize >> 3)); |
966 } | 966 } |
967 } else { | 967 } else { |
968 printf("\nError - g729 is only developed for 8kHz \n"); | 968 printf("\nError - g729 is only developed for 8kHz \n"); |
969 exit(0); | 969 exit(0); |
970 } | 970 } |
971 break; | 971 break; |
972 #endif | 972 #endif |
973 #ifdef CODEC_G729_1 | 973 #ifdef CODEC_G729_1 |
974 case webrtc::kDecoderG729_1: | 974 case webrtc::kDecoderG729_1: |
975 if (sampfreq == 16000) { | 975 if (sampfreq == 16000) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 printf("Error: Couldn't allocate memory for Speex encoding " | 1011 printf("Error: Couldn't allocate memory for Speex encoding " |
1012 "instance\n"); | 1012 "instance\n"); |
1013 exit(0); | 1013 exit(0); |
1014 } | 1014 } |
1015 } else { | 1015 } else { |
1016 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n"); | 1016 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n"); |
1017 exit(0); | 1017 exit(0); |
1018 } | 1018 } |
1019 if ((vad == 1) && (enc_frameSize != 160)) { | 1019 if ((vad == 1) && (enc_frameSize != 160)) { |
1020 printf("\nError - This simulation only supports VAD for Speex at " | 1020 printf("\nError - This simulation only supports VAD for Speex at " |
1021 "20ms packets (not %dms)\n", | 1021 "20ms packets (not %" PRIuS "ms)\n", |
1022 (enc_frameSize >> 3)); | 1022 (enc_frameSize >> 3)); |
1023 vad = 0; | 1023 vad = 0; |
1024 } | 1024 } |
1025 ok = WebRtcSpeex_EncoderInit(SPEEX8enc_inst[k], 0 /*vbr*/, | 1025 ok = WebRtcSpeex_EncoderInit(SPEEX8enc_inst[k], 0 /*vbr*/, |
1026 3 /*complexity*/, vad); | 1026 3 /*complexity*/, vad); |
1027 if (ok != 0) | 1027 if (ok != 0) |
1028 exit(0); | 1028 exit(0); |
1029 } else { | 1029 } else { |
1030 printf("\nError - Speex8 called with sample frequency other than 8 " | 1030 printf("\nError - Speex8 called with sample frequency other than 8 " |
1031 "kHz.\n\n"); | 1031 "kHz.\n\n"); |
(...skipping 10 matching lines...) Expand all Loading... | |
1042 printf("Error: Couldn't allocate memory for Speex encoding " | 1042 printf("Error: Couldn't allocate memory for Speex encoding " |
1043 "instance\n"); | 1043 "instance\n"); |
1044 exit(0); | 1044 exit(0); |
1045 } | 1045 } |
1046 } else { | 1046 } else { |
1047 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n"); | 1047 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n"); |
1048 exit(0); | 1048 exit(0); |
1049 } | 1049 } |
1050 if ((vad == 1) && (enc_frameSize != 320)) { | 1050 if ((vad == 1) && (enc_frameSize != 320)) { |
1051 printf("\nError - This simulation only supports VAD for Speex at " | 1051 printf("\nError - This simulation only supports VAD for Speex at " |
1052 "20ms packets (not %dms)\n", | 1052 "20ms packets (not %" PRIuS "ms)\n", |
1053 (enc_frameSize >> 4)); | 1053 (enc_frameSize >> 4)); |
1054 vad = 0; | 1054 vad = 0; |
1055 } | 1055 } |
1056 ok = WebRtcSpeex_EncoderInit(SPEEX16enc_inst[k], 0 /*vbr*/, | 1056 ok = WebRtcSpeex_EncoderInit(SPEEX16enc_inst[k], 0 /*vbr*/, |
1057 3 /*complexity*/, vad); | 1057 3 /*complexity*/, vad); |
1058 if (ok != 0) | 1058 if (ok != 0) |
1059 exit(0); | 1059 exit(0); |
1060 } else { | 1060 } else { |
1061 printf("\nError - Speex16 called with sample frequency other than 16 " | 1061 printf("\nError - Speex16 called with sample frequency other than 16 " |
1062 "kHz.\n\n"); | 1062 "kHz.\n\n"); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1231 #endif | 1231 #endif |
1232 #ifdef CODEC_AMRWB | 1232 #ifdef CODEC_AMRWB |
1233 case webrtc::kDecoderAMRWB: | 1233 case webrtc::kDecoderAMRWB: |
1234 if (sampfreq == 16000) { | 1234 if (sampfreq == 16000) { |
1235 ok = WebRtcAmrWb_CreateEnc(&AMRWBenc_inst[k]); | 1235 ok = WebRtcAmrWb_CreateEnc(&AMRWBenc_inst[k]); |
1236 if (ok != 0) { | 1236 if (ok != 0) { |
1237 printf("Error: Couldn't allocate memory for AMRWB encoding " | 1237 printf("Error: Couldn't allocate memory for AMRWB encoding " |
1238 "instance\n"); | 1238 "instance\n"); |
1239 exit(0); | 1239 exit(0); |
1240 } | 1240 } |
1241 if (((enc_frameSize / 320) < 0) || ((enc_frameSize / 320) > 3) || | 1241 if (((enc_frameSize / 320) > 3) || ((enc_frameSize % 320) != 0)) { |
1242 ((enc_frameSize % 320) != 0)) { | |
1243 printf("\nError - AMRwb must have frameSize of 20, 40 or 60ms\n"); | 1242 printf("\nError - AMRwb must have frameSize of 20, 40 or 60ms\n"); |
1244 exit(0); | 1243 exit(0); |
1245 } | 1244 } |
1246 WebRtcAmrWb_EncoderInit(AMRWBenc_inst[k], vad); | 1245 WebRtcAmrWb_EncoderInit(AMRWBenc_inst[k], vad); |
1247 if (bitrate == 7000) { | 1246 if (bitrate == 7000) { |
1248 AMRWB_bitrate = AMRWB_MODE_7k; | 1247 AMRWB_bitrate = AMRWB_MODE_7k; |
1249 } else if (bitrate == 9000) { | 1248 } else if (bitrate == 9000) { |
1250 AMRWB_bitrate = AMRWB_MODE_9k; | 1249 AMRWB_bitrate = AMRWB_MODE_9k; |
1251 } else if (bitrate == 12000) { | 1250 } else if (bitrate == 12000) { |
1252 AMRWB_bitrate = AMRWB_MODE_12k; | 1251 AMRWB_bitrate = AMRWB_MODE_12k; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1313 printf("\nError - iSAC only supports frameSize (30 and 60 ms)\n"); | 1312 printf("\nError - iSAC only supports frameSize (30 and 60 ms)\n"); |
1314 exit(0); | 1313 exit(0); |
1315 } | 1314 } |
1316 WebRtcIsac_EncoderInit(ISAC_inst[k], 1); | 1315 WebRtcIsac_EncoderInit(ISAC_inst[k], 1); |
1317 if ((bitrate < 10000) || (bitrate > 32000)) { | 1316 if ((bitrate < 10000) || (bitrate > 32000)) { |
1318 printf("\nError - iSAC bitrate has to be between 10000 and 32000 " | 1317 printf("\nError - iSAC bitrate has to be between 10000 and 32000 " |
1319 "bps (not %i)\n", | 1318 "bps (not %i)\n", |
1320 bitrate); | 1319 bitrate); |
1321 exit(0); | 1320 exit(0); |
1322 } | 1321 } |
1323 WebRtcIsac_Control(ISAC_inst[k], bitrate, enc_frameSize >> 4); | 1322 WebRtcIsac_Control(ISAC_inst[k], bitrate, |
1323 static_cast<int>(enc_frameSize >> 4)); | |
1324 } else { | 1324 } else { |
1325 printf("\nError - iSAC only supports 480 or 960 enc_frameSize (30 or " | 1325 printf("\nError - iSAC only supports 480 or 960 enc_frameSize (30 or " |
1326 "60 ms)\n"); | 1326 "60 ms)\n"); |
1327 exit(0); | 1327 exit(0); |
1328 } | 1328 } |
1329 break; | 1329 break; |
1330 #endif | 1330 #endif |
1331 #ifdef NETEQ_ISACFIX_CODEC | 1331 #ifdef NETEQ_ISACFIX_CODEC |
1332 case webrtc::kDecoderISAC: | 1332 case webrtc::kDecoderISAC: |
1333 if (sampfreq == 16000) { | 1333 if (sampfreq == 16000) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 if (ok != 0) { | 1372 if (ok != 0) { |
1373 printf("Error: Couldn't set sample rate for iSAC SWB instance\n"); | 1373 printf("Error: Couldn't set sample rate for iSAC SWB instance\n"); |
1374 exit(0); | 1374 exit(0); |
1375 } | 1375 } |
1376 WebRtcIsac_EncoderInit(ISACSWB_inst[k], 1); | 1376 WebRtcIsac_EncoderInit(ISACSWB_inst[k], 1); |
1377 if ((bitrate < 32000) || (bitrate > 56000)) { | 1377 if ((bitrate < 32000) || (bitrate > 56000)) { |
1378 printf("\nError - iSAC SWB bitrate has to be between 32000 and " | 1378 printf("\nError - iSAC SWB bitrate has to be between 32000 and " |
1379 "56000 bps (not %i)\n", bitrate); | 1379 "56000 bps (not %i)\n", bitrate); |
1380 exit(0); | 1380 exit(0); |
1381 } | 1381 } |
1382 WebRtcIsac_Control(ISACSWB_inst[k], bitrate, enc_frameSize >> 5); | 1382 WebRtcIsac_Control(ISACSWB_inst[k], bitrate, |
1383 static_cast<int>(enc_frameSize >> 5)); | |
1383 } else { | 1384 } else { |
1384 printf("\nError - iSAC SWB only supports 960 enc_frameSize (30 " | 1385 printf("\nError - iSAC SWB only supports 960 enc_frameSize (30 " |
1385 "ms)\n"); | 1386 "ms)\n"); |
1386 exit(0); | 1387 exit(0); |
1387 } | 1388 } |
1388 break; | 1389 break; |
1389 #endif | 1390 #endif |
1390 #ifdef CODEC_GSMFR | 1391 #ifdef CODEC_GSMFR |
1391 case webrtc::kDecoderGSMFR: | 1392 case webrtc::kDecoderGSMFR: |
1392 if (sampfreq == 8000) { | 1393 if (sampfreq == 8000) { |
(...skipping 24 matching lines...) Expand all Loading... | |
1417 } | 1418 } |
1418 | 1419 |
1419 if (ok != 0) { | 1420 if (ok != 0) { |
1420 return (ok); | 1421 return (ok); |
1421 } | 1422 } |
1422 } // end for | 1423 } // end for |
1423 | 1424 |
1424 return (0); | 1425 return (0); |
1425 } | 1426 } |
1426 | 1427 |
1427 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, int numChannels) { | 1428 int NetEQTest_free_coders(webrtc::NetEqDecoder coder, size_t numChannels) { |
1428 for (int k = 0; k < numChannels; k++) { | 1429 for (size_t k = 0; k < numChannels; k++) { |
1429 WebRtcVad_Free(VAD_inst[k]); | 1430 WebRtcVad_Free(VAD_inst[k]); |
1430 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ | 1431 #if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \ |
1431 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) | 1432 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48)) |
1432 WebRtcCng_FreeEnc(CNGenc_inst[k]); | 1433 WebRtcCng_FreeEnc(CNGenc_inst[k]); |
1433 #endif | 1434 #endif |
1434 | 1435 |
1435 switch (coder) { | 1436 switch (coder) { |
1436 #ifdef CODEC_PCM16B | 1437 #ifdef CODEC_PCM16B |
1437 case webrtc::kDecoderPCM16B: | 1438 case webrtc::kDecoderPCM16B: |
1438 #endif | 1439 #endif |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1545 default: | 1546 default: |
1546 printf("Error: unknown codec in call to NetEQTest_init_coders.\n"); | 1547 printf("Error: unknown codec in call to NetEQTest_init_coders.\n"); |
1547 exit(0); | 1548 exit(0); |
1548 break; | 1549 break; |
1549 } | 1550 } |
1550 } | 1551 } |
1551 | 1552 |
1552 return (0); | 1553 return (0); |
1553 } | 1554 } |
1554 | 1555 |
1555 int NetEQTest_encode(int coder, | 1556 size_t NetEQTest_encode(int coder, |
1556 int16_t* indata, | 1557 int16_t* indata, |
1557 int frameLen, | 1558 size_t frameLen, |
1558 unsigned char* encoded, | 1559 unsigned char* encoded, |
1559 int sampleRate, | 1560 int sampleRate, |
1560 int* vad, | 1561 int* vad, |
1561 int useVAD, | 1562 int useVAD, |
1562 int bitrate, | 1563 int bitrate, |
1563 int numChannels) { | 1564 size_t numChannels) { |
1564 int cdlen = 0; | 1565 size_t cdlen = 0; |
1565 int16_t* tempdata; | 1566 int16_t* tempdata; |
1566 static int first_cng = 1; | 1567 static int first_cng = 1; |
1567 int16_t tempLen; | 1568 size_t tempLen; |
1568 | |
1569 *vad = 1; | 1569 *vad = 1; |
1570 | 1570 |
1571 // check VAD first | 1571 // check VAD first |
1572 if (useVAD) { | 1572 if (useVAD) { |
1573 *vad = 0; | 1573 *vad = 0; |
1574 | 1574 |
1575 int sampleRate_10 = 10 * sampleRate / 1000; | 1575 size_t sampleRate_10 = static_cast<size_t>(10 * sampleRate / 1000); |
1576 int sampleRate_20 = 20 * sampleRate / 1000; | 1576 size_t sampleRate_20 = static_cast<size_t>(20 * sampleRate / 1000); |
1577 int sampleRate_30 = 30 * sampleRate / 1000; | 1577 size_t sampleRate_30 = static_cast<size_t>(30 * sampleRate / 1000); |
1578 for (int k = 0; k < numChannels; k++) { | 1578 for (size_t k = 0; k < numChannels; k++) { |
1579 tempLen = frameLen; | 1579 tempLen = frameLen; |
1580 tempdata = &indata[k * frameLen]; | 1580 tempdata = &indata[k * frameLen]; |
1581 int localVad = 0; | 1581 int localVad = 0; |
1582 /* Partition the signal and test each chunk for VAD. | 1582 /* Partition the signal and test each chunk for VAD. |
1583 All chunks must be VAD=0 to produce a total VAD=0. */ | 1583 All chunks must be VAD=0 to produce a total VAD=0. */ |
1584 while (tempLen >= sampleRate_10) { | 1584 while (tempLen >= sampleRate_10) { |
1585 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms | 1585 if ((tempLen % sampleRate_30) == 0) { // tempLen is multiple of 30ms |
1586 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, | 1586 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, |
1587 sampleRate_30); | 1587 sampleRate_30); |
1588 tempdata += sampleRate_30; | 1588 tempdata += sampleRate_30; |
1589 tempLen -= sampleRate_30; | 1589 tempLen -= sampleRate_30; |
1590 } else if (tempLen >= sampleRate_20) { // tempLen >= 20ms | 1590 } else if (tempLen >= sampleRate_20) { // tempLen >= 20ms |
1591 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, | 1591 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, |
1592 sampleRate_20); | 1592 sampleRate_20); |
1593 tempdata += sampleRate_20; | 1593 tempdata += sampleRate_20; |
1594 tempLen -= sampleRate_20; | 1594 tempLen -= sampleRate_20; |
1595 } else { // use 10ms | 1595 } else { // use 10ms |
1596 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, | 1596 localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata, |
1597 sampleRate_10); | 1597 sampleRate_10); |
1598 tempdata += sampleRate_10; | 1598 tempdata += sampleRate_10; |
1599 tempLen -= sampleRate_10; | 1599 tempLen -= sampleRate_10; |
1600 } | 1600 } |
1601 } | 1601 } |
1602 | 1602 |
1603 // aggregate all VAD decisions over all channels | 1603 // aggregate all VAD decisions over all channels |
1604 *vad |= localVad; | 1604 *vad |= localVad; |
1605 } | 1605 } |
1606 | 1606 |
1607 if (!*vad) { | 1607 if (!*vad) { |
1608 // all channels are silent | 1608 // all channels are silent |
1609 cdlen = 0; | 1609 cdlen = 0; |
1610 for (int k = 0; k < numChannels; k++) { | 1610 for (size_t k = 0; k < numChannels; k++) { |
1611 WebRtcCng_Encode(CNGenc_inst[k], &indata[k * frameLen], | 1611 WebRtcCng_Encode(CNGenc_inst[k], &indata[k * frameLen], |
1612 (frameLen <= 640 ? frameLen : 640) /* max 640 */, | 1612 (frameLen <= 640 ? frameLen : 640) /* max 640 */, |
1613 encoded, &tempLen, first_cng); | 1613 encoded, &tempLen, first_cng); |
1614 encoded += tempLen; | 1614 encoded += tempLen; |
1615 cdlen += tempLen; | 1615 cdlen += tempLen; |
1616 } | 1616 } |
1617 *vad = 0; | 1617 *vad = 0; |
1618 first_cng = 0; | 1618 first_cng = 0; |
1619 return (cdlen); | 1619 return (cdlen); |
1620 } | 1620 } |
1621 } | 1621 } |
1622 | 1622 |
1623 // loop over all channels | 1623 // loop over all channels |
1624 int totalLen = 0; | 1624 size_t totalLen = 0; |
1625 | 1625 |
1626 for (int k = 0; k < numChannels; k++) { | 1626 for (size_t k = 0; k < numChannels; k++) { |
1627 /* Encode with the selected coder type */ | 1627 /* Encode with the selected coder type */ |
1628 if (coder == webrtc::kDecoderPCMu) { /*g711 u-law */ | 1628 if (coder == webrtc::kDecoderPCMu) { /*g711 u-law */ |
1629 #ifdef CODEC_G711 | 1629 #ifdef CODEC_G711 |
1630 cdlen = WebRtcG711_EncodeU(indata, frameLen, encoded); | 1630 cdlen = WebRtcG711_EncodeU(indata, frameLen, encoded); |
1631 #endif | 1631 #endif |
1632 } else if (coder == webrtc::kDecoderPCMa) { /*g711 A-law */ | 1632 } else if (coder == webrtc::kDecoderPCMa) { /*g711 A-law */ |
1633 #ifdef CODEC_G711 | 1633 #ifdef CODEC_G711 |
1634 cdlen = WebRtcG711_EncodeA(indata, frameLen, encoded); | 1634 cdlen = WebRtcG711_EncodeA(indata, frameLen, encoded); |
1635 } | 1635 } |
1636 #endif | 1636 #endif |
1637 #ifdef CODEC_PCM16B | 1637 #ifdef CODEC_PCM16B |
1638 else if ((coder == webrtc::kDecoderPCM16B) || | 1638 else if ((coder == webrtc::kDecoderPCM16B) || |
1639 (coder == webrtc::kDecoderPCM16Bwb) || | 1639 (coder == webrtc::kDecoderPCM16Bwb) || |
1640 (coder == webrtc::kDecoderPCM16Bswb32kHz) || | 1640 (coder == webrtc::kDecoderPCM16Bswb32kHz) || |
1641 (coder == webrtc:: | 1641 (coder == webrtc:: |
1642 kDecoderPCM16Bswb48kHz)) { /*pcm16b (8kHz, 16kHz, | 1642 kDecoderPCM16Bswb48kHz)) { /*pcm16b (8kHz, 16kHz, |
1643 32kHz or 48kHz) */ | 1643 32kHz or 48kHz) */ |
1644 cdlen = WebRtcPcm16b_Encode(indata, frameLen, encoded); | 1644 cdlen = WebRtcPcm16b_Encode(indata, frameLen, encoded); |
1645 } | 1645 } |
1646 #endif | 1646 #endif |
1647 #ifdef CODEC_G722 | 1647 #ifdef CODEC_G722 |
1648 else if (coder == webrtc::kDecoderG722) { /*g722 */ | 1648 else if (coder == webrtc::kDecoderG722) { /*g722 */ |
1649 cdlen = WebRtcG722_Encode(g722EncState[k], indata, frameLen, encoded); | 1649 cdlen = WebRtcG722_Encode(g722EncState[k], indata, frameLen, encoded); |
1650 assert(cdlen == frameLen >> 1); | 1650 assert(cdlen == frameLen >> 1); |
1651 } | 1651 } |
1652 #endif | 1652 #endif |
1653 #ifdef CODEC_ILBC | 1653 #ifdef CODEC_ILBC |
1654 else if (coder == webrtc::kDecoderILBC) { /*iLBC */ | 1654 else if (coder == webrtc::kDecoderILBC) { /*iLBC */ |
1655 cdlen = WebRtcIlbcfix_Encode(iLBCenc_inst[k], indata, frameLen, encoded); | 1655 cdlen = static_cast<size_t>(std::max( |
1656 WebRtcIlbcfix_Encode(iLBCenc_inst[k], indata, frameLen, encoded), 0)); | |
1656 } | 1657 } |
1657 #endif | 1658 #endif |
1658 #if (defined(CODEC_ISAC) || \ | 1659 #if (defined(CODEC_ISAC) || \ |
1659 defined(NETEQ_ISACFIX_CODEC)) // TODO(hlundin): remove all | 1660 defined(NETEQ_ISACFIX_CODEC)) // TODO(hlundin): remove all |
1660 // NETEQ_ISACFIX_CODEC | 1661 // NETEQ_ISACFIX_CODEC |
1661 else if (coder == webrtc::kDecoderISAC) { /*iSAC */ | 1662 else if (coder == webrtc::kDecoderISAC) { /*iSAC */ |
1662 int noOfCalls = 0; | 1663 int noOfCalls = 0; |
1663 cdlen = 0; | 1664 int res = 0; |
1664 while (cdlen <= 0) { | 1665 while (res <= 0) { |
1665 #ifdef CODEC_ISAC /* floating point */ | 1666 #ifdef CODEC_ISAC /* floating point */ |
1666 cdlen = | 1667 res = |
1667 WebRtcIsac_Encode(ISAC_inst[k], &indata[noOfCalls * 160], encoded); | 1668 WebRtcIsac_Encode(ISAC_inst[k], &indata[noOfCalls * 160], encoded); |
1668 #else /* fixed point */ | 1669 #else /* fixed point */ |
1669 cdlen = WebRtcIsacfix_Encode(ISAC_inst[k], &indata[noOfCalls * 160], | 1670 res = WebRtcIsacfix_Encode(ISAC_inst[k], &indata[noOfCalls * 160], |
1670 encoded); | 1671 encoded); |
1671 #endif | 1672 #endif |
1672 noOfCalls++; | 1673 noOfCalls++; |
1673 } | 1674 } |
1675 cdlen = static_cast<size_t>(res); | |
1674 } | 1676 } |
1675 #endif | 1677 #endif |
1676 #ifdef CODEC_ISAC_SWB | 1678 #ifdef CODEC_ISAC_SWB |
1677 else if (coder == webrtc::kDecoderISACswb) { /* iSAC SWB */ | 1679 else if (coder == webrtc::kDecoderISACswb) { /* iSAC SWB */ |
1678 int noOfCalls = 0; | 1680 int noOfCalls = 0; |
1679 cdlen = 0; | 1681 int res = 0; |
1680 while (cdlen <= 0) { | 1682 while (res <= 0) { |
1681 cdlen = WebRtcIsac_Encode(ISACSWB_inst[k], &indata[noOfCalls * 320], | 1683 res = WebRtcIsac_Encode(ISACSWB_inst[k], &indata[noOfCalls * 320], |
1682 encoded); | 1684 encoded); |
1683 noOfCalls++; | 1685 noOfCalls++; |
1684 } | 1686 } |
1687 cdlen = static_cast<size_t>(res); | |
1685 } | 1688 } |
1686 #endif | 1689 #endif |
1687 indata += frameLen; | 1690 indata += frameLen; |
1688 encoded += cdlen; | 1691 encoded += cdlen; |
1689 totalLen += cdlen; | 1692 totalLen += cdlen; |
1690 | 1693 |
1691 } // end for | 1694 } // end for |
1692 | 1695 |
1693 first_cng = 1; | 1696 first_cng = 1; |
1694 return (totalLen); | 1697 return (totalLen); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1750 | 1753 |
1751 // Bit |0|1234567| | 1754 // Bit |0|1234567| |
1752 // |0|payload| | 1755 // |0|payload| |
1753 // | | type | | 1756 // | | type | |
1754 rtpPointer[0] = payloadType[numPayloads - 1] & 0x7F; | 1757 rtpPointer[0] = payloadType[numPayloads - 1] & 0x7F; |
1755 ++rtpPointer; | 1758 ++rtpPointer; |
1756 | 1759 |
1757 return rtpPointer - rtp_data; // length of header in bytes | 1760 return rtpPointer - rtp_data; // length of header in bytes |
1758 } | 1761 } |
1759 | 1762 |
1760 int makeDTMFpayload(unsigned char* payload_data, | 1763 size_t makeDTMFpayload(unsigned char* payload_data, |
1761 int Event, | 1764 int Event, |
1762 int End, | 1765 int End, |
1763 int Volume, | 1766 int Volume, |
1764 int Duration) { | 1767 int Duration) { |
1765 unsigned char E, R, V; | 1768 unsigned char E, R, V; |
1766 R = 0; | 1769 R = 0; |
1767 V = (unsigned char)Volume; | 1770 V = (unsigned char)Volume; |
1768 if (End == 0) { | 1771 if (End == 0) { |
1769 E = 0x00; | 1772 E = 0x00; |
1770 } else { | 1773 } else { |
1771 E = 0x80; | 1774 E = 0x80; |
1772 } | 1775 } |
1773 payload_data[0] = (unsigned char)Event; | 1776 payload_data[0] = (unsigned char)Event; |
1774 payload_data[1] = (unsigned char)(E | R | V); | 1777 payload_data[1] = (unsigned char)(E | R | V); |
1775 // Duration equals 8 times time_ms, default is 8000 Hz. | 1778 // Duration equals 8 times time_ms, default is 8000 Hz. |
1776 payload_data[2] = (unsigned char)((Duration >> 8) & 0xFF); | 1779 payload_data[2] = (unsigned char)((Duration >> 8) & 0xFF); |
1777 payload_data[3] = (unsigned char)(Duration & 0xFF); | 1780 payload_data[3] = (unsigned char)(Duration & 0xFF); |
1778 return (4); | 1781 return (4); |
1779 } | 1782 } |
1780 | 1783 |
1781 void stereoDeInterleave(int16_t* audioSamples, int numSamples) { | 1784 void stereoDeInterleave(int16_t* audioSamples, size_t numSamples) { |
1782 int16_t* tempVec; | 1785 int16_t* tempVec; |
1783 int16_t* readPtr, *writeL, *writeR; | 1786 int16_t* readPtr, *writeL, *writeR; |
1784 | 1787 |
1785 if (numSamples <= 0) | 1788 if (numSamples == 0) |
1786 return; | 1789 return; |
1787 | 1790 |
1788 tempVec = (int16_t*)malloc(sizeof(int16_t) * numSamples); | 1791 tempVec = (int16_t*)malloc(sizeof(int16_t) * numSamples); |
1789 if (tempVec == NULL) { | 1792 if (tempVec == NULL) { |
1790 printf("Error allocating memory\n"); | 1793 printf("Error allocating memory\n"); |
1791 exit(0); | 1794 exit(0); |
1792 } | 1795 } |
1793 | 1796 |
1794 memcpy(tempVec, audioSamples, numSamples * sizeof(int16_t)); | 1797 memcpy(tempVec, audioSamples, numSamples * sizeof(int16_t)); |
1795 | 1798 |
1796 writeL = audioSamples; | 1799 writeL = audioSamples; |
1797 writeR = &audioSamples[numSamples / 2]; | 1800 writeR = &audioSamples[numSamples / 2]; |
1798 readPtr = tempVec; | 1801 readPtr = tempVec; |
1799 | 1802 |
1800 for (int k = 0; k < numSamples; k += 2) { | 1803 for (size_t k = 0; k < numSamples; k += 2) { |
1801 *writeL = *readPtr; | 1804 *writeL = *readPtr; |
1802 readPtr++; | 1805 readPtr++; |
1803 *writeR = *readPtr; | 1806 *writeR = *readPtr; |
1804 readPtr++; | 1807 readPtr++; |
1805 writeL++; | 1808 writeL++; |
1806 writeR++; | 1809 writeR++; |
1807 } | 1810 } |
1808 | 1811 |
1809 free(tempVec); | 1812 free(tempVec); |
1810 } | 1813 } |
1811 | 1814 |
1812 void stereoInterleave(unsigned char* data, int dataLen, int stride) { | 1815 void stereoInterleave(unsigned char* data, size_t dataLen, size_t stride) { |
1813 unsigned char* ptrL, *ptrR; | 1816 unsigned char* ptrL, *ptrR; |
1814 unsigned char temp[10]; | 1817 unsigned char temp[10]; |
1815 | 1818 |
1816 if (stride > 10) { | 1819 if (stride > 10) { |
1817 exit(0); | 1820 exit(0); |
1818 } | 1821 } |
1819 | 1822 |
1820 if (dataLen % 1 != 0) { | 1823 if (dataLen % 1 != 0) { |
1821 // must be even number of samples | 1824 // must be even number of samples |
1822 printf("Error: cannot interleave odd sample number\n"); | 1825 printf("Error: cannot interleave odd sample number\n"); |
(...skipping 11 matching lines...) Expand all Loading... | |
1834 memmove(ptrL + stride, ptrL, ptrR - ptrL); | 1837 memmove(ptrL + stride, ptrL, ptrR - ptrL); |
1835 | 1838 |
1836 // copy from temp to left pointer | 1839 // copy from temp to left pointer |
1837 memcpy(ptrL, temp, stride); | 1840 memcpy(ptrL, temp, stride); |
1838 | 1841 |
1839 // advance pointers | 1842 // advance pointers |
1840 ptrL += stride * 2; | 1843 ptrL += stride * 2; |
1841 ptrR += stride; | 1844 ptrR += stride; |
1842 } | 1845 } |
1843 } | 1846 } |
OLD | NEW |