blob: 08a9d27761b2b1bcbaae633267979a4804bd1090 [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
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000095ISACTest::~ISACTest() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +000096 delete _channel_A2B;
97 delete _channel_B2A;
niklase@google.com470e71d2011-07-07 08:21:25 +000098}
99
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000100void ISACTest::Setup() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000101 int codecCntr;
102 CodecInst codecParam;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000104 for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
105 codecCntr++) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000106 EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000107 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
108 && codecParam.plfreq == 16000) {
109 memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
110 _idISAC16kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000112 if (!STR_CASE_CMP(codecParam.plname, "ISAC")
113 && codecParam.plfreq == 32000) {
114 memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
115 _idISAC32kHz = codecCntr;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000117 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000119 // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
120 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz));
121 EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz));
122 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz));
123 EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz));
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000125 //--- Set A-to-B channel
126 _channel_A2B = new Channel;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000127 EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000128 _channel_A2B->RegisterReceiverACM(_acmB);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000130 //--- Set B-to-A channel
131 _channel_B2A = new Channel;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000132 EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000133 _channel_B2A->RegisterReceiverACM(_acmA);
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000135 file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz",
136 "pcm");
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000138 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
139 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000140
141 _inFileA.Open(file_name_swb_, 32000, "rb");
142 std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm";
143 std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm";
144 _outFileA.Open(fileNameA, 32000, "wb");
145 _outFileB.Open(fileNameB, 32000, "wb");
146
147 while (!_inFileA.EndOfFile()) {
148 Run10ms();
149 }
150 CodecInst receiveCodec;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000151 EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
152 EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000153
154 _inFileA.Close();
155 _outFileA.Close();
156 _outFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000157}
158
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000159void ISACTest::Perform() {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000160 Setup();
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000162 int16_t testNr = 0;
163 ACMTestISACConfig wbISACConfig;
164 ACMTestISACConfig swbISACConfig;
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000166 SetISACConfigDefault(wbISACConfig);
167 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000169 wbISACConfig.currentRateBitPerSec = -1;
170 swbISACConfig.currentRateBitPerSec = -1;
171 testNr++;
172 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
173
174 if (_testMode != 0) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000175 SetISACConfigDefault(wbISACConfig);
176 SetISACConfigDefault(swbISACConfig);
177
178 wbISACConfig.currentRateBitPerSec = -1;
179 swbISACConfig.currentRateBitPerSec = -1;
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000180 wbISACConfig.initRateBitPerSec = 13000;
181 wbISACConfig.initFrameSizeInMsec = 60;
182 swbISACConfig.initRateBitPerSec = 20000;
183 swbISACConfig.initFrameSizeInMsec = 30;
niklase@google.com470e71d2011-07-07 08:21:25 +0000184 testNr++;
185 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
186
niklase@google.com470e71d2011-07-07 08:21:25 +0000187 SetISACConfigDefault(wbISACConfig);
188 SetISACConfigDefault(swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000189
190 wbISACConfig.currentRateBitPerSec = 20000;
191 swbISACConfig.currentRateBitPerSec = 48000;
niklase@google.com470e71d2011-07-07 08:21:25 +0000192 testNr++;
193 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000194
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000195 wbISACConfig.currentRateBitPerSec = 16000;
196 swbISACConfig.currentRateBitPerSec = 30000;
197 wbISACConfig.currentFrameSizeMsec = 60;
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 testNr++;
199 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000200 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000202 SetISACConfigDefault(wbISACConfig);
203 SetISACConfigDefault(swbISACConfig);
204 testNr++;
205 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000206
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000207 int user_input;
208 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000209 swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
210 wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000211 } else {
212 printf("Enter the max payload-size for side A: ");
213 CHECK_ERROR(scanf("%d", &user_input));
214 swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
215 printf("Enter the max payload-size for side B: ");
216 CHECK_ERROR(scanf("%d", &user_input));
217 wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input;
218 }
219 testNr++;
220 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000222 _acmA->ResetEncoder();
223 _acmB->ResetEncoder();
224 SetISACConfigDefault(wbISACConfig);
225 SetISACConfigDefault(swbISACConfig);
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000227 if ((_testMode == 0) || (_testMode == 1)) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000228 swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
229 wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000230 } else {
231 printf("Enter the max rate for side A: ");
232 CHECK_ERROR(scanf("%d", &user_input));
233 swbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
234 printf("Enter the max rate for side B: ");
235 CHECK_ERROR(scanf("%d", &user_input));
236 wbISACConfig.maxRateBitPerSec = (uint32_t) user_input;
237 }
238
239 testNr++;
240 EncodeDecode(testNr, wbISACConfig, swbISACConfig);
241
242 testNr++;
243 if (_testMode == 0) {
244 SwitchingSamplingRate(testNr, 4);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000245 } else {
246 SwitchingSamplingRate(testNr, 80);
247 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000248}
249
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000250void ISACTest::Run10ms() {
251 AudioFrame audioFrame;
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000252 EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0);
253 EXPECT_EQ(0, _acmA->Add10MsData(audioFrame));
254 EXPECT_EQ(0, _acmB->Add10MsData(audioFrame));
255 EXPECT_GT(_acmA->Process(), -1);
256 EXPECT_GT(_acmB->Process(), -1);
257 EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000258 _outFileA.Write10MsData(audioFrame);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000259 EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000260 _outFileB.Write10MsData(audioFrame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000261}
262
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000263void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig,
264 ACMTestISACConfig& swbISACConfig) {
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000265 // Files in Side A and B
266 _inFileA.Open(file_name_swb_, 32000, "rb", true);
267 _inFileB.Open(file_name_swb_, 32000, "rb", true);
268
269 std::string file_name_out;
270 std::stringstream file_stream_a;
271 std::stringstream file_stream_b;
272 file_stream_a << webrtc::test::OutputPath();
273 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000274 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
275 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000276 file_name_out = file_stream_a.str();
277 _outFileA.Open(file_name_out, 32000, "wb");
278 file_name_out = file_stream_b.str();
279 _outFileB.Open(file_name_out, 32000, "wb");
280
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000281 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
282 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
283 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
284 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000285
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000286 // Side A is sending super-wideband, and side B is sending wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000287 SetISAConfig(swbISACConfig, _acmA, _testMode);
288 SetISAConfig(wbISACConfig, _acmB, _testMode);
289
290 bool adaptiveMode = false;
291 if ((swbISACConfig.currentRateBitPerSec == -1)
292 || (wbISACConfig.currentRateBitPerSec == -1)) {
293 adaptiveMode = true;
294 }
295 _myTimer.Reset();
296 _channel_A2B->ResetStats();
297 _channel_B2A->ResetStats();
298
299 char currentTime[500];
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000300 CodecInst sendCodec;
301 EventWrapper* myEvent = EventWrapper::Create();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000302 EXPECT_TRUE(myEvent->StartTimer(true, 10));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000303 while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
304 Run10ms();
305 _myTimer.Tick10ms();
306 _myTimer.CurrentTimeHMS(currentTime);
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000307
308 if ((adaptiveMode) && (_testMode != 0)) {
309 myEvent->Wait(5000);
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000310 EXPECT_EQ(0, _acmA->SendCodec(&sendCodec));
311 EXPECT_EQ(0, _acmB->SendCodec(&sendCodec));
niklase@google.com470e71d2011-07-07 08:21:25 +0000312 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000313 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000315 if (_testMode != 0) {
316 printf("\n\nSide A statistics\n\n");
317 _channel_A2B->PrintStats(_paramISAC32kHz);
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000318
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000319 printf("\n\nSide B statistics\n\n");
320 _channel_B2A->PrintStats(_paramISAC16kHz);
321 }
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000322
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000323 _channel_A2B->ResetStats();
324 _channel_B2A->ResetStats();
niklase@google.com470e71d2011-07-07 08:21:25 +0000325
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000326 _outFileA.Close();
327 _outFileB.Close();
328 _inFileA.Close();
329 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000330}
331
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000332void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
333 // Files in Side A
334 _inFileA.Open(file_name_swb_, 32000, "rb");
335 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgba468042012-08-17 10:38:28 +0000336
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000337 std::string file_name_out;
338 std::stringstream file_stream_a;
339 std::stringstream file_stream_b;
340 file_stream_a << webrtc::test::OutputPath();
341 file_stream_b << webrtc::test::OutputPath();
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000342 file_stream_a << "out_iSACTest_A_" << testNr << ".pcm";
343 file_stream_b << "out_iSACTest_B_" << testNr << ".pcm";
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000344 file_name_out = file_stream_a.str();
345 _outFileA.Open(file_name_out, 32000, "wb");
346 file_name_out = file_stream_b.str();
347 _outFileB.Open(file_name_out, 32000, "wb");
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000349 // Start with side A sending super-wideband and side B seding wideband.
350 // Toggle sending wideband/super-wideband in this test.
351 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
352 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000353
354 int numSendCodecChanged = 0;
355 _myTimer.Reset();
356 char currentTime[50];
357 while (numSendCodecChanged < (maxSampRateChange << 1)) {
358 Run10ms();
359 _myTimer.Tick10ms();
360 _myTimer.CurrentTimeHMS(currentTime);
361 if (_testMode == 2)
362 printf("\r%s", currentTime);
363 if (_inFileA.EndOfFile()) {
364 if (_inFileA.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000365 // Switch side A to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000366 _inFileA.Close();
367 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000368 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000369 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000370 // Switch side A to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000371 _inFileA.Close();
372 _inFileA.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000373 EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000374 }
375 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000376 }
377
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000378 if (_inFileB.EndOfFile()) {
379 if (_inFileB.SamplingFrequency() == 16000) {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000380 // Switch side B to send super-wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000381 _inFileB.Close();
382 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000383 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000384 } else {
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000385 // Switch side B to send wideband.
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000386 _inFileB.Close();
387 _inFileB.Open(file_name_swb_, 32000, "rb");
tina.legrand@webrtc.orgee92b662013-08-27 07:33:51 +0000388 EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz));
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000389 }
390 numSendCodecChanged++;
niklase@google.com470e71d2011-07-07 08:21:25 +0000391 }
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000392 }
393 _outFileA.Close();
394 _outFileB.Close();
395 _inFileA.Close();
396 _inFileB.Close();
niklase@google.com470e71d2011-07-07 08:21:25 +0000397}
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +0000398
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000399} // namespace webrtc