| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using VarianceType = intelligibility::VarianceArray::StepType; | 47 using VarianceType = intelligibility::VarianceArray::StepType; |
| 48 | 48 |
| 49 IntelligibilityEnhancer::TransformCallback::TransformCallback( | 49 IntelligibilityEnhancer::TransformCallback::TransformCallback( |
| 50 IntelligibilityEnhancer* parent, | 50 IntelligibilityEnhancer* parent, |
| 51 IntelligibilityEnhancer::AudioSource source) | 51 IntelligibilityEnhancer::AudioSource source) |
| 52 : parent_(parent), source_(source) { | 52 : parent_(parent), source_(source) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 void IntelligibilityEnhancer::TransformCallback::ProcessAudioBlock( | 55 void IntelligibilityEnhancer::TransformCallback::ProcessAudioBlock( |
| 56 const complex<float>* const* in_block, | 56 const complex<float>* const* in_block, |
| 57 int in_channels, | 57 size_t in_channels, |
| 58 size_t frames, | 58 size_t frames, |
| 59 int /* out_channels */, | 59 size_t /* out_channels */, |
| 60 complex<float>* const* out_block) { | 60 complex<float>* const* out_block) { |
| 61 DCHECK_EQ(parent_->freqs_, frames); | 61 DCHECK_EQ(parent_->freqs_, frames); |
| 62 for (int i = 0; i < in_channels; ++i) { | 62 for (size_t i = 0; i < in_channels; ++i) { |
| 63 parent_->DispatchAudio(source_, in_block[i], out_block[i]); | 63 parent_->DispatchAudio(source_, in_block[i], out_block[i]); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 IntelligibilityEnhancer::IntelligibilityEnhancer(size_t erb_resolution, | 67 IntelligibilityEnhancer::IntelligibilityEnhancer(size_t erb_resolution, |
| 68 int sample_rate_hz, | 68 int sample_rate_hz, |
| 69 int channels, | 69 size_t channels, |
| 70 int cv_type, | 70 int cv_type, |
| 71 float cv_alpha, | 71 float cv_alpha, |
| 72 size_t cv_win, | 72 size_t cv_win, |
| 73 int analysis_rate, | 73 int analysis_rate, |
| 74 int variance_rate, | 74 int variance_rate, |
| 75 float gain_limit) | 75 float gain_limit) |
| 76 : freqs_(RealFourier::ComplexLength( | 76 : freqs_(RealFourier::ComplexLength( |
| 77 RealFourier::FftOrder(sample_rate_hz * kWindowSizeMs / 1000))), | 77 RealFourier::FftOrder(sample_rate_hz * kWindowSizeMs / 1000))), |
| 78 window_size_(static_cast<size_t>(1 << RealFourier::FftOrder(freqs_))), | 78 window_size_(static_cast<size_t>(1 << RealFourier::FftOrder(freqs_))), |
| 79 chunk_length_(static_cast<size_t>(sample_rate_hz * kChunkSizeMs / 1000)), | 79 chunk_length_(static_cast<size_t>(sample_rate_hz * kChunkSizeMs / 1000)), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 110 CreateErbBank(); | 110 CreateErbBank(); |
| 111 | 111 |
| 112 WebRtcVad_Init(vad_high_); | 112 WebRtcVad_Init(vad_high_); |
| 113 WebRtcVad_set_mode(vad_high_, 0); // High likelihood of speech. | 113 WebRtcVad_set_mode(vad_high_, 0); // High likelihood of speech. |
| 114 WebRtcVad_Init(vad_low_); | 114 WebRtcVad_Init(vad_low_); |
| 115 WebRtcVad_set_mode(vad_low_, 3); // Low likelihood of speech. | 115 WebRtcVad_set_mode(vad_low_, 3); // Low likelihood of speech. |
| 116 | 116 |
| 117 temp_out_buffer_ = static_cast<float**>( | 117 temp_out_buffer_ = static_cast<float**>( |
| 118 malloc(sizeof(*temp_out_buffer_) * channels_ + | 118 malloc(sizeof(*temp_out_buffer_) * channels_ + |
| 119 sizeof(**temp_out_buffer_) * chunk_length_ * channels_)); | 119 sizeof(**temp_out_buffer_) * chunk_length_ * channels_)); |
| 120 for (int i = 0; i < channels_; ++i) { | 120 for (size_t i = 0; i < channels_; ++i) { |
| 121 temp_out_buffer_[i] = | 121 temp_out_buffer_[i] = |
| 122 reinterpret_cast<float*>(temp_out_buffer_ + channels_) + | 122 reinterpret_cast<float*>(temp_out_buffer_ + channels_) + |
| 123 chunk_length_ * i; | 123 chunk_length_ * i; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Assumes all rho equal. | 126 // Assumes all rho equal. |
| 127 for (size_t i = 0; i < bank_size_; ++i) { | 127 for (size_t i = 0; i < bank_size_; ++i) { |
| 128 rho_[i] = kConfigRho * kConfigRho; | 128 rho_[i] = kConfigRho * kConfigRho; |
| 129 } | 129 } |
| 130 | 130 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 152 void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio) { | 152 void IntelligibilityEnhancer::ProcessRenderAudio(float* const* audio) { |
| 153 for (size_t i = 0; i < chunk_length_; ++i) { | 153 for (size_t i = 0; i < chunk_length_; ++i) { |
| 154 vad_tmp_buffer_[i] = (int16_t)audio[0][i]; | 154 vad_tmp_buffer_[i] = (int16_t)audio[0][i]; |
| 155 } | 155 } |
| 156 has_voice_low_ = WebRtcVad_Process(vad_low_, sample_rate_hz_, | 156 has_voice_low_ = WebRtcVad_Process(vad_low_, sample_rate_hz_, |
| 157 vad_tmp_buffer_.get(), chunk_length_) == 1; | 157 vad_tmp_buffer_.get(), chunk_length_) == 1; |
| 158 | 158 |
| 159 // Process and enhance chunk of |audio| | 159 // Process and enhance chunk of |audio| |
| 160 render_mangler_->ProcessChunk(audio, temp_out_buffer_); | 160 render_mangler_->ProcessChunk(audio, temp_out_buffer_); |
| 161 | 161 |
| 162 for (int i = 0; i < channels_; ++i) { | 162 for (size_t i = 0; i < channels_; ++i) { |
| 163 memcpy(audio[i], temp_out_buffer_[i], | 163 memcpy(audio[i], temp_out_buffer_[i], |
| 164 chunk_length_ * sizeof(**temp_out_buffer_)); | 164 chunk_length_ * sizeof(**temp_out_buffer_)); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 void IntelligibilityEnhancer::ProcessCaptureAudio(float* const* audio) { | 168 void IntelligibilityEnhancer::ProcessCaptureAudio(float* const* audio) { |
| 169 for (size_t i = 0; i < chunk_length_; ++i) { | 169 for (size_t i = 0; i < chunk_length_; ++i) { |
| 170 vad_tmp_buffer_[i] = (int16_t)audio[0][i]; | 170 vad_tmp_buffer_[i] = (int16_t)audio[0][i]; |
| 171 } | 171 } |
| 172 // TODO(bercic): The VAD was always detecting voice in the noise stream, | 172 // TODO(bercic): The VAD was always detecting voice in the noise stream, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 size_t length) { | 405 size_t length) { |
| 406 float ret = 0.0f; | 406 float ret = 0.0f; |
| 407 | 407 |
| 408 for (size_t i = 0; i < length; ++i) { | 408 for (size_t i = 0; i < length; ++i) { |
| 409 ret = fmaf(a[i], b[i], ret); | 409 ret = fmaf(a[i], b[i], ret); |
| 410 } | 410 } |
| 411 return ret; | 411 return ret; |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace webrtc | 414 } // namespace webrtc |
| OLD | NEW |