Update to current webrtc library
This is from the upstream library commit id 3326535126e435f1ba647885ce43a8f0f3d317eb, corresponding to Chromium 88.0.4290.1.
This commit is contained in:
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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 "modules/audio_processing/echo_detector/circular_buffer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
CircularBuffer::CircularBuffer(size_t size) : buffer_(size) {}
|
||||
CircularBuffer::~CircularBuffer() = default;
|
||||
|
||||
void CircularBuffer::Push(float value) {
|
||||
buffer_[next_insertion_index_] = value;
|
||||
++next_insertion_index_;
|
||||
next_insertion_index_ %= buffer_.size();
|
||||
RTC_DCHECK_LT(next_insertion_index_, buffer_.size());
|
||||
nr_elements_in_buffer_ = std::min(nr_elements_in_buffer_ + 1, buffer_.size());
|
||||
RTC_DCHECK_LE(nr_elements_in_buffer_, buffer_.size());
|
||||
}
|
||||
|
||||
absl::optional<float> CircularBuffer::Pop() {
|
||||
if (nr_elements_in_buffer_ == 0) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
const size_t index =
|
||||
(buffer_.size() + next_insertion_index_ - nr_elements_in_buffer_) %
|
||||
buffer_.size();
|
||||
RTC_DCHECK_LT(index, buffer_.size());
|
||||
--nr_elements_in_buffer_;
|
||||
return buffer_[index];
|
||||
}
|
||||
|
||||
void CircularBuffer::Clear() {
|
||||
std::fill(buffer_.begin(), buffer_.end(), 0.f);
|
||||
next_insertion_index_ = 0;
|
||||
nr_elements_in_buffer_ = 0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_
|
||||
#define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Ring buffer containing floating point values.
|
||||
struct CircularBuffer {
|
||||
public:
|
||||
explicit CircularBuffer(size_t size);
|
||||
~CircularBuffer();
|
||||
|
||||
void Push(float value);
|
||||
absl::optional<float> Pop();
|
||||
size_t Size() const { return nr_elements_in_buffer_; }
|
||||
// This function fills the buffer with zeros, but does not change its size.
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
std::vector<float> buffer_;
|
||||
size_t next_insertion_index_ = 0;
|
||||
// This is the number of elements that have been pushed into the circular
|
||||
// buffer, not the allocated buffer size.
|
||||
size_t nr_elements_in_buffer_ = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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 "modules/audio_processing/echo_detector/mean_variance_estimator.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
// Parameter controlling the adaptation speed.
|
||||
constexpr float kAlpha = 0.001f;
|
||||
|
||||
} // namespace
|
||||
|
||||
void MeanVarianceEstimator::Update(float value) {
|
||||
mean_ = (1.f - kAlpha) * mean_ + kAlpha * value;
|
||||
variance_ =
|
||||
(1.f - kAlpha) * variance_ + kAlpha * (value - mean_) * (value - mean_);
|
||||
RTC_DCHECK(isfinite(mean_));
|
||||
RTC_DCHECK(isfinite(variance_));
|
||||
}
|
||||
|
||||
float MeanVarianceEstimator::std_deviation() const {
|
||||
RTC_DCHECK_GE(variance_, 0.f);
|
||||
return sqrtf(variance_);
|
||||
}
|
||||
|
||||
float MeanVarianceEstimator::mean() const {
|
||||
return mean_;
|
||||
}
|
||||
|
||||
void MeanVarianceEstimator::Clear() {
|
||||
mean_ = 0.f;
|
||||
variance_ = 0.f;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_
|
||||
#define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This class iteratively estimates the mean and variance of a signal.
|
||||
class MeanVarianceEstimator {
|
||||
public:
|
||||
void Update(float value);
|
||||
float std_deviation() const;
|
||||
float mean() const;
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
// Estimate of the expected value of the input values.
|
||||
float mean_ = 0.f;
|
||||
// Estimate of the variance of the input values.
|
||||
float variance_ = 0.f;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MEAN_VARIANCE_ESTIMATOR_H_
|
52
webrtc/modules/audio_processing/echo_detector/moving_max.cc
Normal file
52
webrtc/modules/audio_processing/echo_detector/moving_max.cc
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2017 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 "modules/audio_processing/echo_detector/moving_max.h"
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
// Parameter for controlling how fast the estimated maximum decays after the
|
||||
// previous maximum is no longer valid. With a value of 0.99, the maximum will
|
||||
// decay to 1% of its former value after 460 updates.
|
||||
constexpr float kDecayFactor = 0.99f;
|
||||
|
||||
} // namespace
|
||||
|
||||
MovingMax::MovingMax(size_t window_size) : window_size_(window_size) {
|
||||
RTC_DCHECK_GT(window_size, 0);
|
||||
}
|
||||
|
||||
MovingMax::~MovingMax() {}
|
||||
|
||||
void MovingMax::Update(float value) {
|
||||
if (counter_ >= window_size_ - 1) {
|
||||
max_value_ *= kDecayFactor;
|
||||
} else {
|
||||
++counter_;
|
||||
}
|
||||
if (value > max_value_) {
|
||||
max_value_ = value;
|
||||
counter_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float MovingMax::max() const {
|
||||
return max_value_;
|
||||
}
|
||||
|
||||
void MovingMax::Clear() {
|
||||
max_value_ = 0.f;
|
||||
counter_ = 0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
36
webrtc/modules/audio_processing/echo_detector/moving_max.h
Normal file
36
webrtc/modules/audio_processing/echo_detector/moving_max.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2017 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_
|
||||
#define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class MovingMax {
|
||||
public:
|
||||
explicit MovingMax(size_t window_size);
|
||||
~MovingMax();
|
||||
|
||||
void Update(float value);
|
||||
float max() const;
|
||||
// Reset all of the state in this class.
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
float max_value_ = 0.f;
|
||||
size_t counter_ = 0;
|
||||
size_t window_size_ = 1;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_MOVING_MAX_H_
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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 "modules/audio_processing/echo_detector/normalized_covariance_estimator.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
// Parameter controlling the adaptation speed.
|
||||
constexpr float kAlpha = 0.001f;
|
||||
|
||||
} // namespace
|
||||
|
||||
void NormalizedCovarianceEstimator::Update(float x,
|
||||
float x_mean,
|
||||
float x_sigma,
|
||||
float y,
|
||||
float y_mean,
|
||||
float y_sigma) {
|
||||
covariance_ =
|
||||
(1.f - kAlpha) * covariance_ + kAlpha * (x - x_mean) * (y - y_mean);
|
||||
normalized_cross_correlation_ = covariance_ / (x_sigma * y_sigma + .0001f);
|
||||
RTC_DCHECK(isfinite(covariance_));
|
||||
RTC_DCHECK(isfinite(normalized_cross_correlation_));
|
||||
}
|
||||
|
||||
void NormalizedCovarianceEstimator::Clear() {
|
||||
covariance_ = 0.f;
|
||||
normalized_cross_correlation_ = 0.f;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
|
||||
#define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This class iteratively estimates the normalized covariance between two
|
||||
// signals.
|
||||
class NormalizedCovarianceEstimator {
|
||||
public:
|
||||
void Update(float x,
|
||||
float x_mean,
|
||||
float x_var,
|
||||
float y,
|
||||
float y_mean,
|
||||
float y_var);
|
||||
// This function returns an estimate of the Pearson product-moment correlation
|
||||
// coefficient of the two signals.
|
||||
float normalized_cross_correlation() const {
|
||||
return normalized_cross_correlation_;
|
||||
}
|
||||
float covariance() const { return covariance_; }
|
||||
// This function resets the estimated values to zero.
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
float normalized_cross_correlation_ = 0.f;
|
||||
// Estimate of the covariance value.
|
||||
float covariance_ = 0.f;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
|
Reference in New Issue
Block a user