Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: webrtc/modules/audio_processing/agc2/gain_controller2_unittest.cc

Issue 2848593002: AGC2 as a new APM sub-module operating with hard-coded gain. (Closed)
Patch Set: DigitalGainApplier and UTs, AGC2 before LC, minor changes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
11 #include <memory>
12 #include <string>
13
14 #include "webrtc/base/array_view.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/agc2/gain_controller2.h"
17 #include "webrtc/modules/audio_processing/agc2/digital_gain_applier.h"
18 #include "webrtc/test/gtest.h"
19
20 namespace webrtc {
21 namespace test {
22
23 namespace {
24
25 constexpr size_t kNumFrames = 480u;
26 constexpr size_t kStereo = 2u;
27
28 void SetAudioBufferSamples(float value, AudioBuffer* ab) {
29 for (size_t k = 0; k < ab->num_channels(); ++k) {
30 auto channel = rtc::ArrayView<float>(ab->channels_f()[k], ab->num_frames());
31 for (auto& sample : channel) { sample = value; }
32 }
33 }
34
35 template<typename Functor>
36 bool CheckAudioBufferSamples(Functor validator, AudioBuffer* ab) {
37 for (size_t k = 0; k < ab->num_channels(); ++k) {
38 auto channel = rtc::ArrayView<float>(ab->channels_f()[k], ab->num_frames());
39 for (auto& sample : channel) { if (!validator(sample)) { return false; } }
40 }
41 return true;
42 }
43
44 } // namespace
45
46 TEST(GainController2, Instance) {
47 std::unique_ptr<GainController2> gain_controller2;
48 gain_controller2.reset(new GainController2(
49 AudioProcessing::kSampleRate48kHz));
50 }
51
52 TEST(GainController2, ToString) {
53 AudioProcessing::Config config;
54
55 config.gain_controller2.enabled = false;
56 EXPECT_EQ("{enabled: false}",
57 GainController2::ToString(config.gain_controller2));
58
59 config.gain_controller2.enabled = true;
60 EXPECT_EQ("{enabled: true}",
61 GainController2::ToString(config.gain_controller2));
62 }
63
64 TEST(GainController2, DigitalGainApplierProcess) {
65 AudioBuffer ab(kNumFrames, kStereo, kNumFrames, kStereo, kNumFrames);
66 SetAudioBufferSamples(1000.0f, &ab);
67
68 DigitalGainApplier gain_applier;
69 gain_applier.Process(0.5, &ab);
70
71 auto check_expectation = [](float sample) { return sample == 500.0f; };
72 EXPECT_TRUE(CheckAudioBufferSamples(check_expectation, &ab));
73 }
74
75 TEST(GainController2, DigitalGainApplierCheckPositiveClipping) {
76 AudioBuffer ab(kNumFrames, kStereo, kNumFrames, kStereo, kNumFrames);
77 SetAudioBufferSamples(30000.0f, &ab);
78
79 DigitalGainApplier gain_applier;
80 gain_applier.Process(1.5, &ab);
81
82 auto check_expectation = [](float sample) { return sample == 32767.0f; };
83 EXPECT_TRUE(CheckAudioBufferSamples(check_expectation, &ab));
84 }
85
86 TEST(GainController2, DigitalGainApplierCheckNegativeClipping) {
87 AudioBuffer ab(kNumFrames, kStereo, kNumFrames, kStereo, kNumFrames);
88 SetAudioBufferSamples(-30000.0f, &ab);
89
90 DigitalGainApplier gain_applier;
91 gain_applier.Process(1.5, &ab);
92
93 auto check_expectation = [](float sample) { return sample == -32767.0f; };
94 EXPECT_TRUE(CheckAudioBufferSamples(check_expectation, &ab));
95 }
96
97 } // namespace test
98 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698