niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 9dc45da | 2012-05-23 15:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 11 | #include <cctype> |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | |
| 15 | #if _WIN32 |
| 16 | #include <windows.h> |
| 17 | #elif WEBRTC_LINUX |
| 18 | #include <ctime> |
| 19 | #else |
| 20 | #include <sys/time.h> |
| 21 | #include <time.h> |
| 22 | #endif |
| 23 | |
| 24 | #include "event_wrapper.h" |
| 25 | #include "iSACTest.h" |
| 26 | #include "utility.h" |
| 27 | #include "trace.h" |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 28 | #include "testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | #include "tick_util.h" |
| 30 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 31 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
| 33 | void SetISACConfigDefault( |
| 34 | ACMTestISACConfig& isacConfig) |
| 35 | { |
| 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; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | WebRtc_Word16 SetISAConfig( |
| 49 | ACMTestISACConfig& isacConfig, |
| 50 | AudioCodingModule* acm, |
| 51 | int testMode) |
| 52 | { |
| 53 | |
| 54 | if((isacConfig.currentRateBitPerSec != 0) || |
| 55 | (isacConfig.currentFrameSizeMsec != 0)) |
| 56 | { |
| 57 | CodecInst sendCodec; |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 58 | acm->SendCodec(sendCodec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | if(isacConfig.currentRateBitPerSec < 0) |
| 60 | { |
| 61 | sendCodec.rate = -1; |
| 62 | CHECK_ERROR(acm->RegisterSendCodec(sendCodec)); |
| 63 | if(testMode != 0) |
| 64 | { |
| 65 | printf("ISAC-%s Registered in adaptive (channel-dependent) mode.\n", |
| 66 | (sendCodec.plfreq == 32000)? "swb":"wb"); |
| 67 | } |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | |
| 72 | if(isacConfig.currentRateBitPerSec != 0) |
| 73 | { |
| 74 | sendCodec.rate = isacConfig.currentRateBitPerSec; |
| 75 | } |
| 76 | if(isacConfig.currentFrameSizeMsec != 0) |
| 77 | { |
| 78 | sendCodec.pacsize = isacConfig.currentFrameSizeMsec * |
| 79 | (sendCodec.plfreq / 1000); |
| 80 | } |
| 81 | CHECK_ERROR(acm->RegisterSendCodec(sendCodec)); |
| 82 | if(testMode != 0) |
| 83 | { |
| 84 | printf("Target rate is set to %d bit/sec with frame-size %d ms \n", |
| 85 | (int)isacConfig.currentRateBitPerSec, |
| 86 | (int)sendCodec.pacsize / (sendCodec.plfreq / 1000)); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if(isacConfig.maxRateBitPerSec > 0) |
| 92 | { |
| 93 | CHECK_ERROR(acm->SetISACMaxRate(isacConfig.maxRateBitPerSec)); |
| 94 | if(testMode != 0) |
| 95 | { |
| 96 | printf("Max rate is set to %u bit/sec\n", |
| 97 | isacConfig.maxRateBitPerSec); |
| 98 | } |
| 99 | } |
| 100 | if(isacConfig.maxPayloadSizeByte > 0) |
| 101 | { |
| 102 | CHECK_ERROR(acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte)); |
| 103 | if(testMode != 0) |
| 104 | { |
| 105 | printf("Max payload-size is set to %u bit/sec\n", |
| 106 | isacConfig.maxPayloadSizeByte); |
| 107 | } |
| 108 | } |
| 109 | if((isacConfig.initFrameSizeInMsec != 0) || |
| 110 | (isacConfig.initRateBitPerSec != 0)) |
| 111 | { |
| 112 | CHECK_ERROR(acm->ConfigISACBandwidthEstimator( |
| 113 | (WebRtc_UWord8)isacConfig.initFrameSizeInMsec, |
| 114 | (WebRtc_UWord16)isacConfig.initRateBitPerSec, |
| 115 | isacConfig.enforceFrameSize)); |
| 116 | if((isacConfig.initFrameSizeInMsec != 0) && (testMode != 0)) |
| 117 | { |
| 118 | printf("Initialize BWE to %d msec frame-size\n", |
| 119 | isacConfig.initFrameSizeInMsec); |
| 120 | } |
| 121 | if((isacConfig.initRateBitPerSec != 0) && (testMode != 0)) |
| 122 | { |
| 123 | printf("Initialize BWE to %u bit/sec send-bandwidth\n", |
| 124 | isacConfig.initRateBitPerSec); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | ISACTest::ISACTest(int testMode) |
| 133 | { |
| 134 | _testMode = testMode; |
| 135 | } |
| 136 | |
| 137 | ISACTest::~ISACTest() |
| 138 | { |
| 139 | AudioCodingModule::Destroy(_acmA); |
| 140 | AudioCodingModule::Destroy(_acmB); |
| 141 | |
| 142 | delete _channel_A2B; |
| 143 | delete _channel_B2A; |
| 144 | } |
| 145 | |
| 146 | |
| 147 | WebRtc_Word16 |
| 148 | ISACTest::Setup() |
| 149 | { |
| 150 | int codecCntr; |
| 151 | CodecInst codecParam; |
| 152 | |
| 153 | _acmA = AudioCodingModule::Create(1); |
| 154 | _acmB = AudioCodingModule::Create(2); |
| 155 | |
| 156 | for(codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); codecCntr++) |
| 157 | { |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 158 | AudioCodingModule::Codec(codecCntr, codecParam); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | if(!STR_CASE_CMP(codecParam.plname, "ISAC") && codecParam.plfreq == 16000) |
| 160 | { |
| 161 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 162 | _idISAC16kHz = codecCntr; |
| 163 | } |
| 164 | if(!STR_CASE_CMP(codecParam.plname, "ISAC") && codecParam.plfreq == 32000) |
| 165 | { |
| 166 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 167 | _idISAC32kHz = codecCntr; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // register both iSAC-wb & iSAC-swb in both sides as receiver codecs |
| 172 | CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC16kHz)); |
| 173 | CHECK_ERROR(_acmA->RegisterReceiveCodec(_paramISAC32kHz)); |
| 174 | CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC16kHz)); |
| 175 | CHECK_ERROR(_acmB->RegisterReceiveCodec(_paramISAC32kHz)); |
| 176 | |
| 177 | //--- Set A-to-B channel |
| 178 | _channel_A2B = new Channel; |
| 179 | CHECK_ERROR(_acmA->RegisterTransportCallback(_channel_A2B)); |
| 180 | _channel_A2B->RegisterReceiverACM(_acmB); |
| 181 | |
| 182 | //--- Set B-to-A channel |
| 183 | _channel_B2A = new Channel; |
| 184 | CHECK_ERROR(_acmB->RegisterTransportCallback(_channel_B2A)); |
| 185 | _channel_B2A->RegisterReceiverACM(_acmA); |
| 186 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 187 | file_name_swb_ = |
| 188 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | |
| 190 | _acmB->RegisterSendCodec(_paramISAC16kHz); |
| 191 | _acmA->RegisterSendCodec(_paramISAC32kHz); |
| 192 | |
| 193 | if(_testMode != 0) |
| 194 | { |
| 195 | printf("Side A Send Codec\n"); |
| 196 | printf("%s %d\n", _paramISAC32kHz.plname, _paramISAC32kHz.plfreq); |
| 197 | |
| 198 | printf("Side B Send Codec\n"); |
| 199 | printf("%s %d\n", _paramISAC16kHz.plname, _paramISAC16kHz.plfreq); |
| 200 | } |
| 201 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 202 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 203 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 204 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 205 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 206 | _outFileB.Open(fileNameB, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
| 208 | while(!_inFileA.EndOfFile()) |
| 209 | { |
| 210 | Run10ms(); |
| 211 | } |
| 212 | CodecInst receiveCodec; |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 213 | CHECK_ERROR(_acmA->ReceiveCodec(receiveCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | if(_testMode != 0) |
| 215 | { |
| 216 | printf("Side A Receive Codec\n"); |
| 217 | printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq); |
| 218 | } |
| 219 | |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 220 | CHECK_ERROR(_acmB->ReceiveCodec(receiveCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | if(_testMode != 0) |
| 222 | { |
| 223 | printf("Side B Receive Codec\n"); |
| 224 | printf("%s %d\n", receiveCodec.plname, receiveCodec.plfreq); |
| 225 | } |
| 226 | |
| 227 | _inFileA.Close(); |
| 228 | _outFileA.Close(); |
| 229 | _outFileB.Close(); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | void |
| 236 | ISACTest::Perform() |
| 237 | { |
| 238 | if(_testMode == 0) |
| 239 | { |
| 240 | printf("Running iSAC Test"); |
| 241 | WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1, "---------- iSACTest ----------"); |
| 242 | } |
| 243 | |
| 244 | Setup(); |
| 245 | |
| 246 | WebRtc_Word16 testNr = 0; |
| 247 | ACMTestISACConfig wbISACConfig; |
| 248 | ACMTestISACConfig swbISACConfig; |
| 249 | |
| 250 | SetISACConfigDefault(wbISACConfig); |
| 251 | SetISACConfigDefault(swbISACConfig); |
| 252 | |
| 253 | wbISACConfig.currentRateBitPerSec = -1; |
| 254 | swbISACConfig.currentRateBitPerSec = -1; |
| 255 | testNr++; |
| 256 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 257 | |
| 258 | if (_testMode != 0) |
| 259 | { |
| 260 | SetISACConfigDefault(wbISACConfig); |
| 261 | SetISACConfigDefault(swbISACConfig); |
| 262 | |
| 263 | wbISACConfig.currentRateBitPerSec = -1; |
| 264 | swbISACConfig.currentRateBitPerSec = -1; |
| 265 | wbISACConfig.initRateBitPerSec = 13000; |
| 266 | wbISACConfig.initFrameSizeInMsec = 60; |
| 267 | swbISACConfig.initRateBitPerSec = 20000; |
| 268 | swbISACConfig.initFrameSizeInMsec = 30; |
| 269 | testNr++; |
| 270 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 271 | |
| 272 | SetISACConfigDefault(wbISACConfig); |
| 273 | SetISACConfigDefault(swbISACConfig); |
| 274 | |
| 275 | wbISACConfig.currentRateBitPerSec = 20000; |
| 276 | swbISACConfig.currentRateBitPerSec = 48000; |
| 277 | testNr++; |
| 278 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 279 | |
| 280 | wbISACConfig.currentRateBitPerSec = 16000; |
| 281 | swbISACConfig.currentRateBitPerSec = 30000; |
| 282 | wbISACConfig.currentFrameSizeMsec = 60; |
| 283 | testNr++; |
| 284 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 285 | } |
| 286 | |
| 287 | SetISACConfigDefault(wbISACConfig); |
| 288 | SetISACConfigDefault(swbISACConfig); |
| 289 | testNr++; |
| 290 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 291 | |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 292 | int user_input; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 293 | if((_testMode == 0) || (_testMode == 1)) |
| 294 | { |
| 295 | swbISACConfig.maxPayloadSizeByte = (WebRtc_UWord16)200; |
| 296 | wbISACConfig.maxPayloadSizeByte = (WebRtc_UWord16)200; |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | printf("Enter the max payload-size for side A: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 301 | CHECK_ERROR(scanf("%d", &user_input)); |
| 302 | swbISACConfig.maxPayloadSizeByte = (WebRtc_UWord16)user_input; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | printf("Enter the max payload-size for side B: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 304 | CHECK_ERROR(scanf("%d", &user_input)); |
| 305 | wbISACConfig.maxPayloadSizeByte = (WebRtc_UWord16)user_input; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 306 | } |
| 307 | testNr++; |
| 308 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 309 | |
| 310 | _acmA->ResetEncoder(); |
| 311 | _acmB->ResetEncoder(); |
| 312 | SetISACConfigDefault(wbISACConfig); |
| 313 | SetISACConfigDefault(swbISACConfig); |
| 314 | |
| 315 | if((_testMode == 0) || (_testMode == 1)) |
| 316 | { |
| 317 | swbISACConfig.maxRateBitPerSec = (WebRtc_UWord32)48000; |
| 318 | wbISACConfig.maxRateBitPerSec = (WebRtc_UWord32)48000; |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | printf("Enter the max rate for side A: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 323 | CHECK_ERROR(scanf("%d", &user_input)); |
| 324 | swbISACConfig.maxRateBitPerSec = (WebRtc_UWord32)user_input; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 325 | printf("Enter the max rate for side B: "); |
kjellander@webrtc.org | 543c3ea | 2011-11-23 12:20:35 +0000 | [diff] [blame] | 326 | CHECK_ERROR(scanf("%d", &user_input)); |
| 327 | wbISACConfig.maxRateBitPerSec = (WebRtc_UWord32)user_input; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | testNr++; |
| 331 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 332 | |
| 333 | |
| 334 | testNr++; |
| 335 | if(_testMode == 0) |
| 336 | { |
| 337 | SwitchingSamplingRate(testNr, 4); |
| 338 | printf("Done!\n"); |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | SwitchingSamplingRate(testNr, 80); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | void |
| 348 | ISACTest::Run10ms() |
| 349 | { |
| 350 | AudioFrame audioFrame; |
| 351 | |
| 352 | _inFileA.Read10MsData(audioFrame); |
| 353 | CHECK_ERROR(_acmA->Add10MsData(audioFrame)); |
| 354 | |
| 355 | CHECK_ERROR(_acmB->Add10MsData(audioFrame)); |
| 356 | |
| 357 | CHECK_ERROR(_acmA->Process()); |
| 358 | CHECK_ERROR(_acmB->Process()); |
| 359 | |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 360 | CHECK_ERROR(_acmA->PlayoutData10Ms(32000, audioFrame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 361 | _outFileA.Write10MsData(audioFrame); |
| 362 | |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 363 | CHECK_ERROR(_acmB->PlayoutData10Ms(32000, audioFrame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 364 | _outFileB.Write10MsData(audioFrame); |
| 365 | } |
| 366 | |
| 367 | void |
| 368 | ISACTest::EncodeDecode( |
| 369 | int testNr, |
| 370 | ACMTestISACConfig& wbISACConfig, |
| 371 | ACMTestISACConfig& swbISACConfig) |
| 372 | { |
| 373 | if(_testMode == 0) |
| 374 | { |
| 375 | printf("."); |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | printf("\nTest %d:\n\n", testNr); |
| 380 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 381 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 382 | // Files in Side A and B |
| 383 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 384 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 385 | |
| 386 | std::string file_name_out; |
| 387 | std::stringstream file_stream_a; |
| 388 | std::stringstream file_stream_b; |
| 389 | file_stream_a << webrtc::test::OutputPath(); |
| 390 | file_stream_b << webrtc::test::OutputPath(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | if(_testMode == 0) |
| 392 | { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 393 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 394 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
| 395 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 396 | } |
| 397 | else |
| 398 | { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 399 | file_stream_a << "outA_" << testNr << ".pcm"; |
| 400 | file_stream_b << "outB_" << testNr << ".pcm"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 401 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 402 | file_name_out = file_stream_a.str(); |
| 403 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 404 | file_name_out = file_stream_b.str(); |
| 405 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 406 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 407 | CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 408 | CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 409 | |
| 410 | CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 411 | CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 412 | if(_testMode != 0) |
| 413 | { |
| 414 | printf("Side A Sending Super-Wideband \n"); |
| 415 | printf("Side B Sending Wideband\n\n"); |
| 416 | } |
| 417 | |
| 418 | SetISAConfig(swbISACConfig, _acmA, _testMode); |
| 419 | SetISAConfig(wbISACConfig, _acmB, _testMode); |
| 420 | |
| 421 | bool adaptiveMode = false; |
| 422 | if((swbISACConfig.currentRateBitPerSec == -1) || |
| 423 | (wbISACConfig.currentRateBitPerSec == -1)) |
| 424 | { |
| 425 | adaptiveMode = true; |
| 426 | } |
| 427 | _myTimer.Reset(); |
| 428 | _channel_A2B->ResetStats(); |
| 429 | _channel_B2A->ResetStats(); |
| 430 | |
| 431 | char currentTime[500]; |
| 432 | if(_testMode == 2) printf("\n"); |
| 433 | CodecInst sendCodec; |
| 434 | EventWrapper* myEvent = EventWrapper::Create(); |
| 435 | myEvent->StartTimer(true, 10); |
| 436 | while(!(_inFileA.EndOfFile() || _inFileA.Rewinded())) |
| 437 | { |
| 438 | Run10ms(); |
| 439 | _myTimer.Tick10ms(); |
| 440 | _myTimer.CurrentTimeHMS(currentTime); |
| 441 | if(_testMode == 2) printf("\r%s ", currentTime); |
| 442 | |
| 443 | if((adaptiveMode) && (_testMode != 0)) |
| 444 | { |
| 445 | myEvent->Wait(5000); |
| 446 | |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 447 | _acmA->SendCodec(sendCodec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 448 | if(_testMode == 2) printf("[%d] ", sendCodec.rate); |
tina.legrand@webrtc.org | eb7ebf2 | 2013-02-20 15:57:31 +0000 | [diff] [blame] | 449 | _acmB->SendCodec(sendCodec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 450 | if(_testMode == 2) printf("[%d] ", sendCodec.rate); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if(_testMode != 0) |
| 455 | { |
| 456 | printf("\n\nSide A statistics\n\n"); |
| 457 | _channel_A2B->PrintStats(_paramISAC32kHz); |
| 458 | |
| 459 | printf("\n\nSide B statistics\n\n"); |
| 460 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 461 | } |
| 462 | |
| 463 | _channel_A2B->ResetStats(); |
| 464 | _channel_B2A->ResetStats(); |
| 465 | |
| 466 | if(_testMode != 0) printf("\n"); |
| 467 | _outFileA.Close(); |
| 468 | _outFileB.Close(); |
| 469 | _inFileA.Close(); |
| 470 | _inFileB.Close(); |
| 471 | } |
| 472 | |
| 473 | void |
| 474 | ISACTest::SwitchingSamplingRate( |
| 475 | int testNr, |
| 476 | int maxSampRateChange) |
| 477 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 478 | // Files in Side A |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 479 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 480 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
| 481 | |
| 482 | std::string file_name_out; |
| 483 | std::stringstream file_stream_a; |
| 484 | std::stringstream file_stream_b; |
| 485 | file_stream_a << webrtc::test::OutputPath(); |
| 486 | file_stream_b << webrtc::test::OutputPath(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 487 | if(_testMode == 0) |
| 488 | { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 489 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 490 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 491 | } |
| 492 | else |
| 493 | { |
| 494 | printf("\nTest %d", testNr); |
| 495 | printf(" Alternate between WB and SWB at the sender Side\n\n"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 496 | file_stream_a << "outA_" << testNr << ".pcm"; |
| 497 | file_stream_b << "outB_" << testNr << ".pcm"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 498 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 499 | file_name_out = file_stream_a.str(); |
| 500 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 501 | file_name_out = file_stream_b.str(); |
| 502 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 503 | |
| 504 | CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 505 | CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 506 | if(_testMode != 0) |
| 507 | { |
| 508 | printf("Side A Sending Super-Wideband \n"); |
| 509 | printf("Side B Sending Wideband\n"); |
| 510 | } |
| 511 | |
| 512 | int numSendCodecChanged = 0; |
| 513 | _myTimer.Reset(); |
| 514 | char currentTime[50]; |
| 515 | while(numSendCodecChanged < (maxSampRateChange<<1)) |
| 516 | { |
| 517 | Run10ms(); |
| 518 | _myTimer.Tick10ms(); |
| 519 | _myTimer.CurrentTimeHMS(currentTime); |
| 520 | if(_testMode == 2) printf("\r%s", currentTime); |
| 521 | if(_inFileA.EndOfFile()) |
| 522 | { |
| 523 | if(_inFileA.SamplingFrequency() == 16000) |
| 524 | { |
| 525 | if(_testMode != 0) printf("\nSide A switched to Send Super-Wideband\n"); |
| 526 | _inFileA.Close(); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 527 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 528 | CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 529 | } |
| 530 | else |
| 531 | { |
| 532 | if(_testMode != 0) printf("\nSide A switched to Send Wideband\n"); |
| 533 | _inFileA.Close(); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 534 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 535 | CHECK_ERROR(_acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 536 | } |
| 537 | numSendCodecChanged++; |
| 538 | } |
| 539 | |
| 540 | if(_inFileB.EndOfFile()) |
| 541 | { |
| 542 | if(_inFileB.SamplingFrequency() == 16000) |
| 543 | { |
| 544 | if(_testMode != 0) printf("\nSide B switched to Send Super-Wideband\n"); |
| 545 | _inFileB.Close(); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 546 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 547 | CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | if(_testMode != 0) printf("\nSide B switched to Send Wideband\n"); |
| 552 | _inFileB.Close(); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 553 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 554 | CHECK_ERROR(_acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 555 | } |
| 556 | numSendCodecChanged++; |
| 557 | } |
| 558 | } |
| 559 | _outFileA.Close(); |
| 560 | _outFileB.Close(); |
| 561 | _inFileA.Close(); |
| 562 | _inFileB.Close(); |
| 563 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 564 | |
| 565 | } // namespace webrtc |