File: ringmod_1188.xml

package info (click to toggle)
swh-plugins 0.4.17-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,264 kB
  • sloc: ansic: 23,551; xml: 12,633; perl: 1,114; sh: 964; makefile: 218
file content (172 lines) | stat: -rw-r--r-- 4,508 bytes parent folder | download | duplicates (12)
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
<?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 &lt;steve@plugin.org.uk&gt;"/>
		<meta name="copyright" value="GPL"/>
		<meta name="properties" value="HARD_RT_CAPABLE"/>
		<code>
			#include "ladspa-util.h"

			int refcount;
			LADSPA_Data *sin_tbl, *tri_tbl, *saw_tbl, *squ_tbl;
			long sample_rate;
		</code>
	</global>

	<plugin label="ringmod_2i1o" id="1188" class="ModulatorPlugin">
		<name>Ringmod with two inputs</name>
		<p>This is a simple 2 input ring modulator.</p>
		<p>It is important that the modulator input is bounded to (-1, +1), otherwise you will get rubbish on the output.</p>

		<callback event="run">
			unsigned long pos;
			float tmpa = depth * 0.5f;
			float tmpb = 2.0f - depth;

			for (pos = 0; pos &lt; sample_count; pos++) {
				buffer_write(output[pos], input[pos] * (tmpa * modulator[pos] + tmpb));
			}
		</callback>

		<port label="depth" dir="input" type="control" hint="default_0">
			<name>Modulation depth (0=none, 1=AM, 2=RM)</name>
			<range min="0" max="2"/>
		</port>

		<port label="input" dir="input" type="audio">
			<name>Input</name>
			<p>This is the audio input.</p>
		</port>

		<port label="modulator" dir="input" type="audio" hint="default_0">
			<name>Modulator</name>
			<range min="-1" max="+1"/>
			<p>This is the modulator input.</p>
		</port>

		<port label="output" dir="output" type="audio">
			<name>Output</name>
		</port>
	</plugin>

	<plugin label="ringmod_1i1o1l" id="1189" class="ModulatorPlugin">
		<name>Ringmod with LFO</name>
		<p>This is a simple ring modulator and LFO.</p>

		<callback event="instantiate">
			long i;

			sample_rate = s_rate;

			if (refcount++ == 0) {
				sin_tbl = malloc(sizeof(LADSPA_Data) * sample_rate);
				for (i = 0; i &lt; sample_rate; i++) {
					sin_tbl[i] = sin(i * 2 * M_PI / sample_rate);
				}
				
				tri_tbl = malloc(sizeof(LADSPA_Data) * sample_rate);
				for (i = 0; i &lt; sample_rate; i++) {
					tri_tbl[i] = acos(cos(i * 2 * M_PI / sample_rate)) / M_PI * 2 - 1;
				}

				squ_tbl = malloc(sizeof(LADSPA_Data) * sample_rate);
				for (i = 0; i &lt; sample_rate; i++) {
					squ_tbl[i] = (i &lt; sample_rate/2) ? 1 : -1;
				}

				saw_tbl = malloc(sizeof(LADSPA_Data) * sample_rate);
				for (i = 0; i &lt; sample_rate; i++) {
					saw_tbl[i] = ((2.0 * i) - (float)sample_rate) / (float)sample_rate;
				}
			}

			offset = 0;
		</callback>

		<callback event="activate">
			offset = 0;
		</callback>

		<callback event="cleanup">
			plugin_data = plugin_data;
			if (--refcount == 0) {
				free(sin_tbl);
				free(tri_tbl);
				free(squ_tbl);
				free(saw_tbl);
			}
		</callback>

		<callback event="run">
			LADSPA_Data scale = fabs(sin) + fabs(tri) +
			 fabs(saw) + fabs(squ);
			int o;
			unsigned long pos;

			// Rescale to more useful value
			const float depth = depthp * 0.5f;

			if (scale == 0.0) {
				scale = 1.0;
			}

			for (pos = 0; pos &lt; sample_count; pos++) {
				o = f_round(offset);
				buffer_write(output[pos], input[pos] *
				 (depth * (((sin / scale) * sin_tbl[o]) +
				   ((tri / scale) * tri_tbl[o]) +
				   ((saw / scale) * saw_tbl[o]) +
				   ((squ / scale) * squ_tbl[o])) +
				   (1.0f - depth)));
				offset += freq;
				if (offset > sample_rate) {
					offset -= sample_rate;
				}
			}

			plugin_data->offset = offset;
		</callback>

		<port label="depthp" dir="input" type="control" hint="default_0">
			<name>Modulation depth (0=none, 1=AM, 2=RM)</name>
			<range min="0" max="2"/>
		</port>

		<port label="freq" dir="input" type="control" hint="default_440">
			<name>Frequency (Hz)</name>
			<range min="1" max="1000"/>
		</port>

		<port label="sin" dir="input" type="control" hint="default_1">
			<name>Sine level</name>
			<range min="-1" max="+1"/>
		</port>

		<port label="tri" dir="input" type="control" hint="default_0">
			<name>Triangle level</name>
			<range min="-1" max="+1"/>
		</port>

		<port label="saw" dir="input" type="control" hint="default_0">
			<name>Sawtooth level</name>
			<range min="-1" max="+1"/>
		</port>

		<port label="squ" dir="input" type="control" hint="default_0">
			<name>Square level</name>
			<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="offset" type="LADSPA_Data"/>
	</plugin>
</ladspa>