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

Unified Diff: webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc

Issue 1811443002: Added a bitexactness test for the level estimator in the audio processing module (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@NsBitLatest_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
Index: webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc
diff --git a/webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc b/webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d833d374c394231263f094374ff1fbdd76c2cf86
--- /dev/null
+++ b/webrtc/modules/audio_processing/level_estimator_bitexactness_unittest.cc
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
hlundin-webrtc 2016/03/16 12:57:05 2016
peah-webrtc 2016/03/17 14:18:06 Done.
+ *
+ * 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/base/random.h"
+#include "webrtc/modules/audio_processing/audio_buffer.h"
+#include "webrtc/modules/audio_processing/level_estimator_impl.h"
+#include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
+#include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
+
+namespace webrtc {
+namespace {
+
+enum TestSignalLevels { kLow, kMedium, kHigh };
+
+// Process one frame of data and produce the output.
+void ProcessOneFrame(int sample_rate_hz,
+ AudioBuffer* audio_buffer,
+ LevelEstimatorImpl* level_estimator,
+ int* rms) {
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
hlundin-webrtc 2016/03/16 12:57:05 What is the purpose of splitting and merging bands
peah-webrtc 2016/03/17 14:18:06 None, removed that code. Done.
+ audio_buffer->SplitIntoFrequencyBands();
+ }
+
+ if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) {
+ audio_buffer->MergeFrequencyBands();
+ }
+ level_estimator->ProcessStream(audio_buffer);
+ *rms = level_estimator->RMS();
+}
+
+// Forms a predefined random test vector.
+void ConstructTestVector(int samples_per_channel,
hlundin-webrtc 2016/03/16 12:57:05 This seems very similar to the function in the pre
peah-webrtc 2016/03/17 14:18:06 Done.
+ int num_channels,
+ int frame_counter,
+ Random* rand_gen,
+ TestSignalLevels signal_level,
+ std::vector<float>* testvector) {
+ testvector->resize(samples_per_channel * num_channels);
+
+ float signal_gain = 0.0f;
+ switch (signal_level) {
+ case TestSignalLevels::kLow:
+ signal_gain = 0.1f;
+ break;
+ case TestSignalLevels::kMedium:
+ signal_gain = 0.5f;
+ break;
+ case TestSignalLevels::kHigh:
+ signal_gain = 1.0f;
+ break;
+ default:
+ RTC_DCHECK(false);
+ }
+
+ bool low_level = ((frame_counter / 10) > 5);
+ float scale = (low_level ? 0.01f : 1.0f);
+ for (auto& v : *testvector) {
+ v = signal_gain * scale * (2.0f * rand_gen->Rand<float>() - 1.0f);
+ }
+}
+
+void SetupComponent(LevelEstimatorImpl* level_estimator) {
+ level_estimator->Initialize();
+ level_estimator->Enable(true);
+}
+
+// Processes a specified amount of frames, verifies the results and reports
+// any errors.
+void RunBitexactnessTest(int sample_rate_hz,
minyue-webrtc 2016/03/16 09:55:01 Is |rms_reference| derivable from |signal_level|,
peah-webrtc 2016/03/17 14:18:06 No, signal_level was just a scaling of the signal
+ int num_channels,
+ int num_frames_to_process,
+ TestSignalLevels signal_level,
+ int rms_reference) {
+ Random rand_gen(42);
+ int samples_per_channel = 80 * sample_rate_hz / 8000;
+ const StreamConfig stream_config(sample_rate_hz, num_channels, false);
+ AudioBuffer audio_buffer(
+ stream_config.num_frames(), stream_config.num_channels(),
+ stream_config.num_frames(), stream_config.num_channels(),
+ stream_config.num_frames());
+
+ rtc::CriticalSection crit;
+ LevelEstimatorImpl level_estimator(&crit);
+ SetupComponent(&level_estimator);
+
+ int rms = 0;
+ std::vector<float> frame_input;
+ for (int frame_no = 0; frame_no < num_frames_to_process; ++frame_no) {
+ ConstructTestVector(samples_per_channel, num_channels, frame_no, &rand_gen,
+ signal_level, &frame_input);
+
+ test::CopyVectorToAudioBuffer(stream_config, frame_input, &audio_buffer);
+
+ ProcessOneFrame(sample_rate_hz, &audio_buffer, &level_estimator, &rms);
+ }
+
+ // Compare the output to the reference.
+ EXPECT_PRED_FORMAT2(test::AssertIntegersNotEqual, rms, rms_reference);
hlundin-webrtc 2016/03/16 12:57:05 EXPECT_NEAR
peah-webrtc 2016/03/17 14:18:06 Changed to EXPECT_EQ instead. Done.
+}
+
+} // namespace
+
+TEST(LevelEstimatorBitExactnessTest, Mono8kHzLow) {
+ const int kRmsReference = 65;
hlundin-webrtc 2016/03/16 12:57:05 You are using three different values for kRmsRefer
peah-webrtc 2016/03/17 14:18:06 I'm not too happy about that. It may be that they
hlundin-webrtc 2016/03/17 15:20:57 Fair enough, now that you have fewer test cases.
peah-webrtc 2016/03/20 15:40:55 Acknowledged.
+
+ RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kLow, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono16kHzLow) {
+ const int kRmsReference = 65;
+
+ RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kLow, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono32kHzLow) {
+ const int kRmsReference = 65;
+
+ RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kLow, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono48kHzLow) {
+ const int kRmsReference = 65;
+
+ RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kLow, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Stereo16kHzLow) {
+ const int kRmsReference = 65;
+
+ RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kLow, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono8kHzMedium) {
+ const int kRmsReference = 51;
+
+ RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono16kHzMedium) {
+ const int kRmsReference = 51;
+
+ RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono32kHzMedium) {
+ const int kRmsReference = 51;
+
+ RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono48kHzMedium) {
+ const int kRmsReference = 51;
+
+ RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kMedium, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Stereo16kHzMedium) {
+ const int kRmsReference = 51;
+
+ RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kMedium, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono8kHzHigh) {
+ const int kRmsReference = 45;
+
+ RunBitexactnessTest(8000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono16kHzHigh) {
+ const int kRmsReference = 45;
+
+ RunBitexactnessTest(16000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono32kHzHigh) {
+ const int kRmsReference = 45;
+
+ RunBitexactnessTest(32000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Mono48kHzHigh) {
+ const int kRmsReference = 45;
+
+ RunBitexactnessTest(48000, 1, 200, TestSignalLevels::kHigh, kRmsReference);
+}
+
+TEST(LevelEstimatorBitExactnessTest, Stereo16kHzHigh) {
+ const int kRmsReference = 45;
+
+ RunBitexactnessTest(16000, 2, 200, TestSignalLevels::kHigh, kRmsReference);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698