| 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..d584d37c9337b69f512cd0ad8cbafe486ce685b6
|
| --- /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, DISABLED_Mono8kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Mono16kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Mono32kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 1, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Mono48kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 1, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Stereo8kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 2, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Stereo16kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 2, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Stereo32kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate32kHz, 2, kOutputReference);
|
| +}
|
| +
|
| +TEST(LevelControlBitExactnessTest, DISABLED_Stereo48kHz) {
|
| + const float kOutputReference[] = {0.003263f, 0.004402f, 0.004537f};
|
| + RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference);
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|