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
|
<?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[
#define FADE_IN 1
#define STABLE 2
#define FADE_OUT 3
]]></code>
</global>
<plugin label="stepMuxer" id="1212" class="UtilityPlugin">
<name>Step Demuxer</name>
<p>Inputs up to 8 signals and switches between them on the output when the signal on the clock input goes high.</p>
<p>This plugin is untested, and may not work.</p>
<callback event="instantiate"><![CDATA[
sample_rate = s_rate;
ch_state = malloc(sizeof(int) * 8);
ch_gain = malloc(sizeof(float) * 8);
current_ch = 0;
last_clock = 0.0f;
]]></callback>
<callback event="activate"><![CDATA[
int i;
ch_state[0] = STABLE;
ch_gain[0] = 1.0f;
for (i = 1; i < 8; i++) {
ch_state[i] = STABLE;
ch_gain[i] = 0.0f;
}
current_ch = 0;
last_clock = 0.0f;
sample_rate = sample_rate;
]]></callback>
<callback event="cleanup"><![CDATA[
free(plugin_data->ch_state);
free(plugin_data->ch_gain);
]]></callback>
<callback event="run"><![CDATA[
unsigned long pos;
float fade_inc = 1.0f / (xfadet * sample_rate * 1000.0f);
float accum;
int ch;
for (pos = 0; pos < sample_count; pos++) {
// Calculate output value for this sample
accum = 0.0f;
accum += input0[pos] * ch_gain[0];
accum += input1[pos] * ch_gain[1];
accum += input2[pos] * ch_gain[2];
accum += input3[pos] * ch_gain[3];
accum += input4[pos] * ch_gain[4];
accum += input5[pos] * ch_gain[5];
accum += input6[pos] * ch_gain[6];
accum += input7[pos] * ch_gain[7];
buffer_write(output[pos], accum);
// Run crossfades
for (ch = 0; ch < 8; ch++) {
// Channel is still being faded in
if (ch_state[ch] == FADE_IN) {
ch_gain[ch] += fade_inc;
if (ch_gain[ch] >= 1.0f) {
ch_gain[ch] = 1.0f;
ch_state[ch] = STABLE;
}
// Channel is still being faded out
} else if (ch_state[ch] == FADE_OUT) {
ch_gain[ch] -= fade_inc;
if (ch_gain[ch] <= 0.0f) {
ch_gain[ch] = 0.0f;
ch_state[ch] = STABLE;
}
}
}
// Check for clock signal
if (last_clock <= 0.0f && clock[pos] > 0.0f) {
ch_state[current_ch] = FADE_OUT;
current_ch = (current_ch + 1) % 8;
ch_state[current_ch] = FADE_IN;
}
}
// Save state data
plugin_data->current_ch = current_ch;
plugin_data->last_clock = last_clock;
]]></callback>
<port label="xfadet" dir="input" type="control" hint="default_middle">
<name>Crossfade time (in ms)</name>
<range min="0" max="100"/>
</port>
<port label="clock" dir="input" type="audio">
<name>Clock</name>
</port>
<port label="input0" dir="input" type="audio">
<name>Input 1</name>
</port>
<port label="input1" dir="input" type="audio">
<name>Input 2</name>
</port>
<port label="input2" dir="input" type="audio">
<name>Input 3</name>
</port>
<port label="input3" dir="input" type="audio">
<name>Input 4</name>
</port>
<port label="input4" dir="input" type="audio">
<name>Input 5</name>
</port>
<port label="input5" dir="input" type="audio">
<name>Input 6</name>
</port>
<port label="input6" dir="input" type="audio">
<name>Input 7</name>
</port>
<port label="input7" dir="input" type="audio">
<name>Input 8</name>
</port>
<port label="output" dir="output" type="audio">
<name>Output</name>
</port>
<instance-data label="sample_rate" type="float"/>
<instance-data label="current_ch" type="int"/>
<instance-data label="last_clock" type="LADSPA_Data"/>
<instance-data label="ch_state" type="int *"/>
<instance-data label="ch_gain" type="float *"/>
</plugin>
</ladspa>
|