blob: b2b0fca0e18b998eb8c76a5319403733d9d0eb2b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.org9dc45da2012-05-23 15:39: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
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000011#include "webrtc/modules/audio_coding/main/test/iSACTest.h"
12
niklase@google.com470e71d2011-07-07 08:21:25 +000013#include <cctype>
14#include <stdio.h>
15#include <string.h>
16
17#if _WIN32
18#include <windows.h>
19#elif WEBRTC_LINUX
20#include <ctime>
21#else
22#include <sys/time.h>
23#include <time.h>
24#endif
25
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000026#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
27#include "webrtc/modules/audio_coding/main/test/utility.h"
28#include "webrtc/system_wrappers/interface/event_wrapper.h"
29#include "webrtc/system_wrappers/interface/tick_util.h"
30#include "webrtc/system_wrappers/interface/trace.h"
31#include "webrtc/test/testsupport/fileutils.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000033namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000034
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000035void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
36 isacConfig.currentRateBitPerSec = 0;
37 isacConfig.currentFrameSizeMsec = 0;
38 isacConfig.maxRateBitPerSec = 0;
39 isacConfig.maxPayloadSizeByte = 0;
40 isacConfig.encodingMode = -1;
41 isacConfig.initRateBitPerSec = 0;
42 isacConfig.initFrameSizeInMsec = 0;
43 isacConfig.enforceFrameSize = false;
44 return;
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000047int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm,
48 int testMode) {
niklase@google.com470e71d2011-07-07 08:21:25 +000049
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000050 if ((isacConfig.currentRateBitPerSec != 0)
51 || (isacConfig.currentFrameSizeMsec != 0)) {
52 CodecInst sendCodec;
53 acm->SendCodec(&sendCodec);
54 if (isacConfig.currentRateBitPerSec < 0) {
55 sendCodec.rate = -1;
56 CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
57 if (testMode != 0) {
58 printf("ISAC-%s Registered in adaptive (channel-dependent) mode.\n",
59 (sendCodec.plfreq == 32000) ? "swb" : "wb");
60 }
61 } else {
niklase@google.com470e71d2011-07-07 08:21:25 +000062
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000063 if (isacConfig.currentRateBitPerSec != 0) {
64 sendCodec.rate = isacConfig.currentRateBitPerSec;
65 }
66 if (isacConfig.currentFrameSizeMsec != 0) {
67 sendCodec.pacsize = isacConfig.currentFrameSizeMsec
68 * (sendCodec.plfreq / 1000);
69 }
70 CHECK_ERROR(acm->RegisterSendCodec(sendCodec));
71 if (testMode != 0) {
72 printf("Target rate is set to %d bit/sec with frame-size %d ms \n",
73 (int) isacConfig.currentRateBitPerSec,
74 (int) sendCodec.pacsize / (sendCodec.plfreq / 1000));
75 }
niklase@google.com470e71d2011-07-07 08:21:25 +000076 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 }
niklase@google.com470e71d2011-07-07 08:21:25 +000078
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000079 if (isacConfig.maxRateBitPerSec > 0) {
80 CHECK_ERROR(acm->SetISACMaxRate(isacConfig.maxRateBitPerSec));
81 if (testMode != 0) {
82 printf("Max rate is set to %u bit/sec\n", isacConfig.maxRateBitPerSec);
niklase@google.com470e71d2011-07-07 08:21:25 +000083 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000084 }
85 if (isacConfig.maxPayloadSizeByte > 0) {
86 CHECK_ERROR(acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte));
87 if (testMode != 0) {
88 printf("Max payload-size is set to %u bit/sec\n",
89 isacConfig.maxPayloadSizeByte);
niklase@google.com470e71d2011-07-07 08:21:25 +000090 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000091 }
92 if ((isacConfig.initFrameSizeInMsec != 0)
93 || (isacConfig.initRateBitPerSec != 0)) {
94 CHECK_ERROR(
95 acm->ConfigISACBandwidthEstimator(
96 (uint8_t) isacConfig.initFrameSizeInMsec,
97 (uint16_t) isacConfig.initRateBitPerSec,
niklase@google.com470e71d2011-07-07 08:21:25 +000098 isacConfig.enforceFrameSize));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000099 if ((isacConfig.initFrameSizeInMsec != 0) && (testMode != 0)) {
100 printf("Initialize BWE to %d msec frame-size\n",
101 isacConfig.initFrameSizeInMsec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000103 if ((isacConfig.initRateBitPerSec != 0) && (testMode != 0)) {
104 printf("Initialize BWE to %u bit/sec send-bandwidth\n",
105 isacConfig.initRateBitPerSec);
106 }
107 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000109 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110}
111
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000112ISACTest::ISACTest(int testMode) {
113 _testMode = testMode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114}
115
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116ISACTest::~ISACTest() {
117 AudioCodingModule::Destroy(_acmA);
118 AudioCodingModule::Destroy(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000120 delete _channel_A2B;
121 delete _channel_B2A;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122}
123
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000124int16_t ISACTest::Setup() {
125 int codecCntr;
126 CodecInst codecParam;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000128 _acmA = AudioCodingModule::Create(1);
129 _acmB = AudioCodingModule::Create(2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000131 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
132 codecCntr++) {
133 AudioCodingModule::Codec(codecCntr, &codecParam);
134 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
135 && codecParam.plfreq == 16000) {
136 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
137 _idISAC16kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000139 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
140 && codecParam.plfreq == 32000) {
141 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
142 _idISAC32kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000144 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000146 // register both iSAC-wb & iSAC-swb in both sides as receiver codecs
147 CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC16kHz));
148 CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC32kHz));
149 CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC16kHz));
150 CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC32kHz));
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000152 //--- Set A-to-B channel
153 _channel_A2B = new Channel;
154 CHECK_ERROR(_acmA->RegisterTransportCallback(_channel_A2B));
155 _channel_A2B->RegisterReceiverACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000157 //--- Set B-to-A channel
158 _channel_B2A = new Channel;
159 CHECK_ERROR(_acmB->RegisterTransportCallback(_channel_B2A));
160 _channel_B2A->RegisterReceiverACM(_acmA);
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000162 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
163 "pcm");
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000165 _acmB->RegisterSendCodec(_paramISAC16kHz);
166 _acmA->RegisterSendCodec(_paramISAC32kHz);
167
168 if (_testMode != 0) {
169 printf("Side A Send Codec\n");
170 printf("%s %d\n", _paramISAC32kHz.plname, _paramISAC32kHz.plfreq);
171
172 printf("Side B Send Codec\n");
173 printf("%s %d\n", _paramISAC16kHz.plname, _paramISAC16kHz.plfreq);
174 }
175
176 _inFileA.Open(file_name_swb_, 32000, "rb");
177 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
178 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
179 _outFileA.Open(fileNameA, 32000, "wb");
180 _outFileB.Open(fileNameB, 32000, "wb");
181
182 while (!_inFileA.EndOfFile()) {
183 Run10ms();
184 }
185 CodecInst receiveCodec;
186 CHECK_ERROR(_acmA->ReceiveCodec(&receiveCodec));
187 if (_testMode != 0) {
188 printf("Side A Receive Codec\n");
189 printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
190 }
191
192 CHECK_ERROR(_acmB->ReceiveCodec(&receiveCodec));
193 if (_testMode != 0) {
194 printf("Side B Receive Codec\n");
195 printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq);
196 }
197
198 _inFileA.Close();
199 _outFileA.Close();
200 _outFileB.Close();
201
202 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000203}
204
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000205void ISACTest::Perform() {
206 if (_testMode == 0) {
207 printf("Running iSAC Test");
208 WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1,
209 "---------- iSACTest ----------");
210 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000212 Setup();
niklase@google.com470e71d2011-07-07 08:21:25 +0000213
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000214 int16_t testNr = 0;
215 ACMTestISACConfig wbISACConfig;
216 ACMTestISACConfig swbISACConfig;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000218 SetISACConfigDefault(wbISACConfig);
219 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000221 wbISACConfig.currentRateBitPerSec = -1;
222 swbISACConfig.currentRateBitPerSec = -1;
223 testNr++;
224 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
225
226 if (_testMode != 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000227 SetISACConfigDefault(wbISACConfig);
228 SetISACConfigDefault(swbISACConfig);
229
230 wbISACConfig.currentRateBitPerSec = -1;
231 swbISACConfig.currentRateBitPerSec = -1;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000232 wbISACConfig.initRateBitPerSec = 13000;
233 wbISACConfig.initFrameSizeInMsec = 60;
234 swbISACConfig.initRateBitPerSec = 20000;
235 swbISACConfig.initFrameSizeInMsec = 30;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236 testNr++;
237 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
238
niklase@google.com470e71d2011-07-07 08:21:25 +0000239 SetISACConfigDefault(wbISACConfig);
240 SetISACConfigDefault(swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000241
242 wbISACConfig.currentRateBitPerSec = 20000;
243 swbISACConfig.currentRateBitPerSec = 48000;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 testNr++;
245 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000246
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000247 wbISACConfig.currentRateBitPerSec = 16000;
248 swbISACConfig.currentRateBitPerSec = 30000;
249 wbISACConfig.currentFrameSizeMsec = 60;
niklase@google.com470e71d2011-07-07 08:21:25 +0000250 testNr++;
251 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000252 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000254 SetISACConfigDefault(wbISACConfig);
255 SetISACConfigDefault(swbISACConfig);
256 testNr++;
257 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000259 int user_input;
260 if ((_testMode == 0) || (_testMode == 1)) {
261 swbISACConfig.maxPayloadSizeByte = (uint16_t) 200;
262 wbISACConfig.maxPayloadSizeByte = (uint16_t) 200;
263 } else {
264 printf("Enter the max payload-size for side A: ");
265 CHECK_ERROR(scanf("%d", &user_input));
266 swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
267 printf("Enter the max payload-size for side B: ");
268 CHECK_ERROR(scanf("%d", &user_input));
269 wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
270 }
271 testNr++;
272 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000274 _acmA->ResetEncoder();
275 _acmB->ResetEncoder();
276 SetISACConfigDefault(wbISACConfig);
277 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000279 if ((_testMode == 0) || (_testMode == 1)) {
280 swbISACConfig.maxRateBitPerSec = (uint32_t) 48000;
281 wbISACConfig.maxRateBitPerSec = (uint32_t) 48000;
282 } else {
283 printf("Enter the max rate for side A: ");
284 CHECK_ERROR(scanf("%d", &user_input));
285 swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
286 printf("Enter the max rate for side B: ");
287 CHECK_ERROR(scanf("%d", &user_input));
288 wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
289 }
290
291 testNr++;
292 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
293
294 testNr++;
295 if (_testMode == 0) {
296 SwitchingSamplingRate(testNr, 4);
297 printf("Done!\n");
298 } else {
299 SwitchingSamplingRate(testNr, 80);
300 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000301}
302
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000303void ISACTest::Run10ms() {
304 AudioFrame audioFrame;
niklase@google.com470e71d2011-07-07 08:21:25 +0000305
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000306 _inFileA.Read10MsData(audioFrame);
307 CHECK_ERROR(_acmA->Add10MsData(audioFrame));
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000309 CHECK_ERROR(_acmB->Add10MsData(audioFrame));
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000311 CHECK_ERROR(_acmA->Process());
312 CHECK_ERROR(_acmB->Process());
niklase@google.com470e71d2011-07-07 08:21:25 +0000313
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000314 CHECK_ERROR(_acmA->PlayoutData10Ms(32000, &audioFrame));
315 _outFileA.Write10MsData(audioFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000316
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000317 CHECK_ERROR(_acmB->PlayoutData10Ms(32000, &audioFrame));
318 _outFileB.Write10MsData(audioFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000319}
320
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000321void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
322 ACMTestISACConfig& swbISACConfig) {
323 if (_testMode == 0) {
324 printf(".");
325 } else {
326 printf("\nTest %d:\n\n", testNr);
327 }
328
329 // Files in Side A and B
330 _inFileA.Open(file_name_swb_, 32000, "rb", true);
331 _inFileB.Open(file_name_swb_, 32000, "rb", true);
332
333 std::string file_name_out;
334 std::stringstream file_stream_a;
335 std::stringstream file_stream_b;
336 file_stream_a << webrtc::test::OutputPath();
337 file_stream_b << webrtc::test::OutputPath();
338 if (_testMode == 0) {
339 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
340 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
341
342 } else {
343 file_stream_a << "outA_" << testNr << ".pcm";
344 file_stream_b << "outB_" << testNr << ".pcm";
345 }
346 file_name_out = file_stream_a.str();
347 _outFileA.Open(file_name_out, 32000, "wb");
348 file_name_out = file_stream_b.str();
349 _outFileB.Open(file_name_out, 32000, "wb");
350
351 CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
352 CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
353
354 CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
355 CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
356 if (_testMode != 0) {
357 printf("Side A Sending Super-Wideband \n");
358 printf("Side B Sending Wideband\n\n");
359 }
360
361 SetISAConfig(swbISACConfig, _acmA, _testMode);
362 SetISAConfig(wbISACConfig, _acmB, _testMode);
363
364 bool adaptiveMode = false;
365 if ((swbISACConfig.currentRateBitPerSec == -1)
366 || (wbISACConfig.currentRateBitPerSec == -1)) {
367 adaptiveMode = true;
368 }
369 _myTimer.Reset();
370 _channel_A2B->ResetStats();
371 _channel_B2A->ResetStats();
372
373 char currentTime[500];
374 if (_testMode == 2)
375 printf("\n");
376 CodecInst sendCodec;
377 EventWrapper* myEvent = EventWrapper::Create();
378 myEvent->StartTimer(true, 10);
379 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
380 Run10ms();
381 _myTimer.Tick10ms();
382 _myTimer.CurrentTimeHMS(currentTime);
383 if (_testMode == 2)
384 printf("\r%s ", currentTime);
385
386 if ((adaptiveMode) && (_testMode != 0)) {
387 myEvent->Wait(5000);
388
389 _acmA->SendCodec(&sendCodec);
390 if (_testMode == 2)
391 printf("[%d] ", sendCodec.rate);
392 _acmB->SendCodec(&sendCodec);
393 if (_testMode == 2)
394 printf("[%d] ", sendCodec.rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000396 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000397
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000398 if (_testMode != 0) {
399 printf("\n\nSide A statistics\n\n");
400 _channel_A2B->PrintStats(_paramISAC32kHz);
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000401
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000402 printf("\n\nSide B statistics\n\n");
403 _channel_B2A->PrintStats(_paramISAC16kHz);
404 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000405
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000406 _channel_A2B->ResetStats();
407 _channel_B2A->ResetStats();
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000409 if (_testMode != 0)
410 printf("\n");
411 _outFileA.Close();
412 _outFileB.Close();
413 _inFileA.Close();
414 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000415}
416
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000417void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
418 // Files in Side A
419 _inFileA.Open(file_name_swb_, 32000, "rb");
420 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000421
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000422 std::string file_name_out;
423 std::stringstream file_stream_a;
424 std::stringstream file_stream_b;
425 file_stream_a << webrtc::test::OutputPath();
426 file_stream_b << webrtc::test::OutputPath();
427 if (_testMode == 0) {
428 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
429 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
430 } else {
431 printf("\nTest %d", testNr);
432 printf(" Alternate between WB and SWB at the sender Side\n\n");
433 file_stream_a << "outA_" << testNr << ".pcm";
434 file_stream_b << "outB_" << testNr << ".pcm";
435 }
436 file_name_out = file_stream_a.str();
437 _outFileA.Open(file_name_out, 32000, "wb");
438 file_name_out = file_stream_b.str();
439 _outFileB.Open(file_name_out, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000440
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000441 CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
442 CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
443 if (_testMode != 0) {
444 printf("Side A Sending Super-Wideband \n");
445 printf("Side B Sending Wideband\n");
446 }
447
448 int numSendCodecChanged = 0;
449 _myTimer.Reset();
450 char currentTime[50];
451 while (numSendCodecChanged < (maxSampRateChange << 1)) {
452 Run10ms();
453 _myTimer.Tick10ms();
454 _myTimer.CurrentTimeHMS(currentTime);
455 if (_testMode == 2)
456 printf("\r%s", currentTime);
457 if (_inFileA.EndOfFile()) {
458 if (_inFileA.SamplingFrequency() == 16000) {
459 if (_testMode != 0)
460 printf("\nSide A switched to Send Super-Wideband\n");
461 _inFileA.Close();
462 _inFileA.Open(file_name_swb_, 32000, "rb");
463 CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz));
464 } else {
465 if (_testMode != 0)
466 printf("\nSide A switched to Send Wideband\n");
467 _inFileA.Close();
468 _inFileA.Open(file_name_swb_, 32000, "rb");
469 CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz));
470 }
471 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000472 }
473
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000474 if (_inFileB.EndOfFile()) {
475 if (_inFileB.SamplingFrequency() == 16000) {
476 if (_testMode != 0)
477 printf("\nSide B switched to Send Super-Wideband\n");
478 _inFileB.Close();
479 _inFileB.Open(file_name_swb_, 32000, "rb");
480 CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz));
481 } else {
482 if (_testMode != 0)
483 printf("\nSide B switched to Send Wideband\n");
484 _inFileB.Close();
485 _inFileB.Open(file_name_swb_, 32000, "rb");
486 CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz));
487 }
488 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000489 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000490 }
491 _outFileA.Close();
492 _outFileB.Close();
493 _inFileA.Close();
494 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000495}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000496
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000497} // namespace webrtc