| 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void PostDecodeVad::Init() { | 39 void PostDecodeVad::Init() { |
| 40 running_ = false; | 40 running_ = false; |
| 41 if (vad_instance_) { | 41 if (vad_instance_) { |
| 42 WebRtcVad_Init(vad_instance_); | 42 WebRtcVad_Init(vad_instance_); |
| 43 WebRtcVad_set_mode(vad_instance_, kVadMode); | 43 WebRtcVad_set_mode(vad_instance_, kVadMode); |
| 44 running_ = true; | 44 running_ = true; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void PostDecodeVad::Update(int16_t* signal, int length, | 48 void PostDecodeVad::Update(int16_t* signal, size_t length, |
| 49 AudioDecoder::SpeechType speech_type, | 49 AudioDecoder::SpeechType speech_type, |
| 50 bool sid_frame, | 50 bool sid_frame, |
| 51 int fs_hz) { | 51 int fs_hz) { |
| 52 if (!vad_instance_ || !enabled_) { | 52 if (!vad_instance_ || !enabled_) { |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (speech_type == AudioDecoder::kComfortNoise || sid_frame || | 56 if (speech_type == AudioDecoder::kComfortNoise || sid_frame || |
| 57 fs_hz > 16000) { | 57 fs_hz > 16000) { |
| 58 // TODO(hlundin): Remove restriction on fs_hz. | 58 // TODO(hlundin): Remove restriction on fs_hz. |
| 59 running_ = false; | 59 running_ = false; |
| 60 active_speech_ = true; | 60 active_speech_ = true; |
| 61 sid_interval_counter_ = 0; | 61 sid_interval_counter_ = 0; |
| 62 } else if (!running_) { | 62 } else if (!running_) { |
| 63 ++sid_interval_counter_; | 63 ++sid_interval_counter_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 if (sid_interval_counter_ >= kVadAutoEnable) { | 66 if (sid_interval_counter_ >= kVadAutoEnable) { |
| 67 Init(); | 67 Init(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (length > 0 && running_) { | 70 if (length > 0 && running_) { |
| 71 int vad_sample_index = 0; | 71 size_t vad_sample_index = 0; |
| 72 active_speech_ = false; | 72 active_speech_ = false; |
| 73 // Loop through frame sizes 30, 20, and 10 ms. | 73 // Loop through frame sizes 30, 20, and 10 ms. |
| 74 for (int vad_frame_size_ms = 30; vad_frame_size_ms >= 10; | 74 for (int vad_frame_size_ms = 30; vad_frame_size_ms >= 10; |
| 75 vad_frame_size_ms -= 10) { | 75 vad_frame_size_ms -= 10) { |
| 76 int vad_frame_size_samples = vad_frame_size_ms * fs_hz / 1000; | 76 size_t vad_frame_size_samples = |
| 77 static_cast<size_t>(vad_frame_size_ms * fs_hz / 1000); |
| 77 while (length - vad_sample_index >= vad_frame_size_samples) { | 78 while (length - vad_sample_index >= vad_frame_size_samples) { |
| 78 int vad_return = WebRtcVad_Process( | 79 int vad_return = WebRtcVad_Process( |
| 79 vad_instance_, fs_hz, &signal[vad_sample_index], | 80 vad_instance_, fs_hz, &signal[vad_sample_index], |
| 80 vad_frame_size_samples); | 81 vad_frame_size_samples); |
| 81 active_speech_ |= (vad_return == 1); | 82 active_speech_ |= (vad_return == 1); |
| 82 vad_sample_index += vad_frame_size_samples; | 83 vad_sample_index += vad_frame_size_samples; |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace webrtc | 89 } // namespace webrtc |
| OLD | NEW |