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