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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
<?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 <sys/types.h>
#include "ladspa-util.h"
#define INT_SCALE 16384.0f
/* INT_SCALE reciprocal includes factor of two scaling */
#define INT_SCALE_R 0.000030517578125f
#define MAX_AMP 1.0f
#define CLIP 0.8f
#define CLIP_A ((MAX_AMP - CLIP) * (MAX_AMP - CLIP))
#define CLIP_B (MAX_AMP - 2.0f * CLIP)
]]></code>
</global>
<plugin label="giantFlange" id="1437" class="FlangerPlugin">
<name>Giant flange</name>
<p>This is a fairly normal flanger but with excessively long delay times.
Requested by Patrick Shirkey.</p>
<p>To cut down the memory requirements the internal delay buffer only has
15bits of resolution, so there is no headroom, if you feed in signals over 0dB
it will clip the output. There is code to soften the effect of the clipping,
but beware of it.</p>
<callback event="instantiate"><![CDATA[
int buffer_size = 32768;
fs = s_rate;
while (buffer_size < fs * 10.5f) {
buffer_size *= 2;
}
buffer = calloc(buffer_size, sizeof(int16_t));
buffer_mask = buffer_size - 1;
buffer_pos = 0;
x1 = 0.5f;
y1 = 0.0f;
x2 = 0.5f;
y2 = 0.0f;
]]></callback>
<callback event="activate"><![CDATA[
memset(buffer, 0, (buffer_mask + 1) * sizeof(int16_t));
]]></callback>
<callback event="cleanup"><![CDATA[
free(plugin_data->buffer);
]]></callback>
<callback event="run"><![CDATA[
unsigned long pos;
const float omega1 = 6.2831852f * (freq1 / fs);
const float omega2 = 6.2831852f * (freq2 / fs);
float fb;
float d1, d2;
float d1out, d2out;
float fbs;
if (feedback > 99.0f) {
fb = 0.99f;
} else if (feedback < -99.0f) {
fb = -0.99f;
} else {
fb = feedback * 0.01f;
}
if (f_round(deldouble)) {
const float dr1 = delay1 * fs * 0.25f;
const float dr2 = delay2 * fs * 0.25f;
for (pos = 0; pos < sample_count; pos++) {
/* Write input into delay line */
buffer[buffer_pos] = f_round(input[pos] * INT_SCALE);
/* Calcuate delays */
d1 = (x1 + 1.0f) * dr1;
d2 = (y2 + 1.0f) * dr2;
d1out = buffer[(buffer_pos - f_round(d1)) & buffer_mask] * INT_SCALE_R;
d2out = buffer[(buffer_pos - f_round(d2)) & buffer_mask] * INT_SCALE_R;
/* Add feedback, must be done afterwards for case where delay = 0 */
fbs = input[pos] + (d1out + d2out) * fb;
if(fbs < CLIP && fbs > -CLIP) {
buffer[buffer_pos] = fbs * INT_SCALE;
} else if (fbs > 0.0f) {
buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B + fbs))) *
INT_SCALE;
} else {
buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B - fbs))) *
-INT_SCALE;
}
/* Write output */
buffer_write(output[pos], LIN_INTERP(wet, input[pos], d1out + d2out));
if (pos % 2) {
buffer_pos = (buffer_pos + 1) & buffer_mask;
}
/* Run LFOs */
x1 -= omega1 * y1;
y1 += omega1 * x1;
x2 -= omega2 * y2;
y2 += omega2 * x2;
}
} else {
const float dr1 = delay1 * fs * 0.5f;
const float dr2 = delay2 * fs * 0.5f;
for (pos = 0; pos < sample_count; pos++) {
/* Write input into delay line */
buffer[buffer_pos] = f_round(input[pos] * INT_SCALE);
/* Calcuate delays */
d1 = (x1 + 1.0f) * dr1;
d2 = (y2 + 1.0f) * dr2;
d1out = buffer[(buffer_pos - f_round(d1)) & buffer_mask] * INT_SCALE_R;
d2out = buffer[(buffer_pos - f_round(d2)) & buffer_mask] * INT_SCALE_R;
/* Add feedback, must be done afterwards for case where delay = 0 */
fbs = input[pos] + (d1out + d2out) * fb;
if(fbs < CLIP && fbs > -CLIP) {
buffer[buffer_pos] = fbs * INT_SCALE;
} else if (fbs > 0.0f) {
buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B + fbs))) *
INT_SCALE;
} else {
buffer[buffer_pos] = (MAX_AMP - (CLIP_A / (CLIP_B - fbs))) *
-INT_SCALE;
}
/* Write output */
buffer_write(output[pos], LIN_INTERP(wet, input[pos], d1out + d2out));
buffer_pos = (buffer_pos + 1) & buffer_mask;
/* Run LFOs */
x1 -= omega1 * y1;
y1 += omega1 * x1;
x2 -= omega2 * y2;
y2 += omega2 * x2;
}
}
plugin_data->x1 = x1;
plugin_data->y1 = y1;
plugin_data->x2 = x2;
plugin_data->y2 = y2;
plugin_data->buffer_pos = buffer_pos;
]]></callback>
<port label="deldouble" dir="input" type="control" hint="default_0,toggled">
<name>Double delay</name>
<p>doubles the length of the delays, this will reduce the sound quality.</p>
</port>
<port label="freq1" dir="input" type="control" hint="default_1">
<name>LFO frequency 1 (Hz)</name>
<p>The delay of the first LFO in seconds.</p>
<range min="0" max="30.0"/>
</port>
<port label="delay1" dir="input" type="control" hint="default_low">
<name>Delay 1 range (s)</name>
<p>The delay range of the first LFO in seconds.</p>
<range min="0" max="10.5"/>
</port>
<port label="freq2" dir="input" type="control" hint="default_1">
<name>LFO frequency 2 (Hz)</name>
<p>The delay of the second LFO in seconds.</p>
<range min="0" max="30.0"/>
</port>
<port label="delay2" dir="input" type="control" hint="default_0">
<name>Delay 2 range (s)</name>
<p>The delay range of the second LFO in seconds.</p>
<range min="0" max="10.5"/>
</port>
<port label="feedback" dir="input" type="control" hint="default_0">
<name>Feedback</name>
<p>The amount of the delays output that is mixed back into the delay.</p>
<range min="-100" max="100"/>
</port>
<port label="wet" dir="input" type="control" hint="default_0">
<name>Dry/Wet level</name>
<p>The amounts of the input and effect mixed to produce the output.</p>
<range min="0" 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="buffer" type="int16_t *" />
<instance-data label="buffer_pos" type="unsigned int" />
<instance-data label="buffer_mask" type="unsigned int" />
<instance-data label="fs" type="float" />
<instance-data label="x1" type="float" />
<instance-data label="y1" type="float" />
<instance-data label="x2" type="float" />
<instance-data label="y2" type="float" />
</plugin>
</ladspa>
|