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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 69 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
70 rtc::CritScope cs(crit_render_); | 70 rtc::CritScope cs(crit_render_); |
71 if (!is_component_enabled()) { | 71 if (!is_component_enabled()) { |
72 return AudioProcessing::kNoError; | 72 return AudioProcessing::kNoError; |
73 } | 73 } |
74 | 74 |
75 assert(audio->num_frames_per_band() <= 160); | 75 assert(audio->num_frames_per_band() <= 160); |
76 | 76 |
77 render_queue_buffer_.resize(0); | 77 render_queue_buffer_.resize(0); |
78 for (int i = 0; i < num_handles(); i++) { | 78 for (size_t i = 0; i < num_handles(); i++) { |
79 Handle* my_handle = static_cast<Handle*>(handle(i)); | 79 Handle* my_handle = static_cast<Handle*>(handle(i)); |
80 int err = | 80 int err = |
81 WebRtcAgc_GetAddFarendError(my_handle, audio->num_frames_per_band()); | 81 WebRtcAgc_GetAddFarendError(my_handle, audio->num_frames_per_band()); |
82 | 82 |
83 if (err != AudioProcessing::kNoError) | 83 if (err != AudioProcessing::kNoError) |
84 return GetHandleError(my_handle); | 84 return GetHandleError(my_handle); |
85 | 85 |
86 // Buffer the samples in the render queue. | 86 // Buffer the samples in the render queue. |
87 render_queue_buffer_.insert( | 87 render_queue_buffer_.insert( |
88 render_queue_buffer_.end(), audio->mixed_low_pass_data(), | 88 render_queue_buffer_.end(), audio->mixed_low_pass_data(), |
(...skipping 18 matching lines...) Expand all Loading... |
107 rtc::CritScope cs(crit_capture_); | 107 rtc::CritScope cs(crit_capture_); |
108 | 108 |
109 if (!is_component_enabled()) { | 109 if (!is_component_enabled()) { |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { | 113 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { |
114 size_t buffer_index = 0; | 114 size_t buffer_index = 0; |
115 const size_t num_frames_per_band = | 115 const size_t num_frames_per_band = |
116 capture_queue_buffer_.size() / num_handles(); | 116 capture_queue_buffer_.size() / num_handles(); |
117 for (int i = 0; i < num_handles(); i++) { | 117 for (size_t i = 0; i < num_handles(); i++) { |
118 Handle* my_handle = static_cast<Handle*>(handle(i)); | 118 Handle* my_handle = static_cast<Handle*>(handle(i)); |
119 WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[buffer_index], | 119 WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[buffer_index], |
120 num_frames_per_band); | 120 num_frames_per_band); |
121 | 121 |
122 buffer_index += num_frames_per_band; | 122 buffer_index += num_frames_per_band; |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 127 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
128 rtc::CritScope cs(crit_capture_); | 128 rtc::CritScope cs(crit_capture_); |
129 | 129 |
130 if (!is_component_enabled()) { | 130 if (!is_component_enabled()) { |
131 return AudioProcessing::kNoError; | 131 return AudioProcessing::kNoError; |
132 } | 132 } |
133 | 133 |
134 assert(audio->num_frames_per_band() <= 160); | 134 assert(audio->num_frames_per_band() <= 160); |
135 assert(audio->num_channels() == num_handles()); | 135 assert(audio->num_channels() == num_handles()); |
136 | 136 |
137 int err = AudioProcessing::kNoError; | 137 int err = AudioProcessing::kNoError; |
138 | 138 |
139 if (mode_ == kAdaptiveAnalog) { | 139 if (mode_ == kAdaptiveAnalog) { |
140 capture_levels_.assign(num_handles(), analog_capture_level_); | 140 capture_levels_.assign(num_handles(), analog_capture_level_); |
141 for (int i = 0; i < num_handles(); i++) { | 141 for (size_t i = 0; i < num_handles(); i++) { |
142 Handle* my_handle = static_cast<Handle*>(handle(i)); | 142 Handle* my_handle = static_cast<Handle*>(handle(i)); |
143 err = WebRtcAgc_AddMic( | 143 err = WebRtcAgc_AddMic( |
144 my_handle, | 144 my_handle, |
145 audio->split_bands(i), | 145 audio->split_bands(i), |
146 audio->num_bands(), | 146 audio->num_bands(), |
147 audio->num_frames_per_band()); | 147 audio->num_frames_per_band()); |
148 | 148 |
149 if (err != AudioProcessing::kNoError) { | 149 if (err != AudioProcessing::kNoError) { |
150 return GetHandleError(my_handle); | 150 return GetHandleError(my_handle); |
151 } | 151 } |
152 } | 152 } |
153 } else if (mode_ == kAdaptiveDigital) { | 153 } else if (mode_ == kAdaptiveDigital) { |
154 | 154 |
155 for (int i = 0; i < num_handles(); i++) { | 155 for (size_t i = 0; i < num_handles(); i++) { |
156 Handle* my_handle = static_cast<Handle*>(handle(i)); | 156 Handle* my_handle = static_cast<Handle*>(handle(i)); |
157 int32_t capture_level_out = 0; | 157 int32_t capture_level_out = 0; |
158 | 158 |
159 err = WebRtcAgc_VirtualMic( | 159 err = WebRtcAgc_VirtualMic( |
160 my_handle, | 160 my_handle, |
161 audio->split_bands(i), | 161 audio->split_bands(i), |
162 audio->num_bands(), | 162 audio->num_bands(), |
163 audio->num_frames_per_band(), | 163 audio->num_frames_per_band(), |
164 analog_capture_level_, | 164 analog_capture_level_, |
165 &capture_level_out); | 165 &capture_level_out); |
(...skipping 18 matching lines...) Expand all Loading... |
184 } | 184 } |
185 | 185 |
186 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { | 186 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { |
187 return AudioProcessing::kStreamParameterNotSetError; | 187 return AudioProcessing::kStreamParameterNotSetError; |
188 } | 188 } |
189 | 189 |
190 assert(audio->num_frames_per_band() <= 160); | 190 assert(audio->num_frames_per_band() <= 160); |
191 assert(audio->num_channels() == num_handles()); | 191 assert(audio->num_channels() == num_handles()); |
192 | 192 |
193 stream_is_saturated_ = false; | 193 stream_is_saturated_ = false; |
194 for (int i = 0; i < num_handles(); i++) { | 194 for (size_t i = 0; i < num_handles(); i++) { |
195 Handle* my_handle = static_cast<Handle*>(handle(i)); | 195 Handle* my_handle = static_cast<Handle*>(handle(i)); |
196 int32_t capture_level_out = 0; | 196 int32_t capture_level_out = 0; |
197 uint8_t saturation_warning = 0; | 197 uint8_t saturation_warning = 0; |
198 | 198 |
199 // The call to stream_has_echo() is ok from a deadlock perspective | 199 // The call to stream_has_echo() is ok from a deadlock perspective |
200 // as the capture lock is allready held. | 200 // as the capture lock is allready held. |
201 int err = WebRtcAgc_Process( | 201 int err = WebRtcAgc_Process( |
202 my_handle, | 202 my_handle, |
203 audio->split_bands_const(i), | 203 audio->split_bands_const(i), |
204 audio->num_bands(), | 204 audio->num_bands(), |
(...skipping 10 matching lines...) Expand all Loading... |
215 | 215 |
216 capture_levels_[i] = capture_level_out; | 216 capture_levels_[i] = capture_level_out; |
217 if (saturation_warning == 1) { | 217 if (saturation_warning == 1) { |
218 stream_is_saturated_ = true; | 218 stream_is_saturated_ = true; |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 if (mode_ == kAdaptiveAnalog) { | 222 if (mode_ == kAdaptiveAnalog) { |
223 // Take the analog level to be the average across the handles. | 223 // Take the analog level to be the average across the handles. |
224 analog_capture_level_ = 0; | 224 analog_capture_level_ = 0; |
225 for (int i = 0; i < num_handles(); i++) { | 225 for (size_t i = 0; i < num_handles(); i++) { |
226 analog_capture_level_ += capture_levels_[i]; | 226 analog_capture_level_ += capture_levels_[i]; |
227 } | 227 } |
228 | 228 |
229 analog_capture_level_ /= num_handles(); | 229 analog_capture_level_ /= num_handles(); |
230 } | 230 } |
231 | 231 |
232 was_analog_level_set_ = false; | 232 was_analog_level_set_ = false; |
233 return AudioProcessing::kNoError; | 233 return AudioProcessing::kNoError; |
234 } | 234 } |
235 | 235 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 //assert(target_level_dbfs_ <= 0); | 426 //assert(target_level_dbfs_ <= 0); |
427 //config.targetLevelDbfs = static_cast<int16_t>(-target_level_dbfs_); | 427 //config.targetLevelDbfs = static_cast<int16_t>(-target_level_dbfs_); |
428 config.targetLevelDbfs = static_cast<int16_t>(target_level_dbfs_); | 428 config.targetLevelDbfs = static_cast<int16_t>(target_level_dbfs_); |
429 config.compressionGaindB = | 429 config.compressionGaindB = |
430 static_cast<int16_t>(compression_gain_db_); | 430 static_cast<int16_t>(compression_gain_db_); |
431 config.limiterEnable = limiter_enabled_; | 431 config.limiterEnable = limiter_enabled_; |
432 | 432 |
433 return WebRtcAgc_set_config(static_cast<Handle*>(handle), config); | 433 return WebRtcAgc_set_config(static_cast<Handle*>(handle), config); |
434 } | 434 } |
435 | 435 |
436 int GainControlImpl::num_handles_required() const { | 436 size_t GainControlImpl::num_handles_required() const { |
437 // Not locked as it only relies on APM public API which is threadsafe. | 437 // Not locked as it only relies on APM public API which is threadsafe. |
438 return apm_->num_proc_channels(); | 438 return apm_->num_proc_channels(); |
439 } | 439 } |
440 | 440 |
441 int GainControlImpl::GetHandleError(void* handle) const { | 441 int GainControlImpl::GetHandleError(void* handle) const { |
442 // The AGC has no get_error() function. | 442 // The AGC has no get_error() function. |
443 // (Despite listing errors in its interface...) | 443 // (Despite listing errors in its interface...) |
444 assert(handle != NULL); | 444 assert(handle != NULL); |
445 return AudioProcessing::kUnspecifiedError; | 445 return AudioProcessing::kUnspecifiedError; |
446 } | 446 } |
447 } // namespace webrtc | 447 } // namespace webrtc |
OLD | NEW |