123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- /*
- SweepVF.cc
-
- Copyright 2002-7 Tim Goetze <tim@quitte.de>
-
- http://quitte.de/dsp/
- SweepVFI, a lorenz fractal modulating the cutoff frequency of a
- state-variable (ladder) filter.
- SweepVFII, the same with Q being modulated by a second fractal.
- */
- /*
- 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 <algorithm>
- #include "SweepVF.h"
- #include "Descriptor.h"
- #include "dsp/RBJ.h"
- void
- SweepVFI::init()
- {
- f = .1;
- Q = .1;
- lorenz.init();
- }
- void
- SweepVFI::activate()
- {
- svf.reset();
- svf.set_f_Q (f = getport(1) / fs, Q = getport(2));
- }
- template <sample_func_t F>
- void
- SweepVFI::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- int blocks = frames / BLOCK_SIZE;
- if (frames & (BLOCK_SIZE - 1))
- ++blocks;
- double one_over_blocks = 1 / (double) blocks;
- /* cheesy linear interpolation for f, works well though. */
- double df = (getport(1) / fs - f) * one_over_blocks;
- double dQ = (getport(2) - Q) * one_over_blocks;
- svf.set_out ((int) getport(3));
- lorenz.set_rate (getport(7));
- sample_t * d = ports[8];
- while (frames)
- {
- lorenz.step();
- double modulation =
- getport(4) * lorenz.get_x() +
- getport(5) * lorenz.get_y() +
- getport(6) * lorenz.get_z();
- double scale = getport(4) + getport(5) + getport(6);
- modulation *= scale * f;
- svf.set_f_Q (max (.001, f + modulation), Q);
- int n = std::min<int> (frames, BLOCK_SIZE);
-
- for (int i = 0; i < n; ++i)
- F (d, i, svf.process (s[i] + normal), adding_gain);
- s += n;
- d += n;
- frames -= n;
- f += df;
- Q += dQ;
- }
- f = getport(1) / fs;
- Q = getport(2);
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- SweepVFI::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {0, 0, 0}
- }, {
- "f",
- INPUT | CONTROL,
- {BOUNDED | LOG | DEFAULT_LOW, 83, 3383}
- }, {
- "Q",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0.001, .999}
- }, {
- "mode",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1 | INTEGER, 0, 1} /* only lo and band make sense */
- }, {
- "depth:x",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "depth:y",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 1}
- }, {
- "depth:z",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MAX, 0, 1}
- }, {
- "h",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0.001, 1} /* .039 */
- }, {
- "out",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<SweepVFI>::setup()
- {
- UniqueID = 1782;
- Label = "SweepVFI";
- Properties = HARD_RT;
- Name = CAPS "SweepVFI - Resonant filter swept by a Lorenz fractal";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- void
- SweepVFII::init()
- {
- f = .1;
- Q = .1;
- lorenz1.init();
- lorenz2.init();
- }
- void
- SweepVFII::activate()
- {
- svf.reset();
- svf.set_f_Q (f = getport(1) / fs, Q = getport(2));
- }
- template <sample_func_t F>
- void
- SweepVFII::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- int blocks = frames / BLOCK_SIZE;
- if (frames & (BLOCK_SIZE - 1))
- ++blocks;
- double one_over_blocks = 1 / (double) blocks;
- /* cheesy linear interpolation for f, works well though. */
- double df = (getport(1) / fs - f) * one_over_blocks;
- double dQ = (getport(2) - Q) * one_over_blocks;
- svf.set_out ((int) getport(3));
- lorenz1.set_rate (getport(7));
- lorenz2.set_rate (getport(11));
- sample_t * d = ports[12];
- while (frames)
- {
- /* f modulation */
- lorenz1.step();
- double modulation1 =
- getport(4) * lorenz1.get_x() +
- getport(5) * lorenz1.get_y() +
- getport(6) * lorenz1.get_z();
- double scale1 = getport(4) + getport(5) + getport(6);
- modulation1 *= scale1 * f;
- /* Q modulation */
- lorenz2.step();
- double modulation2 =
- getport(8) * lorenz2.get_x() +
- getport(9) * lorenz2.get_y() +
- getport(10) * lorenz2.get_z();
- double scale2 = getport(8) + getport(9) + getport(10);
- /* enforce Q limit */
- double q = Q + (modulation2 * scale2 * Q);
- q = min (0.96, max (q, 0));
-
- svf.set_f_Q (max (.001, f + modulation1), q);
- int n = std::min<int> (frames, BLOCK_SIZE);
-
- for (int i = 0; i < n; ++i)
- F (d, i, svf.process (s[i] + normal), adding_gain);
- s += n;
- d += n;
- frames -= n;
- f += df;
- Q += dQ;
- }
- f = getport(1) / fs;
- Q = getport(2);
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- SweepVFII::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {0, 0, 0}
- }, {
- "f",
- INPUT | CONTROL,
- {BOUNDED | LOG | DEFAULT_LOW, 83, 3383}
- }, {
- "Q",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0.001, .999}
- }, {
- "mode",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1 | INTEGER, 0, 1} /* only lo and band make sense */
- }, {
- "f:depth:x",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "f:depth:y",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 1}
- }, {
- "f:depth:z",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MAX, 0, 1}
- }, {
- "f:h",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0.001, 1} /* .039 */
- }, {
- "Q:depth:x",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "Q:depth:y",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 1}
- }, {
- "Q:depth:z",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MAX, 0, 1}
- }, {
- "Q:h",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0.001, 1} /* .039 */
- }, {
- "out",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<SweepVFII>::setup()
- {
- UniqueID = 2582;
- Label = "SweepVFII";
- Properties = HARD_RT;
- Name = CAPS "SweepVFII - Resonant filter, f and Q swept by a Lorenz fractal";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- void
- AutoWah::init()
- {
- f = 800 / fs;
- Q = .5;
- }
- void
- AutoWah::activate()
- {
- svf.reset();
- svf.set_f_Q (f = getport(1) / fs, Q = getport(2));
- svf.set_out (DSP::SVF<1>::Band);
- /* hi-passing input for envelope RMS calculation */
- hp.set_f (250. / fs);
- /* smoothing the envelope at 20 Hz */
- DSP::RBJ::LP (20. * BLOCK_SIZE / fs, .6, filter.a, filter.b);
- rms.reset();
- hp.reset();
- filter.reset();
- }
- template <sample_func_t F>
- void
- AutoWah::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- int blocks = frames / BLOCK_SIZE;
- if (frames & (BLOCK_SIZE - 1))
- ++blocks;
- double one_over_blocks = 1 / (double) blocks;
- /* cheesy linear interpolation for f, works well though. */
- double df = (getport(1) / fs - f) * one_over_blocks;
- double dQ = (getport(2) - Q) * one_over_blocks;
- double scale = getport(3);
- sample_t * d = ports[4];
- while (frames)
- {
- double m = rms.rms();
- m = filter.process (m + normal);
- /* Leaving debug output in your code is cheesy! */
- /*
- static int _turn = 0;
- if (_turn++ % 100 == 0)
- fprintf (stderr, "%.4f\n", m);
- */
- m *= scale * .08;
- svf.set_f_Q (max (.001, f + m), Q);
- int n = std::min<int> (frames, BLOCK_SIZE);
-
- for (int i = 0; i < n; ++i)
- {
- sample_t x = s[i] + normal;
- /* A stacked SVF in bandpass mode is rather quiet, which is
- * compensated here */
- F (d, i, 2 * svf.process (x), adding_gain);
- /* for envelope calculation, prefer high f content */
- x = hp.process (x);
- rms.store (x * x);
- }
- s += n;
- d += n;
- frames -= n;
- f += df;
- Q += dQ;
- normal = -normal;
- }
- f = getport(1) / fs;
- Q = getport(2);
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- AutoWah::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {0, 0, 0}
- }, {
- "f",
- INPUT | CONTROL,
- {BOUNDED | LOG | DEFAULT_LOW, 43, 933}
- }, {
- "Q",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0.001, .999}
- }, {
- "depth",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 1}
- }, {
- "out",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<AutoWah>::setup()
- {
- UniqueID = 2593;
- Label = "AutoWah";
- Properties = HARD_RT;
- Name = CAPS "AutoWah - Resonant envelope-following filter";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
|