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 #ifndef MODULES_AUDIO_PROCESSING_AEC3_CASCADED_BIQUAD_FILTER_H_
12 #define MODULES_AUDIO_PROCESSING_AEC3_CASCADED_BIQUAD_FILTER_H_
13 
14 #include <vector>
15 
16 #include "api/array_view.h"
17 #include "rtc_base/constructormagic.h"
18 
19 namespace webrtc {
20 
21 // Applies a number of identical biquads in a cascaded manner. The filter
22 // implementation is direct form 1.
23 class CascadedBiQuadFilter {
24  public:
25   struct BiQuadState {
BiQuadStateBiQuadState26     BiQuadState() : x(), y() {}
27     float x[2];
28     float y[2];
29   };
30 
31   struct BiQuadCoefficients {
32     float b[3];
33     float a[2];
34   };
35 
36   CascadedBiQuadFilter(
37       const CascadedBiQuadFilter::BiQuadCoefficients& coefficients,
38       size_t num_biquads);
39   ~CascadedBiQuadFilter();
40   // Applies the biquads on the values in x in order to form the output in y.
41   void Process(rtc::ArrayView<const float> x, rtc::ArrayView<float> y);
42   // Applies the biquads on the values in y in an in-place manner.
43   void Process(rtc::ArrayView<float> y);
44 
45  private:
46   void ApplyBiQuad(rtc::ArrayView<const float> x,
47                    rtc::ArrayView<float> y,
48                    CascadedBiQuadFilter::BiQuadState* biquad_state);
49 
50   std::vector<BiQuadState> biquad_states_;
51   const BiQuadCoefficients coefficients_;
52 
53   RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CascadedBiQuadFilter);
54 };
55 
56 }  // namespace webrtc
57 
58 #endif  // MODULES_AUDIO_PROCESSING_AEC3_CASCADED_BIQUAD_FILTER_H_
59