Chromium Code Reviews

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: Added reporting of metrics Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 // TODO(peah): Add test vectors and enable the tests.
72 TEST(LevelControlBitExactnessTest, DISABLED_Mono8kHz) {
73 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
74 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference);
75 }
76
77 TEST(LevelControlBitExactnessTest, DISABLED_Mono16kHz) {
78 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
79 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference);
80 }
81
82 TEST(LevelControlBitExactnessTest, DISABLED_Mono32kHz) {
83 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
84 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference);
85 }
86
87 TEST(LevelControlBitExactnessTest, DISABLED_Mono48kHz) {
88 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
89 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference);
90 }
91
92 TEST(LevelControlBitExactnessTest, DISABLED_Stereo8kHz) {
93 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
94 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference);
95 }
96
97 TEST(LevelControlBitExactnessTest, DISABLED_Stereo16kHz) {
98 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
99 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference);
100 }
101
102 TEST(LevelControlBitExactnessTest, DISABLED_Stereo32kHz) {
103 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
104 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference);
105 }
106
107 TEST(LevelControlBitExactnessTest, DISABLED_Stereo48kHz) {
108 const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
109 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference);
110 }
111
112 } // namespace webrtc
OLDNEW

Powered by Google App Engine