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

Side by Side Diff: webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc

Issue 2090583002: New module for the adaptive level controlling functionality in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Temporarily deactivated the level controller until the CL with the proper tuning has been landed Created 4 years, 5 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) 2016 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 <vector>
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/base/array_view.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/include/audio_processing.h"
17 #include "webrtc/modules/audio_processing/level_controller/level_controller.h"
18 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
19 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
20
21 namespace webrtc {
22 namespace {
23
24 const int kNumFramesToProcess = 1000;
25
26 // Processes a specified amount of frames, verifies the results and reports
27 // any errors.
28 void RunBitexactnessTest(int sample_rate_hz,
29 size_t num_channels,
30 rtc::ArrayView<const float> output_reference) {
31 LevelController level_controller;
32 level_controller.Initialize(sample_rate_hz);
33
34 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
35 const StreamConfig capture_config(sample_rate_hz, num_channels, false);
36 AudioBuffer capture_buffer(
37 capture_config.num_frames(), capture_config.num_channels(),
38 capture_config.num_frames(), capture_config.num_channels(),
39 capture_config.num_frames());
40 test::InputAudioFile capture_file(
41 test::GetApmCaptureTestVectorFileName(sample_rate_hz));
42 std::vector<float> capture_input(samples_per_channel * num_channels);
43 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
44 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
45 &capture_file, capture_input);
46
47 test::CopyVectorToAudioBuffer(capture_config, capture_input,
48 &capture_buffer);
49
50 level_controller.Process(&capture_buffer);
51 }
52
53 // Extract test results.
54 std::vector<float> capture_output;
55 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
56 &capture_output);
57
58 // Compare the output with the reference. Only the first values of the output
59 // from last frame processed are compared in order not having to specify all
60 // preceding frames as testvectors. As the algorithm being tested has a
61 // memory, testing only the last frame implicitly also tests the preceeding
62 // frames.
63 const float kVectorElementErrorBound = 1.0f / 32768.0f;
64 EXPECT_TRUE(test::VerifyDeinterleavedArray(
65 capture_config.num_frames(), capture_config.num_channels(),
66 output_reference, capture_output, kVectorElementErrorBound));
67 }
68
69 } // namespace
70
71 TEST(LevelControlBitExactnessTest, Mono8kHz) {
72 const float kOutputReference[] = {-0.023242f, -0.020266f, -0.015097f};
73 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference);
74 }
75
76 TEST(LevelControlBitExactnessTest, Mono16kHz) {
77 const float kOutputReference[] = {-0.019461f, -0.018761f, -0.018481f};
78 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference);
79 }
80
81 TEST(LevelControlBitExactnessTest, Mono32kHz) {
82 const float kOutputReference[] = {-0.016872f, -0.019118f, -0.018722f};
83 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference);
84 }
85
86 // TODO(peah): Investigate why this particular testcase differ between Android
87 // and the rest of the platforms.
88 TEST(LevelControlBitExactnessTest, Mono48kHz) {
89 #if !(defined(WEBRTC_ARCH_ARM64) || defined(WEBRTC_ARCH_ARM) || \
90 defined(WEBRTC_ANDROID))
91 const float kOutputReference[] = {-0.016771f, -0.017831f, -0.020482f};
92 #else
93 const float kOutputReference[] = {-0.015949f, -0.016957f, -0.019478f};
94 #endif
95 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference);
96 }
97
98 TEST(LevelControlBitExactnessTest, Stereo8kHz) {
99 const float kOutputReference[] = {-0.019304f, -0.011600f, -0.016690f,
100 -0.071335f, -0.031849f, -0.065694f};
101 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference);
102 }
103
104 TEST(LevelControlBitExactnessTest, Stereo16kHz) {
105 const float kOutputReference[] = {-0.016302f, -0.007559f, -0.015668f,
106 -0.068346f, -0.031476f, -0.066065f};
107 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference);
108 }
109
110 TEST(LevelControlBitExactnessTest, Stereo32kHz) {
111 const float kOutputReference[] = {-0.013944f, -0.008337f, -0.015972f,
112 -0.063563f, -0.031233f, -0.066784f};
113 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference);
114 }
115
116 TEST(LevelControlBitExactnessTest, Stereo48kHz) {
117 const float kOutputReference[] = {-0.013652f, -0.008125f, -0.014593f,
118 -0.062963f, -0.030270f, -0.064727f};
119 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference);
120 }
121
122 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698