| 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 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 GainControlImpl::~GainControlImpl() {} | 53 GainControlImpl::~GainControlImpl() {} |
| 54 | 54 |
| 55 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 55 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
| 56 if (!is_component_enabled()) { | 56 if (!is_component_enabled()) { |
| 57 return apm_->kNoError; | 57 return apm_->kNoError; |
| 58 } | 58 } |
| 59 | 59 |
| 60 assert(audio->num_frames_per_band() <= 160); | 60 assert(audio->num_frames_per_band() <= 160); |
| 61 | 61 |
| 62 for (int i = 0; i < num_handles(); i++) { | 62 for (size_t i = 0; i < num_handles(); i++) { |
| 63 Handle* my_handle = static_cast<Handle*>(handle(i)); | 63 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 64 int err = WebRtcAgc_AddFarend( | 64 int err = WebRtcAgc_AddFarend( |
| 65 my_handle, | 65 my_handle, |
| 66 audio->mixed_low_pass_data(), | 66 audio->mixed_low_pass_data(), |
| 67 audio->num_frames_per_band()); | 67 audio->num_frames_per_band()); |
| 68 | 68 |
| 69 if (err != apm_->kNoError) { | 69 if (err != apm_->kNoError) { |
| 70 return GetHandleError(my_handle); | 70 return GetHandleError(my_handle); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 return apm_->kNoError; | 74 return apm_->kNoError; |
| 75 } | 75 } |
| 76 | 76 |
| 77 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 77 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
| 78 if (!is_component_enabled()) { | 78 if (!is_component_enabled()) { |
| 79 return apm_->kNoError; | 79 return apm_->kNoError; |
| 80 } | 80 } |
| 81 | 81 |
| 82 assert(audio->num_frames_per_band() <= 160); | 82 assert(audio->num_frames_per_band() <= 160); |
| 83 assert(audio->num_channels() == num_handles()); | 83 assert(audio->num_channels() == num_handles()); |
| 84 | 84 |
| 85 int err = apm_->kNoError; | 85 int err = apm_->kNoError; |
| 86 | 86 |
| 87 if (mode_ == kAdaptiveAnalog) { | 87 if (mode_ == kAdaptiveAnalog) { |
| 88 capture_levels_.assign(num_handles(), analog_capture_level_); | 88 capture_levels_.assign(num_handles(), analog_capture_level_); |
| 89 for (int i = 0; i < num_handles(); i++) { | 89 for (size_t i = 0; i < num_handles(); i++) { |
| 90 Handle* my_handle = static_cast<Handle*>(handle(i)); | 90 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 91 err = WebRtcAgc_AddMic( | 91 err = WebRtcAgc_AddMic( |
| 92 my_handle, | 92 my_handle, |
| 93 audio->split_bands(i), | 93 audio->split_bands(i), |
| 94 audio->num_bands(), | 94 audio->num_bands(), |
| 95 audio->num_frames_per_band()); | 95 audio->num_frames_per_band()); |
| 96 | 96 |
| 97 if (err != apm_->kNoError) { | 97 if (err != apm_->kNoError) { |
| 98 return GetHandleError(my_handle); | 98 return GetHandleError(my_handle); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } else if (mode_ == kAdaptiveDigital) { | 101 } else if (mode_ == kAdaptiveDigital) { |
| 102 | 102 |
| 103 for (int i = 0; i < num_handles(); i++) { | 103 for (size_t i = 0; i < num_handles(); i++) { |
| 104 Handle* my_handle = static_cast<Handle*>(handle(i)); | 104 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 105 int32_t capture_level_out = 0; | 105 int32_t capture_level_out = 0; |
| 106 | 106 |
| 107 err = WebRtcAgc_VirtualMic( | 107 err = WebRtcAgc_VirtualMic( |
| 108 my_handle, | 108 my_handle, |
| 109 audio->split_bands(i), | 109 audio->split_bands(i), |
| 110 audio->num_bands(), | 110 audio->num_bands(), |
| 111 audio->num_frames_per_band(), | 111 audio->num_frames_per_band(), |
| 112 analog_capture_level_, | 112 analog_capture_level_, |
| 113 &capture_level_out); | 113 &capture_level_out); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 130 } | 130 } |
| 131 | 131 |
| 132 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { | 132 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { |
| 133 return apm_->kStreamParameterNotSetError; | 133 return apm_->kStreamParameterNotSetError; |
| 134 } | 134 } |
| 135 | 135 |
| 136 assert(audio->num_frames_per_band() <= 160); | 136 assert(audio->num_frames_per_band() <= 160); |
| 137 assert(audio->num_channels() == num_handles()); | 137 assert(audio->num_channels() == num_handles()); |
| 138 | 138 |
| 139 stream_is_saturated_ = false; | 139 stream_is_saturated_ = false; |
| 140 for (int i = 0; i < num_handles(); i++) { | 140 for (size_t i = 0; i < num_handles(); i++) { |
| 141 Handle* my_handle = static_cast<Handle*>(handle(i)); | 141 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 142 int32_t capture_level_out = 0; | 142 int32_t capture_level_out = 0; |
| 143 uint8_t saturation_warning = 0; | 143 uint8_t saturation_warning = 0; |
| 144 | 144 |
| 145 int err = WebRtcAgc_Process( | 145 int err = WebRtcAgc_Process( |
| 146 my_handle, | 146 my_handle, |
| 147 audio->split_bands_const(i), | 147 audio->split_bands_const(i), |
| 148 audio->num_bands(), | 148 audio->num_bands(), |
| 149 audio->num_frames_per_band(), | 149 audio->num_frames_per_band(), |
| 150 audio->split_bands(i), | 150 audio->split_bands(i), |
| 151 capture_levels_[i], | 151 capture_levels_[i], |
| 152 &capture_level_out, | 152 &capture_level_out, |
| 153 apm_->echo_cancellation()->stream_has_echo(), | 153 apm_->echo_cancellation()->stream_has_echo(), |
| 154 &saturation_warning); | 154 &saturation_warning); |
| 155 | 155 |
| 156 if (err != apm_->kNoError) { | 156 if (err != apm_->kNoError) { |
| 157 return GetHandleError(my_handle); | 157 return GetHandleError(my_handle); |
| 158 } | 158 } |
| 159 | 159 |
| 160 capture_levels_[i] = capture_level_out; | 160 capture_levels_[i] = capture_level_out; |
| 161 if (saturation_warning == 1) { | 161 if (saturation_warning == 1) { |
| 162 stream_is_saturated_ = true; | 162 stream_is_saturated_ = true; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 if (mode_ == kAdaptiveAnalog) { | 166 if (mode_ == kAdaptiveAnalog) { |
| 167 // Take the analog level to be the average across the handles. | 167 // Take the analog level to be the average across the handles. |
| 168 analog_capture_level_ = 0; | 168 analog_capture_level_ = 0; |
| 169 for (int i = 0; i < num_handles(); i++) { | 169 for (size_t i = 0; i < num_handles(); i++) { |
| 170 analog_capture_level_ += capture_levels_[i]; | 170 analog_capture_level_ += capture_levels_[i]; |
| 171 } | 171 } |
| 172 | 172 |
| 173 analog_capture_level_ /= num_handles(); | 173 analog_capture_level_ /= num_handles(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 was_analog_level_set_ = false; | 176 was_analog_level_set_ = false; |
| 177 return apm_->kNoError; | 177 return apm_->kNoError; |
| 178 } | 178 } |
| 179 | 179 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 //assert(target_level_dbfs_ <= 0); | 323 //assert(target_level_dbfs_ <= 0); |
| 324 //config.targetLevelDbfs = static_cast<int16_t>(-target_level_dbfs_); | 324 //config.targetLevelDbfs = static_cast<int16_t>(-target_level_dbfs_); |
| 325 config.targetLevelDbfs = static_cast<int16_t>(target_level_dbfs_); | 325 config.targetLevelDbfs = static_cast<int16_t>(target_level_dbfs_); |
| 326 config.compressionGaindB = | 326 config.compressionGaindB = |
| 327 static_cast<int16_t>(compression_gain_db_); | 327 static_cast<int16_t>(compression_gain_db_); |
| 328 config.limiterEnable = limiter_enabled_; | 328 config.limiterEnable = limiter_enabled_; |
| 329 | 329 |
| 330 return WebRtcAgc_set_config(static_cast<Handle*>(handle), config); | 330 return WebRtcAgc_set_config(static_cast<Handle*>(handle), config); |
| 331 } | 331 } |
| 332 | 332 |
| 333 int GainControlImpl::num_handles_required() const { | 333 size_t GainControlImpl::num_handles_required() const { |
| 334 return apm_->num_output_channels(); | 334 return apm_->num_output_channels(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 int GainControlImpl::GetHandleError(void* handle) const { | 337 int GainControlImpl::GetHandleError(void* handle) const { |
| 338 // The AGC has no get_error() function. | 338 // The AGC has no get_error() function. |
| 339 // (Despite listing errors in its interface...) | 339 // (Despite listing errors in its interface...) |
| 340 assert(handle != NULL); | 340 assert(handle != NULL); |
| 341 return apm_->kUnspecifiedError; | 341 return apm_->kUnspecifiedError; |
| 342 } | 342 } |
| 343 } // namespace webrtc | 343 } // namespace webrtc |
| OLD | NEW |