Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 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 "modules/audio_processing/agc2/biquad_filter.h" |
| 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 13 | #include <stddef.h> |
| 14 | |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 15 | namespace webrtc { |
| 16 | |
Alessio Bazzica | d8d0214 | 2018-05-07 13:26:47 +0200 | [diff] [blame] | 17 | // Transposed direct form I implementation of a bi-quad filter applied to an |
| 18 | // input signal |x| to produce an output signal |y|. |
Alex Loiko | 4ed47d0 | 2018-04-04 15:05:57 +0200 | [diff] [blame] | 19 | void 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 |