blob: 292b632bd2746e2b32509f3641024cfc3d4e25a4 [file] [log] [blame]
andrew@webrtc.org60730cf2014-01-07 17:45:09 +00001/*
2 * Copyright (c) 2014 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/audio_processing_impl.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000012
Alessio Bazzicae4498052018-12-17 09:44:06 +010013#include <memory>
14
Mirko Bonadeid9708072019-01-25 20:26:48 +010015#include "api/scoped_refptr.h"
Alessio Bazzicad2b97402018-08-09 14:23:11 +020016#include "modules/audio_processing/include/audio_processing.h"
Alessio Bazzicae4498052018-12-17 09:44:06 +010017#include "modules/audio_processing/test/echo_control_mock.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_processing/test/test_utils.h"
Alessio Bazzicae4498052018-12-17 09:44:06 +010019#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/ref_counted_object.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "test/gmock.h"
22#include "test/gtest.h"
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000023
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000024namespace webrtc {
peaha9cc40b2017-06-29 08:32:09 -070025namespace {
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000026
Alessio Bazzicae4498052018-12-17 09:44:06 +010027using ::testing::Invoke;
28using ::testing::NotNull;
29
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000030class MockInitialize : public AudioProcessingImpl {
31 public:
peah88ac8532016-09-12 16:47:25 -070032 explicit MockInitialize(const webrtc::Config& config)
33 : AudioProcessingImpl(config) {}
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000034
andrew@webrtc.orge84978f2014-01-25 02:09:06 +000035 MOCK_METHOD0(InitializeLocked, int());
danilchap56359be2017-09-07 07:53:45 -070036 int RealInitializeLocked() RTC_NO_THREAD_SAFETY_ANALYSIS {
pbos@webrtc.org788acd12014-12-15 09:41:24 +000037 return AudioProcessingImpl::InitializeLocked();
38 }
peaha9cc40b2017-06-29 08:32:09 -070039
Niels Möller6f72f562017-10-19 13:15:17 +020040 MOCK_CONST_METHOD0(AddRef, void());
41 MOCK_CONST_METHOD0(Release, rtc::RefCountReleaseStatus());
andrew@webrtc.org60730cf2014-01-07 17:45:09 +000042};
43
Alessio Bazzicae4498052018-12-17 09:44:06 +010044// Creates MockEchoControl instances and provides a raw pointer access to
45// the next created one. The raw pointer is meant to be used with gmock.
46// Returning a pointer of the next created MockEchoControl instance is necessary
47// for the following reasons: (i) gmock expectations must be set before any call
48// occurs, (ii) APM is initialized the first time that
49// AudioProcessingImpl::ProcessStream() is called and the initialization leads
50// to the creation of a new EchoControl object.
51class MockEchoControlFactory : public EchoControlFactory {
52 public:
Mirko Bonadei317a1f02019-09-17 17:06:18 +020053 MockEchoControlFactory() : next_mock_(std::make_unique<MockEchoControl>()) {}
Alessio Bazzicae4498052018-12-17 09:44:06 +010054 // Returns a pointer to the next MockEchoControl that this factory creates.
55 MockEchoControl* GetNext() const { return next_mock_.get(); }
56 std::unique_ptr<EchoControl> Create(int sample_rate_hz) override {
57 std::unique_ptr<EchoControl> mock = std::move(next_mock_);
Mirko Bonadei317a1f02019-09-17 17:06:18 +020058 next_mock_ = std::make_unique<MockEchoControl>();
Alessio Bazzicae4498052018-12-17 09:44:06 +010059 return mock;
60 }
61
62 private:
63 std::unique_ptr<MockEchoControl> next_mock_;
64};
65
Alessio Bazzicad2b97402018-08-09 14:23:11 +020066void InitializeAudioFrame(size_t input_rate,
67 size_t num_channels,
68 AudioFrame* frame) {
Alex Loikob5c9a792018-04-16 16:31:22 +020069 const size_t samples_per_input_channel = rtc::CheckedDivExact(
70 input_rate, static_cast<size_t>(rtc::CheckedDivExact(
71 1000, AudioProcessing::kChunkSizeMs)));
Alex Loikob5c9a792018-04-16 16:31:22 +020072 RTC_DCHECK_LE(samples_per_input_channel * num_channels,
73 AudioFrame::kMaxDataSizeSamples);
Alessio Bazzicad2b97402018-08-09 14:23:11 +020074 frame->samples_per_channel_ = samples_per_input_channel;
75 frame->sample_rate_hz_ = input_rate;
76 frame->num_channels_ = num_channels;
77}
78
79void FillFixedFrame(int16_t audio_level, AudioFrame* frame) {
80 const size_t num_samples = frame->samples_per_channel_ * frame->num_channels_;
81 for (size_t i = 0; i < num_samples; ++i) {
82 frame->mutable_data()[i] = audio_level;
Alex Loikob5c9a792018-04-16 16:31:22 +020083 }
84}
85
Alessio Bazzicad2b97402018-08-09 14:23:11 +020086// Mocks EchoDetector and records the first samples of the last analyzed render
87// stream frame. Used to check what data is read by an EchoDetector
88// implementation injected into an APM.
89class TestEchoDetector : public EchoDetector {
90 public:
91 TestEchoDetector()
92 : analyze_render_audio_called_(false),
93 last_render_audio_first_sample_(0.f) {}
94 ~TestEchoDetector() override = default;
95 void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) override {
96 last_render_audio_first_sample_ = render_audio[0];
97 analyze_render_audio_called_ = true;
98 }
99 void AnalyzeCaptureAudio(rtc::ArrayView<const float> capture_audio) override {
100 }
101 void Initialize(int capture_sample_rate_hz,
102 int num_capture_channels,
103 int render_sample_rate_hz,
104 int num_render_channels) override {}
105 EchoDetector::Metrics GetMetrics() const override { return {}; }
106 // Returns true if AnalyzeRenderAudio() has been called at least once.
107 bool analyze_render_audio_called() const {
108 return analyze_render_audio_called_;
109 }
110 // Returns the first sample of the last analyzed render frame.
111 float last_render_audio_first_sample() const {
112 return last_render_audio_first_sample_;
113 }
114
115 private:
116 bool analyze_render_audio_called_;
117 float last_render_audio_first_sample_;
118};
119
120// Mocks CustomProcessing and applies ProcessSample() to all the samples.
121// Meant to be injected into an APM to modify samples in a known and detectable
122// way.
123class TestRenderPreProcessor : public CustomProcessing {
124 public:
125 TestRenderPreProcessor() = default;
126 ~TestRenderPreProcessor() = default;
127 void Initialize(int sample_rate_hz, int num_channels) override {}
128 void Process(AudioBuffer* audio) override {
129 for (size_t k = 0; k < audio->num_channels(); ++k) {
Per Åhgrend47941e2019-08-22 11:51:13 +0200130 rtc::ArrayView<float> channel_view(audio->channels()[k],
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200131 audio->num_frames());
132 std::transform(channel_view.begin(), channel_view.end(),
133 channel_view.begin(), ProcessSample);
134 }
Mirko Bonadeic4dd7302019-02-25 09:12:02 +0100135 }
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200136 std::string ToString() const override { return "TestRenderPreProcessor"; }
137 void SetRuntimeSetting(AudioProcessing::RuntimeSetting setting) override {}
138 // Modifies a sample. This member is used in Process() to modify a frame and
139 // it is publicly visible to enable tests.
140 static constexpr float ProcessSample(float x) { return 2.f * x; }
141};
142
peaha9cc40b2017-06-29 08:32:09 -0700143} // namespace
144
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000145TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
peah88ac8532016-09-12 16:47:25 -0700146 webrtc::Config config;
andrew@webrtc.orge84978f2014-01-25 02:09:06 +0000147 MockInitialize mock(config);
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000148 ON_CALL(mock, InitializeLocked())
149 .WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked));
150
151 EXPECT_CALL(mock, InitializeLocked()).Times(1);
152 mock.Initialize();
153
154 AudioFrame frame;
peah2ace3f92016-09-10 04:42:27 -0700155 // Call with the default parameters; there should be an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000156 frame.num_channels_ = 1;
157 SetFrameSampleRate(&frame, 16000);
Per Åhgren4bdced52017-06-27 16:00:38 +0200158 EXPECT_CALL(mock, InitializeLocked()).Times(0);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000159 EXPECT_NOERR(mock.ProcessStream(&frame));
aluebsb0319552016-03-17 20:39:53 -0700160 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000161
162 // New sample rate. (Only impacts ProcessStream).
163 SetFrameSampleRate(&frame, 32000);
Yves Gerey665174f2018-06-19 15:03:05 +0200164 EXPECT_CALL(mock, InitializeLocked()).Times(1);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000165 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000166
167 // New number of channels.
peah2ace3f92016-09-10 04:42:27 -0700168 // TODO(peah): Investigate why this causes 2 inits.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000169 frame.num_channels_ = 2;
Yves Gerey665174f2018-06-19 15:03:05 +0200170 EXPECT_CALL(mock, InitializeLocked()).Times(2);
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000171 EXPECT_NOERR(mock.ProcessStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000172 // ProcessStream sets num_channels_ == num_output_channels.
173 frame.num_channels_ = 2;
aluebsb0319552016-03-17 20:39:53 -0700174 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000175
aluebsb0319552016-03-17 20:39:53 -0700176 // A new sample rate passed to ProcessReverseStream should cause an init.
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000177 SetFrameSampleRate(&frame, 16000);
Alex Luebs5b830fe2016-03-08 17:52:52 +0100178 EXPECT_CALL(mock, InitializeLocked()).Times(1);
aluebsb0319552016-03-17 20:39:53 -0700179 EXPECT_NOERR(mock.ProcessReverseStream(&frame));
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000180}
181
Alessio Bazzicac054e782018-04-16 12:10:09 +0200182TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) {
Alex Loikob5c9a792018-04-16 16:31:22 +0200183 std::unique_ptr<AudioProcessing> apm(AudioProcessingBuilder().Create());
184 webrtc::AudioProcessing::Config apm_config;
185 apm_config.pre_amplifier.enabled = true;
186 apm_config.pre_amplifier.fixed_gain_factor = 1.f;
187 apm->ApplyConfig(apm_config);
188
189 AudioFrame frame;
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200190 constexpr int16_t kAudioLevel = 10000;
191 constexpr size_t kSampleRateHz = 48000;
192 constexpr size_t kNumChannels = 2;
193 InitializeAudioFrame(kSampleRateHz, kNumChannels, &frame);
Alex Loikob5c9a792018-04-16 16:31:22 +0200194
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200195 FillFixedFrame(kAudioLevel, &frame);
Alex Loikob5c9a792018-04-16 16:31:22 +0200196 apm->ProcessStream(&frame);
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200197 EXPECT_EQ(frame.data()[100], kAudioLevel)
Alex Loikob5c9a792018-04-16 16:31:22 +0200198 << "With factor 1, frame shouldn't be modified.";
199
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200200 constexpr float kGainFactor = 2.f;
Alex Loikob5c9a792018-04-16 16:31:22 +0200201 apm->SetRuntimeSetting(
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200202 AudioProcessing::RuntimeSetting::CreateCapturePreGain(kGainFactor));
Alex Loikob5c9a792018-04-16 16:31:22 +0200203
204 // Process for two frames to have time to ramp up gain.
205 for (int i = 0; i < 2; ++i) {
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200206 FillFixedFrame(kAudioLevel, &frame);
Alex Loikob5c9a792018-04-16 16:31:22 +0200207 apm->ProcessStream(&frame);
208 }
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200209 EXPECT_EQ(frame.data()[100], kGainFactor * kAudioLevel)
Alex Loikob5c9a792018-04-16 16:31:22 +0200210 << "Frame should be amplified.";
Alessio Bazzicac054e782018-04-16 12:10:09 +0200211}
212
Alessio Bazzicae4498052018-12-17 09:44:06 +0100213TEST(AudioProcessingImplTest,
214 EchoControllerObservesPreAmplifierEchoPathGainChange) {
215 // Tests that the echo controller observes an echo path gain change when the
216 // pre-amplifier submodule changes the gain.
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200217 auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
Alessio Bazzicae4498052018-12-17 09:44:06 +0100218 const auto* echo_control_factory_ptr = echo_control_factory.get();
219
220 std::unique_ptr<AudioProcessing> apm(
221 AudioProcessingBuilder()
222 .SetEchoControlFactory(std::move(echo_control_factory))
223 .Create());
224 apm->gain_control()->Enable(false); // Disable AGC.
225 apm->gain_control()->set_mode(GainControl::Mode::kFixedDigital);
226 webrtc::AudioProcessing::Config apm_config;
227 apm_config.gain_controller2.enabled = false;
228 apm_config.pre_amplifier.enabled = true;
229 apm_config.pre_amplifier.fixed_gain_factor = 1.f;
230 apm->ApplyConfig(apm_config);
231
232 AudioFrame frame;
233 constexpr int16_t kAudioLevel = 10000;
234 constexpr size_t kSampleRateHz = 48000;
235 constexpr size_t kNumChannels = 2;
236 InitializeAudioFrame(kSampleRateHz, kNumChannels, &frame);
237 FillFixedFrame(kAudioLevel, &frame);
238
239 MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext();
240
Per Åhgren0aefbf02019-08-23 21:29:17 +0200241 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistbf47f342019-05-09 10:50:31 +0200242 EXPECT_CALL(*echo_control_mock,
243 ProcessCapture(NotNull(), /*echo_path_change=*/false))
244 .Times(1);
Alessio Bazzicae4498052018-12-17 09:44:06 +0100245 apm->ProcessStream(&frame);
246
Per Åhgren0aefbf02019-08-23 21:29:17 +0200247 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistbf47f342019-05-09 10:50:31 +0200248 EXPECT_CALL(*echo_control_mock,
249 ProcessCapture(NotNull(), /*echo_path_change=*/true))
250 .Times(1);
Alessio Bazzicae4498052018-12-17 09:44:06 +0100251 apm->SetRuntimeSetting(
252 AudioProcessing::RuntimeSetting::CreateCapturePreGain(2.f));
253 apm->ProcessStream(&frame);
254}
255
256TEST(AudioProcessingImplTest,
257 EchoControllerObservesAnalogAgc1EchoPathGainChange) {
258 // Tests that the echo controller observes an echo path gain change when the
259 // AGC1 analog adaptive submodule changes the analog gain.
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200260 auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
Alessio Bazzicae4498052018-12-17 09:44:06 +0100261 const auto* echo_control_factory_ptr = echo_control_factory.get();
262
263 std::unique_ptr<AudioProcessing> apm(
264 AudioProcessingBuilder()
265 .SetEchoControlFactory(std::move(echo_control_factory))
266 .Create());
267 apm->gain_control()->Enable(true); // Enable AGC.
268 apm->gain_control()->set_mode(GainControl::Mode::kAdaptiveAnalog);
269 webrtc::AudioProcessing::Config apm_config;
270 apm_config.gain_controller2.enabled = false;
271 apm_config.pre_amplifier.enabled = false;
272 apm->ApplyConfig(apm_config);
273
274 AudioFrame frame;
275 constexpr int16_t kAudioLevel = 1000;
276 constexpr size_t kSampleRateHz = 48000;
277 constexpr size_t kNumChannels = 2;
278 InitializeAudioFrame(kSampleRateHz, kNumChannels, &frame);
279 FillFixedFrame(kAudioLevel, &frame);
280
281 MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext();
282
283 const int initial_analog_gain = apm->gain_control()->stream_analog_level();
Per Åhgren0aefbf02019-08-23 21:29:17 +0200284 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Alessio Bazzicae4498052018-12-17 09:44:06 +0100285 EXPECT_CALL(*echo_control_mock, ProcessCapture(NotNull(), false)).Times(1);
286 apm->ProcessStream(&frame);
287
288 // Force an analog gain change if it did not happen.
289 if (initial_analog_gain == apm->gain_control()->stream_analog_level()) {
290 apm->gain_control()->set_stream_analog_level(initial_analog_gain + 1);
291 }
292
Per Åhgren0aefbf02019-08-23 21:29:17 +0200293 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Alessio Bazzicae4498052018-12-17 09:44:06 +0100294 EXPECT_CALL(*echo_control_mock, ProcessCapture(NotNull(), true)).Times(1);
295 apm->ProcessStream(&frame);
296}
297
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200298TEST(AudioProcessingImplTest, EchoControllerObservesPlayoutVolumeChange) {
299 // Tests that the echo controller observes an echo path gain change when a
300 // playout volume change is reported.
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200301 auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200302 const auto* echo_control_factory_ptr = echo_control_factory.get();
303
304 std::unique_ptr<AudioProcessing> apm(
305 AudioProcessingBuilder()
306 .SetEchoControlFactory(std::move(echo_control_factory))
307 .Create());
308 apm->gain_control()->Enable(false); // Disable AGC.
309 apm->gain_control()->set_mode(GainControl::Mode::kFixedDigital);
310
311 AudioFrame frame;
312 constexpr int16_t kAudioLevel = 10000;
313 constexpr size_t kSampleRateHz = 48000;
314 constexpr size_t kNumChannels = 2;
315 InitializeAudioFrame(kSampleRateHz, kNumChannels, &frame);
316 FillFixedFrame(kAudioLevel, &frame);
317
318 MockEchoControl* echo_control_mock = echo_control_factory_ptr->GetNext();
319
Per Åhgren0aefbf02019-08-23 21:29:17 +0200320 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200321 EXPECT_CALL(*echo_control_mock,
322 ProcessCapture(NotNull(), /*echo_path_change=*/false))
323 .Times(1);
324 apm->ProcessStream(&frame);
325
Per Åhgren0aefbf02019-08-23 21:29:17 +0200326 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200327 EXPECT_CALL(*echo_control_mock,
328 ProcessCapture(NotNull(), /*echo_path_change=*/false))
329 .Times(1);
330 apm->SetRuntimeSetting(
331 AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(50));
332 apm->ProcessStream(&frame);
333
Per Åhgren0aefbf02019-08-23 21:29:17 +0200334 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200335 EXPECT_CALL(*echo_control_mock,
336 ProcessCapture(NotNull(), /*echo_path_change=*/false))
337 .Times(1);
338 apm->SetRuntimeSetting(
339 AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(50));
340 apm->ProcessStream(&frame);
341
Per Åhgren0aefbf02019-08-23 21:29:17 +0200342 EXPECT_CALL(*echo_control_mock, AnalyzeCapture(testing::_)).Times(1);
Fredrik Hernqvistca362852019-05-10 15:50:02 +0200343 EXPECT_CALL(*echo_control_mock,
344 ProcessCapture(NotNull(), /*echo_path_change=*/true))
345 .Times(1);
346 apm->SetRuntimeSetting(
347 AudioProcessing::RuntimeSetting::CreatePlayoutVolumeChange(100));
348 apm->ProcessStream(&frame);
349}
350
Alessio Bazzicad2b97402018-08-09 14:23:11 +0200351TEST(AudioProcessingImplTest, RenderPreProcessorBeforeEchoDetector) {
352 // Make sure that signal changes caused by a render pre-processing sub-module
353 // take place before any echo detector analysis.
354 rtc::scoped_refptr<TestEchoDetector> test_echo_detector(
355 new rtc::RefCountedObject<TestEchoDetector>());
356 std::unique_ptr<CustomProcessing> test_render_pre_processor(
357 new TestRenderPreProcessor());
358 // Create APM injecting the test echo detector and render pre-processor.
359 std::unique_ptr<AudioProcessing> apm(
360 AudioProcessingBuilder()
361 .SetEchoDetector(test_echo_detector)
362 .SetRenderPreProcessing(std::move(test_render_pre_processor))
363 .Create());
364 webrtc::AudioProcessing::Config apm_config;
365 apm_config.pre_amplifier.enabled = true;
366 apm_config.residual_echo_detector.enabled = true;
367 apm->ApplyConfig(apm_config);
368
369 constexpr int16_t kAudioLevel = 1000;
370 constexpr int kSampleRateHz = 16000;
371 constexpr size_t kNumChannels = 1;
372 AudioFrame frame;
373 InitializeAudioFrame(kSampleRateHz, kNumChannels, &frame);
374
375 constexpr float kAudioLevelFloat = static_cast<float>(kAudioLevel);
376 constexpr float kExpectedPreprocessedAudioLevel =
377 TestRenderPreProcessor::ProcessSample(kAudioLevelFloat);
378 ASSERT_NE(kAudioLevelFloat, kExpectedPreprocessedAudioLevel);
379
380 // Analyze a render stream frame.
381 FillFixedFrame(kAudioLevel, &frame);
382 ASSERT_EQ(AudioProcessing::Error::kNoError,
383 apm->ProcessReverseStream(&frame));
384 // Trigger a call to in EchoDetector::AnalyzeRenderAudio() via
385 // ProcessStream().
386 FillFixedFrame(kAudioLevel, &frame);
387 ASSERT_EQ(AudioProcessing::Error::kNoError, apm->ProcessStream(&frame));
388 // Regardless of how the call to in EchoDetector::AnalyzeRenderAudio() is
389 // triggered, the line below checks that the call has occurred. If not, the
390 // APM implementation may have changed and this test might need to be adapted.
391 ASSERT_TRUE(test_echo_detector->analyze_render_audio_called());
392 // Check that the data read in EchoDetector::AnalyzeRenderAudio() is that
393 // produced by the render pre-processor.
394 EXPECT_EQ(kExpectedPreprocessedAudioLevel,
395 test_echo_detector->last_render_audio_first_sample());
396}
397
andrew@webrtc.org60730cf2014-01-07 17:45:09 +0000398} // namespace webrtc