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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | webrtc/modules/modules.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_processing/intelligibility_enhancer_unittest.cc
diff --git a/webrtc/modules/audio_processing/intelligibility_enhancer_unittest.cc b/webrtc/modules/audio_processing/intelligibility_enhancer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a6861b98f1de7c26485863e8454aa6ae76a72d06
--- /dev/null
+++ b/webrtc/modules/audio_processing/intelligibility_enhancer_unittest.cc
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include <vector>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/array_view.h"
+#include "webrtc/modules/audio_processing/audio_buffer.h"
+#include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer.h"
+#include "webrtc/modules/audio_processing/noise_suppression_impl.h"
+#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
+
+namespace webrtc {
+namespace {
+
+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.
+
+// Process one frame of data and produce the output.
+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.
+ AudioBuffer* render_audio_buffer,
+ AudioBuffer* capture_audio_buffer,
+ NoiseSuppressionImpl* noise_suppressor,
+ IntelligibilityEnhancer* intelligibility_enhancer) {
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
+ render_audio_buffer->SplitIntoFrequencyBands();
+ capture_audio_buffer->SplitIntoFrequencyBands();
+ }
+
+ noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer);
+ noise_suppressor->ProcessCaptureAudio(capture_audio_buffer);
+
+ intelligibility_enhancer->ProcessRenderAudio(
+ render_audio_buffer->split_channels_f(kBand0To8kHz),
+ 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.
+ render_audio_buffer->num_channels());
+
+ 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.
+ noise_suppressor->NoiseEstimate());
+
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
+ render_audio_buffer->MergeFrequencyBands();
+ }
+}
+
+// Processes a specified amount of frames, verifies the results and reports
+// any errors.
+void RunBitexactnessTest(int sample_rate_hz,
+ size_t num_channels,
+ 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.
+ 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.
+ const StreamConfig render_config(sample_rate_hz, num_channels, false);
+ AudioBuffer render_buffer(
+ render_config.num_frames(), render_config.num_channels(),
+ render_config.num_frames(), render_config.num_channels(),
+ render_config.num_frames());
+ test::InputAudioFile render_file(
+ test::GetApmRenderTestVectorFileName(sample_rate_hz));
+ 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.
+
+ const StreamConfig capture_config(sample_rate_hz, num_channels, false);
+ AudioBuffer capture_buffer(
+ capture_config.num_frames(), capture_config.num_channels(),
+ 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
+ test::InputAudioFile capture_file(
+ test::GetApmCaptureTestVectorFileName(sample_rate_hz));
+ 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.
+
+ rtc::CriticalSection crit_render;
aluebs-webrtc 2016/03/18 23:26:41 Not used.
peah-webrtc 2016/03/21 11:54:49 Done.
+ rtc::CriticalSection crit_capture;
+ NoiseSuppressionImpl noise_suppressor(&crit_capture);
+ 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.
+ noise_suppressor.Enable(true);
+
+ IntelligibilityEnhancer intelligibility_enhancer(
+ 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.
+ render_config.num_channels(), NoiseSuppressionImpl::num_noise_bins());
+
+ 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.
+ 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.
+ &render_file, render_input);
+ 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.
+ &capture_file, capture_input);
+
+ test::CopyVectorToAudioBuffer(render_config, render_input, &render_buffer);
+ test::CopyVectorToAudioBuffer(capture_config, capture_input,
+ &capture_buffer);
+
+ ProcessOneFrame(sample_rate_hz, &render_buffer, &capture_buffer,
+ &noise_suppressor, &intelligibility_enhancer);
+ }
+
+ // Extract and verify the test results.
+ std::vector<float> render_output;
+ test::ExtractVectorFromAudioBuffer(render_config, &render_buffer,
+ &render_output);
+
+ 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.
+
+ // Compare the output with the reference. Only the first values of the output
+ // from last frame processed are compared in order not having to specify all
+ // preceeding frames as testvectors. As the algorithm being tested has a
+ // memory, testing only the last frame implicitly also tests the preceeding
+ // frames.
+ 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.
+ render_config.num_channels(),
+ output_reference, render_output, kTolerance));
+}
+
+} // namespace
+
+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
+ const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Mono16kHz) {
+ const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Mono32kHz) {
+ const float kOutputReference[] = {0.003021f, -0.011780f, -0.008209f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Mono48kHz) {
+ const float kOutputReference[] = {-0.027696f, -0.026253f, -0.018001f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Stereo8kHz) {
+ const float kOutputReference[] = {0.021454f, 0.035919f, 0.026428f,
+ -0.000641f, 0.000366f, 0.000641f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Stereo16kHz) {
+ const float kOutputReference[] = {0.021362f, 0.035736f, 0.023895f,
+ -0.001404f, -0.001465f, 0.000549f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Stereo32kHz) {
+ const float kOutputReference[] = {0.030641f, 0.027406f, 0.028321f,
+ -0.001343f, -0.004578f, 0.000977f};
+
+ 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.
+}
+
+TEST(IntelligibilityEnhancerBitExactnessTest, Stereo48kHz) {
+ const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f,
+ -0.012975f, -0.015940f, -0.017820f};
+
+ 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.
+}
+
+} // namespace webrtc
« no previous file with comments | « no previous file | webrtc/modules/modules.gyp » ('j') | webrtc/modules/modules.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698