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

Unified Diff: webrtc/modules/audio_processing/vad/voice_activity_detector_unittest.cc

Issue 1181933002: Pull the Voice Activity Detector out from the AGC (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 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/vad/voice_activity_detector_unittest.cc
diff --git a/webrtc/modules/audio_processing/vad/voice_activity_detector_unittest.cc b/webrtc/modules/audio_processing/vad/voice_activity_detector_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..885f77f7d896c440231d8533c291475dde96fe95
--- /dev/null
+++ b/webrtc/modules/audio_processing/vad/voice_activity_detector_unittest.cc
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2015 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 "webrtc/modules/audio_processing/vad/voice_activity_detector.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/test/testsupport/fileutils.h"
+
+namespace webrtc {
+namespace {
+
+const double kDefaultVoiceValue = 1.0;
+
+} // namespace
+
+TEST(VoiceActivityDetectorTest, ConstructorSetsDefaultValues) {
+ VoiceActivityDetector vad;
+
+ std::vector<double> p = vad.chunkwise_voice_probabilities();
+ std::vector<double> rms = vad.chunkwise_rms();
+
+ EXPECT_EQ(p.size(), 0u);
+ EXPECT_EQ(rms.size(), 0u);
+
+ EXPECT_DOUBLE_EQ(vad.last_voice_probability(), kDefaultVoiceValue);
+}
+
+TEST(VoiceActivityDetectorTest, DetectsVoiceActivityCorrectly) {
+ const size_t kNumChunksPerIsacBlock = 3;
bloch 2015/06/17 22:27:49 At what point in the workflow is this value determ
aluebs-webrtc 2015/06/18 00:49:21 That is a restriction that ISAC imposes on the VAD
+
+ VoiceActivityDetector vad;
+
+ int16_t data[kLength10Ms];
+ double p_ref[kNumChunksPerIsacBlock];
+ double rms_ref[kNumChunksPerIsacBlock];
+ double voice_probability = kDefaultVoiceValue;
+
+ FILE* pcm_file =
+ fopen(test::ResourcePath("audio_processing/agc/agc_audio", "pcm").c_str(),
+ "rb");
+ ASSERT_TRUE(pcm_file != NULL);
+
+ FILE* voice_probability_file =
+ fopen(test::ResourcePath("audio_processing/vad/voice_probability", "dat")
+ .c_str(),
+ "rb");
+ ASSERT_TRUE(voice_probability_file != NULL);
+ FILE* rms_file = fopen(
+ test::ResourcePath("audio_processing/vad/rms", "dat").c_str(), "rb");
+ ASSERT_TRUE(rms_file != NULL);
+
+ size_t num_chunks = 0;
+ while (fread(data, sizeof(*data), kLength10Ms, pcm_file) == kLength10Ms) {
+ vad.ProcessCaptureAudio(data, kLength10Ms);
+
+ std::vector<double> p = vad.chunkwise_voice_probabilities();
+ std::vector<double> rms = vad.chunkwise_rms();
+
+ ++num_chunks %= kNumChunksPerIsacBlock;
+ if (num_chunks == 0) {
+ EXPECT_EQ(p.size(), kNumChunksPerIsacBlock);
+ EXPECT_EQ(rms.size(), kNumChunksPerIsacBlock);
+
+ ASSERT_EQ(fread(p_ref, sizeof(*p_ref), p.size(), voice_probability_file),
+ p.size());
+ ASSERT_EQ(fread(rms_ref, sizeof(*rms_ref), rms.size(), rms_file),
+ rms.size());
+
+ for (size_t i = 0u; i < p.size(); ++i) {
+ EXPECT_DOUBLE_EQ(p[i], p_ref[i]);
+ EXPECT_DOUBLE_EQ(rms[i], rms_ref[i]);
+ }
+
+ voice_probability = vad.last_voice_probability();
+
+ EXPECT_FLOAT_EQ(voice_probability, p[p.size() - 1]);
+ } else {
+ EXPECT_EQ(p.size(), 0u);
+ EXPECT_EQ(rms.size(), 0u);
+
+ EXPECT_DOUBLE_EQ(vad.last_voice_probability(), voice_probability);
+ }
+ }
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698