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

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: Test without relying on golden output 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..c380ddccd415b90f29e9b839eb6cae66f6ab2ca0
--- /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 <algorithm>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/test/testsupport/fileutils.h"
+
+namespace webrtc {
+namespace {
+
+const double kDefaultVoiceValue = 1.0;
+const float kMeanSpeechProbability = 0.3f;
+const float kMaxNoiseProbability = 0.05f;
Andrew MacDonald 2015/06/17 04:14:57 Move these three to the tests where they're used.
aluebs-webrtc 2015/06/17 17:22:03 Done. And yes, there are a few (2 or 3) values whi
+const size_t kNumChunks = 100u;
+const size_t kNumChunksPerIsacBlock = 3;
+
+void GenerateNoise(int16_t* data, size_t length) {
+ for (size_t i = 0; i < length; ++i) {
+ data[i] = std::rand();
Andrew MacDonald 2015/06/17 04:14:57 std::rand returns between 0 and RAND_MAX. I guess
aluebs-webrtc 2015/06/17 17:22:04 Yes, I know, but I assumed the wrapping would stil
+ }
+}
+
+} // 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);
Andrew MacDonald 2015/06/17 04:14:57 EXPECT_FLOAT_EQ
aluebs-webrtc 2015/06/17 17:22:03 I forgot to change this after the double->float ch
+}
+
+TEST(VoiceActivityDetectorTest, SpeechHasHighVoiceProbabilities) {
+ VoiceActivityDetector vad;
+
+ int16_t data[kLength10Ms];
+ float mean_probability = 0.f;
+
+ FILE* pcm_file =
+ fopen(test::ResourcePath("audio_processing/agc/agc_audio", "pcm").c_str(),
Andrew MacDonald 2015/06/17 04:14:57 What is actually in this file? Is it mostly speech
aluebs-webrtc 2015/06/17 17:22:03 Yes, there is some utterances with some silence in
+ "rb");
+ ASSERT_TRUE(pcm_file != NULL);
+
+ size_t num_chunks = 0;
+ while (fread(data, sizeof(*data), kLength10Ms, pcm_file) == kLength10Ms) {
+ vad.ProcessChunk(data, kLength10Ms, kSampleRateHz);
+
+ mean_probability += vad.last_voice_probability();
+
+ ++num_chunks;
+ }
+
+ mean_probability /= num_chunks;
+
+ EXPECT_GT(mean_probability, kMeanSpeechProbability);
+}
+
+TEST(VoiceActivityDetectorTest, NoiseHasLowVoiceProbabilities) {
+ VoiceActivityDetector vad;
+
+ int16_t data[kLength10Ms];
Andrew MacDonald 2015/06/17 04:14:56 nit: Use a vector? Then you don't need to pass the
aluebs-webrtc 2015/06/17 17:22:03 Done.
+ float max_probability = 0.f;
+
+ std::srand(42);
+
+ for (size_t i = 0; i < kNumChunks; ++i) {
+ GenerateNoise(data, kLength10Ms);
+
+ vad.ProcessChunk(data, kLength10Ms, kSampleRateHz);
+
+ if (i > kNumChunksPerIsacBlock) {
Andrew MacDonald 2015/06/17 04:14:57 Do you need to know about this? Why not just check
aluebs-webrtc 2015/06/17 17:22:04 Because before the vad has enough data to process
Andrew MacDonald 2015/06/17 21:15:14 Ah OK. Perhaps add a comment to that effect.
aluebs-webrtc 2015/06/18 00:49:21 Done.
+ max_probability = std::max(max_probability, vad.last_voice_probability());
+ }
+ }
+
+ EXPECT_LT(max_probability, kMaxNoiseProbability);
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/modules/audio_processing/vad/voice_activity_detector.cc ('k') | webrtc/modules/audio_processing/vad/voice_gmm_tables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698