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 11 matching lines...) Expand all Loading... |
22 #include "webrtc/modules/audio_processing/beamformer/covariance_matrix_generator
.h" | 22 #include "webrtc/modules/audio_processing/beamformer/covariance_matrix_generator
.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Alpha for the Kaiser Bessel Derived window. | 27 // Alpha for the Kaiser Bessel Derived window. |
28 const float kKbdAlpha = 1.5f; | 28 const float kKbdAlpha = 1.5f; |
29 | 29 |
30 const float kSpeedOfSoundMeterSeconds = 343; | 30 const float kSpeedOfSoundMeterSeconds = 343; |
31 | 31 |
32 // For both target and interference angles, PI / 2 is perpendicular to the | |
33 // microphone array, facing forwards. The positive direction goes | |
34 // counterclockwise. | |
35 // The angle at which we amplify sound. | |
36 // TODO(aluebs): Make the target angle dynamically settable. | |
37 const float kTargetAngleRadians = static_cast<float>(M_PI) / 2.f; | |
38 | |
39 // The minimum separation in radians between the target direction and an | 32 // The minimum separation in radians between the target direction and an |
40 // interferer scenario. | 33 // interferer scenario. |
41 const float kMinAwayRadians = 0.2f; | 34 const float kMinAwayRadians = 0.2f; |
42 | 35 |
43 // The separation between the target direction and the closest interferer | 36 // The separation between the target direction and the closest interferer |
44 // scenario is proportional to this constant. | 37 // scenario is proportional to this constant. |
45 const float kAwaySlope = 0.008f; | 38 const float kAwaySlope = 0.008f; |
46 | 39 |
47 // When calculating the interference covariance matrix, this is the weight for | 40 // When calculating the interference covariance matrix, this is the weight for |
48 // the weighted average between the uniform covariance matrix and the angled | 41 // the weighted average between the uniform covariance matrix and the angled |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 center += array_geometry[i].c[dim]; | 171 center += array_geometry[i].c[dim]; |
179 } | 172 } |
180 center /= array_geometry.size(); | 173 center /= array_geometry.size(); |
181 for (size_t i = 0; i < array_geometry.size(); ++i) { | 174 for (size_t i = 0; i < array_geometry.size(); ++i) { |
182 array_geometry[i].c[dim] -= center; | 175 array_geometry[i].c[dim] -= center; |
183 } | 176 } |
184 } | 177 } |
185 return array_geometry; | 178 return array_geometry; |
186 } | 179 } |
187 | 180 |
| 181 float DotProduct(std::vector<float> a, std::vector<float> b) { |
| 182 RTC_DCHECK_EQ(a.size(), b.size()); |
| 183 float dot_product = 0.f; |
| 184 for (size_t i = 0u; i < a.size(); ++i) { |
| 185 dot_product += a[i] * b[i]; |
| 186 } |
| 187 return dot_product; |
| 188 } |
| 189 |
| 190 float NormalizedDotProduct(std::vector<float> a, std::vector<float> b) { |
| 191 const float kMinNorm = 1e-6f; |
| 192 float norm_a = DotProduct(a, a); |
| 193 float norm_b = DotProduct(b, b); |
| 194 if (norm_a > kMinNorm && norm_b > kMinNorm) { |
| 195 return DotProduct(a, b) / std::sqrt(norm_a * norm_b); |
| 196 } else { |
| 197 return 0.f; |
| 198 } |
| 199 } |
| 200 |
| 201 bool IsGeometryLinear(std::vector<Point> array_geometry) { |
| 202 const float kMinDotProduct = 0.9999f; |
| 203 bool is_geometry_linear = true; |
| 204 std::vector<float> directiona; |
| 205 directiona.push_back(array_geometry[1].x() - array_geometry[0].x()); |
| 206 directiona.push_back(array_geometry[1].y() - array_geometry[0].y()); |
| 207 directiona.push_back(array_geometry[1].z() - array_geometry[0].z()); |
| 208 for (size_t i = 2u; i < array_geometry.size(); ++i) { |
| 209 std::vector<float> directionb; |
| 210 directionb.push_back(array_geometry[i].x() - array_geometry[i - 1].x()); |
| 211 directionb.push_back(array_geometry[i].y() - array_geometry[i - 1].y()); |
| 212 directionb.push_back(array_geometry[i].z() - array_geometry[i - 1].z()); |
| 213 is_geometry_linear &= |
| 214 std::abs(NormalizedDotProduct(directiona, directionb)) > kMinDotProduct; |
| 215 } |
| 216 return is_geometry_linear; |
| 217 } |
| 218 |
188 } // namespace | 219 } // namespace |
189 | 220 |
190 // static | 221 // static |
191 const size_t NonlinearBeamformer::kNumFreqBins; | 222 const size_t NonlinearBeamformer::kNumFreqBins; |
192 | 223 |
193 NonlinearBeamformer::NonlinearBeamformer( | 224 NonlinearBeamformer::NonlinearBeamformer( |
194 const std::vector<Point>& array_geometry) | 225 const std::vector<Point>& array_geometry, |
| 226 SphericalPointf target_direction) |
195 : num_input_channels_(array_geometry.size()), | 227 : num_input_channels_(array_geometry.size()), |
196 array_geometry_(GetCenteredArray(array_geometry)), | 228 array_geometry_(GetCenteredArray(array_geometry)), |
197 min_mic_spacing_(GetMinimumSpacing(array_geometry)) { | 229 min_mic_spacing_(GetMinimumSpacing(array_geometry)), |
| 230 target_angle_radians_(target_direction.azimuth()) { |
198 WindowGenerator::KaiserBesselDerived(kKbdAlpha, kFftSize, window_); | 231 WindowGenerator::KaiserBesselDerived(kKbdAlpha, kFftSize, window_); |
199 } | 232 } |
200 | 233 |
201 void NonlinearBeamformer::Initialize(int chunk_size_ms, int sample_rate_hz) { | 234 void NonlinearBeamformer::Initialize(int chunk_size_ms, int sample_rate_hz) { |
202 chunk_length_ = | 235 chunk_length_ = |
203 static_cast<size_t>(sample_rate_hz / (1000.f / chunk_size_ms)); | 236 static_cast<size_t>(sample_rate_hz / (1000.f / chunk_size_ms)); |
204 sample_rate_hz_ = sample_rate_hz; | 237 sample_rate_hz_ = sample_rate_hz; |
205 InitFrequencyCorrectionRanges(); | |
206 | 238 |
207 high_pass_postfilter_mask_ = 1.f; | 239 high_pass_postfilter_mask_ = 1.f; |
208 is_target_present_ = false; | 240 is_target_present_ = false; |
209 hold_target_blocks_ = kHoldTargetSeconds * 2 * sample_rate_hz / kFftSize; | 241 hold_target_blocks_ = kHoldTargetSeconds * 2 * sample_rate_hz / kFftSize; |
210 interference_blocks_count_ = hold_target_blocks_; | 242 interference_blocks_count_ = hold_target_blocks_; |
211 | 243 |
212 lapped_transform_.reset(new LappedTransform(num_input_channels_, | 244 lapped_transform_.reset(new LappedTransform(num_input_channels_, |
213 1, | 245 1, |
214 chunk_length_, | 246 chunk_length_, |
215 window_, | 247 window_, |
216 kFftSize, | 248 kFftSize, |
217 kFftSize / 2, | 249 kFftSize / 2, |
218 this)); | 250 this)); |
219 for (size_t i = 0; i < kNumFreqBins; ++i) { | 251 for (size_t i = 0; i < kNumFreqBins; ++i) { |
220 time_smooth_mask_[i] = 1.f; | 252 time_smooth_mask_[i] = 1.f; |
221 final_mask_[i] = 1.f; | 253 final_mask_[i] = 1.f; |
222 float freq_hz = (static_cast<float>(i) / kFftSize) * sample_rate_hz_; | 254 float freq_hz = (static_cast<float>(i) / kFftSize) * sample_rate_hz_; |
223 wave_numbers_[i] = 2 * M_PI * freq_hz / kSpeedOfSoundMeterSeconds; | 255 wave_numbers_[i] = 2 * M_PI * freq_hz / kSpeedOfSoundMeterSeconds; |
224 } | 256 } |
225 | 257 |
226 // Initialize all nonadaptive values before looping through the frames. | 258 InitLowFrequencyCorrectionRanges(); |
227 InitInterfAngles(); | 259 InitDifuseCovMats(); |
228 InitDelaySumMasks(); | 260 AimAt(SphericalPointf(target_angle_radians_, 0.f, 1.f)); |
229 InitTargetCovMats(); | |
230 InitInterfCovMats(); | |
231 | |
232 for (size_t i = 0; i < kNumFreqBins; ++i) { | |
233 rxiws_[i] = Norm(target_cov_mats_[i], delay_sum_masks_[i]); | |
234 rpsiws_[i].clear(); | |
235 for (size_t j = 0; j < interf_angles_radians_.size(); ++j) { | |
236 rpsiws_[i].push_back(Norm(*interf_cov_mats_[i][j], delay_sum_masks_[i])); | |
237 } | |
238 } | |
239 } | 261 } |
240 | 262 |
241 void NonlinearBeamformer::InitFrequencyCorrectionRanges() { | 263 // These bin indexes determine the regions over which a mean is taken. This is |
| 264 // applied as a constant value over the adjacent end "frequency correction" |
| 265 // regions. |
| 266 // |
| 267 // low_mean_start_bin_ high_mean_start_bin_ |
| 268 // v v constant |
| 269 // |----------------|--------|----------------|-------|----------------| |
| 270 // constant ^ ^ |
| 271 // low_mean_end_bin_ high_mean_end_bin_ |
| 272 // |
| 273 void NonlinearBeamformer::InitLowFrequencyCorrectionRanges() { |
| 274 low_mean_start_bin_ = Round(kLowMeanStartHz * kFftSize / sample_rate_hz_); |
| 275 low_mean_end_bin_ = Round(kLowMeanEndHz * kFftSize / sample_rate_hz_); |
| 276 |
| 277 RTC_DCHECK_GT(low_mean_start_bin_, 0U); |
| 278 RTC_DCHECK_LT(low_mean_start_bin_, low_mean_end_bin_); |
| 279 } |
| 280 |
| 281 void NonlinearBeamformer::InitHighFrequencyCorrectionRanges() { |
242 const float kAliasingFreqHz = | 282 const float kAliasingFreqHz = |
243 kSpeedOfSoundMeterSeconds / | 283 kSpeedOfSoundMeterSeconds / |
244 (min_mic_spacing_ * (1.f + std::abs(std::cos(kTargetAngleRadians)))); | 284 (min_mic_spacing_ * (1.f + std::abs(std::cos(target_angle_radians_)))); |
245 const float kHighMeanStartHz = std::min(0.5f * kAliasingFreqHz, | 285 const float kHighMeanStartHz = std::min(0.5f * kAliasingFreqHz, |
246 sample_rate_hz_ / 2.f); | 286 sample_rate_hz_ / 2.f); |
247 const float kHighMeanEndHz = std::min(0.75f * kAliasingFreqHz, | 287 const float kHighMeanEndHz = std::min(0.75f * kAliasingFreqHz, |
248 sample_rate_hz_ / 2.f); | 288 sample_rate_hz_ / 2.f); |
249 | |
250 low_mean_start_bin_ = Round(kLowMeanStartHz * kFftSize / sample_rate_hz_); | |
251 low_mean_end_bin_ = Round(kLowMeanEndHz * kFftSize / sample_rate_hz_); | |
252 high_mean_start_bin_ = Round(kHighMeanStartHz * kFftSize / sample_rate_hz_); | 289 high_mean_start_bin_ = Round(kHighMeanStartHz * kFftSize / sample_rate_hz_); |
253 high_mean_end_bin_ = Round(kHighMeanEndHz * kFftSize / sample_rate_hz_); | 290 high_mean_end_bin_ = Round(kHighMeanEndHz * kFftSize / sample_rate_hz_); |
254 // These bin indexes determine the regions over which a mean is taken. This | 291 |
255 // is applied as a constant value over the adjacent end "frequency correction" | |
256 // regions. | |
257 // | |
258 // low_mean_start_bin_ high_mean_start_bin_ | |
259 // v v constant | |
260 // |----------------|--------|----------------|-------|----------------| | |
261 // constant ^ ^ | |
262 // low_mean_end_bin_ high_mean_end_bin_ | |
263 // | |
264 RTC_DCHECK_GT(low_mean_start_bin_, 0U); | |
265 RTC_DCHECK_LT(low_mean_start_bin_, low_mean_end_bin_); | |
266 RTC_DCHECK_LT(low_mean_end_bin_, high_mean_end_bin_); | 292 RTC_DCHECK_LT(low_mean_end_bin_, high_mean_end_bin_); |
267 RTC_DCHECK_LT(high_mean_start_bin_, high_mean_end_bin_); | 293 RTC_DCHECK_LT(high_mean_start_bin_, high_mean_end_bin_); |
268 RTC_DCHECK_LT(high_mean_end_bin_, kNumFreqBins - 1); | 294 RTC_DCHECK_LT(high_mean_end_bin_, kNumFreqBins - 1); |
269 } | 295 } |
270 | 296 |
271 | |
272 void NonlinearBeamformer::InitInterfAngles() { | 297 void NonlinearBeamformer::InitInterfAngles() { |
273 const float kAwayRadians = | 298 const float kAwayRadians = |
274 std::min(static_cast<float>(M_PI), | 299 std::min(static_cast<float>(M_PI), |
275 std::max(kMinAwayRadians, kAwaySlope * static_cast<float>(M_PI) / | 300 std::max(kMinAwayRadians, kAwaySlope * static_cast<float>(M_PI) / |
276 min_mic_spacing_)); | 301 min_mic_spacing_)); |
277 | 302 |
278 interf_angles_radians_.clear(); | 303 interf_angles_radians_.clear(); |
279 // TODO(aluebs): When the target angle is settable, make sure the interferer | 304 if (IsGeometryLinear(array_geometry_)) { |
280 // scenarios aren't reflected over the target one for linear geometries. | 305 if (target_angle_radians_ - kAwayRadians >= 0.f) { |
281 interf_angles_radians_.push_back(kTargetAngleRadians - kAwayRadians); | 306 interf_angles_radians_.push_back(target_angle_radians_ - kAwayRadians); |
282 interf_angles_radians_.push_back(kTargetAngleRadians + kAwayRadians); | 307 } else { |
| 308 interf_angles_radians_.push_back(M_PI); |
| 309 } |
| 310 if (target_angle_radians_ + kAwayRadians <= M_PI) { |
| 311 interf_angles_radians_.push_back(target_angle_radians_ + kAwayRadians); |
| 312 } else { |
| 313 interf_angles_radians_.push_back(0.f); |
| 314 } |
| 315 } else { |
| 316 interf_angles_radians_.push_back(target_angle_radians_ - kAwayRadians); |
| 317 interf_angles_radians_.push_back(target_angle_radians_ + kAwayRadians); |
| 318 } |
283 } | 319 } |
284 | 320 |
285 void NonlinearBeamformer::InitDelaySumMasks() { | 321 void NonlinearBeamformer::InitDelaySumMasks() { |
286 for (size_t f_ix = 0; f_ix < kNumFreqBins; ++f_ix) { | 322 for (size_t f_ix = 0; f_ix < kNumFreqBins; ++f_ix) { |
287 delay_sum_masks_[f_ix].Resize(1, num_input_channels_); | 323 delay_sum_masks_[f_ix].Resize(1, num_input_channels_); |
288 CovarianceMatrixGenerator::PhaseAlignmentMasks(f_ix, | 324 CovarianceMatrixGenerator::PhaseAlignmentMasks( |
289 kFftSize, | 325 f_ix, kFftSize, sample_rate_hz_, kSpeedOfSoundMeterSeconds, |
290 sample_rate_hz_, | 326 array_geometry_, target_angle_radians_, &delay_sum_masks_[f_ix]); |
291 kSpeedOfSoundMeterSeconds, | |
292 array_geometry_, | |
293 kTargetAngleRadians, | |
294 &delay_sum_masks_[f_ix]); | |
295 | 327 |
296 complex_f norm_factor = sqrt( | 328 complex_f norm_factor = sqrt( |
297 ConjugateDotProduct(delay_sum_masks_[f_ix], delay_sum_masks_[f_ix])); | 329 ConjugateDotProduct(delay_sum_masks_[f_ix], delay_sum_masks_[f_ix])); |
298 delay_sum_masks_[f_ix].Scale(1.f / norm_factor); | 330 delay_sum_masks_[f_ix].Scale(1.f / norm_factor); |
299 normalized_delay_sum_masks_[f_ix].CopyFrom(delay_sum_masks_[f_ix]); | 331 normalized_delay_sum_masks_[f_ix].CopyFrom(delay_sum_masks_[f_ix]); |
300 normalized_delay_sum_masks_[f_ix].Scale(1.f / SumAbs( | 332 normalized_delay_sum_masks_[f_ix].Scale(1.f / SumAbs( |
301 normalized_delay_sum_masks_[f_ix])); | 333 normalized_delay_sum_masks_[f_ix])); |
302 } | 334 } |
303 } | 335 } |
304 | 336 |
305 void NonlinearBeamformer::InitTargetCovMats() { | 337 void NonlinearBeamformer::InitTargetCovMats() { |
306 for (size_t i = 0; i < kNumFreqBins; ++i) { | 338 for (size_t i = 0; i < kNumFreqBins; ++i) { |
307 target_cov_mats_[i].Resize(num_input_channels_, num_input_channels_); | 339 target_cov_mats_[i].Resize(num_input_channels_, num_input_channels_); |
308 TransposedConjugatedProduct(delay_sum_masks_[i], &target_cov_mats_[i]); | 340 TransposedConjugatedProduct(delay_sum_masks_[i], &target_cov_mats_[i]); |
309 } | 341 } |
310 } | 342 } |
311 | 343 |
| 344 void NonlinearBeamformer::InitDifuseCovMats() { |
| 345 for (size_t i = 0; i < kNumFreqBins; ++i) { |
| 346 uniform_cov_mat_[i].Resize(num_input_channels_, num_input_channels_); |
| 347 CovarianceMatrixGenerator::UniformCovarianceMatrix( |
| 348 wave_numbers_[i], array_geometry_, &uniform_cov_mat_[i]); |
| 349 complex_f normalization_factor = uniform_cov_mat_[i].elements()[0][0]; |
| 350 uniform_cov_mat_[i].Scale(1.f / normalization_factor); |
| 351 uniform_cov_mat_[i].Scale(1 - kBalance); |
| 352 } |
| 353 } |
| 354 |
312 void NonlinearBeamformer::InitInterfCovMats() { | 355 void NonlinearBeamformer::InitInterfCovMats() { |
313 for (size_t i = 0; i < kNumFreqBins; ++i) { | 356 for (size_t i = 0; i < kNumFreqBins; ++i) { |
314 ComplexMatrixF uniform_cov_mat(num_input_channels_, num_input_channels_); | |
315 CovarianceMatrixGenerator::UniformCovarianceMatrix(wave_numbers_[i], | |
316 array_geometry_, | |
317 &uniform_cov_mat); | |
318 complex_f normalization_factor = uniform_cov_mat.elements()[0][0]; | |
319 uniform_cov_mat.Scale(1.f / normalization_factor); | |
320 uniform_cov_mat.Scale(1 - kBalance); | |
321 interf_cov_mats_[i].clear(); | 357 interf_cov_mats_[i].clear(); |
322 for (size_t j = 0; j < interf_angles_radians_.size(); ++j) { | 358 for (size_t j = 0; j < interf_angles_radians_.size(); ++j) { |
323 interf_cov_mats_[i].push_back(new ComplexMatrixF(num_input_channels_, | 359 interf_cov_mats_[i].push_back(new ComplexMatrixF(num_input_channels_, |
324 num_input_channels_)); | 360 num_input_channels_)); |
325 ComplexMatrixF angled_cov_mat(num_input_channels_, num_input_channels_); | 361 ComplexMatrixF angled_cov_mat(num_input_channels_, num_input_channels_); |
326 CovarianceMatrixGenerator::AngledCovarianceMatrix( | 362 CovarianceMatrixGenerator::AngledCovarianceMatrix( |
327 kSpeedOfSoundMeterSeconds, | 363 kSpeedOfSoundMeterSeconds, |
328 interf_angles_radians_[j], | 364 interf_angles_radians_[j], |
329 i, | 365 i, |
330 kFftSize, | 366 kFftSize, |
331 kNumFreqBins, | 367 kNumFreqBins, |
332 sample_rate_hz_, | 368 sample_rate_hz_, |
333 array_geometry_, | 369 array_geometry_, |
334 &angled_cov_mat); | 370 &angled_cov_mat); |
335 // Normalize matrices before averaging them. | 371 // Normalize matrices before averaging them. |
336 normalization_factor = angled_cov_mat.elements()[0][0]; | 372 complex_f normalization_factor = angled_cov_mat.elements()[0][0]; |
337 angled_cov_mat.Scale(1.f / normalization_factor); | 373 angled_cov_mat.Scale(1.f / normalization_factor); |
338 // Weighted average of matrices. | 374 // Weighted average of matrices. |
339 angled_cov_mat.Scale(kBalance); | 375 angled_cov_mat.Scale(kBalance); |
340 interf_cov_mats_[i][j]->Add(uniform_cov_mat, angled_cov_mat); | 376 interf_cov_mats_[i][j]->Add(uniform_cov_mat_[i], angled_cov_mat); |
341 } | 377 } |
342 } | 378 } |
343 } | 379 } |
| 380 |
| 381 void NonlinearBeamformer::NormalizeCovMats() { |
| 382 for (size_t i = 0; i < kNumFreqBins; ++i) { |
| 383 rxiws_[i] = Norm(target_cov_mats_[i], delay_sum_masks_[i]); |
| 384 rpsiws_[i].clear(); |
| 385 for (size_t j = 0; j < interf_angles_radians_.size(); ++j) { |
| 386 rpsiws_[i].push_back(Norm(*interf_cov_mats_[i][j], delay_sum_masks_[i])); |
| 387 } |
| 388 } |
| 389 } |
344 | 390 |
345 void NonlinearBeamformer::ProcessChunk(const ChannelBuffer<float>& input, | 391 void NonlinearBeamformer::ProcessChunk(const ChannelBuffer<float>& input, |
346 ChannelBuffer<float>* output) { | 392 ChannelBuffer<float>* output) { |
347 RTC_DCHECK_EQ(input.num_channels(), num_input_channels_); | 393 RTC_DCHECK_EQ(input.num_channels(), num_input_channels_); |
348 RTC_DCHECK_EQ(input.num_frames_per_band(), chunk_length_); | 394 RTC_DCHECK_EQ(input.num_frames_per_band(), chunk_length_); |
349 | 395 |
350 float old_high_pass_mask = high_pass_postfilter_mask_; | 396 float old_high_pass_mask = high_pass_postfilter_mask_; |
351 lapped_transform_->ProcessChunk(input.channels(0), output->channels(0)); | 397 lapped_transform_->ProcessChunk(input.channels(0), output->channels(0)); |
352 // Ramp up/down for smoothing. 1 mask per 10ms results in audible | 398 // Ramp up/down for smoothing. 1 mask per 10ms results in audible |
353 // discontinuities. | 399 // discontinuities. |
(...skipping 11 matching lines...) Expand all Loading... |
365 // averaging). | 411 // averaging). |
366 float sum = 0.f; | 412 float sum = 0.f; |
367 for (int k = 0; k < input.num_channels(); ++k) { | 413 for (int k = 0; k < input.num_channels(); ++k) { |
368 sum += input.channels(i)[k][j]; | 414 sum += input.channels(i)[k][j]; |
369 } | 415 } |
370 output->channels(i)[0][j] = sum / input.num_channels() * smoothed_mask; | 416 output->channels(i)[0][j] = sum / input.num_channels() * smoothed_mask; |
371 } | 417 } |
372 } | 418 } |
373 } | 419 } |
374 | 420 |
| 421 void NonlinearBeamformer::AimAt(const SphericalPointf& target_direction) { |
| 422 target_angle_radians_ = target_direction.azimuth(); |
| 423 InitHighFrequencyCorrectionRanges(); |
| 424 InitInterfAngles(); |
| 425 InitDelaySumMasks(); |
| 426 InitTargetCovMats(); |
| 427 InitInterfCovMats(); |
| 428 NormalizeCovMats(); |
| 429 } |
| 430 |
375 bool NonlinearBeamformer::IsInBeam(const SphericalPointf& spherical_point) { | 431 bool NonlinearBeamformer::IsInBeam(const SphericalPointf& spherical_point) { |
376 // If more than half-beamwidth degrees away from the beam's center, | 432 // If more than half-beamwidth degrees away from the beam's center, |
377 // you are out of the beam. | 433 // you are out of the beam. |
378 return fabs(spherical_point.azimuth() - kTargetAngleRadians) < | 434 return fabs(spherical_point.azimuth() - target_angle_radians_) < |
379 kHalfBeamWidthRadians; | 435 kHalfBeamWidthRadians; |
380 } | 436 } |
381 | 437 |
382 void NonlinearBeamformer::ProcessAudioBlock(const complex_f* const* input, | 438 void NonlinearBeamformer::ProcessAudioBlock(const complex_f* const* input, |
383 int num_input_channels, | 439 int num_input_channels, |
384 size_t num_freq_bins, | 440 size_t num_freq_bins, |
385 int num_output_channels, | 441 int num_output_channels, |
386 complex_f* const* output) { | 442 complex_f* const* output) { |
387 RTC_CHECK_EQ(num_freq_bins, kNumFreqBins); | 443 RTC_CHECK_EQ(num_freq_bins, kNumFreqBins); |
388 RTC_CHECK_EQ(num_input_channels, num_input_channels_); | 444 RTC_CHECK_EQ(num_input_channels, num_input_channels_); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 new_mask_ + high_mean_end_bin_ + 1); | 589 new_mask_ + high_mean_end_bin_ + 1); |
534 if (new_mask_[quantile] > kMaskTargetThreshold) { | 590 if (new_mask_[quantile] > kMaskTargetThreshold) { |
535 is_target_present_ = true; | 591 is_target_present_ = true; |
536 interference_blocks_count_ = 0; | 592 interference_blocks_count_ = 0; |
537 } else { | 593 } else { |
538 is_target_present_ = interference_blocks_count_++ < hold_target_blocks_; | 594 is_target_present_ = interference_blocks_count_++ < hold_target_blocks_; |
539 } | 595 } |
540 } | 596 } |
541 | 597 |
542 } // namespace webrtc | 598 } // namespace webrtc |
OLD | NEW |