alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/gain_controller2.h" |
| 12 | |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 13 | #include <algorithm> |
Alessio Bazzica | 980c460 | 2021-04-14 19:09:17 +0200 | [diff] [blame] | 14 | #include <cmath> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 15 | #include <memory> |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 16 | #include <numeric> |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 17 | #include <tuple> |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/array_view.h" |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 20 | #include "modules/audio_processing/agc2/agc2_testing_common.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/audio_buffer.h" |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 22 | #include "modules/audio_processing/test/audio_buffer_tools.h" |
| 23 | #include "modules/audio_processing/test/bitexactness_tools.h" |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 24 | #include "rtc_base/checks.h" |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 25 | #include "test/gmock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "test/gtest.h" |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | namespace test { |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 32 | using ::testing::Eq; |
| 33 | using ::testing::Optional; |
| 34 | |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 35 | using Agc2Config = AudioProcessing::Config::GainController2; |
| 36 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 37 | // Sets all the samples in `ab` to `value`. |
| 38 | void SetAudioBufferSamples(float value, AudioBuffer& ab) { |
| 39 | for (size_t k = 0; k < ab.num_channels(); ++k) { |
| 40 | std::fill(ab.channels()[k], ab.channels()[k] + ab.num_frames(), value); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 44 | float RunAgc2WithConstantInput(GainController2& agc2, |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 45 | float input_level, |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 46 | int num_frames, |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 47 | int sample_rate_hz, |
| 48 | int num_channels = 1, |
| 49 | int applied_initial_volume = 0) { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 50 | const int num_samples = rtc::CheckedDivExact(sample_rate_hz, 100); |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 51 | AudioBuffer ab(sample_rate_hz, num_channels, sample_rate_hz, num_channels, |
| 52 | sample_rate_hz, num_channels); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 53 | |
| 54 | // Give time to the level estimator to converge. |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 55 | for (int i = 0; i < num_frames + 1; ++i) { |
| 56 | SetAudioBufferSamples(input_level, ab); |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 57 | const auto applied_volume = agc2.GetRecommendedInputVolume(); |
| 58 | agc2.Analyze(i > 0 && applied_volume.has_value() ? *applied_volume |
| 59 | : applied_initial_volume, |
| 60 | ab); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 61 | agc2.Process(/*speech_probability=*/absl::nullopt, |
| 62 | /*input_volume_changed=*/false, &ab); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Return the last sample from the last processed frame. |
Per Ã…hgren | d47941e | 2019-08-22 11:51:13 +0200 | [diff] [blame] | 66 | return ab.channels()[0][num_samples - 1]; |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 69 | std::unique_ptr<GainController2> CreateAgc2FixedDigitalMode( |
| 70 | float fixed_gain_db, |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 71 | int sample_rate_hz) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 72 | Agc2Config config; |
| 73 | config.adaptive_digital.enabled = false; |
| 74 | config.fixed_digital.gain_db = fixed_gain_db; |
| 75 | EXPECT_TRUE(GainController2::Validate(config)); |
| 76 | return std::make_unique<GainController2>(config, sample_rate_hz, |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 77 | /*num_channels=*/1, |
| 78 | /*use_internal_vad=*/true); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 79 | } |
| 80 | |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 81 | } // namespace |
| 82 | |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 83 | TEST(GainController2, CheckDefaultConfig) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 84 | Agc2Config config; |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 85 | EXPECT_TRUE(GainController2::Validate(config)); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 88 | TEST(GainController2, CheckFixedDigitalConfig) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 89 | Agc2Config config; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 90 | // Attenuation is not allowed. |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 91 | config.fixed_digital.gain_db = -5.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 92 | EXPECT_FALSE(GainController2::Validate(config)); |
| 93 | // No gain is allowed. |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 94 | config.fixed_digital.gain_db = 0.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 95 | EXPECT_TRUE(GainController2::Validate(config)); |
| 96 | // Positive gain is allowed. |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 97 | config.fixed_digital.gain_db = 15.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 98 | EXPECT_TRUE(GainController2::Validate(config)); |
| 99 | } |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 100 | |
Alessio Bazzica | a850e6c | 2021-10-04 13:35:55 +0200 | [diff] [blame] | 101 | TEST(GainController2, CheckHeadroomDb) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 102 | Agc2Config config; |
Alessio Bazzica | a850e6c | 2021-10-04 13:35:55 +0200 | [diff] [blame] | 103 | config.adaptive_digital.headroom_db = -1.0f; |
| 104 | EXPECT_FALSE(GainController2::Validate(config)); |
| 105 | config.adaptive_digital.headroom_db = 0.0f; |
| 106 | EXPECT_TRUE(GainController2::Validate(config)); |
| 107 | config.adaptive_digital.headroom_db = 5.0f; |
| 108 | EXPECT_TRUE(GainController2::Validate(config)); |
| 109 | } |
| 110 | |
| 111 | TEST(GainController2, CheckMaxGainDb) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 112 | Agc2Config config; |
Alessio Bazzica | a850e6c | 2021-10-04 13:35:55 +0200 | [diff] [blame] | 113 | config.adaptive_digital.max_gain_db = -1.0f; |
| 114 | EXPECT_FALSE(GainController2::Validate(config)); |
| 115 | config.adaptive_digital.max_gain_db = 0.0f; |
| 116 | EXPECT_FALSE(GainController2::Validate(config)); |
| 117 | config.adaptive_digital.max_gain_db = 5.0f; |
| 118 | EXPECT_TRUE(GainController2::Validate(config)); |
| 119 | } |
| 120 | |
| 121 | TEST(GainController2, CheckInitialGainDb) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 122 | Agc2Config config; |
Alessio Bazzica | a850e6c | 2021-10-04 13:35:55 +0200 | [diff] [blame] | 123 | config.adaptive_digital.initial_gain_db = -1.0f; |
| 124 | EXPECT_FALSE(GainController2::Validate(config)); |
| 125 | config.adaptive_digital.initial_gain_db = 0.0f; |
| 126 | EXPECT_TRUE(GainController2::Validate(config)); |
| 127 | config.adaptive_digital.initial_gain_db = 5.0f; |
| 128 | EXPECT_TRUE(GainController2::Validate(config)); |
| 129 | } |
| 130 | |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 131 | TEST(GainController2, CheckAdaptiveDigitalMaxGainChangeSpeedConfig) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 132 | Agc2Config config; |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 133 | config.adaptive_digital.max_gain_change_db_per_second = -1.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 134 | EXPECT_FALSE(GainController2::Validate(config)); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 135 | config.adaptive_digital.max_gain_change_db_per_second = 0.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 136 | EXPECT_FALSE(GainController2::Validate(config)); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 137 | config.adaptive_digital.max_gain_change_db_per_second = 5.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 138 | EXPECT_TRUE(GainController2::Validate(config)); |
| 139 | } |
| 140 | |
| 141 | TEST(GainController2, CheckAdaptiveDigitalMaxOutputNoiseLevelConfig) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 142 | Agc2Config config; |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 143 | config.adaptive_digital.max_output_noise_level_dbfs = 5.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 144 | EXPECT_FALSE(GainController2::Validate(config)); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 145 | config.adaptive_digital.max_output_noise_level_dbfs = 0.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 146 | EXPECT_TRUE(GainController2::Validate(config)); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 147 | config.adaptive_digital.max_output_noise_level_dbfs = -5.0f; |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 148 | EXPECT_TRUE(GainController2::Validate(config)); |
| 149 | } |
| 150 | |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 151 | TEST(GainController2, |
| 152 | CheckGetRecommendedInputVolumeWhenInputVolumeControllerNotEnabled) { |
| 153 | constexpr float kHighInputLevel = 32767.0f; |
| 154 | constexpr float kLowInputLevel = 1000.0f; |
| 155 | constexpr int kInitialInputVolume = 100; |
| 156 | constexpr int kNumChannels = 2; |
| 157 | constexpr int kNumFrames = 5; |
| 158 | constexpr int kSampleRateHz = 16000; |
| 159 | |
| 160 | Agc2Config config; |
| 161 | config.input_volume_controller.enabled = false; |
Hanna Silen | 27fed45 | 2022-11-22 15:00:58 +0100 | [diff] [blame^] | 162 | |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 163 | auto gain_controller = |
| 164 | std::make_unique<GainController2>(config, kSampleRateHz, kNumChannels, |
| 165 | /*use_internal_vad=*/true); |
| 166 | |
| 167 | EXPECT_FALSE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 168 | |
| 169 | // Run AGC for a signal with no clipping or detected speech. |
| 170 | RunAgc2WithConstantInput(*gain_controller, kLowInputLevel, kNumFrames, |
| 171 | kSampleRateHz, kNumChannels, kInitialInputVolume); |
| 172 | |
| 173 | EXPECT_FALSE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 174 | |
| 175 | // Run AGC for a signal with clipping. |
| 176 | RunAgc2WithConstantInput(*gain_controller, kHighInputLevel, kNumFrames, |
| 177 | kSampleRateHz, kNumChannels, kInitialInputVolume); |
| 178 | |
| 179 | EXPECT_FALSE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 180 | } |
| 181 | |
| 182 | TEST(GainController2, |
| 183 | CheckGetRecommendedInputVolumeWhenInputVolumeControllerEnabled) { |
| 184 | constexpr float kHighInputLevel = 32767.0f; |
| 185 | constexpr float kLowInputLevel = 1000.0f; |
| 186 | constexpr int kInitialInputVolume = 100; |
| 187 | constexpr int kNumChannels = 2; |
| 188 | constexpr int kNumFrames = 5; |
| 189 | constexpr int kSampleRateHz = 16000; |
| 190 | |
| 191 | Agc2Config config; |
| 192 | config.input_volume_controller.enabled = true; |
Hanna Silen | 27fed45 | 2022-11-22 15:00:58 +0100 | [diff] [blame^] | 193 | config.adaptive_digital.enabled = true; |
| 194 | |
Hanna Silen | d7cfbe3 | 2022-11-02 19:12:20 +0100 | [diff] [blame] | 195 | auto gain_controller = |
| 196 | std::make_unique<GainController2>(config, kSampleRateHz, kNumChannels, |
| 197 | /*use_internal_vad=*/true); |
| 198 | |
| 199 | EXPECT_TRUE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 200 | |
| 201 | // Run AGC for a signal with no clipping or detected speech. |
| 202 | RunAgc2WithConstantInput(*gain_controller, kLowInputLevel, kNumFrames, |
| 203 | kSampleRateHz, kNumChannels, kInitialInputVolume); |
| 204 | |
| 205 | EXPECT_TRUE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 206 | |
| 207 | // Run AGC for a signal with clipping. |
| 208 | RunAgc2WithConstantInput(*gain_controller, kHighInputLevel, kNumFrames, |
| 209 | kSampleRateHz, kNumChannels, kInitialInputVolume); |
| 210 | |
| 211 | EXPECT_TRUE(gain_controller->GetRecommendedInputVolume().has_value()); |
| 212 | } |
| 213 | |
Alessio Bazzica | 0c83e15 | 2020-10-14 12:49:54 +0200 | [diff] [blame] | 214 | // Checks that the default config is applied. |
| 215 | TEST(GainController2, ApplyDefaultConfig) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 216 | auto gain_controller2 = std::make_unique<GainController2>( |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 217 | Agc2Config{}, /*sample_rate_hz=*/16000, /*num_channels=*/2, |
| 218 | /*use_internal_vad=*/true); |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 219 | EXPECT_TRUE(gain_controller2.get()); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 222 | TEST(GainController2FixedDigital, GainShouldChangeOnSetGain) { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 223 | constexpr float kInputLevel = 1000.0f; |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 224 | constexpr size_t kNumFrames = 5; |
| 225 | constexpr size_t kSampleRateHz = 8000; |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 226 | constexpr float kGain0Db = 0.0f; |
| 227 | constexpr float kGain20Db = 20.0f; |
Alessio Bazzica | 270f7b5 | 2017-10-13 11:05:17 +0200 | [diff] [blame] | 228 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 229 | auto agc2_fixed = CreateAgc2FixedDigitalMode(kGain0Db, kSampleRateHz); |
| 230 | |
| 231 | // Signal level is unchanged with 0 db gain. |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 232 | EXPECT_FLOAT_EQ(RunAgc2WithConstantInput(*agc2_fixed, kInputLevel, kNumFrames, |
| 233 | kSampleRateHz), |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 234 | kInputLevel); |
| 235 | |
| 236 | // +20 db should increase signal by a factor of 10. |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 237 | agc2_fixed->SetFixedGainDb(kGain20Db); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 238 | EXPECT_FLOAT_EQ(RunAgc2WithConstantInput(*agc2_fixed, kInputLevel, kNumFrames, |
| 239 | kSampleRateHz), |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 240 | kInputLevel * 10); |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 243 | TEST(GainController2FixedDigital, ChangeFixedGainShouldBeFastAndTimeInvariant) { |
| 244 | // Number of frames required for the fixed gain controller to adapt on the |
| 245 | // input signal when the gain changes. |
| 246 | constexpr size_t kNumFrames = 5; |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 247 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 248 | constexpr float kInputLevel = 1000.0f; |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 249 | constexpr size_t kSampleRateHz = 8000; |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 250 | constexpr float kGainDbLow = 0.0f; |
| 251 | constexpr float kGainDbHigh = 25.0f; |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 252 | static_assert(kGainDbLow < kGainDbHigh, ""); |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 253 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 254 | auto agc2_fixed = CreateAgc2FixedDigitalMode(kGainDbLow, kSampleRateHz); |
| 255 | |
| 256 | // Start with a lower gain. |
| 257 | const float output_level_pre = RunAgc2WithConstantInput( |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 258 | *agc2_fixed, kInputLevel, kNumFrames, kSampleRateHz); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 259 | |
| 260 | // Increase gain. |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 261 | agc2_fixed->SetFixedGainDb(kGainDbHigh); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 262 | static_cast<void>(RunAgc2WithConstantInput(*agc2_fixed, kInputLevel, |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 263 | kNumFrames, kSampleRateHz)); |
| 264 | |
| 265 | // Back to the lower gain. |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 266 | agc2_fixed->SetFixedGainDb(kGainDbLow); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 267 | const float output_level_post = RunAgc2WithConstantInput( |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 268 | *agc2_fixed, kInputLevel, kNumFrames, kSampleRateHz); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 269 | |
| 270 | EXPECT_EQ(output_level_pre, output_level_post); |
| 271 | } |
| 272 | |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 273 | class FixedDigitalTest |
| 274 | : public ::testing::TestWithParam<std::tuple<float, float, int, bool>> { |
| 275 | protected: |
| 276 | float gain_db_min() const { return std::get<0>(GetParam()); } |
| 277 | float gain_db_max() const { return std::get<1>(GetParam()); } |
| 278 | int sample_rate_hz() const { return std::get<2>(GetParam()); } |
| 279 | bool saturation_expected() const { return std::get<3>(GetParam()); } |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 280 | }; |
| 281 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 282 | TEST_P(FixedDigitalTest, CheckSaturationBehaviorWithLimiter) { |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 283 | for (const float gain_db : test::LinSpace(gain_db_min(), gain_db_max(), 10)) { |
| 284 | SCOPED_TRACE(gain_db); |
| 285 | auto agc2_fixed = CreateAgc2FixedDigitalMode(gain_db, sample_rate_hz()); |
| 286 | const float processed_sample = |
| 287 | RunAgc2WithConstantInput(*agc2_fixed, /*input_level=*/32767.0f, |
| 288 | /*num_frames=*/5, sample_rate_hz()); |
| 289 | if (saturation_expected()) { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 290 | EXPECT_FLOAT_EQ(processed_sample, 32767.0f); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 291 | } else { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 292 | EXPECT_LT(processed_sample, 32767.0f); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 293 | } |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 294 | } |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 297 | static_assert(test::kLimiterMaxInputLevelDbFs < 10, ""); |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 298 | INSTANTIATE_TEST_SUITE_P( |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 299 | GainController2, |
| 300 | FixedDigitalTest, |
| 301 | ::testing::Values( |
Artem Titov | cfea218 | 2021-08-10 01:22:31 +0200 | [diff] [blame] | 302 | // When gain < `test::kLimiterMaxInputLevelDbFs`, the limiter will not |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 303 | // saturate the signal (at any sample rate). |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 304 | std::make_tuple(0.1f, |
| 305 | test::kLimiterMaxInputLevelDbFs - 0.01f, |
| 306 | 8000, |
| 307 | false), |
| 308 | std::make_tuple(0.1, |
| 309 | test::kLimiterMaxInputLevelDbFs - 0.01f, |
| 310 | 48000, |
| 311 | false), |
Artem Titov | cfea218 | 2021-08-10 01:22:31 +0200 | [diff] [blame] | 312 | // When gain > `test::kLimiterMaxInputLevelDbFs`, the limiter will |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 313 | // saturate the signal (at any sample rate). |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 314 | std::make_tuple(test::kLimiterMaxInputLevelDbFs + 0.01f, |
| 315 | 10.0f, |
| 316 | 8000, |
| 317 | true), |
| 318 | std::make_tuple(test::kLimiterMaxInputLevelDbFs + 0.01f, |
| 319 | 10.0f, |
| 320 | 48000, |
| 321 | true))); |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 322 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 323 | // Processes a test audio file and checks that the gain applied at the end of |
| 324 | // the recording is close to the expected value. |
| 325 | TEST(GainController2, CheckFinalGainWithAdaptiveDigitalController) { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 326 | constexpr int kSampleRateHz = AudioProcessing::kSampleRate48kHz; |
| 327 | constexpr int kStereo = 2; |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 328 | |
| 329 | // Create AGC2 enabling only the adaptive digital controller. |
| 330 | Agc2Config config; |
| 331 | config.fixed_digital.gain_db = 0.0f; |
| 332 | config.adaptive_digital.enabled = true; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 333 | GainController2 agc2(config, kSampleRateHz, kStereo, |
| 334 | /*use_internal_vad=*/true); |
Alessio Bazzica | 3890104 | 2021-10-14 12:14:21 +0200 | [diff] [blame] | 335 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 336 | test::InputAudioFile input_file( |
| 337 | test::GetApmCaptureTestVectorFileName(kSampleRateHz), |
| 338 | /*loop_at_end=*/true); |
Henrik Lundin | 64253a9 | 2022-02-04 09:02:48 +0000 | [diff] [blame] | 339 | const StreamConfig stream_config(kSampleRateHz, kStereo); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 340 | |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 341 | // Init buffers. |
| 342 | constexpr int kFrameDurationMs = 10; |
| 343 | std::vector<float> frame(kStereo * stream_config.num_frames()); |
| 344 | AudioBuffer audio_buffer(kSampleRateHz, kStereo, kSampleRateHz, kStereo, |
| 345 | kSampleRateHz, kStereo); |
| 346 | |
| 347 | // Simulate. |
| 348 | constexpr float kGainDb = -6.0f; |
| 349 | const float gain = std::pow(10.0f, kGainDb / 20.0f); |
| 350 | constexpr int kDurationMs = 10000; |
| 351 | constexpr int kNumFramesToProcess = kDurationMs / kFrameDurationMs; |
| 352 | for (int i = 0; i < kNumFramesToProcess; ++i) { |
| 353 | ReadFloatSamplesFromStereoFile(stream_config.num_frames(), |
| 354 | stream_config.num_channels(), &input_file, |
| 355 | frame); |
| 356 | // Apply a fixed gain to the input audio. |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 357 | for (float& x : frame) { |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 358 | x *= gain; |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 359 | } |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 360 | test::CopyVectorToAudioBuffer(stream_config, frame, &audio_buffer); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 361 | agc2.Process(/*speech_probability=*/absl::nullopt, |
| 362 | /*input_volume_changed=*/false, &audio_buffer); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | // Estimate the applied gain by processing a probing frame. |
| 366 | SetAudioBufferSamples(/*value=*/1.0f, audio_buffer); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 367 | agc2.Process(/*speech_probability=*/absl::nullopt, |
| 368 | /*input_volume_changed=*/false, &audio_buffer); |
Alessio Bazzica | 6ee9734 | 2021-09-27 17:06:40 +0200 | [diff] [blame] | 369 | const float applied_gain_db = |
| 370 | 20.0f * std::log10(audio_buffer.channels_const()[0][0]); |
| 371 | |
| 372 | constexpr float kExpectedGainDb = 5.6f; |
| 373 | constexpr float kToleranceDb = 0.3f; |
| 374 | EXPECT_NEAR(applied_gain_db, kExpectedGainDb, kToleranceDb); |
Alex Loiko | 5e78461 | 2018-11-01 14:51:56 +0100 | [diff] [blame] | 375 | } |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 376 | |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 377 | // Processes a test audio file and checks that the injected speech probability |
| 378 | // is ignored when the internal VAD is used. |
| 379 | TEST(GainController2, |
| 380 | CheckInjectedVadProbabilityNotUsedWithAdaptiveDigitalController) { |
| 381 | constexpr int kSampleRateHz = AudioProcessing::kSampleRate48kHz; |
| 382 | constexpr int kStereo = 2; |
| 383 | |
| 384 | // Create AGC2 enabling only the adaptive digital controller. |
| 385 | Agc2Config config; |
| 386 | config.fixed_digital.gain_db = 0.0f; |
| 387 | config.adaptive_digital.enabled = true; |
| 388 | GainController2 agc2(config, kSampleRateHz, kStereo, |
| 389 | /*use_internal_vad=*/true); |
| 390 | GainController2 agc2_reference(config, kSampleRateHz, kStereo, |
| 391 | /*use_internal_vad=*/true); |
| 392 | |
| 393 | test::InputAudioFile input_file( |
| 394 | test::GetApmCaptureTestVectorFileName(kSampleRateHz), |
| 395 | /*loop_at_end=*/true); |
| 396 | const StreamConfig stream_config(kSampleRateHz, kStereo); |
| 397 | |
| 398 | // Init buffers. |
| 399 | constexpr int kFrameDurationMs = 10; |
| 400 | std::vector<float> frame(kStereo * stream_config.num_frames()); |
| 401 | AudioBuffer audio_buffer(kSampleRateHz, kStereo, kSampleRateHz, kStereo, |
| 402 | kSampleRateHz, kStereo); |
| 403 | AudioBuffer audio_buffer_reference(kSampleRateHz, kStereo, kSampleRateHz, |
| 404 | kStereo, kSampleRateHz, kStereo); |
| 405 | |
| 406 | // Simulate. |
| 407 | constexpr float kGainDb = -6.0f; |
| 408 | const float gain = std::pow(10.0f, kGainDb / 20.0f); |
| 409 | constexpr int kDurationMs = 10000; |
| 410 | constexpr int kNumFramesToProcess = kDurationMs / kFrameDurationMs; |
| 411 | constexpr float kSpeechProbabilities[] = {1.0f, 0.3f}; |
| 412 | constexpr float kEpsilon = 0.0001f; |
| 413 | bool all_samples_zero = true; |
| 414 | for (int i = 0, j = 0; i < kNumFramesToProcess; ++i, j = 1 - j) { |
| 415 | ReadFloatSamplesFromStereoFile(stream_config.num_frames(), |
| 416 | stream_config.num_channels(), &input_file, |
| 417 | frame); |
| 418 | // Apply a fixed gain to the input audio. |
| 419 | for (float& x : frame) { |
| 420 | x *= gain; |
| 421 | } |
| 422 | test::CopyVectorToAudioBuffer(stream_config, frame, &audio_buffer); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 423 | agc2.Process(kSpeechProbabilities[j], /*input_volume_changed=*/false, |
| 424 | &audio_buffer); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 425 | test::CopyVectorToAudioBuffer(stream_config, frame, |
| 426 | &audio_buffer_reference); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 427 | agc2_reference.Process(/*speech_probability=*/absl::nullopt, |
| 428 | /*input_volume_changed=*/false, |
| 429 | &audio_buffer_reference); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 430 | |
| 431 | // Check the output buffers. |
| 432 | for (int i = 0; i < kStereo; ++i) { |
| 433 | for (int j = 0; j < static_cast<int>(audio_buffer.num_frames()); ++j) { |
| 434 | all_samples_zero &= |
| 435 | fabs(audio_buffer.channels_const()[i][j]) < kEpsilon; |
| 436 | EXPECT_FLOAT_EQ(audio_buffer.channels_const()[i][j], |
| 437 | audio_buffer_reference.channels_const()[i][j]); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | EXPECT_FALSE(all_samples_zero); |
| 442 | } |
| 443 | |
| 444 | // Processes a test audio file and checks that the injected speech probability |
| 445 | // is not ignored when the internal VAD is not used. |
| 446 | TEST(GainController2, |
| 447 | CheckInjectedVadProbabilityUsedWithAdaptiveDigitalController) { |
| 448 | constexpr int kSampleRateHz = AudioProcessing::kSampleRate48kHz; |
| 449 | constexpr int kStereo = 2; |
| 450 | |
| 451 | // Create AGC2 enabling only the adaptive digital controller. |
| 452 | Agc2Config config; |
| 453 | config.fixed_digital.gain_db = 0.0f; |
| 454 | config.adaptive_digital.enabled = true; |
| 455 | GainController2 agc2(config, kSampleRateHz, kStereo, |
| 456 | /*use_internal_vad=*/false); |
| 457 | GainController2 agc2_reference(config, kSampleRateHz, kStereo, |
| 458 | /*use_internal_vad=*/true); |
| 459 | |
| 460 | test::InputAudioFile input_file( |
| 461 | test::GetApmCaptureTestVectorFileName(kSampleRateHz), |
| 462 | /*loop_at_end=*/true); |
| 463 | const StreamConfig stream_config(kSampleRateHz, kStereo); |
| 464 | |
| 465 | // Init buffers. |
| 466 | constexpr int kFrameDurationMs = 10; |
| 467 | std::vector<float> frame(kStereo * stream_config.num_frames()); |
| 468 | AudioBuffer audio_buffer(kSampleRateHz, kStereo, kSampleRateHz, kStereo, |
| 469 | kSampleRateHz, kStereo); |
| 470 | AudioBuffer audio_buffer_reference(kSampleRateHz, kStereo, kSampleRateHz, |
| 471 | kStereo, kSampleRateHz, kStereo); |
| 472 | // Simulate. |
| 473 | constexpr float kGainDb = -6.0f; |
| 474 | const float gain = std::pow(10.0f, kGainDb / 20.0f); |
| 475 | constexpr int kDurationMs = 10000; |
| 476 | constexpr int kNumFramesToProcess = kDurationMs / kFrameDurationMs; |
| 477 | constexpr float kSpeechProbabilities[] = {1.0f, 0.3f}; |
| 478 | constexpr float kEpsilon = 0.0001f; |
| 479 | bool all_samples_zero = true; |
| 480 | bool all_samples_equal = true; |
| 481 | for (int i = 0, j = 0; i < kNumFramesToProcess; ++i, j = 1 - j) { |
| 482 | ReadFloatSamplesFromStereoFile(stream_config.num_frames(), |
| 483 | stream_config.num_channels(), &input_file, |
| 484 | frame); |
| 485 | // Apply a fixed gain to the input audio. |
| 486 | for (float& x : frame) { |
| 487 | x *= gain; |
| 488 | } |
| 489 | test::CopyVectorToAudioBuffer(stream_config, frame, &audio_buffer); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 490 | agc2.Process(kSpeechProbabilities[j], /*input_volume_changed=*/false, |
| 491 | &audio_buffer); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 492 | test::CopyVectorToAudioBuffer(stream_config, frame, |
| 493 | &audio_buffer_reference); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 494 | agc2_reference.Process(/*speech_probability=*/absl::nullopt, |
| 495 | /*input_volume_changed=*/false, |
| 496 | &audio_buffer_reference); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 497 | // Check the output buffers. |
| 498 | for (int i = 0; i < kStereo; ++i) { |
| 499 | for (int j = 0; j < static_cast<int>(audio_buffer.num_frames()); ++j) { |
| 500 | all_samples_zero &= |
| 501 | fabs(audio_buffer.channels_const()[i][j]) < kEpsilon; |
| 502 | all_samples_equal &= |
| 503 | fabs(audio_buffer.channels_const()[i][j] - |
| 504 | audio_buffer_reference.channels_const()[i][j]) < kEpsilon; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | EXPECT_FALSE(all_samples_zero); |
| 509 | EXPECT_FALSE(all_samples_equal); |
| 510 | } |
| 511 | |
| 512 | // Processes a test audio file and checks that the output is equal when |
| 513 | // an injected speech probability from `VoiceActivityDetectorWrapper` and |
| 514 | // the speech probability computed by the internal VAD are the same. |
| 515 | TEST(GainController2, |
| 516 | CheckEqualResultFromInjectedVadProbabilityWithAdaptiveDigitalController) { |
| 517 | constexpr int kSampleRateHz = AudioProcessing::kSampleRate48kHz; |
| 518 | constexpr int kStereo = 2; |
| 519 | |
| 520 | // Create AGC2 enabling only the adaptive digital controller. |
| 521 | Agc2Config config; |
| 522 | config.fixed_digital.gain_db = 0.0f; |
| 523 | config.adaptive_digital.enabled = true; |
| 524 | GainController2 agc2(config, kSampleRateHz, kStereo, |
| 525 | /*use_internal_vad=*/false); |
| 526 | GainController2 agc2_reference(config, kSampleRateHz, kStereo, |
| 527 | /*use_internal_vad=*/true); |
| 528 | VoiceActivityDetectorWrapper vad(config.adaptive_digital.vad_reset_period_ms, |
| 529 | GetAvailableCpuFeatures(), kSampleRateHz); |
| 530 | test::InputAudioFile input_file( |
| 531 | test::GetApmCaptureTestVectorFileName(kSampleRateHz), |
| 532 | /*loop_at_end=*/true); |
| 533 | const StreamConfig stream_config(kSampleRateHz, kStereo); |
| 534 | |
| 535 | // Init buffers. |
| 536 | constexpr int kFrameDurationMs = 10; |
| 537 | std::vector<float> frame(kStereo * stream_config.num_frames()); |
| 538 | AudioBuffer audio_buffer(kSampleRateHz, kStereo, kSampleRateHz, kStereo, |
| 539 | kSampleRateHz, kStereo); |
| 540 | AudioBuffer audio_buffer_reference(kSampleRateHz, kStereo, kSampleRateHz, |
| 541 | kStereo, kSampleRateHz, kStereo); |
| 542 | |
| 543 | // Simulate. |
| 544 | constexpr float kGainDb = -6.0f; |
| 545 | const float gain = std::pow(10.0f, kGainDb / 20.0f); |
| 546 | constexpr int kDurationMs = 10000; |
| 547 | constexpr int kNumFramesToProcess = kDurationMs / kFrameDurationMs; |
| 548 | for (int i = 0; i < kNumFramesToProcess; ++i) { |
| 549 | ReadFloatSamplesFromStereoFile(stream_config.num_frames(), |
| 550 | stream_config.num_channels(), &input_file, |
| 551 | frame); |
| 552 | // Apply a fixed gain to the input audio. |
| 553 | for (float& x : frame) { |
| 554 | x *= gain; |
| 555 | } |
| 556 | test::CopyVectorToAudioBuffer(stream_config, frame, |
| 557 | &audio_buffer_reference); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 558 | agc2_reference.Process(absl::nullopt, /*input_volume_changed=*/false, |
| 559 | &audio_buffer_reference); |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 560 | test::CopyVectorToAudioBuffer(stream_config, frame, &audio_buffer); |
Alessio Bazzica | fcf1af3 | 2022-09-07 17:14:26 +0200 | [diff] [blame] | 561 | float speech_probability = vad.Analyze(AudioFrameView<const float>( |
| 562 | audio_buffer.channels(), audio_buffer.num_channels(), |
| 563 | audio_buffer.num_frames())); |
| 564 | agc2.Process(speech_probability, /*input_volume_changed=*/false, |
Hanna Silen | 0c1ad29 | 2022-06-16 16:35:45 +0200 | [diff] [blame] | 565 | &audio_buffer); |
| 566 | // Check the output buffer. |
| 567 | for (int i = 0; i < kStereo; ++i) { |
| 568 | for (int j = 0; j < static_cast<int>(audio_buffer.num_frames()); ++j) { |
| 569 | EXPECT_FLOAT_EQ(audio_buffer.channels_const()[i][j], |
| 570 | audio_buffer_reference.channels_const()[i][j]); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
alessiob | 3ec96df | 2017-05-22 06:57:06 -0700 | [diff] [blame] | 576 | } // namespace test |
| 577 | } // namespace webrtc |