blob: 46b9cd173180caf67ef9b71aafe9818260027ecd [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
henrik.lundin@webrtc.org82e1c8d2012-02-03 09:46:01 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
henrik.lundin@webrtc.org6c877362012-01-03 10:03:19 +000011//TODO(hlundin): Reformat file to meet style guide.
12
niklase@google.com470e71d2011-07-07 08:21:25 +000013/* header includes */
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include "stdio.h"
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000015#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016#include "webrtc_neteq.h" // needed for enum WebRtcNetEQDecoder
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000017#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000018#include <stdlib.h>
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000019#include <string.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21#ifdef WIN32
22#include <winsock2.h>
23#endif
24#ifdef WEBRTC_LINUX
25#include <netinet/in.h>
26#endif
27
28
29/************************/
30/* Define payload types */
31/************************/
32
33#include "PayloadTypes.h"
34
35
36
37/*********************/
38/* Misc. definitions */
39/*********************/
40
41#define STOPSENDTIME 3000
42#define RESTARTSENDTIME 0 //162500
43#define FIRSTLINELEN 40
44#define CHECK_NOT_NULL(a) if((a)==0){printf("\n %s \n line: %d \nerror at %s\n",__FILE__,__LINE__,#a );return(-1);}
45
46//#define MULTIPLE_SAME_TIMESTAMP
47#define REPEAT_PACKET_DISTANCE 17
48#define REPEAT_PACKET_COUNT 1 // number of extra packets to send
49
50//#define INSERT_OLD_PACKETS
51#define OLD_PACKET 5 // how many seconds too old should the packet be?
52
53//#define TIMESTAMP_WRAPAROUND
54
55//#define RANDOM_DATA
56//#define RANDOM_PAYLOAD_DATA
57#define RANDOM_SEED 10
58
59//#define INSERT_DTMF_PACKETS
60//#define NO_DTMF_OVERDUB
61#define DTMF_PACKET_INTERVAL 2000
62#define DTMF_DURATION 500
63
64#define STEREO_MODE_FRAME 0
65#define STEREO_MODE_SAMPLE_1 1 //1 octet per sample
66#define STEREO_MODE_SAMPLE_2 2 //2 octets per sample
67
68/*************************/
69/* Function declarations */
70/*************************/
71
72void NetEQTest_GetCodec_and_PT(char * name, enum WebRtcNetEQDecoder *codec, int *PT, int frameLen, int *fs, int *bitrate, int *useRed);
73int NetEQTest_init_coders(enum WebRtcNetEQDecoder coder, int enc_frameSize, int bitrate, int sampfreq , int vad, int numChannels);
74void defineCodecs(enum WebRtcNetEQDecoder *usedCodec, int *noOfCodecs );
75int NetEQTest_free_coders(enum WebRtcNetEQDecoder coder, int numChannels);
pbos@webrtc.org0946a562013-04-09 00:28:06 +000076int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * encoded,int sampleRate , int * vad, int useVAD, int bitrate, int numChannels);
77void makeRTPheader(unsigned char* rtp_data, int payloadType, int seqNo, uint32_t timestamp, uint32_t ssrc);
78int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen,
79 int seqNo, uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000080int makeDTMFpayload(unsigned char* payload_data, int Event, int End, int Volume, int Duration);
pbos@webrtc.org0946a562013-04-09 00:28:06 +000081void stereoDeInterleave(int16_t* audioSamples, int numSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +000082void stereoInterleave(unsigned char* data, int dataLen, int stride);
83
niklase@google.com470e71d2011-07-07 08:21:25 +000084/*********************/
85/* Codec definitions */
86/*********************/
87
88#include "webrtc_vad.h"
89
90#if ((defined CODEC_PCM16B)||(defined NETEQ_ARBITRARY_CODEC))
91 #include "pcm16b.h"
92#endif
93#ifdef CODEC_G711
94 #include "g711_interface.h"
95#endif
96#ifdef CODEC_G729
97 #include "G729Interface.h"
98#endif
99#ifdef CODEC_G729_1
100 #include "G729_1Interface.h"
101#endif
102#ifdef CODEC_AMR
103 #include "AMRInterface.h"
104 #include "AMRCreation.h"
105#endif
106#ifdef CODEC_AMRWB
107 #include "AMRWBInterface.h"
108 #include "AMRWBCreation.h"
109#endif
110#ifdef CODEC_ILBC
111 #include "ilbc.h"
112#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000113#if (defined CODEC_ISAC || defined CODEC_ISAC_SWB || defined CODEC_ISAC_FB)
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 #include "isac.h"
115#endif
116#ifdef NETEQ_ISACFIX_CODEC
117 #include "isacfix.h"
118 #ifdef CODEC_ISAC
119 #error Cannot have both ISAC and ISACfix defined. Please de-select one in the beginning of RTPencode.cpp
120 #endif
121#endif
122#ifdef CODEC_G722
123 #include "g722_interface.h"
124#endif
125#ifdef CODEC_G722_1_24
126 #include "G722_1Interface.h"
127#endif
128#ifdef CODEC_G722_1_32
129 #include "G722_1Interface.h"
130#endif
131#ifdef CODEC_G722_1_16
132 #include "G722_1Interface.h"
133#endif
134#ifdef CODEC_G722_1C_24
135 #include "G722_1Interface.h"
136#endif
137#ifdef CODEC_G722_1C_32
138 #include "G722_1Interface.h"
139#endif
140#ifdef CODEC_G722_1C_48
141 #include "G722_1Interface.h"
142#endif
143#ifdef CODEC_G726
144 #include "G726Creation.h"
145 #include "G726Interface.h"
146#endif
147#ifdef CODEC_GSMFR
148 #include "GSMFRInterface.h"
149 #include "GSMFRCreation.h"
150#endif
151#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
152 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
153 #include "webrtc_cng.h"
154#endif
155#if ((defined CODEC_SPEEX_8)||(defined CODEC_SPEEX_16))
156 #include "SpeexInterface.h"
157#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000158#ifdef CODEC_CELT_32
159#include "celt_interface.h"
160#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
162
163/***********************************/
164/* Global codec instance variables */
165/***********************************/
166
167WebRtcVadInst *VAD_inst[2];
168
169#ifdef CODEC_G722
170 G722EncInst *g722EncState[2];
171#endif
172
173#ifdef CODEC_G722_1_24
174 G722_1_24_encinst_t *G722_1_24enc_inst[2];
175#endif
176#ifdef CODEC_G722_1_32
177 G722_1_32_encinst_t *G722_1_32enc_inst[2];
178#endif
179#ifdef CODEC_G722_1_16
180 G722_1_16_encinst_t *G722_1_16enc_inst[2];
181#endif
182#ifdef CODEC_G722_1C_24
183 G722_1C_24_encinst_t *G722_1C_24enc_inst[2];
184#endif
185#ifdef CODEC_G722_1C_32
186 G722_1C_32_encinst_t *G722_1C_32enc_inst[2];
187#endif
188#ifdef CODEC_G722_1C_48
189 G722_1C_48_encinst_t *G722_1C_48enc_inst[2];
190#endif
191#ifdef CODEC_G726
192 G726_encinst_t *G726enc_inst[2];
193#endif
194#ifdef CODEC_G729
195 G729_encinst_t *G729enc_inst[2];
196#endif
197#ifdef CODEC_G729_1
198 G729_1_inst_t *G729_1_inst[2];
199#endif
200#ifdef CODEC_AMR
201 AMR_encinst_t *AMRenc_inst[2];
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000202 int16_t AMR_bitrate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000203#endif
204#ifdef CODEC_AMRWB
205 AMRWB_encinst_t *AMRWBenc_inst[2];
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000206 int16_t AMRWB_bitrate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207#endif
208#ifdef CODEC_ILBC
209 iLBC_encinst_t *iLBCenc_inst[2];
210#endif
211#ifdef CODEC_ISAC
212 ISACStruct *ISAC_inst[2];
213#endif
214#ifdef NETEQ_ISACFIX_CODEC
215 ISACFIX_MainStruct *ISAC_inst[2];
216#endif
217#ifdef CODEC_ISAC_SWB
218 ISACStruct *ISACSWB_inst[2];
219#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000220#ifdef CODEC_ISAC_FB
221 ISACStruct *ISACFB_inst[2];
222#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000223#ifdef CODEC_GSMFR
224 GSMFR_encinst_t *GSMFRenc_inst[2];
225#endif
226#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
227 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
228 CNG_enc_inst *CNGenc_inst[2];
229#endif
230#ifdef CODEC_SPEEX_8
231 SPEEX_encinst_t *SPEEX8enc_inst[2];
232#endif
233#ifdef CODEC_SPEEX_16
234 SPEEX_encinst_t *SPEEX16enc_inst[2];
235#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000236#ifdef CODEC_CELT_32
237 CELT_encinst_t *CELT32enc_inst[2];
238#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000239#ifdef CODEC_G711
240 void *G711state[2]={NULL, NULL};
241#endif
242
243
244int main(int argc, char* argv[])
245{
246 int packet_size, fs;
247 enum WebRtcNetEQDecoder usedCodec;
248 int payloadType;
249 int bitrate = 0;
250 int useVAD, vad;
251 int useRed=0;
252 int len, enc_len;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000253 int16_t org_data[4000];
niklase@google.com470e71d2011-07-07 08:21:25 +0000254 unsigned char rtp_data[8000];
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000255 int16_t seqNo=0xFFF;
256 uint32_t ssrc=1235412312;
257 uint32_t timestamp=0xAC1245;
258 uint16_t length, plen;
259 uint32_t offset;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 double sendtime = 0;
henrik.lundin@webrtc.org82e1c8d2012-02-03 09:46:01 +0000261 int red_PT[2] = {0};
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000262 uint32_t red_TS[2] = {0};
263 uint16_t red_len[2] = {0};
niklase@google.com470e71d2011-07-07 08:21:25 +0000264 int RTPheaderLen=12;
265 unsigned char red_data[8000];
266#ifdef INSERT_OLD_PACKETS
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000267 uint16_t old_length, old_plen;
niklase@google.com470e71d2011-07-07 08:21:25 +0000268 int old_enc_len;
269 int first_old_packet=1;
270 unsigned char old_rtp_data[8000];
271 int packet_age=0;
272#endif
273#ifdef INSERT_DTMF_PACKETS
274 int NTone = 1;
275 int DTMFfirst = 1;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000276 uint32_t DTMFtimestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000277 bool dtmfSent = false;
278#endif
279 bool usingStereo = false;
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +0000280 int stereoMode = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000281 int numChannels = 1;
282
283 /* check number of parameters */
284 if ((argc != 6) && (argc != 7)) {
285 /* print help text and exit */
286 printf("Application to encode speech into an RTP stream.\n");
287 printf("The program reads a PCM file and encodes is using the specified codec.\n");
288 printf("The coded speech is packetized in RTP packest and written to the output file.\n");
289 printf("The format of the RTP stream file is simlilar to that of rtpplay,\n");
290 printf("but with the receive time euqal to 0 for all packets.\n");
291 printf("Usage:\n\n");
292 printf("%s PCMfile RTPfile frameLen codec useVAD bitrate\n", argv[0]);
293 printf("where:\n");
294
295 printf("PCMfile : PCM speech input file\n\n");
296
297 printf("RTPfile : RTP stream output file\n\n");
298
299 printf("frameLen : 80...960... Number of samples per packet (limit depends on codec)\n\n");
300
301 printf("codecName\n");
302#ifdef CODEC_PCM16B
303 printf(" : pcm16b 16 bit PCM (8kHz)\n");
304#endif
305#ifdef CODEC_PCM16B_WB
306 printf(" : pcm16b_wb 16 bit PCM (16kHz)\n");
307#endif
308#ifdef CODEC_PCM16B_32KHZ
309 printf(" : pcm16b_swb32 16 bit PCM (32kHz)\n");
310#endif
311#ifdef CODEC_PCM16B_48KHZ
312 printf(" : pcm16b_swb48 16 bit PCM (48kHz)\n");
313#endif
314#ifdef CODEC_G711
315 printf(" : pcma g711 A-law (8kHz)\n");
316#endif
317#ifdef CODEC_G711
318 printf(" : pcmu g711 u-law (8kHz)\n");
319#endif
320#ifdef CODEC_G729
321 printf(" : g729 G729 (8kHz and 8kbps) CELP (One-Three frame(s)/packet)\n");
322#endif
323#ifdef CODEC_G729_1
324 printf(" : g729.1 G729.1 (16kHz) variable rate (8--32 kbps)\n");
325#endif
326#ifdef CODEC_G722_1_16
327 printf(" : g722.1_16 G722.1 coder (16kHz) (g722.1 with 16kbps)\n");
328#endif
329#ifdef CODEC_G722_1_24
330 printf(" : g722.1_24 G722.1 coder (16kHz) (the 24kbps version)\n");
331#endif
332#ifdef CODEC_G722_1_32
333 printf(" : g722.1_32 G722.1 coder (16kHz) (the 32kbps version)\n");
334#endif
335#ifdef CODEC_G722_1C_24
336 printf(" : g722.1C_24 G722.1 C coder (32kHz) (the 24kbps version)\n");
337#endif
338#ifdef CODEC_G722_1C_32
339 printf(" : g722.1C_32 G722.1 C coder (32kHz) (the 32kbps version)\n");
340#endif
341#ifdef CODEC_G722_1C_48
342 printf(" : g722.1C_48 G722.1 C coder (32kHz) (the 48kbps)\n");
343#endif
344
345#ifdef CODEC_G726
346 printf(" : g726_16 G726 coder (8kHz) 16kbps\n");
347 printf(" : g726_24 G726 coder (8kHz) 24kbps\n");
348 printf(" : g726_32 G726 coder (8kHz) 32kbps\n");
349 printf(" : g726_40 G726 coder (8kHz) 40kbps\n");
350#endif
351#ifdef CODEC_AMR
352 printf(" : AMRXk Adaptive Multi Rate CELP codec (8kHz)\n");
353 printf(" X = 4.75, 5.15, 5.9, 6.7, 7.4, 7.95, 10.2 or 12.2\n");
354#endif
355#ifdef CODEC_AMRWB
356 printf(" : AMRwbXk Adaptive Multi Rate Wideband CELP codec (16kHz)\n");
357 printf(" X = 7, 9, 12, 14, 16, 18, 20, 23 or 24\n");
358#endif
359#ifdef CODEC_ILBC
360 printf(" : ilbc iLBC codec (8kHz and 13.8kbps)\n");
361#endif
362#ifdef CODEC_ISAC
363 printf(" : isac iSAC (16kHz and 32.0 kbps). To set rate specify a rate parameter as last parameter\n");
364#endif
365#ifdef CODEC_ISAC_SWB
366 printf(" : isacswb iSAC SWB (32kHz and 32.0-52.0 kbps). To set rate specify a rate parameter as last parameter\n");
367#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000368#ifdef CODEC_ISAC_FB
369 printf(" : isacfb iSAC FB (48kHz encoder 32kHz decoder and 32.0-52.0 kbps). To set rate specify a rate parameter as last parameter\n");
370#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000371#ifdef CODEC_GSMFR
372 printf(" : gsmfr GSM FR codec (8kHz and 13kbps)\n");
373#endif
374#ifdef CODEC_G722
375 printf(" : g722 g722 coder (16kHz) (the 64kbps version)\n");
376#endif
377#ifdef CODEC_SPEEX_8
378 printf(" : speex8 speex coder (8 kHz)\n");
379#endif
380#ifdef CODEC_SPEEX_16
381 printf(" : speex16 speex coder (16 kHz)\n");
382#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +0000383#ifdef CODEC_CELT_32
384 printf(" : celt32 celt coder (32 kHz)\n");
385#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000386#ifdef CODEC_RED
387#ifdef CODEC_G711
388 printf(" : red_pcm Redundancy RTP packet with 2*G711A frames\n");
389#endif
390#ifdef CODEC_ISAC
391 printf(" : red_isac Redundancy RTP packet with 2*iSAC frames\n");
392#endif
393#endif
394 printf("\n");
395
396#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
397 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
398 printf("useVAD : 0 Voice Activity Detection is switched off\n");
399 printf(" : 1 Voice Activity Detection is switched on\n\n");
400#else
401 printf("useVAD : 0 Voice Activity Detection switched off (on not supported)\n\n");
402#endif
403 printf("bitrate : Codec bitrate in bps (only applies to vbr codecs)\n\n");
404
405 return(0);
406 }
407
henrik.lundin@webrtc.org6c877362012-01-03 10:03:19 +0000408 FILE* in_file=fopen(argv[1],"rb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000409 CHECK_NOT_NULL(in_file);
410 printf("Input file: %s\n",argv[1]);
henrik.lundin@webrtc.org6c877362012-01-03 10:03:19 +0000411 FILE* out_file=fopen(argv[2],"wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000412 CHECK_NOT_NULL(out_file);
413 printf("Output file: %s\n\n",argv[2]);
414 packet_size=atoi(argv[3]);
415 CHECK_NOT_NULL(packet_size);
416 printf("Packet size: %i\n",packet_size);
417
418 // check for stereo
419 if(argv[4][strlen(argv[4])-1] == '*') {
420 // use stereo
421 usingStereo = true;
422 numChannels = 2;
423 argv[4][strlen(argv[4])-1] = '\0';
424 }
425
426 NetEQTest_GetCodec_and_PT(argv[4], &usedCodec, &payloadType, packet_size, &fs, &bitrate, &useRed);
427
428 if(useRed) {
429 RTPheaderLen = 12 + 4 + 1; /* standard RTP = 12; 4 bytes per redundant payload, except last one which is 1 byte */
430 }
431
432 useVAD=atoi(argv[5]);
433#if !(defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
434 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
435 if (useVAD!=0) {
436 printf("Error: this simulation does not support VAD/DTX/CNG\n");
437 }
438#endif
439
440 // check stereo type
441 if(usingStereo)
442 {
443 switch(usedCodec)
444 {
445 // sample based codecs
446 case kDecoderPCMu:
447 case kDecoderPCMa:
448 case kDecoderG722:
449 {
450 // 1 octet per sample
451 stereoMode = STEREO_MODE_SAMPLE_1;
452 break;
453 }
454 case kDecoderPCM16B:
455 case kDecoderPCM16Bwb:
456 case kDecoderPCM16Bswb32kHz:
457 case kDecoderPCM16Bswb48kHz:
458 {
459 // 2 octets per sample
460 stereoMode = STEREO_MODE_SAMPLE_2;
461 break;
462 }
463
464 // fixed-rate frame codecs (with internal VAD)
465 case kDecoderG729:
466 {
467 if(useVAD) {
468 printf("Cannot use codec-internal VAD and stereo\n");
469 exit(0);
470 }
471 // break intentionally omitted
472 }
473 case kDecoderG722_1_16:
474 case kDecoderG722_1_24:
475 case kDecoderG722_1_32:
476 case kDecoderG722_1C_24:
477 case kDecoderG722_1C_32:
478 case kDecoderG722_1C_48:
479 {
480 stereoMode = STEREO_MODE_FRAME;
481 break;
482 }
483 default:
484 {
485 printf("Cannot use codec %s as stereo codec\n", argv[4]);
486 exit(0);
487 }
488 }
489 }
490
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000491 if ((usedCodec == kDecoderISAC) || (usedCodec == kDecoderISACswb) ||
492 (usedCodec == kDecoderISACfb))
niklase@google.com470e71d2011-07-07 08:21:25 +0000493 {
494 if (argc != 7)
495 {
496 if (usedCodec == kDecoderISAC)
497 {
498 bitrate = 32000;
499 printf(
500 "Running iSAC at default bitrate of 32000 bps (to specify explicitly add the bps as last parameter)\n");
501 }
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000502 else // usedCodec == kDecoderISACswb || usedCodec == kDecoderISACfb
niklase@google.com470e71d2011-07-07 08:21:25 +0000503 {
504 bitrate = 56000;
505 printf(
506 "Running iSAC at default bitrate of 56000 bps (to specify explicitly add the bps as last parameter)\n");
507 }
508 }
509 else
510 {
511 bitrate = atoi(argv[6]);
512 if (usedCodec == kDecoderISAC)
513 {
514 if ((bitrate < 10000) || (bitrate > 32000))
515 {
516 printf(
517 "Error: iSAC bitrate must be between 10000 and 32000 bps (%i is invalid)\n",
518 bitrate);
519 exit(0);
520 }
521 printf("Running iSAC at bitrate of %i bps\n", bitrate);
522 }
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000523 else // usedCodec == kDecoderISACswb || usedCodec == kDecoderISACfb
niklase@google.com470e71d2011-07-07 08:21:25 +0000524 {
525 if ((bitrate < 32000) || (bitrate > 56000))
526 {
527 printf(
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000528 "Error: iSAC SWB/FB bitrate must be between 32000 and 56000 bps (%i is invalid)\n",
niklase@google.com470e71d2011-07-07 08:21:25 +0000529 bitrate);
530 exit(0);
531 }
532 }
533 }
534 }
535 else
536 {
537 if (argc == 7)
538 {
539 printf(
540 "Error: Bitrate parameter can only be specified for iSAC, G.723, and G.729.1\n");
541 exit(0);
542 }
543 }
544
545 if(useRed) {
546 printf("Redundancy engaged. ");
547 }
548 printf("Used codec: %i\n",usedCodec);
549 printf("Payload type: %i\n",payloadType);
550
551 NetEQTest_init_coders(usedCodec, packet_size, bitrate, fs, useVAD, numChannels);
552
553 /* write file header */
554 //fprintf(out_file, "#!RTPencode%s\n", "1.0");
555 fprintf(out_file, "#!rtpplay%s \n", "1.0"); // this is the string that rtpplay needs
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000556 uint32_t dummy_variable = 0; // should be converted to network endian format, but does not matter when 0
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000557 if (fwrite(&dummy_variable, 4, 1, out_file) != 1) {
558 return -1;
559 }
560 if (fwrite(&dummy_variable, 4, 1, out_file) != 1) {
561 return -1;
562 }
563 if (fwrite(&dummy_variable, 4, 1, out_file) != 1) {
564 return -1;
565 }
566 if (fwrite(&dummy_variable, 2, 1, out_file) != 1) {
567 return -1;
568 }
569 if (fwrite(&dummy_variable, 2, 1, out_file) != 1) {
570 return -1;
571 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000572
573#ifdef TIMESTAMP_WRAPAROUND
574 timestamp = 0xFFFFFFFF - fs*10; /* should give wrap-around in 10 seconds */
575#endif
576#if defined(RANDOM_DATA) | defined(RANDOM_PAYLOAD_DATA)
577 srand(RANDOM_SEED);
578#endif
579
580 /* if redundancy is used, the first redundant payload is zero length */
581 red_len[0] = 0;
582
583 /* read first frame */
584 len=fread(org_data,2,packet_size * numChannels,in_file) / numChannels;
585
586 /* de-interleave if stereo */
587 if ( usingStereo )
588 {
589 stereoDeInterleave(org_data, len * numChannels);
590 }
591
592 while (len==packet_size) {
593
594#ifdef INSERT_DTMF_PACKETS
595 dtmfSent = false;
596
597 if ( sendtime >= NTone * DTMF_PACKET_INTERVAL ) {
598 if ( sendtime < NTone * DTMF_PACKET_INTERVAL + DTMF_DURATION ) {
599 // tone has not ended
600 if (DTMFfirst==1) {
601 DTMFtimestamp = timestamp; // save this timestamp
602 DTMFfirst=0;
603 }
604 makeRTPheader(rtp_data, NETEQ_CODEC_AVT_PT, seqNo,DTMFtimestamp, ssrc);
605 enc_len = makeDTMFpayload(&rtp_data[12], NTone % 12, 0, 4, (int) (sendtime - NTone * DTMF_PACKET_INTERVAL)*(fs/1000) + len);
606 }
607 else {
608 // tone has ended
609 makeRTPheader(rtp_data, NETEQ_CODEC_AVT_PT, seqNo,DTMFtimestamp, ssrc);
610 enc_len = makeDTMFpayload(&rtp_data[12], NTone % 12, 1, 4, DTMF_DURATION*(fs/1000));
611 NTone++;
612 DTMFfirst=1;
613 }
614
615 /* write RTP packet to file */
616 length = htons(12 + enc_len + 8);
617 plen = htons(12 + enc_len);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000618 offset = (uint32_t) sendtime; //(timestamp/(fs/1000));
niklase@google.com470e71d2011-07-07 08:21:25 +0000619 offset = htonl(offset);
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000620 if (fwrite(&length, 2, 1, out_file) != 1) {
621 return -1;
622 }
623 if (fwrite(&plen, 2, 1, out_file) != 1) {
624 return -1;
625 }
626 if (fwrite(&offset, 4, 1, out_file) != 1) {
627 return -1;
628 }
629 if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) {
630 return -1;
631 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000632
633 dtmfSent = true;
634 }
635#endif
636
637#ifdef NO_DTMF_OVERDUB
638 /* If DTMF is sent, we should not send any speech packets during the same time */
639 if (dtmfSent) {
640 enc_len = 0;
641 }
642 else {
643#endif
644 /* encode frame */
645 enc_len=NetEQTest_encode(usedCodec, org_data, packet_size, &rtp_data[12] ,fs,&vad, useVAD, bitrate, numChannels);
646 if (enc_len==-1) {
647 printf("Error encoding frame\n");
648 exit(0);
649 }
650
651 if ( usingStereo &&
652 stereoMode != STEREO_MODE_FRAME &&
653 vad == 1 )
654 {
655 // interleave the encoded payload for sample-based codecs (not for CNG)
656 stereoInterleave(&rtp_data[12], enc_len, stereoMode);
657 }
658#ifdef NO_DTMF_OVERDUB
659 }
660#endif
661
662 if (enc_len > 0 && (sendtime <= STOPSENDTIME || sendtime > RESTARTSENDTIME)) {
663 if(useRed) {
664 if(red_len[0] > 0) {
665 memmove(&rtp_data[RTPheaderLen+red_len[0]], &rtp_data[12], enc_len);
666 memcpy(&rtp_data[RTPheaderLen], red_data, red_len[0]);
667
668 red_len[1] = enc_len;
669 red_TS[1] = timestamp;
670 if(vad)
671 red_PT[1] = payloadType;
672 else
673 red_PT[1] = NETEQ_CODEC_CN_PT;
674
675 makeRedundantHeader(rtp_data, red_PT, 2, red_TS, red_len, seqNo++, ssrc);
676
677
678 enc_len += red_len[0] + RTPheaderLen - 12;
679 }
680 else { // do not use redundancy payload for this packet, i.e., only last payload
681 memmove(&rtp_data[RTPheaderLen-4], &rtp_data[12], enc_len);
682 //memcpy(&rtp_data[RTPheaderLen], red_data, red_len[0]);
683
684 red_len[1] = enc_len;
685 red_TS[1] = timestamp;
686 if(vad)
687 red_PT[1] = payloadType;
688 else
689 red_PT[1] = NETEQ_CODEC_CN_PT;
690
691 makeRedundantHeader(rtp_data, red_PT, 2, red_TS, red_len, seqNo++, ssrc);
692
693
694 enc_len += red_len[0] + RTPheaderLen - 4 - 12; // 4 is length of redundancy header (not used)
695 }
696 }
697 else {
698
699 /* make RTP header */
700 if (vad) // regular speech data
701 makeRTPheader(rtp_data, payloadType, seqNo++,timestamp, ssrc);
702 else // CNG data
703 makeRTPheader(rtp_data, NETEQ_CODEC_CN_PT, seqNo++,timestamp, ssrc);
704
705 }
706#ifdef MULTIPLE_SAME_TIMESTAMP
707 int mult_pack=0;
708 do {
709#endif //MULTIPLE_SAME_TIMESTAMP
710 /* write RTP packet to file */
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000711 length = htons(12 + enc_len + 8);
712 plen = htons(12 + enc_len);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000713 offset = (uint32_t) sendtime;
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000714 //(timestamp/(fs/1000));
715 offset = htonl(offset);
716 if (fwrite(&length, 2, 1, out_file) != 1) {
717 return -1;
718 }
719 if (fwrite(&plen, 2, 1, out_file) != 1) {
720 return -1;
721 }
722 if (fwrite(&offset, 4, 1, out_file) != 1) {
723 return -1;
724 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000725#ifdef RANDOM_DATA
726 for (int k=0; k<12+enc_len; k++) {
727 rtp_data[k] = rand() + rand();
728 }
729#endif
730#ifdef RANDOM_PAYLOAD_DATA
731 for (int k=12; k<12+enc_len; k++) {
732 rtp_data[k] = rand() + rand();
733 }
734#endif
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000735 if (fwrite(rtp_data, 12 + enc_len, 1, out_file) != 1) {
736 return -1;
737 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000738#ifdef MULTIPLE_SAME_TIMESTAMP
739 } while ( (seqNo%REPEAT_PACKET_DISTANCE == 0) && (mult_pack++ < REPEAT_PACKET_COUNT) );
740#endif //MULTIPLE_SAME_TIMESTAMP
741
742#ifdef INSERT_OLD_PACKETS
743 if (packet_age >= OLD_PACKET*fs) {
744 if (!first_old_packet) {
leozwang@webrtc.org354b0ed2012-06-01 17:46:21 +0000745 // send the old packet
746 if (fwrite(&old_length, 2, 1,
747 out_file) != 1) {
748 return -1;
749 }
750 if (fwrite(&old_plen, 2, 1,
751 out_file) != 1) {
752 return -1;
753 }
754 if (fwrite(&offset, 4, 1,
755 out_file) != 1) {
756 return -1;
757 }
758 if (fwrite(old_rtp_data, 12 + old_enc_len,
759 1, out_file) != 1) {
760 return -1;
761 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000762 }
763 // store current packet as old
764 old_length=length;
765 old_plen=plen;
766 memcpy(old_rtp_data,rtp_data,12+enc_len);
767 old_enc_len=enc_len;
768 first_old_packet=0;
769 packet_age=0;
770
771 }
772 packet_age += packet_size;
773#endif
774
775 if(useRed) {
776 /* move data to redundancy store */
777#ifdef CODEC_ISAC
778 if(usedCodec==kDecoderISAC)
779 {
780 assert(!usingStereo); // Cannot handle stereo yet
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000781 red_len[0] = WebRtcIsac_GetRedPayload(ISAC_inst[0], (int16_t*)red_data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000782 }
783 else
784 {
785#endif
786 memcpy(red_data, &rtp_data[RTPheaderLen+red_len[0]], enc_len);
787 red_len[0]=red_len[1];
788#ifdef CODEC_ISAC
789 }
790#endif
791 red_TS[0]=red_TS[1];
792 red_PT[0]=red_PT[1];
793 }
794
795 }
796
797 /* read next frame */
798 len=fread(org_data,2,packet_size * numChannels,in_file) / numChannels;
799 /* de-interleave if stereo */
800 if ( usingStereo )
801 {
802 stereoDeInterleave(org_data, len * numChannels);
803 }
804
tina.legrand@webrtc.org13ac4302012-02-08 13:20:36 +0000805 if (payloadType==NETEQ_CODEC_G722_PT)
806 timestamp+=len>>1;
807 else
808 timestamp+=len;
niklase@google.com470e71d2011-07-07 08:21:25 +0000809
810 sendtime += (double) len/(fs/1000);
811 }
812
813 NetEQTest_free_coders(usedCodec, numChannels);
814 fclose(in_file);
815 fclose(out_file);
816 printf("Done!\n");
817
818 return(0);
819}
820
821
822
823
824/****************/
825/* Subfunctions */
826/****************/
827
828void NetEQTest_GetCodec_and_PT(char * name, enum WebRtcNetEQDecoder *codec, int *PT, int frameLen, int *fs, int *bitrate, int *useRed) {
829
830 *bitrate = 0; /* Default bitrate setting */
831 *useRed = 0; /* Default no redundancy */
832
833 if(!strcmp(name,"pcmu")){
834 *codec=kDecoderPCMu;
835 *PT=NETEQ_CODEC_PCMU_PT;
836 *fs=8000;
837 }
838 else if(!strcmp(name,"pcma")){
839 *codec=kDecoderPCMa;
840 *PT=NETEQ_CODEC_PCMA_PT;
841 *fs=8000;
842 }
843 else if(!strcmp(name,"pcm16b")){
844 *codec=kDecoderPCM16B;
845 *PT=NETEQ_CODEC_PCM16B_PT;
846 *fs=8000;
847 }
848 else if(!strcmp(name,"pcm16b_wb")){
849 *codec=kDecoderPCM16Bwb;
850 *PT=NETEQ_CODEC_PCM16B_WB_PT;
851 *fs=16000;
852 }
853 else if(!strcmp(name,"pcm16b_swb32")){
854 *codec=kDecoderPCM16Bswb32kHz;
855 *PT=NETEQ_CODEC_PCM16B_SWB32KHZ_PT;
856 *fs=32000;
857 }
858 else if(!strcmp(name,"pcm16b_swb48")){
859 *codec=kDecoderPCM16Bswb48kHz;
860 *PT=NETEQ_CODEC_PCM16B_SWB48KHZ_PT;
861 *fs=48000;
862 }
863 else if(!strcmp(name,"g722")){
864 *codec=kDecoderG722;
865 *PT=NETEQ_CODEC_G722_PT;
866 *fs=16000;
867 }
868 else if(!strcmp(name,"g722.1_16")){
869 *codec=kDecoderG722_1_16;
870 *PT=NETEQ_CODEC_G722_1_16_PT;
871 *fs=16000;
872 }
873 else if(!strcmp(name,"g722.1_24")){
874 *codec=kDecoderG722_1_24;
875 *PT=NETEQ_CODEC_G722_1_24_PT;
876 *fs=16000;
877 }
878 else if(!strcmp(name,"g722.1_32")){
879 *codec=kDecoderG722_1_32;
880 *PT=NETEQ_CODEC_G722_1_32_PT;
881 *fs=16000;
882 }
883 else if(!strcmp(name,"g722.1C_24")){
884 *codec=kDecoderG722_1C_24;
885 *PT=NETEQ_CODEC_G722_1C_24_PT;
886 *fs=32000;
887 }
888 else if(!strcmp(name,"g722.1C_32")){
889 *codec=kDecoderG722_1C_32;
890 *PT=NETEQ_CODEC_G722_1C_32_PT;
891 *fs=32000;
892 }
893 else if(!strcmp(name,"g722.1C_48")){
894 *codec=kDecoderG722_1C_48;
895 *PT=NETEQ_CODEC_G722_1C_48_PT;
896 *fs=32000;
897 }
898 else if(!strcmp(name,"g726_16")){
899 *fs=8000;
900 *codec=kDecoderG726_16;
901 *PT=NETEQ_CODEC_G726_16_PT;
902 *bitrate=16;
903 }
904 else if(!strcmp(name,"g726_24")){
905 *fs=8000;
906 *codec=kDecoderG726_24;
907 *PT=NETEQ_CODEC_G726_24_PT;
908 *bitrate=24;
909 }
910 else if(!strcmp(name,"g726_32")){
911 *fs=8000;
912 *codec=kDecoderG726_32;
913 *PT=NETEQ_CODEC_G726_32_PT;
914 *bitrate=32;
915 }
916 else if(!strcmp(name,"g726_40")){
917 *fs=8000;
918 *codec=kDecoderG726_40;
919 *PT=NETEQ_CODEC_G726_40_PT;
920 *bitrate=40;
921 }
922 else if((!strcmp(name,"amr4.75k"))||(!strcmp(name,"amr5.15k"))||(!strcmp(name,"amr5.9k"))||
923 (!strcmp(name,"amr6.7k"))||(!strcmp(name,"amr7.4k"))||(!strcmp(name,"amr7.95k"))||
924 (!strcmp(name,"amr10.2k"))||(!strcmp(name,"amr12.2k"))) {
925 *fs=8000;
926 if (!strcmp(name,"amr4.75k"))
927 *bitrate = 0;
928 if (!strcmp(name,"amr5.15k"))
929 *bitrate = 1;
930 if (!strcmp(name,"amr5.9k"))
931 *bitrate = 2;
932 if (!strcmp(name,"amr6.7k"))
933 *bitrate = 3;
934 if (!strcmp(name,"amr7.4k"))
935 *bitrate = 4;
936 if (!strcmp(name,"amr7.95k"))
937 *bitrate = 5;
938 if (!strcmp(name,"amr10.2k"))
939 *bitrate = 6;
940 if (!strcmp(name,"amr12.2k"))
941 *bitrate = 7;
942 *codec=kDecoderAMR;
943 *PT=NETEQ_CODEC_AMR_PT;
944 }
945 else if((!strcmp(name,"amrwb7k"))||(!strcmp(name,"amrwb9k"))||(!strcmp(name,"amrwb12k"))||
946 (!strcmp(name,"amrwb14k"))||(!strcmp(name,"amrwb16k"))||(!strcmp(name,"amrwb18k"))||
947 (!strcmp(name,"amrwb20k"))||(!strcmp(name,"amrwb23k"))||(!strcmp(name,"amrwb24k"))) {
948 *fs=16000;
949 if (!strcmp(name,"amrwb7k"))
950 *bitrate = 7000;
951 if (!strcmp(name,"amrwb9k"))
952 *bitrate = 9000;
953 if (!strcmp(name,"amrwb12k"))
954 *bitrate = 12000;
955 if (!strcmp(name,"amrwb14k"))
956 *bitrate = 14000;
957 if (!strcmp(name,"amrwb16k"))
958 *bitrate = 16000;
959 if (!strcmp(name,"amrwb18k"))
960 *bitrate = 18000;
961 if (!strcmp(name,"amrwb20k"))
962 *bitrate = 20000;
963 if (!strcmp(name,"amrwb23k"))
964 *bitrate = 23000;
965 if (!strcmp(name,"amrwb24k"))
966 *bitrate = 24000;
967 *codec=kDecoderAMRWB;
968 *PT=NETEQ_CODEC_AMRWB_PT;
969 }
970 else if((!strcmp(name,"ilbc"))&&((frameLen%240==0)||(frameLen%160==0))){
971 *fs=8000;
972 *codec=kDecoderILBC;
973 *PT=NETEQ_CODEC_ILBC_PT;
974 }
975 else if(!strcmp(name,"isac")){
976 *fs=16000;
977 *codec=kDecoderISAC;
978 *PT=NETEQ_CODEC_ISAC_PT;
979 }
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000980 else if(!strcmp(name,"isacswb")){
981 *fs=32000;
982 *codec=kDecoderISACswb;
983 *PT=NETEQ_CODEC_ISACSWB_PT;
niklase@google.com470e71d2011-07-07 08:21:25 +0000984 }
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +0000985 else if(!strcmp(name,"isacfb")){
986 *fs=48000;
987 *codec=kDecoderISACfb;
988 *PT=NETEQ_CODEC_ISACFB_PT;
989 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000990 else if(!strcmp(name,"g729")){
991 *fs=8000;
992 *codec=kDecoderG729;
993 *PT=NETEQ_CODEC_G729_PT;
994 }
995 else if(!strcmp(name,"g729.1")){
996 *fs=16000;
997 *codec=kDecoderG729_1;
998 *PT=NETEQ_CODEC_G729_1_PT;
999 }
1000 else if(!strcmp(name,"gsmfr")){
1001 *fs=8000;
1002 *codec=kDecoderGSMFR;
1003 *PT=NETEQ_CODEC_GSMFR_PT;
1004 }
1005 else if(!strcmp(name,"speex8")){
1006 *fs=8000;
1007 *codec=kDecoderSPEEX_8;
1008 *PT=NETEQ_CODEC_SPEEX8_PT;
1009 }
1010 else if(!strcmp(name,"speex16")){
1011 *fs=16000;
1012 *codec=kDecoderSPEEX_16;
1013 *PT=NETEQ_CODEC_SPEEX16_PT;
1014 }
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00001015 else if(!strcmp(name,"celt32")){
1016 *fs=32000;
1017 *codec=kDecoderCELT_32;
1018 *PT=NETEQ_CODEC_CELT32_PT;
1019 }
niklase@google.com470e71d2011-07-07 08:21:25 +00001020 else if(!strcmp(name,"red_pcm")){
1021 *codec=kDecoderPCMa;
1022 *PT=NETEQ_CODEC_PCMA_PT; /* this will be the PT for the sub-headers */
1023 *fs=8000;
1024 *useRed = 1;
1025 } else if(!strcmp(name,"red_isac")){
1026 *codec=kDecoderISAC;
1027 *PT=NETEQ_CODEC_ISAC_PT; /* this will be the PT for the sub-headers */
1028 *fs=16000;
1029 *useRed = 1;
1030 } else {
1031 printf("Error: Not a supported codec (%s)\n", name);
1032 exit(0);
1033 }
1034
1035}
1036
1037
1038
1039
1040int NetEQTest_init_coders(enum WebRtcNetEQDecoder coder, int enc_frameSize, int bitrate, int sampfreq , int vad, int numChannels){
1041
1042 int ok=0;
1043
1044 for (int k = 0; k < numChannels; k++)
1045 {
1046 ok=WebRtcVad_Create(&VAD_inst[k]);
1047 if (ok!=0) {
1048 printf("Error: Couldn't allocate memory for VAD instance\n");
1049 exit(0);
1050 }
1051 ok=WebRtcVad_Init(VAD_inst[k]);
1052 if (ok==-1) {
1053 printf("Error: Initialization of VAD struct failed\n");
1054 exit(0);
1055 }
1056
1057
1058#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
1059 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
1060 ok=WebRtcCng_CreateEnc(&CNGenc_inst[k]);
1061 if (ok!=0) {
1062 printf("Error: Couldn't allocate memory for CNG encoding instance\n");
1063 exit(0);
1064 }
1065 if(sampfreq <= 16000) {
1066 ok=WebRtcCng_InitEnc(CNGenc_inst[k],sampfreq, 200, 5);
1067 if (ok==-1) {
1068 printf("Error: Initialization of CNG struct failed. Error code %d\n",
1069 WebRtcCng_GetErrorCodeEnc(CNGenc_inst[k]));
1070 exit(0);
1071 }
1072 }
1073#endif
1074
1075 switch (coder) {
1076 case kDecoderReservedStart : // dummy codec
1077#ifdef CODEC_PCM16B
1078 case kDecoderPCM16B :
1079#endif
1080#ifdef CODEC_PCM16B_WB
1081 case kDecoderPCM16Bwb :
1082#endif
1083#ifdef CODEC_PCM16B_32KHZ
1084 case kDecoderPCM16Bswb32kHz :
1085#endif
1086#ifdef CODEC_PCM16B_48KHZ
1087 case kDecoderPCM16Bswb48kHz :
1088#endif
1089#ifdef CODEC_G711
1090 case kDecoderPCMu :
1091 case kDecoderPCMa :
1092#endif
1093 // do nothing
1094 break;
1095#ifdef CODEC_G729
1096 case kDecoderG729:
1097 if (sampfreq==8000) {
1098 if ((enc_frameSize==80)||(enc_frameSize==160)||(enc_frameSize==240)||(enc_frameSize==320)||(enc_frameSize==400)||(enc_frameSize==480)) {
1099 ok=WebRtcG729_CreateEnc(&G729enc_inst[k]);
1100 if (ok!=0) {
1101 printf("Error: Couldn't allocate memory for G729 encoding instance\n");
1102 exit(0);
1103 }
1104 } else {
1105 printf("\nError: g729 only supports 10, 20, 30, 40, 50 or 60 ms!!\n\n");
1106 exit(0);
1107 }
1108 WebRtcG729_EncoderInit(G729enc_inst[k], vad);
1109 if ((vad==1)&&(enc_frameSize!=80)) {
1110 printf("\nError - This simulation only supports VAD for G729 at 10ms packets (not %dms)\n", (enc_frameSize>>3));
1111 }
1112 } else {
1113 printf("\nError - g729 is only developed for 8kHz \n");
1114 exit(0);
1115 }
1116 break;
1117#endif
1118#ifdef CODEC_G729_1
1119 case kDecoderG729_1:
1120 if (sampfreq==16000) {
1121 if ((enc_frameSize==320)||(enc_frameSize==640)||(enc_frameSize==960)
1122 ) {
1123 ok=WebRtcG7291_Create(&G729_1_inst[k]);
1124 if (ok!=0) {
1125 printf("Error: Couldn't allocate memory for G.729.1 codec instance\n");
1126 exit(0);
1127 }
1128 } else {
1129 printf("\nError: G.729.1 only supports 20, 40 or 60 ms!!\n\n");
1130 exit(0);
1131 }
1132 if (!(((bitrate >= 12000) && (bitrate <= 32000) && (bitrate%2000 == 0)) || (bitrate == 8000))) {
1133 /* must be 8, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, or 32 kbps */
1134 printf("\nError: G.729.1 bitrate must be 8000 or 12000--32000 in steps of 2000 bps\n");
1135 exit(0);
1136 }
1137 WebRtcG7291_EncoderInit(G729_1_inst[k], bitrate, 0 /* flag8kHz*/, 0 /*flagG729mode*/);
1138 } else {
1139 printf("\nError - G.729.1 input is always 16 kHz \n");
1140 exit(0);
1141 }
1142 break;
1143#endif
1144#ifdef CODEC_SPEEX_8
1145 case kDecoderSPEEX_8 :
1146 if (sampfreq==8000) {
1147 if ((enc_frameSize==160)||(enc_frameSize==320)||(enc_frameSize==480)) {
1148 ok=WebRtcSpeex_CreateEnc(&SPEEX8enc_inst[k], sampfreq);
1149 if (ok!=0) {
1150 printf("Error: Couldn't allocate memory for Speex encoding instance\n");
1151 exit(0);
1152 }
1153 } else {
1154 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n");
1155 exit(0);
1156 }
1157 if ((vad==1)&&(enc_frameSize!=160)) {
1158 printf("\nError - This simulation only supports VAD for Speex at 20ms packets (not %dms)\n", (enc_frameSize>>3));
1159 vad=0;
1160 }
1161 ok=WebRtcSpeex_EncoderInit(SPEEX8enc_inst[k], 0/*vbr*/, 3 /*complexity*/, vad);
1162 if (ok!=0) exit(0);
1163 } else {
1164 printf("\nError - Speex8 called with sample frequency other than 8 kHz.\n\n");
1165 }
1166 break;
1167#endif
1168#ifdef CODEC_SPEEX_16
1169 case kDecoderSPEEX_16 :
1170 if (sampfreq==16000) {
1171 if ((enc_frameSize==320)||(enc_frameSize==640)||(enc_frameSize==960)) {
1172 ok=WebRtcSpeex_CreateEnc(&SPEEX16enc_inst[k], sampfreq);
1173 if (ok!=0) {
1174 printf("Error: Couldn't allocate memory for Speex encoding instance\n");
1175 exit(0);
1176 }
1177 } else {
1178 printf("\nError: Speex only supports 20, 40, and 60 ms!!\n\n");
1179 exit(0);
1180 }
1181 if ((vad==1)&&(enc_frameSize!=320)) {
1182 printf("\nError - This simulation only supports VAD for Speex at 20ms packets (not %dms)\n", (enc_frameSize>>4));
1183 vad=0;
1184 }
1185 ok=WebRtcSpeex_EncoderInit(SPEEX16enc_inst[k], 0/*vbr*/, 3 /*complexity*/, vad);
1186 if (ok!=0) exit(0);
1187 } else {
1188 printf("\nError - Speex16 called with sample frequency other than 16 kHz.\n\n");
1189 }
1190 break;
1191#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00001192#ifdef CODEC_CELT_32
1193 case kDecoderCELT_32 :
1194 if (sampfreq==32000) {
1195 if (enc_frameSize==320) {
1196 ok=WebRtcCelt_CreateEnc(&CELT32enc_inst[k], 1 /*mono*/);
1197 if (ok!=0) {
1198 printf("Error: Couldn't allocate memory for Celt encoding instance\n");
1199 exit(0);
1200 }
1201 } else {
1202 printf("\nError: Celt only supports 10 ms!!\n\n");
1203 exit(0);
1204 }
1205 ok=WebRtcCelt_EncoderInit(CELT32enc_inst[k], 1 /*mono*/, 48000 /*bitrate*/);
1206 if (ok!=0) exit(0);
1207 } else {
1208 printf("\nError - Celt32 called with sample frequency other than 32 kHz.\n\n");
1209 }
1210 break;
1211#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001212
1213#ifdef CODEC_G722_1_16
1214 case kDecoderG722_1_16 :
1215 if (sampfreq==16000) {
1216 ok=WebRtcG7221_CreateEnc16(&G722_1_16enc_inst[k]);
1217 if (ok!=0) {
1218 printf("Error: Couldn't allocate memory for G.722.1 instance\n");
1219 exit(0);
1220 }
1221 if (enc_frameSize==320) {
1222 } else {
1223 printf("\nError: G722.1 only supports 20 ms!!\n\n");
1224 exit(0);
1225 }
1226 WebRtcG7221_EncoderInit16((G722_1_16_encinst_t*)G722_1_16enc_inst[k]);
1227 } else {
1228 printf("\nError - G722.1 is only developed for 16kHz \n");
1229 exit(0);
1230 }
1231 break;
1232#endif
1233#ifdef CODEC_G722_1_24
1234 case kDecoderG722_1_24 :
1235 if (sampfreq==16000) {
1236 ok=WebRtcG7221_CreateEnc24(&G722_1_24enc_inst[k]);
1237 if (ok!=0) {
1238 printf("Error: Couldn't allocate memory for G.722.1 instance\n");
1239 exit(0);
1240 }
1241 if (enc_frameSize==320) {
1242 } else {
1243 printf("\nError: G722.1 only supports 20 ms!!\n\n");
1244 exit(0);
1245 }
1246 WebRtcG7221_EncoderInit24((G722_1_24_encinst_t*)G722_1_24enc_inst[k]);
1247 } else {
1248 printf("\nError - G722.1 is only developed for 16kHz \n");
1249 exit(0);
1250 }
1251 break;
1252#endif
1253#ifdef CODEC_G722_1_32
1254 case kDecoderG722_1_32 :
1255 if (sampfreq==16000) {
1256 ok=WebRtcG7221_CreateEnc32(&G722_1_32enc_inst[k]);
1257 if (ok!=0) {
1258 printf("Error: Couldn't allocate memory for G.722.1 instance\n");
1259 exit(0);
1260 }
1261 if (enc_frameSize==320) {
1262 } else {
1263 printf("\nError: G722.1 only supports 20 ms!!\n\n");
1264 exit(0);
1265 }
1266 WebRtcG7221_EncoderInit32((G722_1_32_encinst_t*)G722_1_32enc_inst[k]);
1267 } else {
1268 printf("\nError - G722.1 is only developed for 16kHz \n");
1269 exit(0);
1270 }
1271 break;
1272#endif
1273#ifdef CODEC_G722_1C_24
1274 case kDecoderG722_1C_24 :
1275 if (sampfreq==32000) {
1276 ok=WebRtcG7221C_CreateEnc24(&G722_1C_24enc_inst[k]);
1277 if (ok!=0) {
1278 printf("Error: Couldn't allocate memory for G.722.1C instance\n");
1279 exit(0);
1280 }
1281 if (enc_frameSize==640) {
1282 } else {
1283 printf("\nError: G722.1 C only supports 20 ms!!\n\n");
1284 exit(0);
1285 }
1286 WebRtcG7221C_EncoderInit24((G722_1C_24_encinst_t*)G722_1C_24enc_inst[k]);
1287 } else {
1288 printf("\nError - G722.1 C is only developed for 32kHz \n");
1289 exit(0);
1290 }
1291 break;
1292#endif
1293#ifdef CODEC_G722_1C_32
1294 case kDecoderG722_1C_32 :
1295 if (sampfreq==32000) {
1296 ok=WebRtcG7221C_CreateEnc32(&G722_1C_32enc_inst[k]);
1297 if (ok!=0) {
1298 printf("Error: Couldn't allocate memory for G.722.1C instance\n");
1299 exit(0);
1300 }
1301 if (enc_frameSize==640) {
1302 } else {
1303 printf("\nError: G722.1 C only supports 20 ms!!\n\n");
1304 exit(0);
1305 }
1306 WebRtcG7221C_EncoderInit32((G722_1C_32_encinst_t*)G722_1C_32enc_inst[k]);
1307 } else {
1308 printf("\nError - G722.1 C is only developed for 32kHz \n");
1309 exit(0);
1310 }
1311 break;
1312#endif
1313#ifdef CODEC_G722_1C_48
1314 case kDecoderG722_1C_48 :
1315 if (sampfreq==32000) {
1316 ok=WebRtcG7221C_CreateEnc48(&G722_1C_48enc_inst[k]);
1317 if (ok!=0) {
1318 printf("Error: Couldn't allocate memory for G.722.1C instance\n");
1319 exit(0);
1320 }
1321 if (enc_frameSize==640) {
1322 } else {
1323 printf("\nError: G722.1 C only supports 20 ms!!\n\n");
1324 exit(0);
1325 }
1326 WebRtcG7221C_EncoderInit48((G722_1C_48_encinst_t*)G722_1C_48enc_inst[k]);
1327 } else {
1328 printf("\nError - G722.1 C is only developed for 32kHz \n");
1329 exit(0);
1330 }
1331 break;
1332#endif
1333#ifdef CODEC_G722
1334 case kDecoderG722 :
1335 if (sampfreq==16000) {
1336 if (enc_frameSize%2==0) {
1337 } else {
1338 printf("\nError - g722 frames must have an even number of enc_frameSize\n");
1339 exit(0);
1340 }
1341 WebRtcG722_CreateEncoder(&g722EncState[k]);
1342 WebRtcG722_EncoderInit(g722EncState[k]);
1343 } else {
1344 printf("\nError - g722 is only developed for 16kHz \n");
1345 exit(0);
1346 }
1347 break;
1348#endif
1349#ifdef CODEC_AMR
1350 case kDecoderAMR :
1351 if (sampfreq==8000) {
1352 ok=WebRtcAmr_CreateEnc(&AMRenc_inst[k]);
1353 if (ok!=0) {
1354 printf("Error: Couldn't allocate memory for AMR encoding instance\n");
1355 exit(0);
1356 }if ((enc_frameSize==160)||(enc_frameSize==320)||(enc_frameSize==480)) {
1357 } else {
1358 printf("\nError - AMR must have a multiple of 160 enc_frameSize\n");
1359 exit(0);
1360 }
1361 WebRtcAmr_EncoderInit(AMRenc_inst[k], vad);
1362 WebRtcAmr_EncodeBitmode(AMRenc_inst[k], AMRBandwidthEfficient);
1363 AMR_bitrate = bitrate;
1364 } else {
1365 printf("\nError - AMR is only developed for 8kHz \n");
1366 exit(0);
1367 }
1368 break;
1369#endif
1370#ifdef CODEC_AMRWB
1371 case kDecoderAMRWB :
1372 if (sampfreq==16000) {
1373 ok=WebRtcAmrWb_CreateEnc(&AMRWBenc_inst[k]);
1374 if (ok!=0) {
1375 printf("Error: Couldn't allocate memory for AMRWB encoding instance\n");
1376 exit(0);
1377 }
1378 if (((enc_frameSize/320)<0)||((enc_frameSize/320)>3)||((enc_frameSize%320)!=0)) {
1379 printf("\nError - AMRwb must have frameSize of 20, 40 or 60ms\n");
1380 exit(0);
1381 }
1382 WebRtcAmrWb_EncoderInit(AMRWBenc_inst[k], vad);
1383 if (bitrate==7000) {
1384 AMRWB_bitrate = AMRWB_MODE_7k;
1385 } else if (bitrate==9000) {
1386 AMRWB_bitrate = AMRWB_MODE_9k;
1387 } else if (bitrate==12000) {
1388 AMRWB_bitrate = AMRWB_MODE_12k;
1389 } else if (bitrate==14000) {
1390 AMRWB_bitrate = AMRWB_MODE_14k;
1391 } else if (bitrate==16000) {
1392 AMRWB_bitrate = AMRWB_MODE_16k;
1393 } else if (bitrate==18000) {
1394 AMRWB_bitrate = AMRWB_MODE_18k;
1395 } else if (bitrate==20000) {
1396 AMRWB_bitrate = AMRWB_MODE_20k;
1397 } else if (bitrate==23000) {
1398 AMRWB_bitrate = AMRWB_MODE_23k;
1399 } else if (bitrate==24000) {
1400 AMRWB_bitrate = AMRWB_MODE_24k;
1401 }
1402 WebRtcAmrWb_EncodeBitmode(AMRWBenc_inst[k], AMRBandwidthEfficient);
1403
1404 } else {
1405 printf("\nError - AMRwb is only developed for 16kHz \n");
1406 exit(0);
1407 }
1408 break;
1409#endif
1410#ifdef CODEC_ILBC
1411 case kDecoderILBC :
1412 if (sampfreq==8000) {
1413 ok=WebRtcIlbcfix_EncoderCreate(&iLBCenc_inst[k]);
1414 if (ok!=0) {
1415 printf("Error: Couldn't allocate memory for iLBC encoding instance\n");
1416 exit(0);
1417 }
1418 if ((enc_frameSize==160)||(enc_frameSize==240)||(enc_frameSize==320)||(enc_frameSize==480)) {
1419 } else {
1420 printf("\nError - iLBC only supports 160, 240, 320 and 480 enc_frameSize (20, 30, 40 and 60 ms)\n");
1421 exit(0);
1422 }
1423 if ((enc_frameSize==160)||(enc_frameSize==320)) {
1424 /* 20 ms version */
1425 WebRtcIlbcfix_EncoderInit(iLBCenc_inst[k], 20);
1426 } else {
1427 /* 30 ms version */
1428 WebRtcIlbcfix_EncoderInit(iLBCenc_inst[k], 30);
1429 }
1430 } else {
1431 printf("\nError - iLBC is only developed for 8kHz \n");
1432 exit(0);
1433 }
1434 break;
1435#endif
1436#ifdef CODEC_ISAC
1437 case kDecoderISAC:
1438 if (sampfreq==16000) {
1439 ok=WebRtcIsac_Create(&ISAC_inst[k]);
1440 if (ok!=0) {
1441 printf("Error: Couldn't allocate memory for iSAC instance\n");
1442 exit(0);
1443 }if ((enc_frameSize==480)||(enc_frameSize==960)) {
1444 } else {
1445 printf("\nError - iSAC only supports frameSize (30 and 60 ms)\n");
1446 exit(0);
1447 }
1448 WebRtcIsac_EncoderInit(ISAC_inst[k],1);
1449 if ((bitrate<10000)||(bitrate>32000)) {
1450 printf("\nError - iSAC bitrate has to be between 10000 and 32000 bps (not %i)\n", bitrate);
1451 exit(0);
1452 }
1453 WebRtcIsac_Control(ISAC_inst[k], bitrate, enc_frameSize>>4);
1454 } else {
1455 printf("\nError - iSAC only supports 480 or 960 enc_frameSize (30 or 60 ms)\n");
1456 exit(0);
1457 }
1458 break;
1459#endif
1460#ifdef NETEQ_ISACFIX_CODEC
1461 case kDecoderISAC:
1462 if (sampfreq==16000) {
1463 ok=WebRtcIsacfix_Create(&ISAC_inst[k]);
1464 if (ok!=0) {
1465 printf("Error: Couldn't allocate memory for iSAC instance\n");
1466 exit(0);
1467 }if ((enc_frameSize==480)||(enc_frameSize==960)) {
1468 } else {
1469 printf("\nError - iSAC only supports frameSize (30 and 60 ms)\n");
1470 exit(0);
1471 }
1472 WebRtcIsacfix_EncoderInit(ISAC_inst[k],1);
1473 if ((bitrate<10000)||(bitrate>32000)) {
1474 printf("\nError - iSAC bitrate has to be between 10000 and 32000 bps (not %i)\n", bitrate);
1475 exit(0);
1476 }
1477 WebRtcIsacfix_Control(ISAC_inst[k], bitrate, enc_frameSize>>4);
1478 } else {
1479 printf("\nError - iSAC only supports 480 or 960 enc_frameSize (30 or 60 ms)\n");
1480 exit(0);
1481 }
1482 break;
1483#endif
1484#ifdef CODEC_ISAC_SWB
1485 case kDecoderISACswb:
1486 if (sampfreq==32000) {
1487 ok=WebRtcIsac_Create(&ISACSWB_inst[k]);
1488 if (ok!=0) {
1489 printf("Error: Couldn't allocate memory for iSAC SWB instance\n");
1490 exit(0);
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001491 }if (enc_frameSize==960) {
niklase@google.com470e71d2011-07-07 08:21:25 +00001492 } else {
1493 printf("\nError - iSAC SWB only supports frameSize 30 ms\n");
1494 exit(0);
1495 }
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +00001496 ok = WebRtcIsac_SetEncSampRate(ISACSWB_inst[k], 32000);
niklase@google.com470e71d2011-07-07 08:21:25 +00001497 if (ok!=0) {
1498 printf("Error: Couldn't set sample rate for iSAC SWB instance\n");
1499 exit(0);
1500 }
1501 WebRtcIsac_EncoderInit(ISACSWB_inst[k],1);
1502 if ((bitrate<32000)||(bitrate>56000)) {
1503 printf("\nError - iSAC SWB bitrate has to be between 32000 and 56000 bps (not %i)\n", bitrate);
1504 exit(0);
1505 }
1506 WebRtcIsac_Control(ISACSWB_inst[k], bitrate, enc_frameSize>>5);
1507 } else {
1508 printf("\nError - iSAC SWB only supports 960 enc_frameSize (30 ms)\n");
1509 exit(0);
1510 }
1511 break;
1512#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +00001513#ifdef CODEC_ISAC_FB
1514 case kDecoderISACfb:
1515 if (sampfreq == 48000) {
1516 ok = WebRtcIsac_Create(&ISACFB_inst[k]);
1517 if (ok != 0) {
1518 printf("Error: Couldn't allocate memory for iSAC FB "
1519 "instance\n");
1520 exit(0);
1521 }
1522 if (enc_frameSize != 1440) {
1523 printf("\nError - iSAC FB only supports frameSize 30 ms\n");
1524 exit(0);
1525 }
1526 ok = WebRtcIsac_SetEncSampRate(ISACFB_inst[k], 48000);
1527 if (ok != 0) {
1528 printf("Error: Couldn't set sample rate for iSAC FB "
1529 "instance\n");
1530 exit(0);
1531 }
1532 WebRtcIsac_EncoderInit(ISACFB_inst[k], 1);
1533 if ((bitrate < 32000) || (bitrate > 56000)) {
1534 printf("\nError - iSAC FB bitrate has to be between 32000 and"
1535 "56000 bps (not %i)\n", bitrate);
1536 exit(0);
1537 }
1538 WebRtcIsac_Control(ISACFB_inst[k], bitrate, 30);
1539 } else {
1540 printf("\nError - iSAC FB only support 48 kHz sampling rate.\n");
1541 exit(0);
1542 }
1543 break;
1544#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001545#ifdef CODEC_GSMFR
1546 case kDecoderGSMFR:
1547 if (sampfreq==8000) {
1548 ok=WebRtcGSMFR_CreateEnc(&GSMFRenc_inst[k]);
1549 if (ok!=0) {
1550 printf("Error: Couldn't allocate memory for GSM FR encoding instance\n");
1551 exit(0);
1552 }
1553 if ((enc_frameSize==160)||(enc_frameSize==320)||(enc_frameSize==480)) {
1554 } else {
1555 printf("\nError - GSM FR must have a multiple of 160 enc_frameSize\n");
1556 exit(0);
1557 }
1558 WebRtcGSMFR_EncoderInit(GSMFRenc_inst[k], 0);
1559 } else {
1560 printf("\nError - GSM FR is only developed for 8kHz \n");
1561 exit(0);
1562 }
1563 break;
1564#endif
1565 default :
1566 printf("Error: unknown codec in call to NetEQTest_init_coders.\n");
1567 exit(0);
1568 break;
1569 }
1570
1571 if (ok != 0) {
1572 return(ok);
1573 }
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +00001574 } // end for
niklase@google.com470e71d2011-07-07 08:21:25 +00001575
1576 return(0);
1577}
1578
1579
1580
1581
1582int NetEQTest_free_coders(enum WebRtcNetEQDecoder coder, int numChannels) {
1583
1584 for (int k = 0; k < numChannels; k++)
1585 {
1586 WebRtcVad_Free(VAD_inst[k]);
1587#if (defined(CODEC_CNGCODEC8) || defined(CODEC_CNGCODEC16) || \
1588 defined(CODEC_CNGCODEC32) || defined(CODEC_CNGCODEC48))
1589 WebRtcCng_FreeEnc(CNGenc_inst[k]);
1590#endif
1591
1592 switch (coder)
1593 {
1594 case kDecoderReservedStart : // dummy codec
1595#ifdef CODEC_PCM16B
1596 case kDecoderPCM16B :
1597#endif
1598#ifdef CODEC_PCM16B_WB
1599 case kDecoderPCM16Bwb :
1600#endif
1601#ifdef CODEC_PCM16B_32KHZ
1602 case kDecoderPCM16Bswb32kHz :
1603#endif
1604#ifdef CODEC_PCM16B_48KHZ
1605 case kDecoderPCM16Bswb48kHz :
1606#endif
1607#ifdef CODEC_G711
1608 case kDecoderPCMu :
1609 case kDecoderPCMa :
1610#endif
1611 // do nothing
1612 break;
1613#ifdef CODEC_G729
1614 case kDecoderG729:
1615 WebRtcG729_FreeEnc(G729enc_inst[k]);
1616 break;
1617#endif
1618#ifdef CODEC_G729_1
1619 case kDecoderG729_1:
1620 WebRtcG7291_Free(G729_1_inst[k]);
1621 break;
1622#endif
1623#ifdef CODEC_SPEEX_8
1624 case kDecoderSPEEX_8 :
1625 WebRtcSpeex_FreeEnc(SPEEX8enc_inst[k]);
1626 break;
1627#endif
1628#ifdef CODEC_SPEEX_16
1629 case kDecoderSPEEX_16 :
1630 WebRtcSpeex_FreeEnc(SPEEX16enc_inst[k]);
1631 break;
1632#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00001633#ifdef CODEC_CELT_32
1634 case kDecoderCELT_32 :
1635 WebRtcCelt_FreeEnc(CELT32enc_inst[k]);
1636 break;
1637#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001638
1639#ifdef CODEC_G722_1_16
1640 case kDecoderG722_1_16 :
1641 WebRtcG7221_FreeEnc16(G722_1_16enc_inst[k]);
1642 break;
1643#endif
1644#ifdef CODEC_G722_1_24
1645 case kDecoderG722_1_24 :
1646 WebRtcG7221_FreeEnc24(G722_1_24enc_inst[k]);
1647 break;
1648#endif
1649#ifdef CODEC_G722_1_32
1650 case kDecoderG722_1_32 :
1651 WebRtcG7221_FreeEnc32(G722_1_32enc_inst[k]);
1652 break;
1653#endif
1654#ifdef CODEC_G722_1C_24
1655 case kDecoderG722_1C_24 :
1656 WebRtcG7221C_FreeEnc24(G722_1C_24enc_inst[k]);
1657 break;
1658#endif
1659#ifdef CODEC_G722_1C_32
1660 case kDecoderG722_1C_32 :
1661 WebRtcG7221C_FreeEnc32(G722_1C_32enc_inst[k]);
1662 break;
1663#endif
1664#ifdef CODEC_G722_1C_48
1665 case kDecoderG722_1C_48 :
1666 WebRtcG7221C_FreeEnc48(G722_1C_48enc_inst[k]);
1667 break;
1668#endif
1669#ifdef CODEC_G722
1670 case kDecoderG722 :
1671 WebRtcG722_FreeEncoder(g722EncState[k]);
1672 break;
1673#endif
1674#ifdef CODEC_AMR
1675 case kDecoderAMR :
1676 WebRtcAmr_FreeEnc(AMRenc_inst[k]);
1677 break;
1678#endif
1679#ifdef CODEC_AMRWB
1680 case kDecoderAMRWB :
1681 WebRtcAmrWb_FreeEnc(AMRWBenc_inst[k]);
1682 break;
1683#endif
1684#ifdef CODEC_ILBC
1685 case kDecoderILBC :
1686 WebRtcIlbcfix_EncoderFree(iLBCenc_inst[k]);
1687 break;
1688#endif
1689#ifdef CODEC_ISAC
1690 case kDecoderISAC:
1691 WebRtcIsac_Free(ISAC_inst[k]);
1692 break;
1693#endif
1694#ifdef NETEQ_ISACFIX_CODEC
1695 case kDecoderISAC:
1696 WebRtcIsacfix_Free(ISAC_inst[k]);
1697 break;
1698#endif
1699#ifdef CODEC_ISAC_SWB
1700 case kDecoderISACswb:
1701 WebRtcIsac_Free(ISACSWB_inst[k]);
1702 break;
1703#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +00001704#ifdef CODEC_ISAC_FB
1705 case kDecoderISACfb:
1706 WebRtcIsac_Free(ISACFB_inst[k]);
1707 break;
1708#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001709#ifdef CODEC_GSMFR
1710 case kDecoderGSMFR:
1711 WebRtcGSMFR_FreeEnc(GSMFRenc_inst[k]);
1712 break;
1713#endif
1714 default :
1715 printf("Error: unknown codec in call to NetEQTest_init_coders.\n");
1716 exit(0);
1717 break;
1718 }
1719 }
1720
1721 return(0);
1722}
1723
1724
1725
1726
1727
1728
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001729int NetEQTest_encode(int coder, int16_t *indata, int frameLen, unsigned char * encoded,int sampleRate ,
niklase@google.com470e71d2011-07-07 08:21:25 +00001730 int * vad, int useVAD, int bitrate, int numChannels){
1731
kjellander@webrtc.org543c3ea2011-11-23 12:20:35 +00001732 short cdlen = 0;
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001733 int16_t *tempdata;
niklase@google.com470e71d2011-07-07 08:21:25 +00001734 static int first_cng=1;
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001735 int16_t tempLen;
niklase@google.com470e71d2011-07-07 08:21:25 +00001736
1737 *vad =1;
1738
1739 // check VAD first
1740 if(useVAD&&
1741 (coder!=kDecoderG729)&&(coder!=kDecoderAMR)&&
1742 (coder!=kDecoderSPEEX_8)&&(coder!=kDecoderSPEEX_16))
1743 {
1744 *vad = 0;
1745
1746 for (int k = 0; k < numChannels; k++)
1747 {
1748 tempLen = frameLen;
1749 tempdata = &indata[k*frameLen];
1750 int localVad=0;
1751 /* Partition the signal and test each chunk for VAD.
1752 All chunks must be VAD=0 to produce a total VAD=0. */
1753 while (tempLen >= 10*sampleRate/1000) {
1754 if ((tempLen % 30*sampleRate/1000) == 0) { // tempLen is multiple of 30ms
1755 localVad |= WebRtcVad_Process(VAD_inst[k] ,sampleRate, tempdata, 30*sampleRate/1000);
1756 tempdata += 30*sampleRate/1000;
1757 tempLen -= 30*sampleRate/1000;
1758 }
1759 else if (tempLen >= 20*sampleRate/1000) { // tempLen >= 20ms
1760 localVad |= WebRtcVad_Process(VAD_inst[k] ,sampleRate, tempdata, 20*sampleRate/1000);
1761 tempdata += 20*sampleRate/1000;
1762 tempLen -= 20*sampleRate/1000;
1763 }
1764 else { // use 10ms
1765 localVad |= WebRtcVad_Process(VAD_inst[k] ,sampleRate, tempdata, 10*sampleRate/1000);
1766 tempdata += 10*sampleRate/1000;
1767 tempLen -= 10*sampleRate/1000;
1768 }
1769 }
1770
1771 // aggregate all VAD decisions over all channels
1772 *vad |= localVad;
1773 }
1774
1775 if(!*vad){
1776 // all channels are silent
1777 cdlen = 0;
1778 for (int k = 0; k < numChannels; k++)
1779 {
1780 WebRtcCng_Encode(CNGenc_inst[k],&indata[k*frameLen], (frameLen <= 640 ? frameLen : 640) /* max 640 */,
1781 encoded,&tempLen,first_cng);
1782 encoded += tempLen;
1783 cdlen += tempLen;
1784 }
1785 *vad=0;
1786 first_cng=0;
1787 return(cdlen);
1788 }
1789 }
1790
1791
1792 // loop over all channels
1793 int totalLen = 0;
1794
1795 for (int k = 0; k < numChannels; k++)
1796 {
1797 /* Encode with the selected coder type */
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001798 if (coder==kDecoderPCMu) { /*g711 u-law */
niklase@google.com470e71d2011-07-07 08:21:25 +00001799#ifdef CODEC_G711
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001800 cdlen = WebRtcG711_EncodeU(G711state[k], indata, frameLen, (int16_t*) encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001801#endif
1802 }
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001803 else if (coder==kDecoderPCMa) { /*g711 A-law */
niklase@google.com470e71d2011-07-07 08:21:25 +00001804#ifdef CODEC_G711
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001805 cdlen = WebRtcG711_EncodeA(G711state[k], indata, frameLen, (int16_t*) encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001806 }
1807#endif
1808#ifdef CODEC_PCM16B
1809 else if ((coder==kDecoderPCM16B)||(coder==kDecoderPCM16Bwb)||
1810 (coder==kDecoderPCM16Bswb32kHz)||(coder==kDecoderPCM16Bswb48kHz)) { /*pcm16b (8kHz, 16kHz, 32kHz or 48kHz) */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001811 cdlen = WebRtcPcm16b_EncodeW16(indata, frameLen, (int16_t*) encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001812 }
1813#endif
1814#ifdef CODEC_G722
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001815 else if (coder==kDecoderG722) { /*g722 */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001816 cdlen=WebRtcG722_Encode(g722EncState[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001817 cdlen=frameLen>>1;
1818 }
1819#endif
1820#ifdef CODEC_G722_1_16
1821 else if (coder==kDecoderG722_1_16) { /* g722.1 16kbit/s mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001822 cdlen=WebRtcG7221_Encode16((G722_1_16_encinst_t*)G722_1_16enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001823 }
1824#endif
1825#ifdef CODEC_G722_1_24
1826 else if (coder==kDecoderG722_1_24) { /* g722.1 24kbit/s mode*/
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001827 cdlen=WebRtcG7221_Encode24((G722_1_24_encinst_t*)G722_1_24enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001828 }
1829#endif
1830#ifdef CODEC_G722_1_32
1831 else if (coder==kDecoderG722_1_32) { /* g722.1 32kbit/s mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001832 cdlen=WebRtcG7221_Encode32((G722_1_32_encinst_t*)G722_1_32enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001833 }
1834#endif
1835#ifdef CODEC_G722_1C_24
1836 else if (coder==kDecoderG722_1C_24) { /* g722.1 32 kHz 24kbit/s mode*/
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001837 cdlen=WebRtcG7221C_Encode24((G722_1C_24_encinst_t*)G722_1C_24enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001838 }
1839#endif
1840#ifdef CODEC_G722_1C_32
1841 else if (coder==kDecoderG722_1C_32) { /* g722.1 32 kHz 32kbit/s mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001842 cdlen=WebRtcG7221C_Encode32((G722_1C_32_encinst_t*)G722_1C_32enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001843 }
1844#endif
1845#ifdef CODEC_G722_1C_48
1846 else if (coder==kDecoderG722_1C_48) { /* g722.1 32 kHz 48kbit/s mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001847 cdlen=WebRtcG7221C_Encode48((G722_1C_48_encinst_t*)G722_1C_48enc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001848 }
1849#endif
1850#ifdef CODEC_G729
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001851 else if (coder==kDecoderG729) { /*g729 */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001852 int16_t dataPos=0;
1853 int16_t len=0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001854 cdlen = 0;
1855 for (dataPos=0;dataPos<frameLen;dataPos+=80) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001856 len=WebRtcG729_Encode(G729enc_inst[k], &indata[dataPos], 80, (int16_t*)(&encoded[cdlen]));
niklase@google.com470e71d2011-07-07 08:21:25 +00001857 cdlen += len;
1858 }
1859 }
1860#endif
1861#ifdef CODEC_G729_1
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001862 else if (coder==kDecoderG729_1) { /*g729.1 */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001863 int16_t dataPos=0;
1864 int16_t len=0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001865 cdlen = 0;
1866 for (dataPos=0;dataPos<frameLen;dataPos+=160) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001867 len=WebRtcG7291_Encode(G729_1_inst[k], &indata[dataPos], (int16_t*)(&encoded[cdlen]), bitrate, frameLen/320 /* num 20ms frames*/);
niklase@google.com470e71d2011-07-07 08:21:25 +00001868 cdlen += len;
1869 }
1870 }
1871#endif
1872#ifdef CODEC_AMR
1873 else if (coder==kDecoderAMR) { /*AMR */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001874 cdlen=WebRtcAmr_Encode(AMRenc_inst[k], indata, frameLen, (int16_t*)encoded, AMR_bitrate);
niklase@google.com470e71d2011-07-07 08:21:25 +00001875 }
1876#endif
1877#ifdef CODEC_AMRWB
1878 else if (coder==kDecoderAMRWB) { /*AMR-wb */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001879 cdlen=WebRtcAmrWb_Encode(AMRWBenc_inst[k], indata, frameLen, (int16_t*)encoded, AMRWB_bitrate);
niklase@google.com470e71d2011-07-07 08:21:25 +00001880 }
1881#endif
1882#ifdef CODEC_ILBC
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001883 else if (coder==kDecoderILBC) { /*iLBC */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001884 cdlen=WebRtcIlbcfix_Encode(iLBCenc_inst[k], indata,frameLen,(int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001885 }
1886#endif
1887#if (defined(CODEC_ISAC) || defined(NETEQ_ISACFIX_CODEC)) // TODO(hlundin): remove all NETEQ_ISACFIX_CODEC
1888 else if (coder==kDecoderISAC) { /*iSAC */
1889 int noOfCalls=0;
1890 cdlen=0;
1891 while (cdlen<=0) {
1892#ifdef CODEC_ISAC /* floating point */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001893 cdlen=WebRtcIsac_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001894#else /* fixed point */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001895 cdlen=WebRtcIsacfix_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001896#endif
1897 noOfCalls++;
1898 }
1899 }
1900#endif
1901#ifdef CODEC_ISAC_SWB
1902 else if (coder==kDecoderISACswb) { /* iSAC SWB */
1903 int noOfCalls=0;
1904 cdlen=0;
1905 while (cdlen<=0) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001906 cdlen=WebRtcIsac_Encode(ISACSWB_inst[k],&indata[noOfCalls*320],(int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001907 noOfCalls++;
1908 }
1909 }
1910#endif
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +00001911#ifdef CODEC_ISAC_FB
1912 else if (coder == kDecoderISACfb) { /* iSAC FB */
1913 int noOfCalls = 0;
1914 cdlen = 0;
1915 while (cdlen <= 0) {
1916 cdlen = WebRtcIsac_Encode(ISACFB_inst[k],
1917 &indata[noOfCalls * 480],
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001918 (int16_t*)encoded);
turaj@webrtc.orgb0dff122012-12-03 17:43:52 +00001919 noOfCalls++;
1920 }
1921 }
1922#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001923#ifdef CODEC_GSMFR
henrik.lundin@webrtc.org61986242011-12-09 13:58:17 +00001924 else if (coder==kDecoderGSMFR) { /* GSM FR */
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001925 cdlen=WebRtcGSMFR_Encode(GSMFRenc_inst[k], indata, frameLen, (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001926 }
1927#endif
1928#ifdef CODEC_SPEEX_8
1929 else if (coder==kDecoderSPEEX_8) { /* Speex */
1930 int encodedLen = 0;
1931 int retVal = 1;
1932 while (retVal == 1 && encodedLen < frameLen) {
1933 retVal = WebRtcSpeex_Encode(SPEEX8enc_inst[k], &indata[encodedLen], 15000);
1934 encodedLen += 20*8; /* 20 ms */
1935 }
1936 if( (retVal == 0 && encodedLen != frameLen) || retVal < 0) {
1937 printf("Error encoding speex frame!\n");
1938 exit(0);
1939 }
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001940 cdlen=WebRtcSpeex_GetBitstream(SPEEX8enc_inst[k], (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001941 }
1942#endif
1943#ifdef CODEC_SPEEX_16
1944 else if (coder==kDecoderSPEEX_16) { /* Speex */
1945 int encodedLen = 0;
1946 int retVal = 1;
1947 while (retVal == 1 && encodedLen < frameLen) {
1948 retVal = WebRtcSpeex_Encode(SPEEX16enc_inst[k], &indata[encodedLen], 15000);
1949 encodedLen += 20*16; /* 20 ms */
1950 }
1951 if( (retVal == 0 && encodedLen != frameLen) || retVal < 0) {
1952 printf("Error encoding speex frame!\n");
1953 exit(0);
1954 }
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001955 cdlen=WebRtcSpeex_GetBitstream(SPEEX16enc_inst[k], (int16_t*)encoded);
niklase@google.com470e71d2011-07-07 08:21:25 +00001956 }
1957#endif
tina.legrand@webrtc.orgdf697752012-02-08 10:22:21 +00001958#ifdef CODEC_CELT_32
1959 else if (coder==kDecoderCELT_32) { /* Celt */
1960 int encodedLen = 0;
1961 cdlen = 0;
1962 while (cdlen <= 0) {
1963 cdlen = WebRtcCelt_Encode(CELT32enc_inst[k], &indata[encodedLen], encoded);
1964 encodedLen += 10*32; /* 10 ms */
1965 }
1966 if( (encodedLen != frameLen) || cdlen < 0) {
1967 printf("Error encoding Celt frame!\n");
1968 exit(0);
1969 }
1970 }
1971#endif
niklase@google.com470e71d2011-07-07 08:21:25 +00001972
1973 indata += frameLen;
1974 encoded += cdlen;
1975 totalLen += cdlen;
1976
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +00001977 } // end for
niklase@google.com470e71d2011-07-07 08:21:25 +00001978
1979 first_cng=1;
1980 return(totalLen);
1981}
1982
1983
1984
pbos@webrtc.org0946a562013-04-09 00:28:06 +00001985void makeRTPheader(unsigned char* rtp_data, int payloadType, int seqNo, uint32_t timestamp, uint32_t ssrc){
niklase@google.com470e71d2011-07-07 08:21:25 +00001986
1987 rtp_data[0]=(unsigned char)0x80;
1988 rtp_data[1]=(unsigned char)(payloadType & 0xFF);
1989 rtp_data[2]=(unsigned char)((seqNo>>8)&0xFF);
1990 rtp_data[3]=(unsigned char)((seqNo)&0xFF);
1991 rtp_data[4]=(unsigned char)((timestamp>>24)&0xFF);
1992 rtp_data[5]=(unsigned char)((timestamp>>16)&0xFF);
1993
1994 rtp_data[6]=(unsigned char)((timestamp>>8)&0xFF);
1995 rtp_data[7]=(unsigned char)(timestamp & 0xFF);
1996
1997 rtp_data[8]=(unsigned char)((ssrc>>24)&0xFF);
1998 rtp_data[9]=(unsigned char)((ssrc>>16)&0xFF);
1999
2000 rtp_data[10]=(unsigned char)((ssrc>>8)&0xFF);
2001 rtp_data[11]=(unsigned char)(ssrc & 0xFF);
2002}
2003
2004
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002005int makeRedundantHeader(unsigned char* rtp_data, int *payloadType, int numPayloads, uint32_t *timestamp, uint16_t *blockLen,
2006 int seqNo, uint32_t ssrc)
niklase@google.com470e71d2011-07-07 08:21:25 +00002007{
2008
2009 int i;
2010 unsigned char *rtpPointer;
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002011 uint16_t offset;
niklase@google.com470e71d2011-07-07 08:21:25 +00002012
2013 /* first create "standard" RTP header */
2014 makeRTPheader(rtp_data, NETEQ_CODEC_RED_PT, seqNo, timestamp[numPayloads-1], ssrc);
2015
2016 rtpPointer = &rtp_data[12];
2017
2018 /* add one sub-header for each redundant payload (not the primary) */
2019 for(i=0; i<numPayloads-1; i++) { /* |0 1 2 3 4 5 6 7| */
2020 if(blockLen[i] > 0) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002021 offset = (uint16_t) (timestamp[numPayloads-1] - timestamp[i]);
niklase@google.com470e71d2011-07-07 08:21:25 +00002022
2023 rtpPointer[0] = (unsigned char) ( 0x80 | (0x7F & payloadType[i]) ); /* |F| block PT | */
2024 rtpPointer[1] = (unsigned char) ((offset >> 6) & 0xFF); /* | timestamp- | */
2025 rtpPointer[2] = (unsigned char) ( ((offset & 0x3F)<<2) |
2026 ( (blockLen[i]>>8) & 0x03 ) ); /* | -offset |bl-| */
2027 rtpPointer[3] = (unsigned char) ( blockLen[i] & 0xFF ); /* | -ock length | */
2028
2029 rtpPointer += 4;
2030 }
2031 }
2032
2033 /* last sub-header */
2034 rtpPointer[0]= (unsigned char) (0x00 | (0x7F&payloadType[numPayloads-1]));/* |F| block PT | */
2035 rtpPointer += 1;
2036
2037 return(rtpPointer - rtp_data); /* length of header in bytes */
2038}
2039
2040
2041
2042int makeDTMFpayload(unsigned char* payload_data, int Event, int End, int Volume, int Duration) {
2043 unsigned char E,R,V;
2044 R=0;
2045 V=(unsigned char)Volume;
2046 if (End==0) {
2047 E = 0x00;
2048 } else {
2049 E = 0x80;
2050 }
2051 payload_data[0]=(unsigned char)Event;
2052 payload_data[1]=(unsigned char)(E|R|V);
2053 //Duration equals 8 times time_ms, default is 8000 Hz.
2054 payload_data[2]=(unsigned char)((Duration>>8)&0xFF);
2055 payload_data[3]=(unsigned char)(Duration&0xFF);
2056 return(4);
2057}
2058
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002059void stereoDeInterleave(int16_t* audioSamples, int numSamples)
niklase@google.com470e71d2011-07-07 08:21:25 +00002060{
2061
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002062 int16_t *tempVec;
2063 int16_t *readPtr, *writeL, *writeR;
niklase@google.com470e71d2011-07-07 08:21:25 +00002064
2065 if (numSamples <= 0)
2066 return;
2067
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002068 tempVec = (int16_t *) malloc(sizeof(int16_t) * numSamples);
niklase@google.com470e71d2011-07-07 08:21:25 +00002069 if (tempVec == NULL) {
2070 printf("Error allocating memory\n");
2071 exit(0);
2072 }
2073
pbos@webrtc.org0946a562013-04-09 00:28:06 +00002074 memcpy(tempVec, audioSamples, numSamples*sizeof(int16_t));
niklase@google.com470e71d2011-07-07 08:21:25 +00002075
2076 writeL = audioSamples;
2077 writeR = &audioSamples[numSamples/2];
2078 readPtr = tempVec;
2079
2080 for (int k = 0; k < numSamples; k += 2)
2081 {
2082 *writeL = *readPtr;
2083 readPtr++;
2084 *writeR = *readPtr;
2085 readPtr++;
2086 writeL++;
2087 writeR++;
2088 }
2089
2090 free(tempVec);
2091
2092}
2093
2094
2095void stereoInterleave(unsigned char* data, int dataLen, int stride)
2096{
2097
2098 unsigned char *ptrL, *ptrR;
2099 unsigned char temp[10];
2100
2101 if (stride > 10)
2102 {
2103 exit(0);
2104 }
2105
2106 if (dataLen%1 != 0)
2107 {
2108 // must be even number of samples
2109 printf("Error: cannot interleave odd sample number\n");
2110 exit(0);
2111 }
2112
2113 ptrL = data + stride;
2114 ptrR = &data[dataLen/2];
2115
2116 while (ptrL < ptrR) {
2117 // copy from right pointer to temp
2118 memcpy(temp, ptrR, stride);
2119
2120 // shift data between pointers
2121 memmove(ptrL + stride, ptrL, ptrR - ptrL);
2122
2123 // copy from temp to left pointer
2124 memcpy(ptrL, temp, stride);
2125
2126 // advance pointers
2127 ptrL += stride*2;
2128 ptrR += stride;
2129 }
2130
2131}