OLD | NEW |
---|---|
(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 int kNumFramesToProcess = 1000; | |
aluebs-webrtc
2016/03/18 23:26:40
Should probably be a size_t.
peah-webrtc
2016/03/21 11:54:50
Done.
| |
24 | |
25 // Process one frame of data and produce the output. | |
26 void ProcessOneFrame(int sample_rate_hz, | |
aluebs-webrtc
2016/03/18 23:26:41
You don't need to pass in the sample_rate_hz separ
peah-webrtc
2016/03/21 11:54:49
I cannot see that the AudioBuffer returns the samp
aluebs-webrtc
2016/03/22 11:53:29
You are right, my bad.
peah-webrtc
2016/03/23 22:09:34
Acknowledged.
| |
27 AudioBuffer* render_audio_buffer, | |
28 AudioBuffer* capture_audio_buffer, | |
29 NoiseSuppressionImpl* noise_suppressor, | |
30 IntelligibilityEnhancer* intelligibility_enhancer) { | |
31 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { | |
32 render_audio_buffer->SplitIntoFrequencyBands(); | |
33 capture_audio_buffer->SplitIntoFrequencyBands(); | |
34 } | |
35 | |
36 noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer); | |
37 noise_suppressor->ProcessCaptureAudio(capture_audio_buffer); | |
38 | |
39 intelligibility_enhancer->ProcessRenderAudio( | |
40 render_audio_buffer->split_channels_f(kBand0To8kHz), | |
41 sample_rate_hz > 16000 ? 16000 : sample_rate_hz, | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate16kHz instead of 1
peah-webrtc
2016/03/21 11:54:50
Done.
| |
42 render_audio_buffer->num_channels()); | |
43 | |
44 intelligibility_enhancer->SetCaptureNoiseEstimate( | |
aluebs-webrtc
2016/03/18 23:26:40
Just to mimic the APM, you should probably put thi
peah-webrtc
2016/03/21 11:54:50
Good point!
Done.
| |
45 noise_suppressor->NoiseEstimate()); | |
46 | |
47 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { | |
48 render_audio_buffer->MergeFrequencyBands(); | |
49 } | |
50 } | |
51 | |
52 // Processes a specified amount of frames, verifies the results and reports | |
53 // any errors. | |
54 void RunBitexactnessTest(int sample_rate_hz, | |
55 size_t num_channels, | |
56 const rtc::ArrayView<const float>& output_reference) { | |
aluebs-webrtc
2016/03/18 23:26:40
In the ArrayView documentation it says: "ArrayView
peah-webrtc
2016/03/21 11:54:51
Done.
| |
57 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); | |
hlundin-webrtc
2016/03/18 08:47:43
const
aluebs-webrtc
2016/03/18 23:26:41
You don't need to calculate this explicitly, you c
peah-webrtc
2016/03/21 11:54:50
Done.
peah-webrtc
2016/03/21 11:54:50
Done.
| |
58 const StreamConfig render_config(sample_rate_hz, num_channels, false); | |
59 AudioBuffer render_buffer( | |
60 render_config.num_frames(), render_config.num_channels(), | |
61 render_config.num_frames(), render_config.num_channels(), | |
62 render_config.num_frames()); | |
63 test::InputAudioFile render_file( | |
64 test::GetApmRenderTestVectorFileName(sample_rate_hz)); | |
65 std::vector<float> render_input(samples_per_channel * num_channels); | |
aluebs-webrtc
2016/03/18 23:26:40
Use render_config.num_frames() or even the render_
peah-webrtc
2016/03/21 11:54:49
Done.
| |
66 | |
67 const StreamConfig capture_config(sample_rate_hz, num_channels, false); | |
68 AudioBuffer capture_buffer( | |
69 capture_config.num_frames(), capture_config.num_channels(), | |
70 capture_config.num_frames(), 1, capture_config.num_frames()); | |
aluebs-webrtc
2016/03/18 23:26:41
Why do you need to hard-code to mono? Also, it wou
peah-webrtc
2016/03/21 11:54:51
That is a mistake done caused by mistakenly only c
| |
71 test::InputAudioFile capture_file( | |
72 test::GetApmCaptureTestVectorFileName(sample_rate_hz)); | |
73 std::vector<float> capture_input(samples_per_channel * num_channels); | |
aluebs-webrtc
2016/03/18 23:26:40
Use render_config.num_frames() or even the render_
peah-webrtc
2016/03/21 11:54:51
Done.
| |
74 | |
75 rtc::CriticalSection crit_render; | |
aluebs-webrtc
2016/03/18 23:26:41
Not used.
peah-webrtc
2016/03/21 11:54:49
Done.
| |
76 rtc::CriticalSection crit_capture; | |
77 NoiseSuppressionImpl noise_suppressor(&crit_capture); | |
78 noise_suppressor.Initialize(1, sample_rate_hz); | |
aluebs-webrtc
2016/03/18 23:26:41
Why do you need to hard-code to mono? Also, it wou
peah-webrtc
2016/03/21 11:54:51
Done.
| |
79 noise_suppressor.Enable(true); | |
80 | |
81 IntelligibilityEnhancer intelligibility_enhancer( | |
82 sample_rate_hz > 16000 ? 16000 : sample_rate_hz, | |
aluebs-webrtc
2016/03/18 23:26:40
Use AudioProcessing::kSampleRate16kHz instead of 1
peah-webrtc
2016/03/21 11:54:50
Done.
| |
83 render_config.num_channels(), NoiseSuppressionImpl::num_noise_bins()); | |
84 | |
85 for (int frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | |
aluebs-webrtc
2016/03/18 23:26:41
This should probably be size_t.
peah-webrtc
2016/03/21 11:54:49
Done.
| |
86 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels, | |
aluebs-webrtc
2016/03/18 23:26:40
Where does this function come from? Also, use rend
peah-webrtc
2016/03/21 11:54:50
The function is declared in
webrtc/modules/audio_p
aluebs-webrtc
2016/03/22 11:53:28
Thanks for clarifying. I don't know why my greppin
peah-webrtc
2016/03/23 22:13:53
Done.
| |
87 &render_file, render_input); | |
88 ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels, | |
aluebs-webrtc
2016/03/18 23:26:40
Where does this function come from? Also, use capt
peah-webrtc
2016/03/21 11:54:50
The function is declared in
webrtc/modules/audio_p
aluebs-webrtc
2016/03/22 11:53:29
Thanks for clarifying. I don't know why my greppin
peah-webrtc
2016/03/23 22:09:34
Acknowledged.
| |
89 &capture_file, capture_input); | |
90 | |
91 test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer); | |
92 test::CopyVectorToAudioBuffer(capture_config, capture_input, | |
93 &capture_buffer); | |
94 | |
95 ProcessOneFrame(sample_rate_hz, &render_buffer, &capture_buffer, | |
96 &noise_suppressor, &intelligibility_enhancer); | |
97 } | |
98 | |
99 // Extract and verify the test results. | |
100 std::vector<float> render_output; | |
101 test::ExtractVectorFromAudioBuffer(render_config, &render_buffer, | |
102 &render_output); | |
103 | |
104 const float kTolerance = 1.0f / 32768.0f; | |
aluebs-webrtc
2016/03/18 23:26:40
The 0s after the dot are not necessary. There is p
peah-webrtc
2016/03/21 11:54:50
Great point!
Done.
| |
105 | |
106 // Compare the output with the reference. Only the first values of the output | |
107 // from last frame processed are compared in order not having to specify all | |
108 // preceeding frames as testvectors. As the algorithm being tested has a | |
109 // memory, testing only the last frame implicitly also tests the preceeding | |
110 // frames. | |
111 EXPECT_TRUE(test::BitExactFrame(render_config.num_frames(), | |
aluebs-webrtc
2016/03/18 23:26:40
If it receives a tolerance it is not a bit-exact t
peah-webrtc
2016/03/21 11:54:49
Good point!
What about VectorDifferenceBounded an
aluebs-webrtc
2016/03/22 11:53:29
I think your suggestion sounds much more intuitive
peah-webrtc
2016/03/23 22:09:34
Great! Then I'll do that in another CL.
Done.
aluebs-webrtc
2016/03/24 11:18:40
Acknowledged.
| |
112 render_config.num_channels(), | |
113 output_reference, render_output, kTolerance)); | |
114 } | |
115 | |
116 } // namespace | |
117 | |
118 TEST(IntelligibilityEnhancerBitExactnessTest, Mono8kHz) { | |
aluebs-webrtc
2016/03/18 23:26:41
This test would be a lot simpler if we use TEST_P
peah-webrtc
2016/03/21 11:54:49
Very likely, but I could not come up with a good w
aluebs-webrtc
2016/03/22 11:53:29
How about having a method that returns a reference
peah-webrtc
2016/03/23 22:09:34
As I wrote in the CL for the bitexactness test for
aluebs-webrtc
2016/03/24 11:18:40
As I wrote in the other CL, TEST_P would be exactl
| |
119 const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f}; | |
120 | |
121 RunBitexactnessTest(8000, 1, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate8kHz and define yo
peah-webrtc
2016/03/21 11:54:50
Done.
| |
122 } | |
123 | |
124 TEST(IntelligibilityEnhancerBitExactnessTest, Mono16kHz) { | |
125 const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f}; | |
126 | |
127 RunBitexactnessTest(16000, 1, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate16kHz and define y
peah-webrtc
2016/03/21 11:54:49
Done.
| |
128 } | |
129 | |
130 TEST(IntelligibilityEnhancerBitExactnessTest, Mono32kHz) { | |
131 const float kOutputReference[] = {0.003021f, -0.011780f, -0.008209f}; | |
132 | |
133 RunBitexactnessTest(32000, 1, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate32kHz and define y
peah-webrtc
2016/03/21 11:54:50
Done.
| |
134 } | |
135 | |
136 TEST(IntelligibilityEnhancerBitExactnessTest, Mono48kHz) { | |
137 const float kOutputReference[] = {-0.027696f, -0.026253f, -0.018001f}; | |
138 | |
139 RunBitexactnessTest(48000, 1, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate48kHz and define y
peah-webrtc
2016/03/21 11:54:49
Done.
| |
140 } | |
141 | |
142 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo8kHz) { | |
143 const float kOutputReference[] = {0.021454f, 0.035919f, 0.026428f, | |
144 -0.000641f, 0.000366f, 0.000641f}; | |
145 | |
146 RunBitexactnessTest(8000, 2, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:40
Use AudioProcessing::kSampleRate8kHz and define yo
peah-webrtc
2016/03/21 11:54:50
Done.
| |
147 } | |
148 | |
149 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo16kHz) { | |
150 const float kOutputReference[] = {0.021362f, 0.035736f, 0.023895f, | |
151 -0.001404f, -0.001465f, 0.000549f}; | |
152 | |
153 RunBitexactnessTest(16000, 2, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate16kHz and define y
peah-webrtc
2016/03/21 11:54:49
Done.
| |
154 } | |
155 | |
156 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo32kHz) { | |
157 const float kOutputReference[] = {0.030641f, 0.027406f, 0.028321f, | |
158 -0.001343f, -0.004578f, 0.000977f}; | |
159 | |
160 RunBitexactnessTest(32000, 2, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate32kHz and define y
peah-webrtc
2016/03/21 11:54:50
Done.
| |
161 } | |
162 | |
163 TEST(IntelligibilityEnhancerBitExactnessTest, Stereo48kHz) { | |
164 const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f, | |
165 -0.012975f, -0.015940f, -0.017820f}; | |
166 | |
167 RunBitexactnessTest(48000, 2, kOutputReference); | |
aluebs-webrtc
2016/03/18 23:26:41
Use AudioProcessing::kSampleRate32kHz and define y
peah-webrtc
2016/03/21 11:54:50
Done.
| |
168 } | |
169 | |
170 } // namespace webrtc | |
OLD | NEW |