blob: f7fef4a80afcff8964f1ac16598f4dd5d756d251 [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>
andrew@webrtc.org89df0922013-09-12 01:27:43 +000024#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000025
turaj@webrtc.org532f3dc2013-09-19 00:12:23 +000026#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000027#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
turaj@webrtc.org6ea3d1c2013-10-02 21:44:33 +000089ISACTest::ISACTest(int testMode, const Config& config)
90 : _acmA(config.Get<AudioCodingModuleFactory>().Create(1)),
91 _acmB(config.Get<AudioCodingModuleFactory>().Create(2)),
andrew@webrtc.org89df0922013-09-12 01:27:43 +000092 _testMode(testMode) {
niklase@google.com470e71d2011-07-07 08:21:25 +000093}
94
turaj@webrtc.org55e17232013-10-29 04:40:09 +000095ISACTest::~ISACTest() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000096
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +000097void ISACTest::Setup() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000098 int codecCntr;
99 CodecInst codecParam;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
102 codecCntr++) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000103 EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000104 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
105 && codecParam.plfreq == 16000) {
106 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
107 _idISAC16kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000109 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
110 && codecParam.plfreq == 32000) {
111 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
112 _idISAC32kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000114 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000116 // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
117 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz));
118 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz));
119 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz));
120 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz));
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000122 //--- Set A-to-B channel
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000123 _channel_A2B.reset(new Channel);
124 EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get()));
125 _channel_A2B->RegisterReceiverACM(_acmB.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000127 //--- Set B-to-A channel
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000128 _channel_B2A.reset(new Channel);
129 EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get()));
130 _channel_B2A->RegisterReceiverACM(_acmA.get());
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000132 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
133 "pcm");
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000135 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
136 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000137
138 _inFileA.Open(file_name_swb_, 32000, "rb");
139 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
140 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
141 _outFileA.Open(fileNameA, 32000, "wb");
142 _outFileB.Open(fileNameB, 32000, "wb");
143
144 while (!_inFileA.EndOfFile()) {
145 Run10ms();
146 }
147 CodecInst receiveCodec;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000148 EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
149 EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000150
151 _inFileA.Close();
152 _outFileA.Close();
153 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000154}
155
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000156void ISACTest::Perform() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000157 Setup();
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000159 int16_t testNr = 0;
160 ACMTestISACConfig wbISACConfig;
161 ACMTestISACConfig swbISACConfig;
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000163 SetISACConfigDefault(wbISACConfig);
164 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000166 wbISACConfig.currentRateBitPerSec = -1;
167 swbISACConfig.currentRateBitPerSec = -1;
168 testNr++;
169 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
170
171 if (_testMode != 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000172 SetISACConfigDefault(wbISACConfig);
173 SetISACConfigDefault(swbISACConfig);
174
175 wbISACConfig.currentRateBitPerSec = -1;
176 swbISACConfig.currentRateBitPerSec = -1;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000177 wbISACConfig.initRateBitPerSec = 13000;
178 wbISACConfig.initFrameSizeInMsec = 60;
179 swbISACConfig.initRateBitPerSec = 20000;
180 swbISACConfig.initFrameSizeInMsec = 30;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181 testNr++;
182 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
183
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 SetISACConfigDefault(wbISACConfig);
185 SetISACConfigDefault(swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000186
187 wbISACConfig.currentRateBitPerSec = 20000;
188 swbISACConfig.currentRateBitPerSec = 48000;
niklase@google.com470e71d2011-07-07 08:21:25 +0000189 testNr++;
190 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000191
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000192 wbISACConfig.currentRateBitPerSec = 16000;
193 swbISACConfig.currentRateBitPerSec = 30000;
194 wbISACConfig.currentFrameSizeMsec = 60;
niklase@google.com470e71d2011-07-07 08:21:25 +0000195 testNr++;
196 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000197 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000199 SetISACConfigDefault(wbISACConfig);
200 SetISACConfigDefault(swbISACConfig);
201 testNr++;
202 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000204 int user_input;
205 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000206 swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
207 wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000208 } else {
209 printf("Enter the max payload-size for side A: ");
210 CHECK_ERROR(scanf("%d", &user_input));
211 swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
212 printf("Enter the max payload-size for side B: ");
213 CHECK_ERROR(scanf("%d", &user_input));
214 wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
215 }
216 testNr++;
217 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000218
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000219 _acmA->ResetEncoder();
220 _acmB->ResetEncoder();
221 SetISACConfigDefault(wbISACConfig);
222 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000224 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000225 swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
226 wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000227 } else {
228 printf("Enter the max rate for side A: ");
229 CHECK_ERROR(scanf("%d", &user_input));
230 swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
231 printf("Enter the max rate for side B: ");
232 CHECK_ERROR(scanf("%d", &user_input));
233 wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
234 }
235
236 testNr++;
237 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
238
239 testNr++;
240 if (_testMode == 0) {
241 SwitchingSamplingRate(testNr, 4);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000242 } else {
243 SwitchingSamplingRate(testNr, 80);
244 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000245}
246
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000247void ISACTest::Run10ms() {
248 AudioFrame audioFrame;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000249 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
250 EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
251 EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
252 EXPECT_GT(_acmA->Process(), -1);
253 EXPECT_GT(_acmB->Process(), -1);
254 EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000255 _outFileA.Write10MsData(audioFrame);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000256 EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000257 _outFileB.Write10MsData(audioFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258}
259
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000260void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
261 ACMTestISACConfig& swbISACConfig) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000262 // Files in Side A and B
263 _inFileA.Open(file_name_swb_, 32000, "rb", true);
264 _inFileB.Open(file_name_swb_, 32000, "rb", true);
265
266 std::string file_name_out;
267 std::stringstream file_stream_a;
268 std::stringstream file_stream_b;
269 file_stream_a << webrtc::test::OutputPath();
270 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000271 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
272 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000273 file_name_out = file_stream_a.str();
274 _outFileA.Open(file_name_out, 32000, "wb");
275 file_name_out = file_stream_b.str();
276 _outFileB.Open(file_name_out, 32000, "wb");
277
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000278 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
279 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
280 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
281 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000282
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000283 // Side A is sending super-wideband, and side B is sending wideband.
turaj@webrtc.org55e17232013-10-29 04:40:09 +0000284 SetISAConfig(swbISACConfig, _acmA.get(), _testMode);
285 SetISAConfig(wbISACConfig, _acmB.get(), _testMode);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000286
287 bool adaptiveMode = false;
288 if ((swbISACConfig.currentRateBitPerSec == -1)
289 || (wbISACConfig.currentRateBitPerSec == -1)) {
290 adaptiveMode = true;
291 }
292 _myTimer.Reset();
293 _channel_A2B->ResetStats();
294 _channel_B2A->ResetStats();
295
296 char currentTime[500];
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000297 CodecInst sendCodec;
298 EventWrapper* myEvent = EventWrapper::Create();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000299 EXPECT_TRUE(myEvent->StartTimer(true, 10));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000300 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
301 Run10ms();
302 _myTimer.Tick10ms();
303 _myTimer.CurrentTimeHMS(currentTime);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000304
305 if ((adaptiveMode) && (_testMode != 0)) {
306 myEvent->Wait(5000);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000307 EXPECT_EQ(0, _acmA->SendCodec(&sendCodec));
308 EXPECT_EQ(0, _acmB->SendCodec(&sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000310 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000311
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000312 if (_testMode != 0) {
313 printf("\n\nSide A statistics\n\n");
314 _channel_A2B->PrintStats(_paramISAC32kHz);
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000315
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000316 printf("\n\nSide B statistics\n\n");
317 _channel_B2A->PrintStats(_paramISAC16kHz);
318 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000319
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000320 _channel_A2B->ResetStats();
321 _channel_B2A->ResetStats();
niklase@google.com470e71d2011-07-07 08:21:25 +0000322
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000323 _outFileA.Close();
324 _outFileB.Close();
325 _inFileA.Close();
326 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000327}
328
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000329void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
330 // Files in Side A
331 _inFileA.Open(file_name_swb_, 32000, "rb");
332 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000333
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000334 std::string file_name_out;
335 std::stringstream file_stream_a;
336 std::stringstream file_stream_b;
337 file_stream_a << webrtc::test::OutputPath();
338 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000339 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
340 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000341 file_name_out = file_stream_a.str();
342 _outFileA.Open(file_name_out, 32000, "wb");
343 file_name_out = file_stream_b.str();
344 _outFileB.Open(file_name_out, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000346 // Start with side A sending super-wideband and side B seding wideband.
347 // Toggle sending wideband/super-wideband in this test.
348 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
349 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000350
351 int numSendCodecChanged = 0;
352 _myTimer.Reset();
353 char currentTime[50];
354 while (numSendCodecChanged < (maxSampRateChange << 1)) {
355 Run10ms();
356 _myTimer.Tick10ms();
357 _myTimer.CurrentTimeHMS(currentTime);
358 if (_testMode == 2)
359 printf("\r%s", currentTime);
360 if (_inFileA.EndOfFile()) {
361 if (_inFileA.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000362 // Switch side A to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000363 _inFileA.Close();
364 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000365 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000366 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000367 // Switch side A to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000368 _inFileA.Close();
369 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000370 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000371 }
372 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000373 }
374
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000375 if (_inFileB.EndOfFile()) {
376 if (_inFileB.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000377 // Switch side B to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000378 _inFileB.Close();
379 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000380 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000381 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000382 // Switch side B to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000383 _inFileB.Close();
384 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000385 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000386 }
387 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000388 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000389 }
390 _outFileA.Close();
391 _outFileB.Close();
392 _inFileA.Close();
393 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000394}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000395
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000396} // namespace webrtc