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
|
<?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"/>
<code><![CDATA[
#include <math.h>
#include "ladspa-util.h"
]]></code>
</global>
<plugin label="decimator" id="1202" class="DistortionPlugin">
<name>Decimator</name>
<p>Decimates (reduces the effective sample rate), and reduces the bit depth of the input signal, allows non integer values for smooth transitions between clean and lofi signals.</p>
<callback event="instantiate">
sample_rate = s_rate;
count = 0.0f;
last_out = 0.0f;
</callback>
<callback event="run"><![CDATA[
unsigned long pos;
float step, stepr, delta, ratio;
double dummy;
if (bits >= 31.0f || bits < 1.0f) {
step = 0.0f;
stepr = 1.0f;
} else {
step = pow(0.5f, bits - 0.999f);
stepr = 1/step;
}
if (fs >= sample_rate) {
ratio = 1.0f;
} else {
ratio = fs/sample_rate;
}
for (pos = 0; pos < sample_count; pos++) {
count += ratio;
if (count >= 1.0f) {
count -= 1.0f;
delta = modf((input[pos] + (input[pos]<0?-1.0:1.0)*step*0.5) * stepr, &dummy) * step;
last_out = input[pos] - delta;
buffer_write(output[pos], last_out);
} else {
buffer_write(output[pos], last_out);
}
}
plugin_data->last_out = last_out;
plugin_data->count = count;
]]></callback>
<port label="bits" dir="input" type="control" hint="default_maximum">
<name>Bit depth</name>
<range min="1" max="24"/>
<p>The bit depth that the signal will be reduced to.</p>
</port>
<port label="fs" dir="input" type="control" hint="sample_rate,default_maximum">
<name>Sample rate (Hz)</name>
<range min="0.001" max="1"/>
<p>The sample rate that the signal will be resampled at.</p>
</port>
<port label="input" dir="input" type="audio">
<name>Input</name>
<range min="-1.0" max="+1.0"/>
</port>
<port label="output" dir="output" type="audio">
<name>Output</name>
<range min="-1.0" max="+1.0"/>
</port>
<instance-data label="sample_rate" type="long"/>
<instance-data label="count" type="float"/>
<instance-data label="last_out" type="LADSPA_Data"/>
</plugin>
</ladspa>
|