Make the separation between target and interferer scenario depend on microphone spacing in NonlinearBeamformer

Depends on this CL: https://codereview.webrtc.org/1378973003/

Review URL: https://codereview.webrtc.org/1388033002

Cr-Commit-Position: refs/heads/master@{#10330}
This commit is contained in:
aluebs
2015-10-19 18:02:39 -07:00
committed by Commit bot
parent c6aec4b8ed
commit 4a66e4a4d8
8 changed files with 92 additions and 4 deletions

View File

@ -54,6 +54,8 @@ source_set("audio_processing") {
"audio_buffer.h", "audio_buffer.h",
"audio_processing_impl.cc", "audio_processing_impl.cc",
"audio_processing_impl.h", "audio_processing_impl.h",
"beamformer/array_util.cc",
"beamformer/array_util.h",
"beamformer/beamformer.h", "beamformer/beamformer.h",
"beamformer/complex_matrix.h", "beamformer/complex_matrix.h",
"beamformer/covariance_matrix_generator.cc", "beamformer/covariance_matrix_generator.cc",

View File

@ -64,6 +64,8 @@
'audio_buffer.h', 'audio_buffer.h',
'audio_processing_impl.cc', 'audio_processing_impl.cc',
'audio_processing_impl.h', 'audio_processing_impl.h',
'beamformer/array_util.cc',
'beamformer/array_util.h',
'beamformer/beamformer.h', 'beamformer/beamformer.h',
'beamformer/complex_matrix.h', 'beamformer/complex_matrix.h',
'beamformer/covariance_matrix_generator.cc', 'beamformer/covariance_matrix_generator.cc',

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_processing/beamformer/array_util.h"
#include <algorithm>
#include <limits>
#include "webrtc/base/checks.h"
namespace webrtc {
float GetMinimumSpacing(const std::vector<Point>& array_geometry) {
RTC_CHECK_GT(array_geometry.size(), 1u);
float mic_spacing = std::numeric_limits<float>::max();
for (size_t i = 0; i < (array_geometry.size() - 1); ++i) {
for (size_t j = i + 1; j < array_geometry.size(); ++j) {
mic_spacing =
std::min(mic_spacing, Distance(array_geometry[i], array_geometry[j]));
}
}
return mic_spacing;
}
} // namespace webrtc

View File

@ -12,6 +12,7 @@
#define WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_BEAMFORMER_ARRAY_UTIL_H_
#include <cmath> #include <cmath>
#include <vector>
namespace webrtc { namespace webrtc {
@ -31,6 +32,10 @@ struct CartesianPoint {
using Point = CartesianPoint<float>; using Point = CartesianPoint<float>;
// Returns the minimum distance between any two Points in the given
// |array_geometry|.
float GetMinimumSpacing(const std::vector<Point>& array_geometry);
template<typename T> template<typename T>
float Distance(CartesianPoint<T> a, CartesianPoint<T> b) { float Distance(CartesianPoint<T> a, CartesianPoint<T> b) {
return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) + return std::sqrt((a.x() - b.x()) * (a.x() - b.x()) +

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/audio_processing/beamformer/array_util.h"
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
namespace webrtc {
TEST(ArrayUtilTest, GetMinimumSpacing) {
std::vector<Point> array_geometry;
array_geometry.push_back(Point(0.f, 0.f, 0.f));
array_geometry.push_back(Point(0.1f, 0.f, 0.f));
EXPECT_FLOAT_EQ(0.1f, GetMinimumSpacing(array_geometry));
array_geometry.push_back(Point(0.f, 0.05f, 0.f));
EXPECT_FLOAT_EQ(0.05f, GetMinimumSpacing(array_geometry));
array_geometry.push_back(Point(0.f, 0.f, 0.02f));
EXPECT_FLOAT_EQ(0.02f, GetMinimumSpacing(array_geometry));
array_geometry.push_back(Point(-0.003f, -0.004f, 0.02f));
EXPECT_FLOAT_EQ(0.005f, GetMinimumSpacing(array_geometry));
}
} // namespace webrtc

View File

@ -36,6 +36,14 @@ const float kSpeedOfSoundMeterSeconds = 343;
// TODO(aluebs): Make the target angle dynamically settable. // TODO(aluebs): Make the target angle dynamically settable.
const float kTargetAngleRadians = static_cast<float>(M_PI) / 2.f; const float kTargetAngleRadians = static_cast<float>(M_PI) / 2.f;
// The minimum separation in radians between the target direction and an
// interferer scenario.
const float kMinAwayRadians = 0.2f;
// The separation between the target direction and the closest interferer
// scenario is proportional to this constant.
const float kAwaySlope = 0.008f;
// When calculating the interference covariance matrix, this is the weight for // When calculating the interference covariance matrix, this is the weight for
// the weighted average between the uniform covariance matrix and the angled // the weighted average between the uniform covariance matrix and the angled
// covariance matrix. // covariance matrix.
@ -189,8 +197,9 @@ const size_t NonlinearBeamformer::kNumFreqBins;
NonlinearBeamformer::NonlinearBeamformer( NonlinearBeamformer::NonlinearBeamformer(
const std::vector<Point>& array_geometry) const std::vector<Point>& array_geometry)
: num_input_channels_(array_geometry.size()), : num_input_channels_(array_geometry.size()),
array_geometry_(GetCenteredArray(array_geometry)) { array_geometry_(GetCenteredArray(array_geometry)),
min_mic_spacing_(GetMinimumSpacing(array_geometry)) {
WindowGenerator::KaiserBesselDerived(kKbdAlpha, kFftSize, window_); WindowGenerator::KaiserBesselDerived(kKbdAlpha, kFftSize, window_);
} }
@ -253,8 +262,10 @@ void NonlinearBeamformer::Initialize(int chunk_size_ms, int sample_rate_hz) {
} }
void NonlinearBeamformer::InitInterfAngles() { void NonlinearBeamformer::InitInterfAngles() {
// TODO(aluebs): Make kAwayRadians dependent on the mic spacing. const float kAwayRadians =
const float kAwayRadians = 0.5; std::min(static_cast<float>(M_PI),
std::max(kMinAwayRadians, kAwaySlope * static_cast<float>(M_PI) /
min_mic_spacing_));
interf_angles_radians_.clear(); interf_angles_radians_.clear();
// TODO(aluebs): When the target angle is settable, make sure the interferer // TODO(aluebs): When the target angle is settable, make sure the interferer

View File

@ -116,6 +116,9 @@ class NonlinearBeamformer
const std::vector<Point> array_geometry_; const std::vector<Point> array_geometry_;
// Minimum spacing between microphone pairs.
const float min_mic_spacing_;
// Calculated based on user-input and constants in the .cc file. // Calculated based on user-input and constants in the .cc file.
size_t low_mean_start_bin_; size_t low_mean_start_bin_;
size_t low_mean_end_bin_; size_t low_mean_end_bin_;

View File

@ -168,6 +168,7 @@
# 'audio_processing/agc/agc_unittest.cc', # 'audio_processing/agc/agc_unittest.cc',
'audio_processing/agc/histogram_unittest.cc', 'audio_processing/agc/histogram_unittest.cc',
'audio_processing/agc/mock_agc.h', 'audio_processing/agc/mock_agc.h',
'audio_processing/beamformer/array_util_unittest.cc',
'audio_processing/beamformer/complex_matrix_unittest.cc', 'audio_processing/beamformer/complex_matrix_unittest.cc',
'audio_processing/beamformer/covariance_matrix_generator_unittest.cc', 'audio_processing/beamformer/covariance_matrix_generator_unittest.cc',
'audio_processing/beamformer/matrix_unittest.cc', 'audio_processing/beamformer/matrix_unittest.cc',