~ubuntu-branches/ubuntu/raring/fomp/raring

« back to all changes in this revision

Viewing changes to src/cs_phaser.cc

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-11-05 10:49:59 UTC
  • Revision ID: package-import@ubuntu.com-20121105104959-2q6sje2d5fhjevfv
Tags: upstream-1.0.0~dfsg0
ImportĀ upstreamĀ versionĀ 1.0.0~dfsg0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
 
3
   
 
4
  This program is free software; you can redistribute it and/or modify
 
5
  it under the terms of the GNU General Public License as published by
 
6
  the Free Software Foundation; either version 2 of the License, or
 
7
  (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public License
 
15
  along with this program; if not, write to the Free Software
 
16
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
 
 
20
#include <stdio.h>
 
21
#include <math.h>
 
22
#include "cs_phaser.h"
 
23
#include "exp2ap.h"
 
24
 
 
25
 
 
26
void Ladspa_CS_phaser1::setport (PortIndex port, PortData *data)
 
27
{
 
28
        _port [port] = (float*)data;
 
29
}
 
30
 
 
31
 
 
32
void Ladspa_CS_phaser1::active (bool act)
 
33
{
 
34
    if (act)
 
35
    {
 
36
        _w = _z = 0;
 
37
        for (int i = 0; i < NSECT; i++) _c [i] = 0;
 
38
    }
 
39
}
 
40
 
 
41
 
 
42
void Ladspa_CS_phaser1::runproc (SampleCount len, bool add)
 
43
{
 
44
    int   i, k, ns;
 
45
    float *p0, *p1, *p2, *p3, *p4;
 
46
    float g0, gf, gi, gm;
 
47
    float d, t, w, dw, x, z;
 
48
 
 
49
    p0 = _port [0];    
 
50
    p1 = _port [1];    
 
51
    p2 = _port [2] - 1;    
 
52
    p3 = _port [3] - 1;    
 
53
    p4 = _port [4] - 1;    
 
54
    
 
55
    ns = (int)(floor (_port [6][0] + 0.5));
 
56
    g0 = exp2ap (0.1661f * _port [5][0]);
 
57
    gf = _port [10][0];
 
58
    gm = _port [11][0];
 
59
    gi = 1 - fabs (gm);
 
60
   
 
61
    w = _w;
 
62
    z = _z + 1e-10f;
 
63
 
 
64
    do
 
65
    {
 
66
        k = (len > 24) ? 16 : len;
 
67
        p2 += k;
 
68
        p3 += k;
 
69
        p4 += k;
 
70
        len -= k;
 
71
 
 
72
        t = (exp2ap (_port [8][0] * *p3 + _port [7][0] + *p2 + 9.683f) + _port [9][0] * *p4 * 1000.0f) / _fsam;
 
73
        if (t < 0.0f) t = 0.0f;
 
74
        if (t > 1.5f) t = 1.5f;
 
75
        t = (sinf (t) - 1) / cosf (t) + 1;
 
76
        dw = (t - w) / k;
 
77
 
 
78
        while (k--)
 
79
        {
 
80
            w += dw;
 
81
            x = g0 * *p0++;
 
82
            z = gf * z + x;
 
83
            z = 4 * tanhf (0.25f * z);
 
84
            for (i = 0; i < ns; i++)
 
85
            {
 
86
                t = _c [i];
 
87
                d = w * (2 * z - t);
 
88
                t += d;
 
89
                _c [i] = t + d;
 
90
                z = t - z;
 
91
            }  
 
92
            t = gm * z + gi * x;                
 
93
            if (add) *p1++ += t * _gain;
 
94
            else     *p1++  = t;
 
95
        } 
 
96
    }
 
97
    while (len);
 
98
 
 
99
    _w = w;
 
100
    _z = z;
 
101
}
 
102
 
 
103
 
 
104
 
 
105
void Ladspa_CS_phaser1lfo::setport (PortIndex port, PortData *data)
 
106
{
 
107
        _port [port] = (float*)data;
 
108
}
 
109
 
 
110
 
 
111
void Ladspa_CS_phaser1lfo::active (bool act)
 
112
{
 
113
    if (act)
 
114
    {
 
115
        _gi = 0;
 
116
        _z = _w = _v = _p = 0;
 
117
        for (int i = 0; i < NSECT; i++) _c [i] = 0;
 
118
    }
 
119
}
 
120
 
 
121
 
 
122
 
 
123
 
 
124
void Ladspa_CS_phaser1lfo::runproc (SampleCount len, bool add)
 
125
{
 
126
    int   i, k, ns;
 
127
    float *p0, *p1;
 
128
    float g0, gf, gi, gm;
 
129
    float d, t, w, v, x, z;
 
130
 
 
131
    p0 = _port [0];    
 
132
    p1 = _port [1];    
 
133
 
 
134
    ns = (int)(floor (_port [3][0] + 0.5));
 
135
    g0 = exp2ap (0.1661f * _port [2][0]);
 
136
    gf = _port [8][0];
 
137
    gm = _port [9][0];
 
138
    gi = 1 - fabs (gm);
 
139
 
 
140
    z = _z + 1e-10f;
 
141
    w = _w;
 
142
    v = _v;
 
143
 
 
144
    do
 
145
    {
 
146
        if (_gi == 0)
 
147
        {
 
148
            _gi = DSUB;
 
149
            _p += 2 * DSUB * _port [5][0] / _fsam;
 
150
            if (_p > 1) _p -= 2;
 
151
            x = 0.999f * _port [6][0];
 
152
            d = _p - x;
 
153
            if (d < 0) t = 0.5f + d / (1 + x);
 
154
            else       t = 0.5f - d / (1 - x);            
 
155
            t = exp2ap (_port [7][0] * t + _port [4][0] + 9.683f) / _fsam;
 
156
            if (t < 0.0f) t = 0.0f;
 
157
            if (t > 1.5f) t = 1.5f;
 
158
            t = (sinf (t) - 1) / cosf (t) + 1;
 
159
            v = (t - w) / DSUB;
 
160
        }
 
161
 
 
162
        k = (_gi < len) ? _gi : len;
 
163
        _gi -= k;
 
164
        len -= k;
 
165
        while (k--)
 
166
        {
 
167
            x = g0 * *p0++;
 
168
            z = gf * z + x;
 
169
            z = 4 * tanhf (0.25f * z);
 
170
            for (i = 0; i < ns; i++)
 
171
            {
 
172
                t = _c [i];
 
173
                d = w * (2 * z - t);
 
174
                t += d;
 
175
                _c [i] = t + d;
 
176
                z = t - z;
 
177
            }  
 
178
            t = gm * z + gi * x;                
 
179
            if (add) *p1++ += t * _gain;
 
180
            else     *p1++  = t;
 
181
            w += v;
 
182
        } 
 
183
    }
 
184
    while (len);
 
185
 
 
186
    _z = z;
 
187
    _w = w;
 
188
    _v = v;
 
189
}
 
190
 
 
191