blob: e8b77ace07ba609e72f345c4e774c471adb26405 [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
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <ctype.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000014#include <stdio.h>
15#include <string.h>
16
17#if _WIN32
18#include <windows.h>
19#elif WEBRTC_LINUX
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000020#include <time.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000021#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;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000053 EXPECT_EQ(0, acm->SendCodec(&sendCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000054 if (isacConfig.currentRateBitPerSec < 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000055 // Register iSAC in adaptive (channel-dependent) mode.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000056 sendCodec.rate = -1;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000057 EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000058 } else {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000059 if (isacConfig.currentRateBitPerSec != 0) {
60 sendCodec.rate = isacConfig.currentRateBitPerSec;
61 }
62 if (isacConfig.currentFrameSizeMsec != 0) {
63 sendCodec.pacsize = isacConfig.currentFrameSizeMsec
64 * (sendCodec.plfreq / 1000);
65 }
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000066 EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +000067 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000068 }
niklase@google.com470e71d2011-07-07 08:21:25 +000069
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000070 if (isacConfig.maxRateBitPerSec > 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000071 // Set max rate.
72 EXPECT_EQ(0, acm->SetISACMaxRate(isacConfig.maxRateBitPerSec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000073 }
74 if (isacConfig.maxPayloadSizeByte > 0) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000075 // Set max payload size.
76 EXPECT_EQ(0, acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000077 }
78 if ((isacConfig.initFrameSizeInMsec != 0)
79 || (isacConfig.initRateBitPerSec != 0)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000080 EXPECT_EQ(0, acm->ConfigISACBandwidthEstimator(
81 static_cast<uint8_t>(isacConfig.initFrameSizeInMsec),
82 static_cast<uint16_t>(isacConfig.initRateBitPerSec),
83 isacConfig.enforceFrameSize));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000084 }
niklase@google.com470e71d2011-07-07 08:21:25 +000085
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000086 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000089ISACTest::ISACTest(int testMode) {
90 _testMode = testMode;
niklase@google.com470e71d2011-07-07 08:21:25 +000091}
92
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000093ISACTest::~ISACTest() {
94 AudioCodingModule::Destroy(_acmA);
95 AudioCodingModule::Destroy(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000097 delete _channel_A2B;
98 delete _channel_B2A;
niklase@google.com470e71d2011-07-07 08:21:25 +000099}
100
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000101void ISACTest::Setup() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000102 int codecCntr;
103 CodecInst codecParam;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000105 _acmA = AudioCodingModule::Create(1);
106 _acmB = AudioCodingModule::Create(2);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000108 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
109 codecCntr++) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000110 EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000111 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
112 && codecParam.plfreq == 16000) {
113 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
114 _idISAC16kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000116 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
117 && codecParam.plfreq == 32000) {
118 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
119 _idISAC32kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000121 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000123 // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
124 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz));
125 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz));
126 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz));
127 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz));
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000129 //--- Set A-to-B channel
130 _channel_A2B = new Channel;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000131 EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000132 _channel_A2B->RegisterReceiverACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000134 //--- Set B-to-A channel
135 _channel_B2A = new Channel;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000136 EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000137 _channel_B2A->RegisterReceiverACM(_acmA);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000139 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
140 "pcm");
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000142 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
143 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000144
145 _inFileA.Open(file_name_swb_, 32000, "rb");
146 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
147 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
148 _outFileA.Open(fileNameA, 32000, "wb");
149 _outFileB.Open(fileNameB, 32000, "wb");
150
151 while (!_inFileA.EndOfFile()) {
152 Run10ms();
153 }
154 CodecInst receiveCodec;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000155 EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
156 EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000157
158 _inFileA.Close();
159 _outFileA.Close();
160 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000161}
162
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000163void ISACTest::Perform() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000164 Setup();
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000166 int16_t testNr = 0;
167 ACMTestISACConfig wbISACConfig;
168 ACMTestISACConfig swbISACConfig;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000170 SetISACConfigDefault(wbISACConfig);
171 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000173 wbISACConfig.currentRateBitPerSec = -1;
174 swbISACConfig.currentRateBitPerSec = -1;
175 testNr++;
176 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
177
178 if (_testMode != 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 SetISACConfigDefault(wbISACConfig);
180 SetISACConfigDefault(swbISACConfig);
181
182 wbISACConfig.currentRateBitPerSec = -1;
183 swbISACConfig.currentRateBitPerSec = -1;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000184 wbISACConfig.initRateBitPerSec = 13000;
185 wbISACConfig.initFrameSizeInMsec = 60;
186 swbISACConfig.initRateBitPerSec = 20000;
187 swbISACConfig.initFrameSizeInMsec = 30;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188 testNr++;
189 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
190
niklase@google.com470e71d2011-07-07 08:21:25 +0000191 SetISACConfigDefault(wbISACConfig);
192 SetISACConfigDefault(swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000193
194 wbISACConfig.currentRateBitPerSec = 20000;
195 swbISACConfig.currentRateBitPerSec = 48000;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196 testNr++;
197 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000198
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000199 wbISACConfig.currentRateBitPerSec = 16000;
200 swbISACConfig.currentRateBitPerSec = 30000;
201 wbISACConfig.currentFrameSizeMsec = 60;
niklase@google.com470e71d2011-07-07 08:21:25 +0000202 testNr++;
203 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000204 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000206 SetISACConfigDefault(wbISACConfig);
207 SetISACConfigDefault(swbISACConfig);
208 testNr++;
209 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000210
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000211 int user_input;
212 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000213 swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
214 wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000215 } else {
216 printf("Enter the max payload-size for side A: ");
217 CHECK_ERROR(scanf("%d", &user_input));
218 swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
219 printf("Enter the max payload-size for side B: ");
220 CHECK_ERROR(scanf("%d", &user_input));
221 wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
222 }
223 testNr++;
224 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000226 _acmA->ResetEncoder();
227 _acmB->ResetEncoder();
228 SetISACConfigDefault(wbISACConfig);
229 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000231 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000232 swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
233 wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000234 } else {
235 printf("Enter the max rate for side A: ");
236 CHECK_ERROR(scanf("%d", &user_input));
237 swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
238 printf("Enter the max rate for side B: ");
239 CHECK_ERROR(scanf("%d", &user_input));
240 wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
241 }
242
243 testNr++;
244 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
245
246 testNr++;
247 if (_testMode == 0) {
248 SwitchingSamplingRate(testNr, 4);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000249 } else {
250 SwitchingSamplingRate(testNr, 80);
251 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000252}
253
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000254void ISACTest::Run10ms() {
255 AudioFrame audioFrame;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000256 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
257 EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
258 EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
259 EXPECT_GT(_acmA->Process(), -1);
260 EXPECT_GT(_acmB->Process(), -1);
261 EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000262 _outFileA.Write10MsData(audioFrame);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000263 EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000264 _outFileB.Write10MsData(audioFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265}
266
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000267void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
268 ACMTestISACConfig& swbISACConfig) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000269 // Files in Side A and B
270 _inFileA.Open(file_name_swb_, 32000, "rb", true);
271 _inFileB.Open(file_name_swb_, 32000, "rb", true);
272
273 std::string file_name_out;
274 std::stringstream file_stream_a;
275 std::stringstream file_stream_b;
276 file_stream_a << webrtc::test::OutputPath();
277 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000278 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
279 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000280 file_name_out = file_stream_a.str();
281 _outFileA.Open(file_name_out, 32000, "wb");
282 file_name_out = file_stream_b.str();
283 _outFileB.Open(file_name_out, 32000, "wb");
284
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000285 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
286 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
287 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
288 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000289
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000290 // Side A is sending super-wideband, and side B is sending wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000291 SetISAConfig(swbISACConfig, _acmA, _testMode);
292 SetISAConfig(wbISACConfig, _acmB, _testMode);
293
294 bool adaptiveMode = false;
295 if ((swbISACConfig.currentRateBitPerSec == -1)
296 || (wbISACConfig.currentRateBitPerSec == -1)) {
297 adaptiveMode = true;
298 }
299 _myTimer.Reset();
300 _channel_A2B->ResetStats();
301 _channel_B2A->ResetStats();
302
303 char currentTime[500];
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000304 CodecInst sendCodec;
305 EventWrapper* myEvent = EventWrapper::Create();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000306 EXPECT_TRUE(myEvent->StartTimer(true, 10));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000307 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
308 Run10ms();
309 _myTimer.Tick10ms();
310 _myTimer.CurrentTimeHMS(currentTime);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000311
312 if ((adaptiveMode) && (_testMode != 0)) {
313 myEvent->Wait(5000);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000314 EXPECT_EQ(0, _acmA->SendCodec(&sendCodec));
315 EXPECT_EQ(0, _acmB->SendCodec(&sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000316 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000317 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000318
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000319 if (_testMode != 0) {
320 printf("\n\nSide A statistics\n\n");
321 _channel_A2B->PrintStats(_paramISAC32kHz);
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000322
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000323 printf("\n\nSide B statistics\n\n");
324 _channel_B2A->PrintStats(_paramISAC16kHz);
325 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000326
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000327 _channel_A2B->ResetStats();
328 _channel_B2A->ResetStats();
niklase@google.com470e71d2011-07-07 08:21:25 +0000329
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000330 _outFileA.Close();
331 _outFileB.Close();
332 _inFileA.Close();
333 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000334}
335
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000336void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
337 // Files in Side A
338 _inFileA.Open(file_name_swb_, 32000, "rb");
339 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000340
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000341 std::string file_name_out;
342 std::stringstream file_stream_a;
343 std::stringstream file_stream_b;
344 file_stream_a << webrtc::test::OutputPath();
345 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000346 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
347 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000348 file_name_out = file_stream_a.str();
349 _outFileA.Open(file_name_out, 32000, "wb");
350 file_name_out = file_stream_b.str();
351 _outFileB.Open(file_name_out, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000353 // Start with side A sending super-wideband and side B seding wideband.
354 // Toggle sending wideband/super-wideband in this test.
355 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
356 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000357
358 int numSendCodecChanged = 0;
359 _myTimer.Reset();
360 char currentTime[50];
361 while (numSendCodecChanged < (maxSampRateChange << 1)) {
362 Run10ms();
363 _myTimer.Tick10ms();
364 _myTimer.CurrentTimeHMS(currentTime);
365 if (_testMode == 2)
366 printf("\r%s", currentTime);
367 if (_inFileA.EndOfFile()) {
368 if (_inFileA.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000369 // Switch side A to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000370 _inFileA.Close();
371 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000372 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000373 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000374 // Switch side A to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000375 _inFileA.Close();
376 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000377 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000378 }
379 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000380 }
381
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000382 if (_inFileB.EndOfFile()) {
383 if (_inFileB.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000384 // Switch side B to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000385 _inFileB.Close();
386 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000387 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000388 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000389 // Switch side B to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000390 _inFileB.Close();
391 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000392 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000393 }
394 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000395 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000396 }
397 _outFileA.Close();
398 _outFileB.Close();
399 _inFileA.Close();
400 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000401}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000402
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000403} // namespace webrtc