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..ae8d41b6437ec0bd3b87437c8503c2de9e072129 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/level_controller/level_controller_unittest.cc |
@@ -0,0 +1,112 @@ |
+/* |
+ * 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/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); |
+ |
+ 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 |
+ // preceding frames as testvectors. As the algorithm being tested has a |
+ // memory, testing only the last frame implicitly also tests the preceeding |
+ // frames. |
+ const float kVectorElementErrorBound = 1.0f / 32768.0f; |
+ EXPECT_TRUE(test::VerifyDeinterleavedArray( |
+ capture_config.num_frames(), capture_config.num_channels(), |
+ output_reference, capture_output, kVectorElementErrorBound)); |
+} |
+ |
+} // namespace |
+ |
+// TODO(peah): Add test vectors and enable the tests. |
+TEST(LevelControlBitExactnessTest, Mono8kHz_DISABLED) { |
hlundin-webrtc
2016/06/28 11:29:01
Should be DISABLED_Mono8kHz, otherwise the test wi
peah-webrtc
2016/06/28 22:19:38
Done.
|
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Mono16kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Mono32kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Mono48kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Stereo8kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Stereo16kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Stereo32kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference); |
+} |
+ |
+TEST(LevelControlBitExactnessTest, Stereo48kHz_DISABLED) { |
+ const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f}; |
+ RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference); |
+} |
+ |
+} // namespace webrtc |