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

Side by Side Diff: webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc

Issue 1811443002: Added a bitexactness test for the level estimator in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@NsBitLatest_CL
Patch Set: Created 4 years, 9 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) 2015 The WebRTC project authors. All Rights Reserved.
hlundin-webrtc 2016/03/16 12:57:05 2016
peah-webrtc 2016/03/17 14:18:06 Done.
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 #include <vector>
11
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webrtc/base/array_view.h"
14 #include "webrtc/base/random.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/level_estimator_impl.h"
17 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
18 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
19
20 namespace webrtc {
21 namespace {
22
23 enum TestSignalLevels { kLow, kMedium, kHigh };
24
25 // Process one frame of data and produce the output.
26 void ProcessOneFrame(int sample_rate_hz,
27 AudioBuffer* audio_buffer,
28 LevelEstimatorImpl* level_estimator,
29 int* rms) {
30 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
hlundin-webrtc 2016/03/16 12:57:05 What is the purpose of splitting and merging bands
peah-webrtc 2016/03/17 14:18:06 None, removed that code. Done.
31 audio_buffer->SplitIntoFrequencyBands();
32 }
33
34 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
35 audio_buffer->MergeFrequencyBands();
36 }
37 level_estimator->ProcessStream(audio_buffer);
38 *rms = level_estimator->RMS();
39 }
40
41 // Forms a predefined random test vector.
42 void ConstructTestVector(int samples_per_channel,
hlundin-webrtc 2016/03/16 12:57:05 This seems very similar to the function in the pre
peah-webrtc 2016/03/17 14:18:06 Done.
43 int num_channels,
44 int frame_counter,
45 Random* rand_gen,
46 TestSignalLevels signal_level,
47 std::vector<float>* testvector) {
48 testvector->resize(samples_per_channel * num_channels);
49
50 float signal_gain = 0.0f;
51 switch (signal_level) {
52 case TestSignalLevels::kLow:
53 signal_gain = 0.1f;
54 break;
55 case TestSignalLevels::kMedium:
56 signal_gain = 0.5f;
57 break;
58 case TestSignalLevels::kHigh:
59 signal_gain = 1.0f;
60 break;
61 default:
62 RTC_DCHECK(false);
63 }
64
65 bool low_level = ((frame_counter / 10) > 5);
66 float scale = (low_level ? 0.01f : 1.0f);
67 for (auto& v : *testvector) {
68 v = signal_gain * scale * (2.0f * rand_gen->Rand<float>() - 1.0f);
69 }
70 }
71
72 void SetupComponent(LevelEstimatorImpl* level_estimator) {
73 level_estimator->Initialize();
74 level_estimator->Enable(true);
75 }
76
77 // Processes a specified amount of frames, verifies the results and reports
78 // any errors.
79 void RunBitexactnessTest(int sample_rate_hz,
minyue-webrtc 2016/03/16 09:55:01 Is |rms_reference| derivable from |signal_level|,
peah-webrtc 2016/03/17 14:18:06 No, signal_level was just a scaling of the signal
80 int num_channels,
81 int num_frames_to_process,
82 TestSignalLevels signal_level,
83 int rms_reference) {
84 Random rand_gen(42);
85 int samples_per_channel = 80 * sample_rate_hz / 8000;
86 const StreamConfig stream_config(sample_rate_hz, num_channels, false);
87 AudioBuffer audio_buffer(
88 stream_config.num_frames(), stream_config.num_channels(),
89 stream_config.num_frames(), stream_config.num_channels(),
90 stream_config.num_frames());
91
92 rtc::CriticalSection crit;
93 LevelEstimatorImpl level_estimator(&crit);
94 SetupComponent(&level_estimator);
95
96 int rms = 0;
97 std::vector<float> frame_input;
98 for (int frame_no = 0; frame_no < num_frames_to_process; ++frame_no) {
99 ConstructTestVector(samples_per_channel, num_channels, frame_no, &rand_gen,
100 signal_level, &frame_input);
101
102 test::CopyVectorToAudioBuffer(stream_config, frame_input, &audio_buffer);
103
104 ProcessOneFrame(sample_rate_hz, &audio_buffer, &level_estimator, &rms);
105 }
106
107 // Compare the output to the reference.
108 EXPECT_PRED_FORMAT2(test::AssertIntegersNotEqual, rms, rms_reference);
hlundin-webrtc 2016/03/16 12:57:05 EXPECT_NEAR
peah-webrtc 2016/03/17 14:18:06 Changed to EXPECT_EQ instead. Done.
109 }
110
111 } // namespace
112
113 TEST(LevelEstimatorBitExactnessTest, Mono8kHzLow) {
114 const int kRmsReference = 65;
hlundin-webrtc 2016/03/16 12:57:05 You are using three different values for kRmsRefer
peah-webrtc 2016/03/17 14:18:06 I'm not too happy about that. It may be that they
hlundin-webrtc 2016/03/17 15:20:57 Fair enough, now that you have fewer test cases.
peah-webrtc 2016/03/20 15:40:55 Acknowledged.
115
116 RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kLow, kRmsReference);
117 }
118
119 TEST(LevelEstimatorBitExactnessTest, Mono16kHzLow) {
120 const int kRmsReference = 65;
121
122 RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kLow, kRmsReference);
123 }
124
125 TEST(LevelEstimatorBitExactnessTest, Mono32kHzLow) {
126 const int kRmsReference = 65;
127
128 RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kLow, kRmsReference);
129 }
130
131 TEST(LevelEstimatorBitExactnessTest, Mono48kHzLow) {
132 const int kRmsReference = 65;
133
134 RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kLow, kRmsReference);
135 }
136
137 TEST(LevelEstimatorBitExactnessTest, Stereo16kHzLow) {
138 const int kRmsReference = 65;
139
140 RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kLow, kRmsReference);
141 }
142
143 TEST(LevelEstimatorBitExactnessTest, Mono8kHzMedium) {
144 const int kRmsReference = 51;
145
146 RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
147 }
148
149 TEST(LevelEstimatorBitExactnessTest, Mono16kHzMedium) {
150 const int kRmsReference = 51;
151
152 RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
153 }
154
155 TEST(LevelEstimatorBitExactnessTest, Mono32kHzMedium) {
156 const int kRmsReference = 51;
157
158 RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
159 }
160
161 TEST(LevelEstimatorBitExactnessTest, Mono48kHzMedium) {
162 const int kRmsReference = 51;
163
164 RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
165 }
166
167 TEST(LevelEstimatorBitExactnessTest, Stereo16kHzMedium) {
168 const int kRmsReference = 51;
169
170 RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kMedium, kRmsReference);
171 }
172
173 TEST(LevelEstimatorBitExactnessTest, Mono8kHzHigh) {
174 const int kRmsReference = 45;
175
176 RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
177 }
178
179 TEST(LevelEstimatorBitExactnessTest, Mono16kHzHigh) {
180 const int kRmsReference = 45;
181
182 RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
183 }
184
185 TEST(LevelEstimatorBitExactnessTest, Mono32kHzHigh) {
186 const int kRmsReference = 45;
187
188 RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
189 }
190
191 TEST(LevelEstimatorBitExactnessTest, Mono48kHzHigh) {
192 const int kRmsReference = 45;
193
194 RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
195 }
196
197 TEST(LevelEstimatorBitExactnessTest, Stereo16kHzHigh) {
198 const int kRmsReference = 45;
199
200 RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kHigh, kRmsReference);
201 }
202
203 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698