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

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

Issue 1814723003: Added a bitexactness test for the intelligibility enhancer in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@BeamformerBitExactness_CL
Patch Set: Changes in response to reviewer comments 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
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <vector>
11
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webrtc/base/array_view.h"
14 #include "webrtc/modules/audio_processing/audio_buffer.h"
15 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc er.h"
16 #include "webrtc/modules/audio_processing/noise_suppression_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 const size_t kNumFramesToProcess = 1000;
24
25 int IntelligibilityEnhancerSampleRate(int sample_rate_hz) {
26 return (sample_rate_hz > AudioProcessing::kSampleRate16kHz
27 ? AudioProcessing::kSampleRate16kHz
28 : sample_rate_hz);
29 }
30
31 // Process one frame of data and produce the output.
32 void ProcessOneFrame(int sample_rate_hz,
33 AudioBuffer* render_audio_buffer,
34 AudioBuffer* capture_audio_buffer,
35 NoiseSuppressionImpl* noise_suppressor,
36 IntelligibilityEnhancer* intelligibility_enhancer) {
37 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
38 render_audio_buffer->SplitIntoFrequencyBands();
39 capture_audio_buffer->SplitIntoFrequencyBands();
40 }
41
42 intelligibility_enhancer->ProcessRenderAudio(
43 render_audio_buffer->split_channels_f(kBand0To8kHz),
44 IntelligibilityEnhancerSampleRate(sample_rate_hz),
45 render_audio_buffer->num_channels());
46
47 noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer);
48 noise_suppressor->ProcessCaptureAudio(capture_audio_buffer);
49
50 intelligibility_enhancer->SetCaptureNoiseEstimate(
51 noise_suppressor->NoiseEstimate());
52
53 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
54 render_audio_buffer->MergeFrequencyBands();
55 }
56 }
57
58 // Processes a specified amount of frames, verifies the results and reports
59 // any errors.
60 void RunBitexactnessTest(int sample_rate_hz,
61 size_t num_channels,
62 rtc::ArrayView<const float> output_reference) {
63 const StreamConfig render_config(sample_rate_hz, num_channels, false);
64 AudioBuffer render_buffer(
65 render_config.num_frames(), render_config.num_channels(),
66 render_config.num_frames(), render_config.num_channels(),
67 render_config.num_frames());
68 test::InputAudioFile render_file(
69 test::GetApmRenderTestVectorFileName(sample_rate_hz));
70 std::vector<float> render_input(render_buffer.num_frames() *
71 render_buffer.num_channels());
72
73 const StreamConfig capture_config(sample_rate_hz, num_channels, false);
74 AudioBuffer capture_buffer(
75 capture_config.num_frames(), capture_config.num_channels(),
76 capture_config.num_frames(), capture_config.num_channels(),
77 capture_config.num_frames());
78 test::InputAudioFile capture_file(
79 test::GetApmCaptureTestVectorFileName(sample_rate_hz));
80 std::vector<float> capture_input(render_buffer.num_frames() *
81 capture_buffer.num_channels());
82
83 rtc::CriticalSection crit_capture;
84 NoiseSuppressionImpl noise_suppressor(&crit_capture);
85 noise_suppressor.Initialize(capture_config.num_channels(), sample_rate_hz);
86 noise_suppressor.Enable(true);
87
88 IntelligibilityEnhancer intelligibility_enhancer(
89 IntelligibilityEnhancerSampleRate(sample_rate_hz),
90 render_config.num_channels(), NoiseSuppressionImpl::num_noise_bins());
91
92 for (size_t frame_no = 0u; frame_no < kNumFramesToProcess; ++frame_no) {
93 ReadFloatSamplesFromStereoFile(render_buffer.num_frames(),
94 render_buffer.num_channels(), &render_file,
95 render_input);
96 ReadFloatSamplesFromStereoFile(render_buffer.num_frames(),
aluebs-webrtc 2016/03/22 11:53:29 capture_buffer
peah-webrtc 2016/03/23 22:13:53 Good catch!!! Done.
97 capture_buffer.num_channels(), &capture_file,
98 capture_input);
99
100 test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer);
101 test::CopyVectorToAudioBuffer(capture_config, capture_input,
102 &capture_buffer);
103
104 ProcessOneFrame(sample_rate_hz, &render_buffer, &capture_buffer,
105 &noise_suppressor, &intelligibility_enhancer);
106 }
107
108 // Extract and verify the test results.
109 std::vector<float> render_output;
110 test::ExtractVectorFromAudioBuffer(render_config, &render_buffer,
111 &render_output);
112
113 const float kTolerance = 1.f / static_cast<float>(1 << 15);
114
115 // Compare the output with the reference. Only the first values of the output
116 // from last frame processed are compared in order not having to specify all
117 // preceeding frames as testvectors. As the algorithm being tested has a
118 // memory, testing only the last frame implicitly also tests the preceeding
119 // frames.
120 EXPECT_TRUE(test::BitExactFrame(render_buffer.num_frames(),
121 render_config.num_channels(),
122 output_reference, render_output, kTolerance));
123 }
124
125 } // namespace
126
127 TEST(IntelligibilityEnhancerBitExactnessTest, Mono8kHz) {
128 const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f};
129
130 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference);
131 }
132
133 TEST(IntelligibilityEnhancerBitExactnessTest, Mono16kHz) {
134 const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f};
135
136 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference);
137 }
138
139 TEST(IntelligibilityEnhancerBitExactnessTest, Mono32kHz) {
140 const float kOutputReference[] = {0.003021f, -0.011780f, -0.008209f};
141
142 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference);
143 }
144
145 TEST(IntelligibilityEnhancerBitExactnessTest, Mono48kHz) {
146 const float kOutputReference[] = {-0.027696f, -0.026253f, -0.018001f};
147
148 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference);
149 }
150
151 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo8kHz) {
152 const float kOutputReference[] = {0.021454f, 0.035919f, 0.026428f,
153 -0.000641f, 0.000366f, 0.000641f};
154
155 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference);
156 }
157
158 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo16kHz) {
159 const float kOutputReference[] = {0.021362f, 0.035736f, 0.023895f,
160 -0.001404f, -0.001465f, 0.000549f};
161
162 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference);
163 }
164
165 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo32kHz) {
166 const float kOutputReference[] = {0.030641f, 0.027406f, 0.028321f,
167 -0.001343f, -0.004578f, 0.000977f};
168
169 RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference);
170 }
171
172 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo48kHz) {
173 const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f,
174 -0.012975f, -0.015940f, -0.017820f};
175
176 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference);
177 }
178
179 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698