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 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/iSACTest.h" |
| 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame^] | 13 | #include <ctype.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #if _WIN32 |
| 18 | #include <windows.h> |
| 19 | #elif WEBRTC_LINUX |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame^] | 20 | #include <time.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #else |
| 22 | #include <sys/time.h> |
| 23 | #include <time.h> |
| 24 | #endif |
| 25 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 26 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 33 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 35 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 47 | int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm, |
| 48 | int testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 63 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 79 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 84 | } |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 91 | } |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | isacConfig.enforceFrameSize)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 99 | if ((isacConfig.initFrameSizeInMsec != 0) && (testMode != 0)) { |
| 100 | printf("Initialize BWE to %d msec frame-size\n", |
| 101 | isacConfig.initFrameSizeInMsec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 103 | if ((isacConfig.initRateBitPerSec != 0) && (testMode != 0)) { |
| 104 | printf("Initialize BWE to %u bit/sec send-bandwidth\n", |
| 105 | isacConfig.initRateBitPerSec); |
| 106 | } |
| 107 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 109 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | } |
| 111 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 112 | ISACTest::ISACTest(int testMode) { |
| 113 | _testMode = testMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 116 | ISACTest::~ISACTest() { |
| 117 | AudioCodingModule::Destroy(_acmA); |
| 118 | AudioCodingModule::Destroy(_acmB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 120 | delete _channel_A2B; |
| 121 | delete _channel_B2A; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | } |
| 123 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 124 | int16_t ISACTest::Setup() { |
| 125 | int codecCntr; |
| 126 | CodecInst codecParam; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 128 | _acmA = AudioCodingModule::Create(1); |
| 129 | _acmB = AudioCodingModule::Create(2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 131 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 139 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 140 | && codecParam.plfreq == 32000) { |
| 141 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 142 | _idISAC32kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 144 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 146 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 151 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 152 | //--- Set A-to-B channel |
| 153 | _channel_A2B = new Channel; |
| 154 | CHECK_ERROR(_acmA->RegisterTransportCallback(_channel_A2B)); |
| 155 | _channel_A2B->RegisterReceiverACM(_acmB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 157 | //--- Set B-to-A channel |
| 158 | _channel_B2A = new Channel; |
| 159 | CHECK_ERROR(_acmB->RegisterTransportCallback(_channel_B2A)); |
| 160 | _channel_B2A->RegisterReceiverACM(_acmA); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 162 | file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz", |
| 163 | "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 165 | _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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | } |
| 204 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 205 | void ISACTest::Perform() { |
| 206 | if (_testMode == 0) { |
| 207 | printf("Running iSAC Test"); |
| 208 | WEBRTC_TRACE(webrtc::kTraceStateInfo, webrtc::kTraceAudioCoding, -1, |
| 209 | "---------- iSACTest ----------"); |
| 210 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 211 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 212 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 214 | int16_t testNr = 0; |
| 215 | ACMTestISACConfig wbISACConfig; |
| 216 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 218 | SetISACConfigDefault(wbISACConfig); |
| 219 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 221 | wbISACConfig.currentRateBitPerSec = -1; |
| 222 | swbISACConfig.currentRateBitPerSec = -1; |
| 223 | testNr++; |
| 224 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 225 | |
| 226 | if (_testMode != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | SetISACConfigDefault(wbISACConfig); |
| 228 | SetISACConfigDefault(swbISACConfig); |
| 229 | |
| 230 | wbISACConfig.currentRateBitPerSec = -1; |
| 231 | swbISACConfig.currentRateBitPerSec = -1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 232 | wbISACConfig.initRateBitPerSec = 13000; |
| 233 | wbISACConfig.initFrameSizeInMsec = 60; |
| 234 | swbISACConfig.initRateBitPerSec = 20000; |
| 235 | swbISACConfig.initFrameSizeInMsec = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | testNr++; |
| 237 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 238 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | SetISACConfigDefault(wbISACConfig); |
| 240 | SetISACConfigDefault(swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 241 | |
| 242 | wbISACConfig.currentRateBitPerSec = 20000; |
| 243 | swbISACConfig.currentRateBitPerSec = 48000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 244 | testNr++; |
| 245 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 246 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 247 | wbISACConfig.currentRateBitPerSec = 16000; |
| 248 | swbISACConfig.currentRateBitPerSec = 30000; |
| 249 | wbISACConfig.currentFrameSizeMsec = 60; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | testNr++; |
| 251 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 252 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 253 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 254 | SetISACConfigDefault(wbISACConfig); |
| 255 | SetISACConfigDefault(swbISACConfig); |
| 256 | testNr++; |
| 257 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 259 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 274 | _acmA->ResetEncoder(); |
| 275 | _acmB->ResetEncoder(); |
| 276 | SetISACConfigDefault(wbISACConfig); |
| 277 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 279 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | } |
| 302 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 303 | void ISACTest::Run10ms() { |
| 304 | AudioFrame audioFrame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 306 | _inFileA.Read10MsData(audioFrame); |
| 307 | CHECK_ERROR(_acmA->Add10MsData(audioFrame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 309 | CHECK_ERROR(_acmB->Add10MsData(audioFrame)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 311 | CHECK_ERROR(_acmA->Process()); |
| 312 | CHECK_ERROR(_acmB->Process()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 313 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 314 | CHECK_ERROR(_acmA->PlayoutData10Ms(32000, &audioFrame)); |
| 315 | _outFileA.Write10MsData(audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 317 | CHECK_ERROR(_acmB->PlayoutData10Ms(32000, &audioFrame)); |
| 318 | _outFileB.Write10MsData(audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 319 | } |
| 320 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 321 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 396 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 397 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 398 | if (_testMode != 0) { |
| 399 | printf("\n\nSide A statistics\n\n"); |
| 400 | _channel_A2B->PrintStats(_paramISAC32kHz); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 401 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 402 | printf("\n\nSide B statistics\n\n"); |
| 403 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 404 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 405 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 406 | _channel_A2B->ResetStats(); |
| 407 | _channel_B2A->ResetStats(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 408 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 409 | if (_testMode != 0) |
| 410 | printf("\n"); |
| 411 | _outFileA.Close(); |
| 412 | _outFileB.Close(); |
| 413 | _inFileA.Close(); |
| 414 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 415 | } |
| 416 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 417 | void 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.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 421 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 422 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 440 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 441 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 472 | } |
| 473 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 474 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 489 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 490 | } |
| 491 | _outFileA.Close(); |
| 492 | _outFileB.Close(); |
| 493 | _inFileA.Close(); |
| 494 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 495 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 496 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 497 | } // namespace webrtc |