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

Unified Diff: webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc

Issue 2090583002: New module for the adaptive level controlling functionality in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Corrected the initial behavior for the peak level estimate, and ensured a nonzero minimum peak leveā€¦ Created 4 years, 6 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
Index: webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc
diff --git a/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc b/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5bc855bf99cbf5ac415108833649bb2fc273e712
--- /dev/null
+++ b/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc
@@ -0,0 +1,113 @@
+/*
+ * 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>
hlundin-webrtc 2016/06/27 11:21:16 Space before.
peah-webrtc 2016/06/27 22:51:49 Done.
+
+#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/include/audio_processing.h"
+#include "webrtc/modules/audio_processing/level_controller/level_controller.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;
+
+// Processes a specified amount of frames, verifies the results and reports
+// any errors.
+void RunBitexactnessTest(int sample_rate_hz,
+ size_t num_channels,
+ rtc::ArrayView<const float> output_reference) {
+ LevelController level_controller;
+ level_controller.Initialize(sample_rate_hz, num_channels);
+
+ int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
+ 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(), capture_config.num_channels(),
+ capture_config.num_frames());
+ test::InputAudioFile capture_file(
+ test::GetApmCaptureTestVectorFileName(sample_rate_hz));
+ std::vector<float> capture_input(samples_per_channel * num_channels);
+ for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
+ ReadFloatSamplesFromStereoFile(samples_per_channel, num_channels,
+ &capture_file, capture_input);
+
+ test::CopyVectorToAudioBuffer(capture_config, capture_input,
+ &capture_buffer);
+
+ level_controller.Process(&capture_buffer);
+ }
+
+ // Extract test results.
+ std::vector<float> capture_output;
+ test::ExtractVectorFromAudioBuffer(capture_config, &capture_buffer,
+ &capture_output);
+
+ // 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
hlundin-webrtc 2016/06/27 11:21:16 preceeding -> preceding
peah-webrtc 2016/06/27 22:51:49 Done.
+ // frames.
+ // TODO(peah): Activate bitexactness test
hlundin-webrtc 2016/06/27 11:21:16 I suggest you disable the tests by prepending DISA
peah-webrtc 2016/06/27 22:51:49 Good point! Done.
+ /*
+ EXPECT_TRUE(test::VerifyDeinterleavedArray(
+ capture_config.num_frames(), capture_config.num_channels(),
+ output_reference, capture_output, kVectorElementErrorBound));
+ */
+}
+
+} // namespace
+
+// TODO(peah): Add test vectors.
+TEST(LevelControlBitExactnessTest, Mono8kHzLow) {
hlundin-webrtc 2016/06/27 11:21:16 What does "low" mean?
peah-webrtc 2016/06/27 22:51:49 Don't know. Must be a type. Removed that. Done.
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Mono16kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Mono32kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Mono48kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Stereo8kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Stereo16kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Stereo32kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference);
+}
+
+TEST(LevelControlBitExactnessTest, Stereo48kHzLow) {
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
+ RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698