~ubuntu-branches/ubuntu/quantal/tetraproc/quantal

« back to all changes in this revision

Viewing changes to source/pmfilt.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-03-24 14:56:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110324145648-r9qi83fs3wej4801
Tags: upstream-0.8.2
ImportĀ upstreamĀ versionĀ 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ----------------------------------------------------------------------------
 
2
//
 
3
//  Copyright (C) 2006-2008 Fons Adriaensen <fons@linuxaudio.org>
 
4
//    
 
5
//  This program is free software; you can redistribute it and/or modify
 
6
//  it under the terms of the GNU General Public License as published by
 
7
//  the Free Software Foundation; either version 2 of the License, or
 
8
//  (at your option) any later version.
 
9
//
 
10
//  This program is distributed in the hope that it will be useful,
 
11
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
//  GNU General Public License for more details.
 
14
//
 
15
//  You should have received a copy of the GNU General Public License
 
16
//  along with this program; if not, write to the Free Software
 
17
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
//
 
19
// ----------------------------------------------------------------------------
 
20
 
 
21
 
 
22
#include <math.h>
 
23
#include "pmfilt.h"
 
24
 
 
25
 
 
26
#define PIF 3.141592f
 
27
#define P2F 6.283185f
 
28
 
 
29
 
 
30
void PM_filt1::init (float w, float b, float g)
 
31
{
 
32
    b *= PIF * w;         
 
33
//    if (g < 1.0f) b /= g;  // Uncomment for +/- gain symmetry - NOT for TetraProc
 
34
    _g = 0.5f * (g - 1);
 
35
    _c1 = -cosf (P2F * w);
 
36
    _c2 = (1 - b) / (1 + b);
 
37
}
 
38
 
 
39
 
 
40
void PM_filt1::init (PM_filt1& F)
 
41
{
 
42
    _g  = F._g;
 
43
    _c1 = F._c1;
 
44
    _c2 = F._c2;
 
45
}
 
46
 
 
47
 
 
48
void PM_filt1::process (int n, float *ip, float *op)
 
49
{
 
50
    float x, y, z1, z2;
 
51
 
 
52
    z1 = _z1;
 
53
    z2 = _z2;
 
54
    while (n--)
 
55
    {
 
56
        x = *ip++;
 
57
        y = x - _c2 * z2;
 
58
        x -= _g * (z2 + _c2 * y - x);                           
 
59
        y -= _c1 * z1;
 
60
        z2 = z1 + _c1 * y;
 
61
        z1 = y + 1e-10f;
 
62
        *op++ = x;
 
63
    }
 
64
    _z1 = z1;
 
65
    _z2 = z2;
 
66
}
 
67
 
 
68
 
 
69
 
 
70
void PM_filt2::init (float w1, float b1, float g1, float w2, float b2, float g2, float gc)
 
71
{
 
72
    b1 *= PIF * w1;         
 
73
//    if (g1 < 1.0f) b1 /= g1;  // Uncomment for +/- gain symmetry - NOT for TetraProc
 
74
    _g1 = (g1 - 1) / 2;
 
75
    _c1 = -cosf (P2F * w1);
 
76
    _c2 = (1 - b1) / (1 + b1);
 
77
    b2 *= PIF * w2;         
 
78
//    if (g2 < 1.0f) b2 /= g2;  // Uncomment for +/- gain symmetry - NOT for TetraProc 
 
79
    _g2 = (g2 - 1) / 2;
 
80
    _c3 = -cosf (P2F * w2);
 
81
    _c4 = (1 - b2) / (1 + b2);
 
82
    _gc = gc;
 
83
}
 
84
 
 
85
 
 
86
void PM_filt2::init (PM_filt2& F)
 
87
{
 
88
    _g1 = F._g1;
 
89
    _g2 = F._g2;
 
90
    _gc = F._gc;
 
91
    _c1 = F._c1;
 
92
    _c2 = F._c2;
 
93
    _c3 = F._c3;
 
94
    _c4 = F._c4;
 
95
}
 
96
 
 
97
 
 
98
void PM_filt2::process (int n, float *ip, float *op)
 
99
{
 
100
    float x, y, z1, z2, z3, z4;
 
101
 
 
102
    z1 = _z1;
 
103
    z2 = _z2;
 
104
    z3 = _z3;
 
105
    z4 = _z4;
 
106
    while (n--)
 
107
    {
 
108
        x = *ip++;
 
109
        y = x - _c2 * z2;
 
110
        x -= _g1 * (z2 + _c2 * y - x);                           
 
111
        y -= _c1 * z1;
 
112
        z2 = z1 + _c1 * y;
 
113
        z1 = y + 1e-10f;
 
114
        y = x - _c4 * z4;
 
115
        x -= _g2 * (z4 + _c4 * y - x);                           
 
116
        y -= _c3 * z3;
 
117
        z4 = z3 + _c3 * y;
 
118
        z3 = y + 1e-10f;
 
119
        *op++ = x * _gc;
 
120
    }
 
121
    _z1 = z1;
 
122
    _z2 = z2;
 
123
    _z3 = z3;
 
124
    _z4 = z4;
 
125
}