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

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: Changed VoiceActivityDetectorTest to use vector 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 <algorithm>
14 #include <vector>
15
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/test/testsupport/fileutils.h"
18
19 namespace webrtc {
20 namespace {
21
22 void GenerateNoise(std::vector<int16_t>* data) {
23 for (size_t i = 0; i < data->size(); ++i) {
24 // std::rand returns between 0 and RAND_MAX, but this will work because it
25 // wraps into some random place.
26 (*data)[i] = std::rand();
27 }
28 }
29
30 } // namespace
31
32 TEST(VoiceActivityDetectorTest, ConstructorSetsDefaultValues) {
bloch 2015/06/17 22:27:49 Where do you test your resampling (/sample rate)?
aluebs-webrtc 2015/06/18 00:49:22 That is a good point. Added tests for 32kHz audio
33 const float kDefaultVoiceValue = 1.f;
34
35 VoiceActivityDetector vad;
36
37 std::vector<double> p = vad.chunkwise_voice_probabilities();
38 std::vector<double> rms = vad.chunkwise_rms();
39
40 EXPECT_EQ(p.size(), 0u);
41 EXPECT_EQ(rms.size(), 0u);
42
43 EXPECT_FLOAT_EQ(vad.last_voice_probability(), kDefaultVoiceValue);
44 }
45
46 TEST(VoiceActivityDetectorTest, SpeechHasHighVoiceProbabilities) {
47 const float kMeanSpeechProbability = 0.3f;
48
49 VoiceActivityDetector vad;
50
51 std::vector<int16_t> data(kLength10Ms);
52 float mean_probability = 0.f;
53
54 FILE* pcm_file =
55 fopen(test::ResourcePath("audio_processing/agc/agc_audio", "pcm").c_str(),
56 "rb");
57 ASSERT_TRUE(pcm_file != NULL);
58
59 size_t num_chunks = 0;
60 while (fread(&data[0], sizeof(data[0]), data.size(), pcm_file) ==
61 data.size()) {
62 vad.ProcessChunk(&data[0], data.size(), kSampleRateHz);
63
64 mean_probability += vad.last_voice_probability();
65
66 ++num_chunks;
67 }
68
69 mean_probability /= num_chunks;
70
71 EXPECT_GT(mean_probability, kMeanSpeechProbability);
72 }
73
74 TEST(VoiceActivityDetectorTest, NoiseHasLowVoiceProbabilities) {
75 const float kMaxNoiseProbability = 0.05f;
76 const size_t kNumChunks = 100u;
77 const size_t kNumChunksPerIsacBlock = 3;
78
79 VoiceActivityDetector vad;
80
81 std::vector<int16_t> data(kLength10Ms);
82 float max_probability = 0.f;
83
84 std::srand(42);
85
86 for (size_t i = 0; i < kNumChunks; ++i) {
87 GenerateNoise(&data);
88
89 vad.ProcessChunk(&data[0], data.size(), kSampleRateHz);
90
91 if (i > kNumChunksPerIsacBlock) {
92 max_probability = std::max(max_probability, vad.last_voice_probability());
93 }
94 }
95
96 EXPECT_LT(max_probability, kMaxNoiseProbability);
97 }
98
99 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698