File: filter1.h

package info (click to toggle)
amb-plugins 0.3.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 192 kB
  • ctags: 412
  • sloc: cpp: 1,664; makefile: 25
file content (125 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
    Copyright (C) 2004-2006 Fons Adriaensen
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#ifndef __FILTER1_H
#define __FILTER1_H


/* --------------------------------------------------------------- 

Lowpass1

First order lowpass, -3dB at f3dB.

--------------------------------------------------------------- */

class Lowpass1
{
public:

    Lowpass1 (void) : _a (0), _z (0) {}
    ~Lowpass1 (void) {}

    void init (float fsam, float f3db);
    void reset (void) { _z = 0; }
    float process (float x)
    {
        float d;
        d = _a * (x - _z);
        x  = _z + d;
        _z =  x + d + 1e-20f;      
        return x;    
    }

    float    _a;
    float    _z;
};


/* --------------------------------------------------------------- 

Allpass1

First order allpass having 0, 90, 180 degrees phase shift at
resp. LF, fmid, HF.

--------------------------------------------------------------- */

class Allpass1
{
public:

    Allpass1 (void) : _d (0), _z (0) {}
    ~Allpass1 (void) {}

    void init (float fsam, float fmid);
    void reset (void) { _z = 0; }
    float process (float x)
    {
        float y;
        x =  x - _d * _z;
        y = _z + _d *  x;
        _z = x + 1e-20f;        
        return y;
    }

    float    _d;
    float    _z;
};


/* --------------------------------------------------------------- 

Pcshelf1

First order shelf filter having the same phase response as a
first order allpass set for 90 degrees at fmid.
Useful for phase aligned shelfs for Ambisonics decoders etc.
See shelf1-plot.cc for tests.

--------------------------------------------------------------- */

class Pcshelf1
{
public:

    Pcshelf1 (void) : _d1 (0), _d2 (0), _g (0), _z (0) {}
    ~Pcshelf1 (void) {}

    void init (float fsam, float fmid, float glf, float ghf);
    void reset (void) { _z = 0; }
    float process (float x)
    {
 	float y;
        x =  x - _d2 * _z;
        y = _z + _d1 *  x;
        _z = x + 1e-20f;        
        return _g * y;
    }

    float    _d1;
    float    _d2;
    float    _g;
    float    _z;
};



#endif