OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/transient/transient_suppressor.h" | 11 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <cmath> | 15 #include <cmath> |
16 #include <complex> | 16 #include <complex> |
17 #include <deque> | 17 #include <deque> |
18 #include <set> | 18 #include <set> |
19 | 19 |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
21 #include "webrtc/common_audio/fft4g.h" | 21 #include "webrtc/common_audio/fft4g.h" |
22 #include "webrtc/common_audio/include/audio_util.h" | 22 #include "webrtc/common_audio/include/audio_util.h" |
23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
24 #include "webrtc/modules/audio_processing/transient/common.h" | 24 #include "webrtc/modules/audio_processing/transient/common.h" |
25 #include "webrtc/modules/audio_processing/transient/transient_detector.h" | 25 #include "webrtc/modules/audio_processing/transient/transient_detector.h" |
26 #include "webrtc/modules/audio_processing/ns/windows_private.h" | 26 #include "webrtc/modules/audio_processing/ns/windows_private.h" |
27 #include "webrtc/system_wrappers/include/logging.h" | |
28 #include "webrtc/typedefs.h" | 27 #include "webrtc/typedefs.h" |
29 | 28 |
30 namespace webrtc { | 29 namespace webrtc { |
31 | 30 |
32 static const float kMeanIIRCoefficient = 0.5f; | 31 static const float kMeanIIRCoefficient = 0.5f; |
33 static const float kVoiceThreshold = 0.02f; | 32 static const float kVoiceThreshold = 0.02f; |
34 | 33 |
35 // TODO(aluebs): Check if these values work also for 48kHz. | 34 // TODO(aluebs): Check if these values work also for 48kHz. |
36 static const size_t kMinVoiceBin = 3; | 35 static const size_t kMinVoiceBin = 3; |
37 static const size_t kMaxVoiceBin = 60; | 36 static const size_t kMaxVoiceBin = 60; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 287 |
289 if (key_pressed) { | 288 if (key_pressed) { |
290 keypress_counter_ += kKeypressPenalty; | 289 keypress_counter_ += kKeypressPenalty; |
291 chunks_since_keypress_ = 0; | 290 chunks_since_keypress_ = 0; |
292 detection_enabled_ = true; | 291 detection_enabled_ = true; |
293 } | 292 } |
294 keypress_counter_ = std::max(0, keypress_counter_ - 1); | 293 keypress_counter_ = std::max(0, keypress_counter_ - 1); |
295 | 294 |
296 if (keypress_counter_ > kIsTypingThreshold) { | 295 if (keypress_counter_ > kIsTypingThreshold) { |
297 if (!suppression_enabled_) { | 296 if (!suppression_enabled_) { |
298 LOG(LS_INFO) << "[ts] Transient suppression is now enabled."; | |
299 } | 297 } |
300 suppression_enabled_ = true; | 298 suppression_enabled_ = true; |
301 keypress_counter_ = 0; | 299 keypress_counter_ = 0; |
302 } | 300 } |
303 | 301 |
304 if (detection_enabled_ && | 302 if (detection_enabled_ && |
305 ++chunks_since_keypress_ > kChunksUntilNotTyping) { | 303 ++chunks_since_keypress_ > kChunksUntilNotTyping) { |
306 if (suppression_enabled_) { | 304 if (suppression_enabled_) { |
307 LOG(LS_INFO) << "[ts] Transient suppression is now disabled."; | |
308 } | 305 } |
309 detection_enabled_ = false; | 306 detection_enabled_ = false; |
310 suppression_enabled_ = false; | 307 suppression_enabled_ = false; |
311 keypress_counter_ = 0; | 308 keypress_counter_ = 0; |
312 } | 309 } |
313 } | 310 } |
314 | 311 |
315 void TransientSuppressor::UpdateRestoration(float voice_probability) { | 312 void TransientSuppressor::UpdateRestoration(float voice_probability) { |
316 const int kHardRestorationOffsetDelay = 3; | 313 const int kHardRestorationOffsetDelay = 3; |
317 const int kHardRestorationOnsetDelay = 80; | 314 const int kHardRestorationOnsetDelay = 80; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 const float magnitude_ratio = new_magnitude / magnitudes_[i]; | 412 const float magnitude_ratio = new_magnitude / magnitudes_[i]; |
416 | 413 |
417 fft_buffer_[i * 2] *= magnitude_ratio; | 414 fft_buffer_[i * 2] *= magnitude_ratio; |
418 fft_buffer_[i * 2 + 1] *= magnitude_ratio; | 415 fft_buffer_[i * 2 + 1] *= magnitude_ratio; |
419 magnitudes_[i] = new_magnitude; | 416 magnitudes_[i] = new_magnitude; |
420 } | 417 } |
421 } | 418 } |
422 } | 419 } |
423 | 420 |
424 } // namespace webrtc | 421 } // namespace webrtc |
OLD | NEW |