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