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 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <memory> | 17 #include <memory> |
18 | 18 |
19 #include "webrtc/base/flags.h" | 19 #include "webrtc/base/flags.h" |
| 20 #include "webrtc/base/safe_minmax.h" |
20 #include "webrtc/modules/audio_processing/agc/agc.h" | 21 #include "webrtc/modules/audio_processing/agc/agc.h" |
21 #include "webrtc/modules/audio_processing/agc/loudness_histogram.h" | 22 #include "webrtc/modules/audio_processing/agc/loudness_histogram.h" |
22 #include "webrtc/modules/audio_processing/agc/utility.h" | 23 #include "webrtc/modules/audio_processing/agc/utility.h" |
23 #include "webrtc/modules/audio_processing/vad/common.h" | 24 #include "webrtc/modules/audio_processing/vad/common.h" |
24 #include "webrtc/modules/audio_processing/vad/pitch_based_vad.h" | 25 #include "webrtc/modules/audio_processing/vad/pitch_based_vad.h" |
25 #include "webrtc/modules/audio_processing/vad/standalone_vad.h" | 26 #include "webrtc/modules/audio_processing/vad/standalone_vad.h" |
26 #include "webrtc/modules/audio_processing/vad/vad_audio_proc.h" | 27 #include "webrtc/modules/audio_processing/vad/vad_audio_proc.h" |
27 #include "webrtc/modules/include/module_common_types.h" | 28 #include "webrtc/modules/include/module_common_types.h" |
28 #include "webrtc/test/gtest.h" | 29 #include "webrtc/test/gtest.h" |
29 | 30 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 double p[kMaxNumFrames] = {0.5, 0.5, 0.5, 0.5}; | 115 double p[kMaxNumFrames] = {0.5, 0.5, 0.5, 0.5}; |
115 if (FLAG_standalone_vad) { | 116 if (FLAG_standalone_vad) { |
116 standalone_vad_->GetActivity(p, kMaxNumFrames); | 117 standalone_vad_->GetActivity(p, kMaxNumFrames); |
117 } | 118 } |
118 // TODO(turajs) combining and limiting are used in the source files as | 119 // TODO(turajs) combining and limiting are used in the source files as |
119 // well they can be moved to utility. | 120 // well they can be moved to utility. |
120 // Combine Video and stand-alone VAD. | 121 // Combine Video and stand-alone VAD. |
121 for (size_t n = 0; n < features.num_frames; n++) { | 122 for (size_t n = 0; n < features.num_frames; n++) { |
122 double p_active = p[n] * video_vad_[n]; | 123 double p_active = p[n] * video_vad_[n]; |
123 double p_passive = (1 - p[n]) * (1 - video_vad_[n]); | 124 double p_passive = (1 - p[n]) * (1 - video_vad_[n]); |
124 p[n] = p_active / (p_active + p_passive); | 125 p[n] = rtc::SafeClamp(p_active / (p_active + p_passive), 0.01, 0.99); |
125 // Limit probabilities. | |
126 p[n] = std::min(std::max(p[n], 0.01), 0.99); | |
127 } | 126 } |
128 if (vad_->VoicingProbability(features, p) < 0) | 127 if (vad_->VoicingProbability(features, p) < 0) |
129 return -1; | 128 return -1; |
130 for (size_t n = 0; n < features.num_frames; n++) { | 129 for (size_t n = 0; n < features.num_frames; n++) { |
131 audio_content_->Update(features.rms[n], p[n]); | 130 audio_content_->Update(features.rms[n], p[n]); |
132 double ac = audio_content_->AudioContent(); | 131 double ac = audio_content_->AudioContent(); |
133 if (audio_content_fid_ != NULL) { | 132 if (audio_content_fid_ != NULL) { |
134 fwrite(&ac, sizeof(ac), 1, audio_content_fid_); | 133 fwrite(&ac, sizeof(ac), 1, audio_content_fid_); |
135 } | 134 } |
136 if (ac > kAgcAnalWindowSamples * activity_threshold_) { | 135 if (ac > kAgcAnalWindowSamples * activity_threshold_) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return 0; | 384 return 0; |
386 } | 385 } |
387 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); | 386 rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); |
388 if (FLAG_help) { | 387 if (FLAG_help) { |
389 rtc::FlagList::Print(nullptr, false); | 388 rtc::FlagList::Print(nullptr, false); |
390 return 0; | 389 return 0; |
391 } | 390 } |
392 webrtc::void_main(argc, argv); | 391 webrtc::void_main(argc, argv); |
393 return 0; | 392 return 0; |
394 } | 393 } |
OLD | NEW |