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
|
<?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>
#define HARMONICS 11
#define STAGES 2
static float cd_lut[STAGES][HARMONICS];
/* Calculate Chebychev coefficents from partial magnitudes, adapted from
* example in Num. Rec. */
void chebpc(float c[], float d[])
{
int k, j;
float sv, dd[HARMONICS];
for (j = 0; j < HARMONICS; j++) {
d[j] = dd[j] = 0.0;
}
d[0] = c[HARMONICS - 1];
for (j = HARMONICS - 2; j >= 1; j--) {
for (k = HARMONICS - j; k >= 1; k--) {
sv = d[k];
d[k] = 2.0 * d[k - 1] - dd[k];
dd[k] = sv;
}
sv = d[0];
d[0] = -dd[0] + c[j];
dd[0] = sv;
}
for (j = HARMONICS - 1; j >= 1; j--) {
d[j] = d[j - 1] - dd[j];
}
d[0] = -dd[0] + 0.5 * c[0];
}
]]></code>
</global>
<plugin label="chebstortion" id="1430" class="DistortionPlugin">
<name>Chebyshev distortion</name>
<p>This is an interesting distortion effect that is seeded from incoming
signal envelope. As the level of the signal rises more and more harmonics will
for added to the output signal.</p>
<p>The distortion control sets the sensitivity of the input.</p>
<p>The effect eveolved from some experiments between Tim Goetze and myself,
apptempting to emulate valve based guitar amp distortion. This was one of the
failures, but it still makes an interesting noise.</p>
<callback event="instantiate"><![CDATA[
unsigned int i;
cd_lut[0][0] = 0.0f;
cd_lut[0][1] = 1.0f;
for (i=2; i<HARMONICS; i++) {
cd_lut[0][i] = 0.0f;
}
cd_lut[1][0] = 0.0f;
cd_lut[1][1] = 1.0f;
for (i=2; i<HARMONICS; i++) {
cd_lut[1][i] = 1.0f/(float)i;
}
itm1 = 0.0f;
otm1 = 0.0f;
env = 0.0f;
count = 0;
]]></callback>
<callback event="activate"><![CDATA[
itm1 = 0.0f;
otm1 = 0.0f;
env = 0.0f;
count = 0;
]]></callback>
<callback event="run"><![CDATA[
unsigned long pos, i;
float p[HARMONICS], interp[HARMONICS];
for (pos = 0; pos < sample_count; pos++) {
const float x = input[pos];
const float a = fabs(input[pos]);
float y;
if (a > env) {
env = env * 0.9f + a * 0.1f;
} else {
env = env * 0.97f + a * 0.03f;
}
if (count-- == 0) {
for (i=0; i<HARMONICS; i++) {
interp[i] = cd_lut[0][i] * (1.0f - env * dist) +
cd_lut[1][i] * env * dist;
}
chebpc(interp, p);
count = 4;
}
// Evaluate the polynomial using Horner's Rule
y = p[0] + (p[1] + (p[2] + (p[3] + (p[4] + (p[5] + (p[6] + (p[7] +
(p[8] + (p[9] + p[10] * x) * x) * x) * x) * x) * x) * x) * x) *
x) * x;
// DC offset remove (odd harmonics cause DC offset)
otm1 = 0.999f * otm1 + y - itm1;
itm1 = y;
buffer_write(output[pos], otm1);
}
plugin_data->itm1 = itm1;
plugin_data->otm1 = otm1;
plugin_data->env = env;
plugin_data->count = count;
]]></callback>
<port label="dist" dir="input" type="control" hint="default_0">
<name>Distortion</name>
<range min="0" max="3"/>
</port>
<port label="input" dir="input" type="audio">
<name>Input</name>
<range min="-1" max="+1"/>
</port>
<port label="output" dir="output" type="audio">
<name>Output</name>
<range min="-1" max="+1"/>
</port>
<instance-data label="itm1" type="float" />
<instance-data label="otm1" type="float" />
<instance-data label="env" type="float" />
<instance-data label="count" type="unsigned int" />
</plugin>
</ladspa>
|