blob: da8557c19082c1ca18091b3b6f484ae5ebb46ef3 [file] [log] [blame]
Alex Loiko4ed47d02018-04-04 15:05:57 +02001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "modules/audio_processing/agc2/biquad_filter.h"
12
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stddef.h>
14
Alex Loiko4ed47d02018-04-04 15:05:57 +020015namespace webrtc {
16
Alessio Bazzicad8d02142018-05-07 13:26:47 +020017// Transposed direct form I implementation of a bi-quad filter applied to an
18// input signal |x| to produce an output signal |y|.
Alex Loiko4ed47d02018-04-04 15:05:57 +020019void BiQuadFilter::Process(rtc::ArrayView<const float> x,
20 rtc::ArrayView<float> y) {
21 for (size_t k = 0; k < x.size(); ++k) {
22 // Use temporary variable for x[k] to allow in-place function call
23 // (that x and y refer to the same array).
24 const float tmp = x[k];
25 y[k] = coefficients_.b[0] * tmp + coefficients_.b[1] * biquad_state_.b[0] +
26 coefficients_.b[2] * biquad_state_.b[1] -
27 coefficients_.a[0] * biquad_state_.a[0] -
28 coefficients_.a[1] * biquad_state_.a[1];
29 biquad_state_.b[1] = biquad_state_.b[0];
30 biquad_state_.b[0] = tmp;
31 biquad_state_.a[1] = biquad_state_.a[0];
32 biquad_state_.a[0] = y[k];
33 }
34}
35
36} // namespace webrtc