File: filters.h

package info (click to toggle)
fil-plugins 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 136 kB
  • ctags: 141
  • sloc: cpp: 432; makefile: 14
file content (130 lines) | stat: -rw-r--r-- 3,035 bytes parent folder | download | duplicates (3)
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
126
127
128
129
130
/*
    Copyright (C) 2004-2009 Fons Adriaensen <fons@kokkinizita.net>
    
    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 __FILTERS_H
#define __FILTERS_H

#include <math.h>
#include "ladspaplugin.h"


class Paramsect
{
public:

    enum { SECT, FREQ, BAND, GAIN };

    void init (void)
    {
        _f = 0.25f;
        _b = _g = 1.0f;
	_a = _s1 = _s2 = _z1 = _z2 = 0.0f;
    }
    
    void proc (int k, float *sig, float f, float b, float g)
    {
        float s1, s2, d1, d2, a, da, x, y;
        bool  u2 = false;

        s1 = _s1;        
        s2 = _s2;
        a = _a; 
        d1 = 0;
        d2 = 0;
        da = 0;

        if (f != _f)
	{
  	    if      (f < 0.5f * _f) f = 0.5f * _f;
            else if (f > 2.0f * _f) f = 2.0f * _f;
            _f = f;
            _s1 = -cosf (6.283185f * f);
            d1 = (_s1 - s1) / k;           
            u2 = true;
	}             
       
        if (g != _g)
	{
            if      (g < 0.5f * _g) g = 0.5f * _g;
            else if (g > 2.0f * _g) g = 2.0f * _g;
	    _g = g;
            _a = 0.5f * (g - 1.0f);
            da = (_a - a) / k;
            u2 = true;
	}

        if (b != _b)
	{
            if      (b < 0.5f * _b) b = 0.5f * _b;
            else if (b > 2.0f * _b) b = 2.0f * _b;
            _b = b; 
            u2 = true;
	}

        if (u2)
	{
            b *= 7 * f / sqrtf (g);         
            _s2 = (1 - b) / (1 + b);
            d2 = (_s2 - s2) / k;        
	}

        while (k--)
	{  
	    s1 += d1;
	    s2 += d2;
            a += da;
            x = *sig;
            y = x - s2 * _z2;
            *sig++ -= a * (_z2 + s2 * y - x);                           
            y -= s1 * _z1;
            _z2 = _z1 + s1 * y;
            _z1 = y + 1e-10f;
	}
    }
    
private:

    float  _f, _b, _g;
    float  _s1, _s2, _a;
    float  _z1, _z2;
};


class Ladspa_Paramfilt : public LadspaPlugin
{
public:

    enum { AIP, AOP, FILT, GAIN, SECT, NSECT = 4, NPORT = 20 };

    Ladspa_Paramfilt (unsigned long fsam) : LadspaPlugin (fsam) {}
    virtual void setport (unsigned long port, LADSPA_Data *data);  
    virtual void active  (bool act);  
    virtual void runproc (unsigned long len, bool add);
    virtual ~Ladspa_Paramfilt (void) {}  

private:

    float     *_port [NPORT];
    float      _gain;
    int        _fade;
    Paramsect  _sect [NSECT];
};


#endif