Chromium Code Reviews| Index: webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc |
| diff --git a/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc b/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f3e24d9c2ad9c0933a34adc235094f1af2dddc5 |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.cc |
| @@ -0,0 +1,56 @@ |
| +/* |
| + * 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 "webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.h" |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +CascadedBiQuadFilter::CascadedBiQuadFilter( |
| + const CascadedBiQuadFilter::BiQuadCoefficients& coefficients, |
| + size_t num_biquads) |
| + : biquad_states_(num_biquads), coefficients_(coefficients) {} |
| + |
| +CascadedBiQuadFilter::~CascadedBiQuadFilter() = default; |
| + |
| +void CascadedBiQuadFilter::Process(rtc::ArrayView<const float> x, |
| + rtc::ArrayView<float> y) { |
| + ApplyBiQuad(x, y, &biquad_states_[0]); |
| + for (size_t k = 1; k < biquad_states_.size(); ++k) { |
| + ApplyBiQuad(y, y, &biquad_states_[k]); |
| + } |
| +} |
| + |
| +void CascadedBiQuadFilter::Process(rtc::ArrayView<float> y) { |
| + for (auto& biquad : biquad_states_) { |
| + ApplyBiQuad(y, y, &biquad); |
| + } |
| +} |
| + |
| +void CascadedBiQuadFilter::ApplyBiQuad( |
| + rtc::ArrayView<const float> x, |
| + rtc::ArrayView<float> y, |
| + CascadedBiQuadFilter::BiQuadState* biquad_state) { |
|
aleloi
2016/12/20 15:55:35
Please check that y is large enough.
ivoc
2016/12/21 13:04:05
x as well, and a dcheck that biquad_state is not a
peah-webrtc
2016/12/21 23:13:50
Good point!
Done.
peah-webrtc
2016/12/21 23:13:50
Good find!
Done.
|
| + const auto c_b = coefficients_.b; |
| + const auto c_a = coefficients_.a; |
| + auto m_x = biquad_state->x; |
| + auto m_y = biquad_state->y; |
| + for (size_t k = 0; k < x.size(); ++k) { |
| + const float tmp = x[k]; |
| + y[k] = c_b[0] * tmp + c_b[1] * m_x[0] + c_b[2] * m_x[1] - c_a[0] * m_y[0] - |
| + c_a[1] * m_y[1]; |
| + m_x[1] = m_x[0]; |
| + m_x[0] = tmp; |
| + m_y[1] = m_y[0]; |
| + m_y[0] = y[k]; |
| + } |
| +} |
| + |
| +} // namespace webrtc |