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