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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/test/iSACTest.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 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 | |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 17 | #ifdef _WIN32 |
| 18 | #include <windows.h> |
| 19 | #elif defined(WEBRTC_LINUX) |
| 20 | #include <time.h> |
| 21 | #else |
| 22 | #include <sys/time.h> |
| 23 | #include <time.h> |
| 24 | #endif |
| 25 | |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 26 | #include "absl/strings/match.h" |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 27 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 28 | #include "api/audio_codecs/isac/audio_encoder_isac_float.h" |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 29 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 30 | #include "modules/audio_coding/test/utility.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 31 | #include "rtc_base/strings/string_builder.h" |
Danil Chapovalov | db12856 | 2018-09-17 13:11:50 +0200 | [diff] [blame] | 32 | #include "rtc_base/timeutils.h" |
Niels Möller | fe3240a | 2018-09-06 16:47:42 +0200 | [diff] [blame] | 33 | #include "system_wrappers/include/sleep.h" |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 34 | #include "test/gmock.h" |
| 35 | #include "test/gtest.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 38 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 40 | using ::testing::AnyOf; |
| 41 | using ::testing::Eq; |
| 42 | using ::testing::StrCaseEq; |
| 43 | |
| 44 | namespace { |
| 45 | |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 46 | AudioEncoderIsacFloat::Config MakeConfig(const CodecInst& ci) { |
| 47 | EXPECT_THAT(ci.plname, StrCaseEq("ISAC")); |
| 48 | EXPECT_THAT(ci.plfreq, AnyOf(Eq(16000), Eq(32000))); |
| 49 | EXPECT_THAT(ci.channels, Eq(1u)); |
| 50 | AudioEncoderIsacFloat::Config config; |
| 51 | config.sample_rate_hz = ci.plfreq; |
| 52 | EXPECT_THAT(config.IsOk(), Eq(true)); |
| 53 | return config; |
| 54 | } |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 55 | |
| 56 | AudioEncoderIsacFloat::Config TweakConfig( |
| 57 | AudioEncoderIsacFloat::Config config, |
| 58 | const ACMTestISACConfig& test_config) { |
| 59 | if (test_config.currentRateBitPerSec > 0) { |
| 60 | config.bit_rate = test_config.currentRateBitPerSec; |
| 61 | } |
| 62 | if (test_config.currentFrameSizeMsec != 0) { |
| 63 | config.frame_size_ms = test_config.currentFrameSizeMsec; |
| 64 | } |
| 65 | EXPECT_THAT(config.IsOk(), Eq(true)); |
| 66 | return config; |
| 67 | } |
| 68 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 69 | void SetISACConfigDefault(ACMTestISACConfig& isacConfig) { |
| 70 | isacConfig.currentRateBitPerSec = 0; |
| 71 | isacConfig.currentFrameSizeMsec = 0; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 72 | isacConfig.encodingMode = -1; |
| 73 | isacConfig.initRateBitPerSec = 0; |
| 74 | isacConfig.initFrameSizeInMsec = 0; |
| 75 | isacConfig.enforceFrameSize = false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Karl Wiberg | bf7a046 | 2018-09-25 14:48:33 +0200 | [diff] [blame] | 78 | } // namespace |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 80 | ISACTest::ISACTest(int testMode) |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 81 | : _acmA(AudioCodingModule::Create( |
| 82 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 83 | _acmB(AudioCodingModule::Create( |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 84 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), |
| 85 | _testMode(testMode) {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 87 | ISACTest::~ISACTest() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 89 | void ISACTest::Setup() { |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 90 | int codecCntr; |
| 91 | CodecInst codecParam; |
| 92 | |
| 93 | for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); |
| 94 | codecCntr++) { |
| 95 | EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam)); |
| 96 | if (absl::EqualsIgnoreCase(codecParam.plname, "ISAC") && |
| 97 | codecParam.plfreq == 16000) { |
| 98 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 99 | _idISAC16kHz = codecCntr; |
| 100 | } |
| 101 | if (absl::EqualsIgnoreCase(codecParam.plname, "ISAC") && |
| 102 | codecParam.plfreq == 32000) { |
| 103 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 104 | _idISAC32kHz = codecCntr; |
| 105 | } |
| 106 | } |
| 107 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 108 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 109 | EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype, |
| 110 | CodecInstToSdp(_paramISAC16kHz))); |
| 111 | EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype, |
| 112 | CodecInstToSdp(_paramISAC32kHz))); |
| 113 | EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC16kHz.pltype, |
| 114 | CodecInstToSdp(_paramISAC16kHz))); |
| 115 | EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC32kHz.pltype, |
| 116 | CodecInstToSdp(_paramISAC32kHz))); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 118 | //--- Set A-to-B channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 119 | _channel_A2B.reset(new Channel); |
| 120 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B.get())); |
| 121 | _channel_A2B->RegisterReceiverACM(_acmB.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 123 | //--- Set B-to-A channel |
turaj@webrtc.org | 55e1723 | 2013-10-29 04:40:09 +0000 | [diff] [blame] | 124 | _channel_B2A.reset(new Channel); |
| 125 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A.get())); |
| 126 | _channel_B2A->RegisterReceiverACM(_acmA.get()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 128 | file_name_swb_ = |
| 129 | webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 131 | _acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 132 | MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); |
| 133 | _acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 134 | MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 135 | |
| 136 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 137 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 138 | _inFileA.SetNum10MsBlocksToRead(50); |
| 139 | // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 140 | _inFileA.FastForward(100); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 141 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 142 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 143 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 144 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 145 | |
| 146 | while (!_inFileA.EndOfFile()) { |
| 147 | Run10ms(); |
| 148 | } |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 149 | CodecInst receiveCodec; |
| 150 | EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); |
| 151 | EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 152 | |
| 153 | _inFileA.Close(); |
| 154 | _outFileA.Close(); |
| 155 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | } |
| 157 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 158 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 159 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 161 | int16_t testNr = 0; |
| 162 | ACMTestISACConfig wbISACConfig; |
| 163 | ACMTestISACConfig swbISACConfig; |
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 | SetISACConfigDefault(wbISACConfig); |
| 166 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 168 | wbISACConfig.currentRateBitPerSec = -1; |
| 169 | swbISACConfig.currentRateBitPerSec = -1; |
| 170 | testNr++; |
| 171 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 172 | |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 173 | if (_testMode != 0) { |
| 174 | SetISACConfigDefault(wbISACConfig); |
| 175 | SetISACConfigDefault(swbISACConfig); |
| 176 | |
| 177 | wbISACConfig.currentRateBitPerSec = -1; |
| 178 | swbISACConfig.currentRateBitPerSec = -1; |
| 179 | wbISACConfig.initRateBitPerSec = 13000; |
| 180 | wbISACConfig.initFrameSizeInMsec = 60; |
| 181 | swbISACConfig.initRateBitPerSec = 20000; |
| 182 | swbISACConfig.initFrameSizeInMsec = 30; |
| 183 | testNr++; |
| 184 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 185 | |
| 186 | SetISACConfigDefault(wbISACConfig); |
| 187 | SetISACConfigDefault(swbISACConfig); |
| 188 | |
| 189 | wbISACConfig.currentRateBitPerSec = 20000; |
| 190 | swbISACConfig.currentRateBitPerSec = 48000; |
| 191 | testNr++; |
| 192 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 193 | |
| 194 | wbISACConfig.currentRateBitPerSec = 16000; |
| 195 | swbISACConfig.currentRateBitPerSec = 30000; |
| 196 | wbISACConfig.currentFrameSizeMsec = 60; |
| 197 | testNr++; |
| 198 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 199 | } |
| 200 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 201 | SetISACConfigDefault(wbISACConfig); |
| 202 | SetISACConfigDefault(swbISACConfig); |
| 203 | testNr++; |
| 204 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 206 | testNr++; |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 207 | if (_testMode == 0) { |
| 208 | SwitchingSamplingRate(testNr, 4); |
| 209 | } else { |
| 210 | SwitchingSamplingRate(testNr, 80); |
| 211 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | } |
| 213 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 214 | void ISACTest::Run10ms() { |
| 215 | AudioFrame audioFrame; |
| 216 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 217 | EXPECT_GE(_acmA->Add10MsData(audioFrame), 0); |
| 218 | EXPECT_GE(_acmB->Add10MsData(audioFrame), 0); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 219 | bool muted; |
| 220 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 221 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 222 | _outFileA.Write10MsData(audioFrame); |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 223 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame, &muted)); |
| 224 | ASSERT_FALSE(muted); |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 225 | _outFileB.Write10MsData(audioFrame); |
| 226 | } |
| 227 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 228 | void ISACTest::EncodeDecode(int testNr, |
| 229 | ACMTestISACConfig& wbISACConfig, |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 230 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 231 | // Files in Side A and B |
| 232 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 233 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 234 | |
| 235 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 236 | rtc::StringBuilder file_stream_a; |
| 237 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 238 | file_stream_a << webrtc::test::OutputPath(); |
| 239 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 240 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 241 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 242 | file_name_out = file_stream_a.str(); |
| 243 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 244 | file_name_out = file_stream_b.str(); |
| 245 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 246 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 247 | // Side A is sending super-wideband, and side B is sending wideband. |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 248 | _acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 249 | TweakConfig(MakeConfig(_paramISAC32kHz), swbISACConfig), |
| 250 | _paramISAC32kHz.pltype)); |
| 251 | _acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 252 | TweakConfig(MakeConfig(_paramISAC16kHz), wbISACConfig), |
| 253 | _paramISAC16kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 254 | |
| 255 | bool adaptiveMode = false; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 256 | if ((swbISACConfig.currentRateBitPerSec == -1) || |
| 257 | (wbISACConfig.currentRateBitPerSec == -1)) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 258 | adaptiveMode = true; |
| 259 | } |
| 260 | _myTimer.Reset(); |
| 261 | _channel_A2B->ResetStats(); |
| 262 | _channel_B2A->ResetStats(); |
| 263 | |
| 264 | char currentTime[500]; |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 265 | int64_t time_ms = rtc::TimeMillis(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 266 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 267 | Run10ms(); |
| 268 | _myTimer.Tick10ms(); |
| 269 | _myTimer.CurrentTimeHMS(currentTime); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 270 | |
| 271 | if ((adaptiveMode) && (_testMode != 0)) { |
| 272 | time_ms += 10; |
| 273 | int64_t time_left_ms = time_ms - rtc::TimeMillis(); |
| 274 | if (time_left_ms > 0) { |
| 275 | SleepMs(time_left_ms); |
| 276 | } |
| 277 | |
| 278 | EXPECT_TRUE(_acmA->SendCodec()); |
| 279 | EXPECT_TRUE(_acmB->SendCodec()); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (_testMode != 0) { |
| 284 | printf("\n\nSide A statistics\n\n"); |
| 285 | _channel_A2B->PrintStats(_paramISAC32kHz); |
| 286 | |
| 287 | printf("\n\nSide B statistics\n\n"); |
| 288 | _channel_B2A->PrintStats(_paramISAC16kHz); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 289 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 290 | |
andresp@webrtc.org | d0b436a | 2014-01-13 13:15:59 +0000 | [diff] [blame] | 291 | _channel_A2B->ResetStats(); |
| 292 | _channel_B2A->ResetStats(); |
| 293 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 294 | _outFileA.Close(); |
| 295 | _outFileB.Close(); |
| 296 | _inFileA.Close(); |
| 297 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | } |
| 299 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 300 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 301 | // Files in Side A |
| 302 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 303 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 304 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 305 | std::string file_name_out; |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 306 | rtc::StringBuilder file_stream_a; |
| 307 | rtc::StringBuilder file_stream_b; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 308 | file_stream_a << webrtc::test::OutputPath(); |
| 309 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 310 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 311 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 312 | file_name_out = file_stream_a.str(); |
| 313 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 314 | file_name_out = file_stream_b.str(); |
| 315 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 317 | // Start with side A sending super-wideband and side B seding wideband. |
| 318 | // Toggle sending wideband/super-wideband in this test. |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 319 | _acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 320 | MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); |
| 321 | _acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 322 | MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 323 | |
| 324 | int numSendCodecChanged = 0; |
| 325 | _myTimer.Reset(); |
| 326 | char currentTime[50]; |
| 327 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 328 | Run10ms(); |
| 329 | _myTimer.Tick10ms(); |
| 330 | _myTimer.CurrentTimeHMS(currentTime); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 331 | if (_testMode == 2) |
| 332 | printf("\r%s", currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 333 | if (_inFileA.EndOfFile()) { |
| 334 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 335 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 336 | _inFileA.Close(); |
| 337 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 338 | _acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 339 | MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 340 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 341 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 342 | _inFileA.Close(); |
| 343 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 344 | _acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 345 | MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 346 | } |
| 347 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | } |
| 349 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 350 | if (_inFileB.EndOfFile()) { |
| 351 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 352 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 353 | _inFileB.Close(); |
| 354 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 355 | _acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 356 | MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 357 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 358 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 359 | _inFileB.Close(); |
| 360 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
Fredrik Solenberg | ec0f45b | 2018-12-03 15:50:44 +0000 | [diff] [blame] | 361 | _acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( |
| 362 | MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 363 | } |
| 364 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 365 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 366 | } |
| 367 | _outFileA.Close(); |
| 368 | _outFileB.Close(); |
| 369 | _inFileA.Close(); |
| 370 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 372 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 373 | } // namespace webrtc |