Add a reliability term to the echo detector.

This will ensure that the estimated likelihood starts at a low value and prevents initial spikes.

BUG=webrtc:6525

Review-Url: https://codereview.webrtc.org/2503843004
Cr-Commit-Position: refs/heads/master@{#15131}
This commit is contained in:
ivoc 2016-11-17 06:19:47 -08:00 committed by Commit bot
parent d51c4dccd7
commit fbb374d8ed
3 changed files with 13 additions and 0 deletions

View File

@ -25,6 +25,7 @@ float Power(rtc::ArrayView<const float> input) {
constexpr size_t kLookbackFrames = 650;
// TODO(ivoc): Verify the size of this buffer.
constexpr size_t kRenderBufferSize = 30;
constexpr float kAlpha = 0.001f;
} // namespace
@ -100,6 +101,8 @@ void ResidualEchoDetector::AnalyzeCaptureAudio(
echo_likelihood_ = std::max(
echo_likelihood_, covariances_[delay].normalized_cross_correlation());
}
reliability_ = (1.0f - kAlpha) * reliability_ + kAlpha * 1.0f;
echo_likelihood_ *= reliability_;
int echo_percentage = static_cast<int>(echo_likelihood_ * 100);
RTC_HISTOGRAM_COUNTS("WebRTC.Audio.ResidualEchoDetector.EchoLikelihood",
echo_percentage, 0, 100, 100 /* number of bins */);
@ -121,6 +124,7 @@ void ResidualEchoDetector::Initialize() {
}
echo_likelihood_ = 0.f;
next_insertion_index_ = 0;
reliability_ = 0.f;
}
void ResidualEchoDetector::PackRenderAudioBuffer(

View File

@ -37,6 +37,9 @@ class ResidualEchoDetector {
// This function should be called while holding the capture lock.
void Initialize();
// This function is for testing purposes only.
void SetReliabilityForTest(float value) { reliability_ = value; }
static void PackRenderAudioBuffer(AudioBuffer* audio,
std::vector<float>* packed_buffer);
@ -71,6 +74,8 @@ class ResidualEchoDetector {
MeanVarianceEstimator capture_statistics_;
// Current echo likelihood.
float echo_likelihood_ = 0.f;
// Reliability of the current likelihood.
float reliability_ = 0.f;
};
} // namespace webrtc

View File

@ -17,6 +17,7 @@ namespace webrtc {
TEST(ResidualEchoDetectorTests, Echo) {
ResidualEchoDetector echo_detector;
echo_detector.SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
@ -41,6 +42,7 @@ TEST(ResidualEchoDetectorTests, Echo) {
TEST(ResidualEchoDetectorTests, NoEcho) {
ResidualEchoDetector echo_detector;
echo_detector.SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
@ -60,6 +62,7 @@ TEST(ResidualEchoDetectorTests, NoEcho) {
TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) {
ResidualEchoDetector echo_detector;
echo_detector.SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
@ -94,6 +97,7 @@ TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) {
TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) {
ResidualEchoDetector echo_detector;
echo_detector.SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);