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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
Scape.cc
Copyright 2004-6 Tim Goetze <tim@quitte.de>
http://quitte.de/dsp/
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA or point your web browser to http://www.gnu.org.
*/
#include "basics.h"
#include "Scape.h"
#include "Descriptor.h"
void
Scape::activate()
{
time = 0;
fb = 0;
for (int i = 0; i < 4; ++i)
svf[i].reset(),
svf[i].set_out (SVF::Band),
hipass[i].set_f (250. / fs);
svf[3].set_out (SVF::Low),
delay.reset();
period = 0;
}
static double
dividers [] = {
1 /* 0 sentinel */,
1, 0.5, 0.66666666666666666667, 0.75
};
float
frandom2()
{
float f = frandom();
return f * f * f;
}
template <sample_func_t F>
void
Scape::one_cycle (int frames)
{
d_sample * s = ports[0];
// double one_over_n = 1 / (double) frames;
/* delay times */
double t1 = fs * 60. / *ports[1];
int div = (int) *ports[2];
double t2 = t1 * dividers[div];
fb = *ports[3];
double dry = *ports[4];
dry = dry * dry;
double blend = *ports[5];
d_sample * dl = ports[6];
d_sample * dr = ports[7];
DSP::FPTruncateMode truncate;
while (frames)
{
/* flip 'renormal' addition constant */
normal = -normal;
/* retune filters */
if (period <= 1)
{
period = t2 * .5;
float f, q;
//fprintf (stderr, "%.3f: %d\n", period, (int) period);
f = frandom2();
svf[0].set_f_Q (300 + 300 * f / fs, .3);
svf[3].set_f_Q (300 + 600 * 2 * f / fs, .6);
f = frandom2();
q = f;
svf[1].set_f_Q (400 + 2400 * f / fs, q);
q = 1 - f;
svf[2].set_f_Q (400 + 2400 * f / fs, q);
}
int n = min ((int) period, frames);
if (n < 1)
{
fprintf (stderr, "Scape: %d - %d/%d frames, t2 = %.3f?!?\n", (int) period, n, frames, t2);
return;
}
/* sample loop */
for (int i = 0; i < n; ++i)
{
d_sample x = s[i] + normal;
d_sample x1 = delay.get_at (t1);
d_sample x2 = delay.get_at (t2);
delay.put (x + fb * x1 + normal);
x = dry * x + .2 * svf[0].process (x) + .6 * svf[3].process(x);
x1 = svf[1].process (x1 - normal);
x2 = svf[2].process (x2 - normal);
x1 = hipass[1].process (x1);
x2 = hipass[2].process (x2);
d_sample x1l, x1r, x2l, x2r;
x1l = fabs (lfo[0].get());
x1r = 1 - x1l;
x2r = fabs (lfo[1].get());
x2l = 1 - x2r;
F (dl, i, x + blend * (x1 * x1l + x2 * x2l), adding_gain);
F (dr, i, x + blend * (x2 * x2r + x1 * x1r), adding_gain);
}
frames -= n;
period -= n;
s += n;
dl += n;
dr += n;
}
}
/* //////////////////////////////////////////////////////////////////////// */
PortInfo
Scape::port_info [] =
{
{
"in",
INPUT | AUDIO,
{BOUNDED, -1, 1}
}, {
"bpm",
INPUT | CONTROL,
{BOUNDED | DEFAULT_LOW, 30, 240}
}, {
"divider",
INPUT | CONTROL,
{BOUNDED | INTEGER | DEFAULT_MIN, 2, 4}
}, {
"feedback",
INPUT | CONTROL,
{BOUNDED | DEFAULT_LOW, 0, 1}
}, {
"dry",
INPUT | CONTROL,
{BOUNDED | DEFAULT_LOW, 0, 1}
}, {
"blend",
INPUT | CONTROL,
{BOUNDED | DEFAULT_HIGH, 0, 1}
}, {
"out:l",
OUTPUT | AUDIO,
{0}
}, {
"out:r",
OUTPUT | AUDIO,
{0}
}
};
template <> void
Descriptor<Scape>::setup()
{
UniqueID = 2588;
Label = "Scape";
Properties = HARD_RT;
Name = "CAPS: Scape - Stereo delay + Filters";
Maker = "Tim Goetze <tim@quitte.de>";
Copyright = "GPL, 2004-6";
/* fill port info and vtable */
autogen();
}
|