blob: 85698ca636bbb5dffd93f9dd1ba348768f792641 [file] [log] [blame]
Mathias Agopian671a6ff2010-11-11 17:58:51 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H
18#define ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23// ---------------------------------------------------------------------------
24
25namespace android {
26// ---------------------------------------------------------------------------
27
28class BiquadFilter;
29
30/*
31 * State of a 2nd order low-pass IIR filter
32 */
33class SecondOrderLowPassFilter {
34 friend class BiquadFilter;
35 float iQ, fc;
36 float K, iD;
37 float a0, a1;
38 float b1, b2;
39public:
40 SecondOrderLowPassFilter(float Q, float fc);
41 void setSamplingPeriod(float dT);
42};
43
44/*
45 * Implements a Biquad IIR filter
46 */
47class BiquadFilter {
48 float x1, x2;
49 float y1, y2;
50 const SecondOrderLowPassFilter& s;
51public:
52 BiquadFilter(const SecondOrderLowPassFilter& s);
53 float init(float in);
54 float operator()(float in);
55};
56
Mathias Agopian6038db32010-11-11 17:58:51 -080057/*
58 * Two cascaded biquad IIR filters
59 * (4-poles IIR)
60 */
61class CascadedBiquadFilter {
62 BiquadFilter mA;
63 BiquadFilter mB;
64public:
65 CascadedBiquadFilter(const SecondOrderLowPassFilter& s);
66 float init(float in);
67 float operator()(float in);
68};
Mathias Agopian671a6ff2010-11-11 17:58:51 -080069
70// ---------------------------------------------------------------------------
71}; // namespace android
72
73#endif // ANDROID_SECOND_ORDER_LOW_PASS_FILTER_H