123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- /*
- Chorus.cc
-
- Copyright 2004-7 Tim Goetze <tim@quitte.de>
-
- http://quitte.de/dsp/
- mono and mono-to-stereo chorus units.
-
- */
- /*
- 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 "Chorus.h"
- #include "Descriptor.h"
- template <sample_func_t F>
- void
- ChorusI::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- double one_over_n = 1 / (double) frames;
- double ms = .001 * fs;
- double t = time;
- time = getport(1) * ms;
- double dt = (time - t) * one_over_n;
- double w = width;
- width = getport(2) * ms;
- /* clamp, or we need future samples from the delay line */
- if (width >= t - 3) width = t - 3;
- double dw = (width - w) * one_over_n;
- if (rate != *ports[3])
- lfo.set_f (max (rate = getport(3), .000001), fs, lfo.get_phase());
-
- double blend = getport(4);
- double ff = getport(5);
- double fb = getport(6);
- sample_t * d = ports[7];
- DSP::FPTruncateMode truncate;
- for (int i = 0; i < frames; ++i)
- {
- sample_t x = s[i];
- /* truncate the feedback tap to integer, better quality for less
- * cycles (just a bit of zipper when changing 't', but it does sound
- * interesting) */
- int ti;
- fistp (t, ti);
- x -= fb * delay[ti];
- delay.put (x + normal);
- # if 0
- /* allpass delay sounds a little cleaner for a chorus
- * but sucks big time when flanging. */
- x = blend * x + ff * tap.get (delay, t + w * lfo.get());
- # elif 0
- /* linear interpolation */
- x = blend * x + ff * delay.get_at (t + w * lfo.get());
- # else
- /* cubic interpolation */
- x = blend * x + ff * delay.get_cubic (t + w * lfo.get());
- # endif
- F (d, i, x, adding_gain);
- t += dt;
- w += dw;
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- ChorusI::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "t (ms)",
- INPUT | CONTROL,
- {BOUNDED | LOG | DEFAULT_LOW, 2.5, 40}
- }, {
- "width (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, .5, 10}
- }, {
- "rate (Hz)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 5}
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, 0, 1}
- }, {
- "feedforward",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "feedback",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_0, 0, 1}
- }, {
- "out",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<ChorusI>::setup()
- {
- UniqueID = 1767;
- Label = "ChorusI";
- Properties = HARD_RT;
- Name = CAPS "ChorusI - Mono chorus/flanger";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- template <sample_func_t F>
- void
- StereoChorusI::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- double one_over_n = 1 / (double) frames;
- double ms = .001 * fs;
- double t = time;
- time = getport(1) * ms;
- double dt = (time - t) * one_over_n;
- double w = width;
- width = getport(2) * ms;
- /* clamp, or we need future samples from the delay line */
- if (width >= t - 1) width = t - 1;
- double dw = (width - w) * one_over_n;
- if (rate != *ports[3] && phase != *ports[4])
- {
- rate = getport(3);
- phase = getport(4);
- double phi = left.lfo.get_phase();
- left.lfo.set_f (max (rate, .000001), fs, phi);
- right.lfo.set_f (max (rate, .000001), fs, phi + phase * M_PI);
- }
- double blend = getport(5);
- double ff = getport(6);
- double fb = getport(7);
- sample_t * dl = ports[8];
- sample_t * dr = ports[9];
- /* to go sure (on i386) that the fistp instruction does the right thing
- * when looking up fractional sample indices */
- DSP::FPTruncateMode truncate;
- for (int i = 0; i < frames; ++i)
- {
- sample_t x = s[i];
- /* truncate the feedback tap to integer, better quality for less
- * cycles (just a bit of zipper when changing 't', but it does sound
- * interesting) */
- int ti;
- fistp (t, ti);
- x -= fb * delay[ti];
- delay.put (x + normal);
- sample_t l = blend * x + ff * delay.get_cubic (t + w * left.lfo.get());
- sample_t r = blend * x + ff * delay.get_cubic (t + w * right.lfo.get());
- F (dl, i, l, adding_gain);
- F (dr, i, r, adding_gain);
- t += dt;
- w += dw;
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- StereoChorusI::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "t (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MIN, 2.5, 40}
- }, {
- "width (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, .5, 10}
- }, {
- "rate (Hz)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 5}
- }, {
- "phase",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MAX, 0, 1}
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, 0, 1}
- }, {
- "feedforward",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "feedback",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_0, 0, 1}
- }, {
- "out:l",
- OUTPUT | AUDIO,
- {0}
- }, {
- "out:r",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<StereoChorusI>::setup()
- {
- UniqueID = 1768;
- Label = "StereoChorusI";
- Properties = HARD_RT;
- Name = CAPS "StereoChorusI - Stereo chorus/flanger";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- template <sample_func_t F>
- void
- ChorusII::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- double one_over_n = 1 / (double) frames;
- double ms = .001 * fs;
- double t = time;
- time = getport(1) * ms;
- double dt = (time - t) * one_over_n;
- double w = width;
- width = getport(2) * ms;
- /* clamp, or we need future samples from the delay line */
- if (width >= t - 3) width = t - 3;
- double dw = (width - w) * one_over_n;
- if (rate != *ports[3])
- set_rate (*ports[3]);
-
- double blend = getport(4);
- double ff = getport(5);
- double fb = getport(6);
- sample_t * d = ports[7];
- DSP::FPTruncateMode truncate;
- for (int i = 0; i < frames; ++i)
- {
- sample_t x = s[i];
- x -= fb * delay.get_cubic (t);
- delay.put (filter.process (x + normal));
- double a = 0;
- for (int j = 0; j < Taps; ++j)
- a += taps[j].get (delay, t, w);
- x = blend * x + ff * a;
- F (d, i, x, adding_gain);
- t += dt;
- w += dw;
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- ChorusII::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "t (ms)",
- INPUT | CONTROL,
- {BOUNDED | LOG | DEFAULT_LOW, 2.5, 40}
- }, {
- "width (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, .5, 10}
- }, {
- "rate",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, 0, 1}
- }, {
- "feedforward",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "feedback",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_0, 0, 1}
- }, {
- "out",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<ChorusII>::setup()
- {
- UniqueID = 2583;
- Label = "ChorusII";
- Properties = HARD_RT;
- Name = CAPS "ChorusII - Mono chorus/flanger modulated by a fractal";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- template <sample_func_t F>
- void
- StereoChorusII::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- double one_over_n = 1 / (double) frames;
- double ms = .001 * fs;
- double t = time;
- time = getport(1) * ms;
- double dt = (time - t) * one_over_n;
- double w = width;
- width = getport(2) * ms;
- /* clamp, or we need future samples from the delay line */
- if (width >= t - 1) width = t - 1;
- double dw = (width - w) * one_over_n;
- set_rate (*ports[3]);
- double blend = getport(4);
- double ff = getport(5);
- double fb = getport(6);
- sample_t * dl = ports[7];
- sample_t * dr = ports[8];
- /* to go sure (on i386) that the fistp instruction does the right thing
- * when looking up fractional sample indices */
- DSP::FPTruncateMode truncate;
- for (int i = 0; i < frames; ++i)
- {
- sample_t x = s[i];
- /* truncate the feedback tap to integer, better quality for less
- * cycles (just a bit of zipper when changing 't', but it does sound
- * interesting) */
- int ti;
- fistp (t, ti);
- x -= fb * delay[ti];
- delay.put (x + normal);
- double m;
- m = left.lfo_lp.process (left.fractal.get());
- sample_t l = blend * x + ff * delay.get_cubic (t + w * m);
- m = right.lfo_lp.process (right.fractal.get());
- sample_t r = blend * x + ff * delay.get_cubic (t + w * m);
- F (dl, i, l, adding_gain);
- F (dr, i, r, adding_gain);
- t += dt;
- w += dw;
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- StereoChorusII::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "t (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 2.5, 40}
- }, {
- "width (ms)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, .5, 10}
- }, {
- "rate",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_1, 0, 1}
- }, {
- "feedforward",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 1}
- }, {
- "feedback",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_0, 0, 1}
- }, {
- "out:l",
- OUTPUT | AUDIO,
- {0}
- }, {
- "out:r",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<StereoChorusII>::setup()
- {
- UniqueID = 2584;
- Label = "StereoChorusII";
- Properties = HARD_RT;
- Name = CAPS "StereoChorusII - Stereo chorus/flanger modulated by a fractal";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
|