Chromium Code Reviews| 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/beamformer/nonlinear_beamformer.h" | |
| 16 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" | |
| 17 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 namespace { | |
| 21 | |
| 22 const int kNumFramesToProcess = 1000; | |
|
aluebs-webrtc
2016/03/18 22:51:51
Should probably be a size_t.
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 23 | |
| 24 void ProcessOneFrame(int sample_rate_hz, | |
|
aluebs-webrtc
2016/03/18 22:51:52
You don't need to pass in the sample_rate_hz separ
peah-webrtc
2016/03/21 08:02:07
I cannot see that the AudioBuffer returns the samp
aluebs-webrtc
2016/03/22 12:15:55
You are right, my bad.
peah-webrtc
2016/03/23 22:06:20
Acknowledged.
| |
| 25 AudioBuffer* capture_audio_buffer, | |
| 26 Beamformer<float>* beamformer) { | |
| 27 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { | |
| 28 capture_audio_buffer->SplitIntoFrequencyBands(); | |
| 29 } | |
| 30 | |
| 31 beamformer->ProcessChunk(*capture_audio_buffer->split_data_f(), | |
|
aluebs-webrtc
2016/03/18 22:51:50
After running the beamformer, the number of channe
peah-webrtc
2016/03/21 08:02:08
Thanks! I saw that from the AudioProcessingImpl bu
aluebs-webrtc
2016/03/22 12:15:55
That is done so that the AudioBuffer is aware abou
peah-webrtc
2016/03/23 22:06:20
Acknowledged.
| |
| 32 capture_audio_buffer->split_data_f()); | |
| 33 | |
| 34 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { | |
| 35 capture_audio_buffer->MergeFrequencyBands(); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void RunBitExactnessTest(int sample_rate_hz, | |
| 40 const std::vector<Point>& array_geometry, | |
| 41 const SphericalPointf& target_direction, | |
| 42 const rtc::ArrayView<const float>& output_reference) { | |
|
aluebs-webrtc
2016/03/18 22:51:52
In the ArrayView documentation it says: "ArrayView
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 43 NonlinearBeamformer beamformer(array_geometry, target_direction); | |
| 44 beamformer.Initialize(10, sample_rate_hz > 16000 ? 16000 : sample_rate_hz); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Use AudioProcessing::kChunkSizeMs instead of 10, o
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 45 | |
| 46 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100); | |
|
aluebs-webrtc
2016/03/18 22:51:52
You don't need to calculate this explicitly, you c
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 47 const StreamConfig capture_config(sample_rate_hz, 2, false); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use array_geometry.size() instead of hardcoding 2.
peah-webrtc
2016/03/21 08:02:09
Done.
| |
| 48 AudioBuffer capture_buffer( | |
| 49 capture_config.num_frames(), capture_config.num_channels(), | |
| 50 capture_config.num_frames(), capture_config.num_channels(), | |
|
aluebs-webrtc
2016/03/18 22:51:51
num_process_channels should probably be mono, when
peah-webrtc
2016/03/21 08:02:07
No, that does not work, as the CopyFrom then produ
aluebs-webrtc
2016/03/22 12:15:55
Yes, you are right. My bad.
peah-webrtc
2016/03/23 22:06:20
Acknowledged.
| |
| 51 capture_config.num_frames()); | |
| 52 test::InputAudioFile capture_file( | |
| 53 test::GetApmCaptureTestVectorFileName(sample_rate_hz)); | |
| 54 std::vector<float> capture_input(samples_per_channel * 2); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use capture_config.num_channels() or capture_buffe
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 55 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { | |
|
aluebs-webrtc
2016/03/18 22:51:51
0u?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 56 ReadFloatSamplesFromStereoFile(samples_per_channel, 2, &capture_file, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Where does this function come from? Also use captu
peah-webrtc
2016/03/21 08:02:06
The function is declared in webrtc/modules/audio_p
aluebs-webrtc
2016/03/22 12:15:55
Thanks for clarifying. I am not sure why this didn
peah-webrtc
2016/03/23 22:06:19
Acknowledged.
| |
| 57 capture_input); | |
| 58 | |
| 59 test::CopyVectorToAudioBuffer(capture_config, capture_input, | |
| 60 &capture_buffer); | |
| 61 | |
| 62 ProcessOneFrame(sample_rate_hz, &capture_buffer, &beamformer); | |
| 63 } | |
| 64 | |
| 65 // Extract and verify the test results. | |
| 66 std::vector<float> capture_output; | |
| 67 test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer, | |
| 68 &capture_output); | |
| 69 | |
| 70 const float kTolerance = 1.0f / 32768.0f; | |
|
aluebs-webrtc
2016/03/18 22:51:51
The 0s after the dot are not necessary. There is p
peah-webrtc
2016/03/21 08:02:07
Good point!
Done.
| |
| 71 | |
| 72 // Compare the output with the reference. Only the first values of the output | |
| 73 // from last frame processed are compared in order not having to specify all | |
| 74 // preceeding frames as testvectors. As the algorithm being tested has a | |
| 75 // memory, testing only the last frame implicitly also tests the preceeding | |
| 76 // frames. | |
| 77 EXPECT_TRUE(test::BitExactFrame( | |
|
aluebs-webrtc
2016/03/18 22:51:50
If it receives a tolerance it is not a bit-exact t
peah-webrtc
2016/03/21 08:02:08
Good point!
What about VectorDifferenceBounded an
aluebs-webrtc
2016/03/22 12:15:56
I think your suggestion is much more intuitive. Bu
peah-webrtc
2016/03/23 22:06:19
Good, I think that change will be for the better.
aluebs-webrtc
2016/03/24 11:14:25
Acknowledged.
| |
| 78 capture_config.num_frames(), capture_config.num_channels(), | |
| 79 output_reference, capture_output, kTolerance)); | |
| 80 } | |
| 81 | |
| 82 std::vector<Point> CreateArrayGeometry(int variant) { | |
| 83 std::vector<Point> array_geometry; | |
| 84 switch (variant) { | |
|
aluebs-webrtc
2016/03/18 22:51:52
Maybe have a variant with more than 2 points?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 85 case 1: | |
| 86 array_geometry.push_back(Point(-0.025f, 0.f, 0.f)); | |
| 87 array_geometry.push_back(Point(0.025f, 0.f, 0.f)); | |
| 88 break; | |
| 89 case 2: | |
| 90 | |
|
aluebs-webrtc
2016/03/18 22:51:52
Remove blank line?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 91 array_geometry.push_back(Point(-0.035f, 0.f, 0.f)); | |
| 92 array_geometry.push_back(Point(0.035f, 0.f, 0.f)); | |
| 93 | |
|
aluebs-webrtc
2016/03/18 22:51:52
Remove blank line?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 94 break; | |
| 95 case 3: | |
| 96 | |
|
aluebs-webrtc
2016/03/18 22:51:52
Remove blank line?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 97 array_geometry.push_back(Point(-0.5f, 0.f, 0.f)); | |
| 98 array_geometry.push_back(Point(0.5f, 0.f, 0.f)); | |
| 99 break; | |
| 100 default: | |
| 101 RTC_CHECK(false); | |
| 102 } | |
| 103 return array_geometry; | |
| 104 } | |
| 105 | |
| 106 const SphericalPointf TargetDirection1(static_cast<float>(M_PI) / 2.f, | |
| 107 0.f, | |
| 108 1.f); | |
| 109 const SphericalPointf TargetDirection2(static_cast<float>(M_PI) / 2.f, | |
| 110 0.f, | |
| 111 2.f); | |
|
aluebs-webrtc
2016/03/18 22:51:51
The radius is completely ignored, but it would be
peah-webrtc
2016/03/21 08:02:06
Absolutely, what about the new one?
aluebs-webrtc
2016/03/22 12:15:56
That is elevation, right? I meant azimuth, the fir
peah-webrtc
2016/03/23 22:06:19
Ah, sorry about that! I will change that.
| |
| 112 | |
| 113 } // namespace | |
| 114 | |
| 115 // TODO(peah): Investigate why the nonlinear_beamformer.cc causes a DCHECK in | |
|
aluebs-webrtc
2016/03/18 22:51:52
I think this should be resolved before landing thi
peah-webrtc
2016/03/21 08:02:08
I don't agree and I cannot see why that would be d
aluebs-webrtc
2016/03/22 12:15:55
What I am afraid of, is that this might be an issu
peah-webrtc
2016/03/23 22:06:19
I don't think it is an issue with the test as the
aluebs-webrtc
2016/03/24 11:14:25
Well, it definitively is possible to DCHECK on the
peah-webrtc
2016/03/24 11:51:30
True. Firstly, using the new configurations, I was
aluebs-webrtc
2016/03/28 23:01:17
That is weird, since those DCHECKs only depend on
| |
| 116 // this setup. | |
| 117 TEST(BeamformerBitExactnessTest, | |
|
aluebs-webrtc
2016/03/18 22:51:52
This test would be a lot simpler if we use TEST_P
peah-webrtc
2016/03/21 08:02:08
Very likely, but I could not come up with a good w
aluebs-webrtc
2016/03/22 12:15:55
You can have a function, similar to CreateArrayGeo
peah-webrtc
2016/03/23 22:06:19
Ah, then I see. That is a good suggestion and most
aluebs-webrtc
2016/03/24 11:14:25
I think using TEST_P is exactly as verbose, since
peah-webrtc
2016/03/24 11:51:30
Yes, the initial version of the bitexactness test
aluebs-webrtc
2016/03/28 23:01:17
I don't see any comments of the reviewers before t
peah-webrtc
2016/03/29 05:19:19
The comment is there with the timestamp 2015-12-10
| |
| 118 DISABLED_Stereo8kHz_ArrayGeometry1_TargetDirection1) { | |
| 119 const float kOutputReference[] = {-0.000161f, 0.000171f, -0.000096f, | |
| 120 0.001007f, 0.000427f, 0.000977f}; | |
| 121 | |
| 122 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:09
Done.
| |
| 123 | |
| 124 RunBitExactnessTest(8000, array_geometry, TargetDirection1, kOutputReference); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate8kHz or define you
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 125 } | |
| 126 | |
| 127 TEST(BeamformerBitExactnessTest, Stereo16kHz_ArrayGeometry1_TargetDirection1) { | |
| 128 const float kOutputReference[] = {0.001144f, -0.001026f, 0.001074f, | |
| 129 -0.016205f, -0.007324f, -0.015656f}; | |
| 130 | |
| 131 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:09
Done.
| |
| 132 | |
| 133 RunBitExactnessTest(16000, array_geometry, TargetDirection1, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate16kHz or define yo
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 134 kOutputReference); | |
| 135 } | |
| 136 | |
| 137 TEST(BeamformerBitExactnessTest, Stereo32kHz_ArrayGeometry1_TargetDirection1) { | |
| 138 const float kOutputReference[] = {0.000732f, -0.000397f, 0.000610f, | |
| 139 -0.005768f, -0.001495f, -0.007111f}; | |
| 140 | |
| 141 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 142 | |
| 143 RunBitExactnessTest(32000, array_geometry, TargetDirection1, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate32kHz or define yo
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 144 kOutputReference); | |
| 145 } | |
| 146 | |
| 147 TEST(BeamformerBitExactnessTest, Stereo48kHz_ArrayGeometry1_TargetDirection1) { | |
| 148 const float kOutputReference[] = {0.000106f, -0.000464f, 0.000188f, | |
| 149 -0.007476f, 0.002662f, -0.007240f}; | |
| 150 | |
| 151 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 152 | |
| 153 RunBitExactnessTest(48000, array_geometry, TargetDirection1, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate48kHz or define yo
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 154 kOutputReference); | |
| 155 } | |
| 156 | |
| 157 TEST(BeamformerBitExactnessTest, | |
| 158 DISABLED_Stereo8kHz_ArrayGeometry1_TargetDirection2) { | |
| 159 const float kOutputReference[] = {0.001144f, -0.001026f, 0.001074f, | |
| 160 -0.016205f, -0.007324f, -0.015656f}; | |
| 161 | |
| 162 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 163 | |
| 164 RunBitExactnessTest(8000, array_geometry, TargetDirection2, kOutputReference); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Use AudioProcessing::kSampleRate8kHz or define you
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 165 } | |
| 166 | |
| 167 TEST(BeamformerBitExactnessTest, Stereo16kHz_ArrayGeometry1_TargetDirection2) { | |
| 168 const float kOutputReference[] = {0.001144f, -0.001026f, 0.001074f, | |
| 169 -0.016205f, -0.007324f, -0.015656f}; | |
| 170 | |
| 171 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 172 | |
| 173 RunBitExactnessTest(16000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:52
Use AudioProcessing::kSampleRate16kHz or define yo
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 174 kOutputReference); | |
| 175 } | |
| 176 | |
| 177 TEST(BeamformerBitExactnessTest, Stereo32kHz_ArrayGeometry1_TargetDirection2) { | |
| 178 const float kOutputReference[] = {0.000732f, -0.000397f, 0.000610f, | |
| 179 -0.005768f, -0.001495f, -0.007111f}; | |
| 180 | |
| 181 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 182 | |
| 183 RunBitExactnessTest(32000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate32kHz or define yo
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 184 kOutputReference); | |
| 185 } | |
| 186 | |
| 187 TEST(BeamformerBitExactnessTest, Stereo48kHz_ArrayGeometry1_TargetDirection2) { | |
| 188 const float kOutputReference[] = {0.000106f, -0.000464f, 0.000188f, | |
| 189 -0.007476f, 0.002662f, -0.007240f}; | |
| 190 | |
| 191 std::vector<Point> array_geometry = CreateArrayGeometry(1); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:09
Done.
| |
| 192 | |
| 193 RunBitExactnessTest(48000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:50
Use AudioProcessing::kSampleRate48kHz or define yo
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 194 kOutputReference); | |
| 195 } | |
| 196 | |
| 197 TEST(BeamformerBitExactnessTest, Stereo8kHz_ArrayGeometry2_TargetDirection2) { | |
| 198 const float kOutputReference[] = {-0.000649f, 0.000576f, -0.000148f, | |
| 199 -0.015625f, -0.006866f, -0.014374f}; | |
| 200 | |
| 201 std::vector<Point> array_geometry = CreateArrayGeometry(2); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 202 | |
| 203 RunBitExactnessTest(8000, array_geometry, TargetDirection2, kOutputReference); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate8kHz or define you
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 204 } | |
| 205 | |
| 206 TEST(BeamformerBitExactnessTest, Stereo16kHz_ArrayGeometry2_TargetDirection2) { | |
| 207 const float kOutputReference[] = {0.000808f, -0.000695f, 0.000739f, | |
| 208 -0.016205f, -0.007324f, -0.015656f}; | |
| 209 | |
| 210 std::vector<Point> array_geometry = CreateArrayGeometry(2); | |
|
aluebs-webrtc
2016/03/18 22:51:50
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:08
Done.
| |
| 211 | |
| 212 RunBitExactnessTest(16000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:52
Use AudioProcessing::kSampleRate16kHz or define yo
peah-webrtc
2016/03/21 08:02:09
Done.
| |
| 213 kOutputReference); | |
| 214 } | |
| 215 | |
| 216 TEST(BeamformerBitExactnessTest, Stereo32kHz_ArrayGeometry2_TargetDirection2) { | |
| 217 const float kOutputReference[] = {0.000580f, -0.000183f, 0.000458f, | |
| 218 -0.005768f, -0.001495f, -0.007111f}; | |
| 219 | |
| 220 std::vector<Point> array_geometry = CreateArrayGeometry(2); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 221 | |
| 222 RunBitExactnessTest(32000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:52
Use AudioProcessing::kSampleRate32kHz or define yo
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 223 kOutputReference); | |
| 224 } | |
| 225 | |
| 226 TEST(BeamformerBitExactnessTest, Stereo48kHz_ArrayGeometry2_TargetDirection2) { | |
| 227 const float kOutputReference[] = {0.000075f, -0.000288f, 0.000156f, | |
| 228 -0.007476f, 0.002662f, -0.007240f}; | |
| 229 | |
| 230 std::vector<Point> array_geometry = CreateArrayGeometry(2); | |
|
aluebs-webrtc
2016/03/18 22:51:52
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 231 | |
| 232 RunBitExactnessTest(48000, array_geometry, TargetDirection2, | |
|
aluebs-webrtc
2016/03/18 22:51:51
Use AudioProcessing::kSampleRate48kHz or define yo
peah-webrtc
2016/03/21 08:02:06
Done.
| |
| 233 kOutputReference); | |
| 234 } | |
| 235 | |
| 236 // TODO(peah): Investigate why the nonlinear_beamformer.cc causes a DCHECK in | |
|
aluebs-webrtc
2016/03/18 22:51:51
I think this should be resolved before landing thi
peah-webrtc
2016/03/21 08:02:08
As for the corresponding above comment, I don't ag
| |
| 237 // this setup. | |
| 238 TEST(BeamformerBitExactnessTest, | |
| 239 DISABLED_Stereo16kHz_ArrayGeometry3_TargetDirection1) { | |
| 240 const float kOutputReference[] = {-0.000161f, 0.000171f, -0.000096f, | |
| 241 0.001007f, 0.000427f, 0.000977f}; | |
| 242 | |
| 243 std::vector<Point> array_geometry = CreateArrayGeometry(3); | |
|
aluebs-webrtc
2016/03/18 22:51:51
Do we need this intermediate variable?
peah-webrtc
2016/03/21 08:02:07
Done.
| |
| 244 | |
| 245 RunBitExactnessTest(16000, array_geometry, TargetDirection1, | |
| 246 kOutputReference); | |
| 247 } | |
| 248 | |
| 249 } // namespace webrtc | |
| OLD | NEW |