OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/vad/standalone_vad.h" | 11 #include "webrtc/modules/audio_processing/vad/standalone_vad.h" |
12 | 12 |
13 #include <assert.h> | 13 #include "webrtc/base/checks.h" |
14 | |
15 #include "webrtc/modules/include/module_common_types.h" | 14 #include "webrtc/modules/include/module_common_types.h" |
16 #include "webrtc/modules/utility/include/audio_frame_operations.h" | 15 #include "webrtc/modules/utility/include/audio_frame_operations.h" |
17 #include "webrtc/typedefs.h" | 16 #include "webrtc/typedefs.h" |
18 | 17 |
19 namespace webrtc { | 18 namespace webrtc { |
20 | 19 |
21 static const int kDefaultStandaloneVadMode = 3; | 20 static const int kDefaultStandaloneVadMode = 3; |
22 | 21 |
23 StandaloneVad::StandaloneVad(VadInst* vad) | 22 StandaloneVad::StandaloneVad(VadInst* vad) |
24 : vad_(vad), buffer_(), index_(0), mode_(kDefaultStandaloneVadMode) { | 23 : vad_(vad), buffer_(), index_(0), mode_(kDefaultStandaloneVadMode) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return 0; | 56 return 0; |
58 } | 57 } |
59 | 58 |
60 int StandaloneVad::GetActivity(double* p, size_t length_p) { | 59 int StandaloneVad::GetActivity(double* p, size_t length_p) { |
61 if (index_ == 0) | 60 if (index_ == 0) |
62 return -1; | 61 return -1; |
63 | 62 |
64 const size_t num_frames = index_ / kLength10Ms; | 63 const size_t num_frames = index_ / kLength10Ms; |
65 if (num_frames > length_p) | 64 if (num_frames > length_p) |
66 return -1; | 65 return -1; |
67 assert(WebRtcVad_ValidRateAndFrameLength(kSampleRateHz, index_) == 0); | 66 RTC_DCHECK_EQ(0, WebRtcVad_ValidRateAndFrameLength(kSampleRateHz, index_)); |
68 | 67 |
69 int activity = WebRtcVad_Process(vad_, kSampleRateHz, buffer_, index_); | 68 int activity = WebRtcVad_Process(vad_, kSampleRateHz, buffer_, index_); |
70 if (activity < 0) | 69 if (activity < 0) |
71 return -1; | 70 return -1; |
72 else if (activity == 0) | 71 else if (activity == 0) |
73 p[0] = 0.01; // Arbitrary but small and non-zero. | 72 p[0] = 0.01; // Arbitrary but small and non-zero. |
74 else | 73 else |
75 p[0] = 0.5; // 0.5 is neutral values when combinned by other probabilities. | 74 p[0] = 0.5; // 0.5 is neutral values when combinned by other probabilities. |
76 for (size_t n = 1; n < num_frames; n++) | 75 for (size_t n = 1; n < num_frames; n++) |
77 p[n] = p[0]; | 76 p[n] = p[0]; |
78 // Reset the buffer to start from the beginning. | 77 // Reset the buffer to start from the beginning. |
79 index_ = 0; | 78 index_ = 0; |
80 return activity; | 79 return activity; |
81 } | 80 } |
82 | 81 |
83 int StandaloneVad::set_mode(int mode) { | 82 int StandaloneVad::set_mode(int mode) { |
84 if (mode < 0 || mode > 3) | 83 if (mode < 0 || mode > 3) |
85 return -1; | 84 return -1; |
86 if (WebRtcVad_set_mode(vad_, mode) != 0) | 85 if (WebRtcVad_set_mode(vad_, mode) != 0) |
87 return -1; | 86 return -1; |
88 | 87 |
89 mode_ = mode; | 88 mode_ = mode; |
90 return 0; | 89 return 0; |
91 } | 90 } |
92 | 91 |
93 } // namespace webrtc | 92 } // namespace webrtc |
OLD | NEW |