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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/vad/voice_activity_detector.h"
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/test/testsupport/fileutils.h"
15
16 namespace webrtc {
17 namespace {
18
19 const double kDefaultVoiceValue = 1.0;
20
21 } // namespace
22
23 TEST(VoiceActivityDetectorTest, ConstructorSetsDefaultValues) {
24 VoiceActivityDetector vad;
25
26 std::vector<double> p = vad.chunkwise_voice_probabilities();
27 std::vector<double> rms = vad.chunkwise_rms();
28
29 EXPECT_EQ(p.size(), 0u);
30 EXPECT_EQ(rms.size(), 0u);
31
32 EXPECT_DOUBLE_EQ(vad.last_voice_probability(), kDefaultVoiceValue);
33 }
34
35 TEST(VoiceActivityDetectorTest, DetectsVoiceActivityCorrectly) {
36 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
37
38 VoiceActivityDetector vad;
39
40 int16_t data[kLength10Ms];
41 double p_ref[kNumChunksPerIsacBlock];
42 double rms_ref[kNumChunksPerIsacBlock];
43 double voice_probability = kDefaultVoiceValue;
44
45 FILE* pcm_file =
46 fopen(test::ResourcePath("audio_processing/agc/agc_audio", "pcm").c_str(),
47 "rb");
48 ASSERT_TRUE(pcm_file != NULL);
49
50 FILE* voice_probability_file =
51 fopen(test::ResourcePath("audio_processing/vad/voice_probability", "dat")
52 .c_str(),
53 "rb");
54 ASSERT_TRUE(voice_probability_file != NULL);
55 FILE* rms_file = fopen(
56 test::ResourcePath("audio_processing/vad/rms", "dat").c_str(), "rb");
57 ASSERT_TRUE(rms_file != NULL);
58
59 size_t num_chunks = 0;
60 while (fread(data, sizeof(*data), kLength10Ms, pcm_file) == kLength10Ms) {
61 vad.ProcessCaptureAudio(data, kLength10Ms);
62
63 std::vector<double> p = vad.chunkwise_voice_probabilities();
64 std::vector<double> rms = vad.chunkwise_rms();
65
66 ++num_chunks %= kNumChunksPerIsacBlock;
67 if (num_chunks == 0) {
68 EXPECT_EQ(p.size(), kNumChunksPerIsacBlock);
69 EXPECT_EQ(rms.size(), kNumChunksPerIsacBlock);
70
71 ASSERT_EQ(fread(p_ref, sizeof(*p_ref), p.size(), voice_probability_file),
72 p.size());
73 ASSERT_EQ(fread(rms_ref, sizeof(*rms_ref), rms.size(), rms_file),
74 rms.size());
75
76 for (size_t i = 0u; i < p.size(); ++i) {
77 EXPECT_DOUBLE_EQ(p[i], p_ref[i]);
78 EXPECT_DOUBLE_EQ(rms[i], rms_ref[i]);
79 }
80
81 voice_probability = vad.last_voice_probability();
82
83 EXPECT_FLOAT_EQ(voice_probability, p[p.size() - 1]);
84 } else {
85 EXPECT_EQ(p.size(), 0u);
86 EXPECT_EQ(rms.size(), 0u);
87
88 EXPECT_DOUBLE_EQ(vad.last_voice_probability(), voice_probability);
89 }
90 }
91 }
92
93 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698