Line data Source code
1 : /*
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 "webrtc/modules/audio_processing/level_controller/biquad_filter.h"
12 :
13 : namespace webrtc {
14 :
15 : // This method applies a biquad filter to an input signal x to produce an
16 : // output signal y. The biquad coefficients are specified at the construction
17 : // of the object.
18 0 : void BiQuadFilter::Process(rtc::ArrayView<const float> x,
19 : rtc::ArrayView<float> y) {
20 0 : for (size_t k = 0; k < x.size(); ++k) {
21 : // Use temporary variable for x[k] to allow in-place function call
22 : // (that x and y refer to the same array).
23 0 : const float tmp = x[k];
24 0 : y[k] = coefficients_.b[0] * tmp + coefficients_.b[1] * biquad_state_.b[0] +
25 0 : coefficients_.b[2] * biquad_state_.b[1] -
26 0 : coefficients_.a[0] * biquad_state_.a[0] -
27 0 : coefficients_.a[1] * biquad_state_.a[1];
28 0 : biquad_state_.b[1] = biquad_state_.b[0];
29 0 : biquad_state_.b[0] = tmp;
30 0 : biquad_state_.a[1] = biquad_state_.a[0];
31 0 : biquad_state_.a[0] = y[k];
32 : }
33 0 : }
34 :
35 : } // namespace webrtc
|