-
Notifications
You must be signed in to change notification settings - Fork 52
/
harmonic_gen_1220.xml
170 lines (141 loc) · 5.8 KB
/
harmonic_gen_1220.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
<?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 <[email protected]>"/>
<meta name="copyright" value="GPL"/>
<meta name="properties" value="HARD_RT_CAPABLE"/>
<code><![CDATA[
#define HARMONICS 11
/* 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="harmonicGen" id="1220" class="GeneratorPlugin">
<name>Harmonic generator</name>
<p>\subsubsection{What does it do?}</p>
<p>Allows you to add harmonics and remove the fundamental from any audio signal.</p>
<p>\subsubsection{Known bugs}</p>
<p>There is no bandwith limiting filter on the output, so it is easy to create excessively high frequency harmonics that could cause aliasing problems. In practice this doesn't seem to be a serious problem however.</p>
<p>\subsubsection{Examples}</p>
<p>There are many interesting effects you can achieve with sinewaves, one example is producing bandlimited squarewaves from sinewaves. To do this set the parameters to 1, 0, -0.3333, 0, 0.2, 0, -0.14285, 0, 0.11111.</p>
<p>To get a triangle like signal use 1, 0, -0.3333, 0, -0.2, 0, -0.14285, 0, -0.11111.</p>
<callback event="activate"><![CDATA[
itm1 = 0.0f;
otm1 = 0.0f;
]]></callback>
<callback event="run"><![CDATA[
unsigned long pos, i;
float mag_fix;
float mag[HARMONICS] = {0.0f, mag_1, mag_2, mag_3, mag_4, mag_5, mag_6,
mag_7, mag_8, mag_9, mag_10};
float p[HARMONICS];
// Normalise magnitudes
mag_fix = (fabs(mag_1) + fabs(mag_2) + fabs(mag_3) + fabs(mag_4) +
fabs(mag_5) + fabs(mag_6) + fabs(mag_7) + fabs(mag_8) +
fabs(mag_9) + fabs(mag_10));
if (mag_fix < 1.0f) {
mag_fix = 1.0f;
} else {
mag_fix = 1.0f / mag_fix;
}
for (i=0; i<HARMONICS; i++) {
mag[i] *= mag_fix;
}
// Calculate polynomial coefficients, using Chebychev aproximation
chebpc(mag, p);
for (pos = 0; pos < sample_count; pos++) {
float x = input[pos], y;
// Calculate 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;
]]></callback>
<port label="mag_1" dir="input" type="control" hint="default_1">
<name>Fundamental magnitude</name>
<p>The amplitude of the fundamental of the signal, reduce it to 0 to remove the base signal altogether, or -1 to phase invert it.</p>
<range min="-1" max="+1"/>
</port>
<port label="mag_2" dir="input" type="control" hint="default_0">
<name>2nd harmonic magnitude</name>
<p>The 2nd harmonic, its frequency is twice the frequency of the fundamental.</p>
<p>Even harmonics add a distorted feel to the sound, valve (tube) amplifiers introduce distortions at all the harmonics.</p>
<range min="-1" max="+1"/>
</port>
<port label="mag_3" dir="input" type="control" hint="default_0">
<name>3rd harmonic magnitude</name>
<p>The 3rd harmonic, its frequency is three times the frequency of the fundamental.</p>
<p>Transistor amplifiers only introduce distortion into the odd harmonics.</p>
<range min="-1" max="+1"/>
</port>
<port label="mag_4" dir="input" type="control" hint="default_0">
<name>4th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_5" dir="input" type="control" hint="default_0">
<name>5th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_6" dir="input" type="control" hint="default_0">
<name>6th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_7" dir="input" type="control" hint="default_0">
<name>7th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_8" dir="input" type="control" hint="default_0">
<name>8th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_9" dir="input" type="control" hint="default_0">
<name>9th harmonic magnitude</name>
<range min="-1" max="+1"/>
</port>
<port label="mag_10" dir="input" type="control" hint="default_0">
<name>10th harmonic magnitude</name>
<range min="-1" max="+1"/>
</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" />
</plugin>
</ladspa>