-
Notifications
You must be signed in to change notification settings - Fork 52
/
gate_1410.xml
186 lines (159 loc) · 5.46 KB
/
gate_1410.xml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?xml version="1.0"?>
<!DOCTYPE ladspa SYSTEM "ladspa-swh.dtd">
<?xml-stylesheet href="ladspa.css" type="text/css"?>
<ladspa>
<global>
<meta name="maker" value="Steve Harris <steve@plugin.org.uk>"/>
<meta name="copyright" value="GPL"/>
<meta name="properties" value="HARD_RT_CAPABLE"/>
<code><![CDATA[
#include "ladspa-util.h"
#include "util/biquad.h"
#define ENV_TR 0.0001f
#define CLOSED 1
#define OPENING 2
#define OPEN 3
#define CLOSING 4
]]></code>
</global>
<plugin label="gate" id="1410" class="GatePlugin">
<name>Gate</name>
<p>The parameters are copied from the Drawmer DS-201, but I've never used one, so if someone out there has one, please tell me if it behaves differently.</p>
<callback event="instantiate"><![CDATA[
fs = s_rate;
env = 0.0f;
gate = 0.0f;
state = CLOSED;
hold_count = 0;
lf = malloc(sizeof(biquad));
hf = malloc(sizeof(biquad));
biquad_init(lf);
biquad_init(hf);
]]></callback>
<callback event="activate"><![CDATA[
env = 0.0f;
gate = 0.0f;
state = CLOSED;
biquad_init(lf);
biquad_init(hf);
]]></callback>
<callback event="cleanup"><![CDATA[
free(plugin_data->lf);
free(plugin_data->hf);
]]></callback>
<callback event="run"><![CDATA[
unsigned long pos;
float cut = DB_CO(range);
float t_level = DB_CO(threshold);
float a_rate = 1000.0f / (attack * fs);
float d_rate = 1000.0f / (decay * fs);
float post_filter, apost_filter;
int op = f_round(select);
ls_set_params(lf, lf_fc, -40.0f, 0.6f, fs);
hs_set_params(hf, hf_fc, -50.0f, 0.6f, fs);
for (pos = 0; pos < sample_count; pos++) {
post_filter = biquad_run(lf, input[pos]);
post_filter = biquad_run(hf, post_filter);
apost_filter = fabs(post_filter);
if (apost_filter > env) {
env = apost_filter;
} else {
env = apost_filter * ENV_TR + env * (1.0f - ENV_TR);
}
if (state == CLOSED) {
if (env >= t_level) {
state = OPENING;
}
} else if (state == OPENING) {
gate += a_rate;
if (gate >= 1.0f) {
gate = 1.0f;
state = OPEN;
hold_count = f_round(hold * fs * 0.001f);
plugin_data->hold_count = hold_count;
}
} else if (state == OPEN) {
if (hold_count <= 0) {
if (env < t_level) {
state = CLOSING;
}
} else {
hold_count--;
}
} else if (state == CLOSING) {
gate -= d_rate;
if (env >= t_level) {
state = OPENING;
} else if (gate <= 0.0f) {
gate = 0.0f;
state = CLOSED;
}
}
if (op == 0) {
buffer_write(output[pos], input[pos] * (cut * (1.0f - gate) + gate));
} else if (op == -1) {
buffer_write(output[pos], post_filter);
} else {
buffer_write(output[pos], input[pos]);
}
}
plugin_data->env = env;
plugin_data->gate = gate;
plugin_data->state = state;
plugin_data->hold_count = hold_count;
]]></callback>
<port label="lf_fc" dir="input" type="control" hint="sample_rate,default_minimum">
<name>LF key filter (Hz)</name>
<p>Controls the cutoff of the low frequency filter (highpass).</p>
<range min="0.0007f" max="0.1"/>
</port>
<port label="hf_fc" dir="input" type="control" hint="sample_rate,default_maximum">
<name>HF key filter (Hz)</name>
<p>Controls the cutoff of the high frequency filter (lowpass).</p>
<range min="0.005f" max="0.49"/>
</port>
<port label="threshold" dir="input" type="control" hint="default_minimum">
<name>Threshold (dB)</name>
<p>Controls the level at which the gate will open.</p>
<range min="-70" max="+20"/>
</port>
<port label="attack" dir="input" type="control" hint="default_low">
<name>Attack (ms)</name>
<p>Controls the time the gate will take to open fully.</p>
<range min="0.01" max="1000"/>
</port>
<port label="hold" dir="input" type="control" hint="default_high">
<name>Hold (ms)</name>
<p>Controls the minimum time the gate will stay open for.</p>
<range min="2" max="2000"/>
</port>
<port label="decay" dir="input" type="control" hint="default_middle">
<name>Decay (ms)</name>
<p>Controls the time the gate will take to close fully.</p>
<range min="2" max="4000"/>
</port>
<port label="range" dir="input" type="control" hint="default_minimum">
<name>Range (dB)</name>
<p>Controls the difference between the gate's open and closed state.</p>
<range min="-90" max="0"/>
</port>
<port label="select" dir="input" type="control" hint="integer,default_0">
<name>Output select (-1 = key listen, 0 = gate, 1 = bypass)</name>
<p>Controls output monitor. -1 is the output of the key filters (so you can check what is being gated on). 0 is the normal, gated output. 1 is bypass mode.</p>
<range min="-1" max="1"/>
</port>
<port label="input" dir="input" type="audio">
<name>Input</name>
</port>
<port label="output" dir="output" type="audio">
<name>Output</name>
</port>
<instance-data label="fs" type="float" />
<instance-data label="env" type="float" />
<instance-data label="gate" type="float" />
<instance-data label="state" type="int" />
<instance-data label="hold_count" type="int" />
<instance-data label="lf" type="biquad *" />
<instance-data label="hf" type="biquad *" />
</plugin>
</ladspa>