123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- /*
- Reverb.cc
-
- Copyright 2002-7 Tim Goetze <tim@quitte.de>
-
- http://quitte.de/dsp/
- three reverb units: JVRev, Plate and Plate2x2.
-
- the former is a rewrite of STK's JVRev, a traditional design.
-
- original comment:
-
- This is based on some of the famous
- Stanford CCRMA reverbs (NRev, KipRev)
- all based on the Chowning/Moorer/
- Schroeder reverberators, which use
- networks of simple allpass and comb
- delay filters.
- the algorithm is mostly unchanged in this implementation; the delay
- line lengths have been fiddled with to make the stereo field more
- evenly weighted, and denormal protection has been added.
- the latter two are based on the circuit discussed in Jon Dattorro's
- september 1997 JAES paper on effect design (part 1: reverb & filters).
- */
- /*
- 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 "Reverb.h"
- #include "Descriptor.h"
- int
- JVRev::default_length[9] = {
- #if 1 /* slightly modified, tg */
- 1777, 1847, 1993, 2137, 389, 127, 43, 211, 209
- #else
- 4799, 4999, 5399, 5801, 1051, 337, 113, 573, 487
- #endif
- };
- void
- JVRev::init()
- {
- memcpy (length, default_length, sizeof (length));
- if (fs != 44100)
- {
- double s = fs / 44100.;
- for (int i = 0; i < 9; ++i)
- {
- int v = (int) (s * length[i]);
- v |= 1;
- while (!DSP::isprime (v))
- v += 2;
- length[i] = v;
- }
- }
-
- for (int i = 0; i < 4; ++i)
- comb[i].init (length[i]);
- for (int i = 0; i < 3; ++i)
- allpass[i].init (length[i+4]);
- left.init (length[7]);
- right.init (length[8]);
- /* such a simple number, but i couldn't find a better one. */
- apc = .7;
- }
- void
- JVRev::set_t60 (sample_t t)
- {
- t60 = t;
- t = max (.00001, t);
- for (int i = 0; i < 4; ++i)
- comb[i].c = pow (10, (-3 * length[i] / (t * fs)));
- }
- void
- JVRev::activate()
- {
- for (int i = 0; i < 3; ++i)
- allpass[i].reset();
-
- for (int i = 0; i < 4; ++i)
- comb[i].reset();
- left.reset();
- right.reset();
- set_t60 (getport(1));
- }
- template <sample_func_t F>
- void
- JVRev::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- if (t60 != *ports[1])
- set_t60 (getport(1));
- double wet = getport(2), dry = 1 - wet;
-
- sample_t * dl = ports[3];
- sample_t * dr = ports[4];
- for (int i = 0; i < frames; ++i)
- {
- sample_t x = s[i], a = x + normal;
- x *= dry;
- /* diffusors */
- a = allpass[0].process (a, -apc);
- a = allpass[1].process (a, -apc);
- a = allpass[2].process (a, -apc);
- /* tank */
- sample_t t = 0;
- a -= normal;
- for (int j = 0; j < 4; ++j)
- t += comb[j].process (a);
- F (dl, i, x + wet * left.putget (t), adding_gain);
- F (dr, i, x + wet * right.putget (t), adding_gain);
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- JVRev::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "t60 (s)",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, 4.6}
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, .28}
- }, {
- "out:l",
- OUTPUT | AUDIO,
- {0}
- }, {
- "out:r",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<JVRev>::setup()
- {
- UniqueID = 1778;
- Label = "JVRev";
- Properties = HARD_RT;
- Name = CAPS "JVRev - Stanford-style reverb from STK";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- void
- PlateStub::init()
- {
- f_lfo = -1;
-
- # define L(i) ((int) (l[i] * fs))
- static float l[] = {
- 0.004771345048889486, 0.0035953092974026408,
- 0.01273478713752898, 0.0093074829474816042,
- 0.022579886428547427, 0.030509727495715868,
- 0.14962534861059779, 0.060481838647894894, 0.12499579987231611,
- 0.14169550754342933, 0.089244313027116023, 0.10628003091293972
- };
- /* lh */
- input.lattice[0].init (L(0));
- input.lattice[1].init (L(1));
-
- /* rh */
- input.lattice[2].init (L(2));
- input.lattice[3].init (L(3));
- /* modulated, width about 12 samples @ 44.1 */
- tank.mlattice[0].init (L(4), (int) (0.00040322707570310132 * fs));
- tank.mlattice[1].init (L(5), (int) (0.00040322707570310132 * fs));
- /* lh */
- tank.delay[0].init (L(6));
- tank.lattice[0].init (L(7));
- tank.delay[1].init (L(8));
- /* rh */
- tank.delay[2].init (L(9));
- tank.lattice[1].init (L(10));
- tank.delay[3].init (L(11));
- # undef L
- # define T(i) ((int) (t[i] * fs))
- static float t[] = {
- 0.0089378717113000241, 0.099929437854910791, 0.064278754074123853,
- 0.067067638856221232, 0.066866032727394914, 0.006283391015086859,
- 0.01186116057928161, 0.12187090487550822, 0.041262054366452743,
- 0.089815530392123921, 0.070931756325392295, 0.011256342192802662
- };
- for (int i = 0; i < 12; ++i)
- tank.taps[i] = T(i);
- # undef T
-
- /* tuned for soft attack, ambience */
- indiff1 = .742;
- indiff2 = .712;
- dediff1 = .723;
- dediff2 = .729;
- }
- inline void
- PlateStub::process (sample_t x, sample_t decay, sample_t * _xl, sample_t * _xr)
- {
- x = input.bandwidth.process (x);
-
- /* lh */
- x = input.lattice[0].process (x, indiff1);
- x = input.lattice[1].process (x, indiff1);
-
- /* rh */
- x = input.lattice[2].process (x, indiff2);
- x = input.lattice[3].process (x, indiff2);
- /* summation point */
- register sample_t xl = x + decay * tank.delay[3].get();
- register sample_t xr = x + decay * tank.delay[1].get();
- /* lh */
- xl = tank.mlattice[0].process (xl, dediff1);
- xl = tank.delay[0].putget (xl);
- xl = tank.damping[0].process (xl);
- xl *= decay;
- xl = tank.lattice[0].process (xl, dediff2);
- tank.delay[1].put (xl);
- /* rh */
- xr = tank.mlattice[1].process (xr, dediff1);
- xr = tank.delay[2].putget (xr);
- xr = tank.damping[1].process (xr);
- xr *= decay;
- xr = tank.lattice[1].process (xr, dediff2);
- tank.delay[3].put (xr);
- /* gather output */
- xl = .6 * tank.delay[2] [tank.taps[0]];
- xl += .6 * tank.delay[2] [tank.taps[1]];
- xl -= .6 * tank.lattice[1] [tank.taps[2]];
- xl += .6 * tank.delay[3] [tank.taps[3]];
- xl -= .6 * tank.delay[0] [tank.taps[4]];
- xl += .6 * tank.lattice[0] [tank.taps[5]];
- xr = .6 * tank.delay[0] [tank.taps[6]];
- xr += .6 * tank.delay[0] [tank.taps[7]];
- xr -= .6 * tank.lattice[0] [tank.taps[8]];
- xr += .6 * tank.delay[1] [tank.taps[9]];
- xr -= .6 * tank.delay[2] [tank.taps[10]];
- xr += .6 * tank.lattice[1] [tank.taps[11]];
- *_xl = xl;
- *_xr = xr;
- }
- /* //////////////////////////////////////////////////////////////////////// */
- template <sample_func_t F>
- void
- Plate::one_cycle (int frames)
- {
- sample_t * s = ports[0];
- input.bandwidth.set (exp (-M_PI * (1. - getport(1))));
- sample_t decay = getport(2);
- double damp = exp (-M_PI * getport(3));
- tank.damping[0].set (damp);
- tank.damping[1].set (damp);
- sample_t blend = getport(4), dry = 1 - blend;
- sample_t * dl = ports[5];
- sample_t * dr = ports[6];
- /* the modulated lattices interpolate, which needs truncated float */
- DSP::FPTruncateMode _truncate;
- for (int i = 0; i < frames; ++i)
- {
- normal = -normal;
- sample_t x = s[i] + normal;
- sample_t xl, xr;
- PlateStub::process (x, decay, &xl, &xr);
- x = dry * s[i];
- F (dl, i, x + blend * xl, adding_gain);
- F (dr, i, x + blend * xr, adding_gain);
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- Plate::port_info [] =
- {
- {
- "in",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "bandwidth",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0.005, .999} /* .9995 */
- }, {
- "tail",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, .749} /* .5 */
- }, {
- "damping",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, .0005, 1} /* .0005 */
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "out:l",
- OUTPUT | AUDIO,
- {0}
- }, {
- "out:r",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<Plate>::setup()
- {
- UniqueID = 1779;
- Label = "Plate";
- Properties = HARD_RT;
- Name = CAPS "Plate - Versatile plate reverb";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
- /* //////////////////////////////////////////////////////////////////////// */
- template <sample_func_t F>
- void
- Plate2x2::one_cycle (int frames)
- {
- sample_t * sl = ports[0];
- sample_t * sr = ports[1];
- input.bandwidth.set (exp (-M_PI * (1. - getport(2))));
- sample_t decay = getport(3);
- double damp = exp (-M_PI * getport(4));
- tank.damping[0].set (damp);
- tank.damping[1].set (damp);
- sample_t blend = getport(5), dry = 1 - blend;
- sample_t * dl = ports[6];
- sample_t * dr = ports[7];
- /* the modulated lattices interpolate, which needs truncated float */
- DSP::FPTruncateMode _truncate;
- for (int i = 0; i < frames; ++i)
- {
- normal = -normal;
- sample_t x = (sl[i] + sr[i] + normal) * .5;
- sample_t xl, xr;
- PlateStub::process (x, decay, &xl, &xr);
- xl = blend * xl + dry * sl[i];
- xr = blend * xr + dry * sr[i];
- F (dl, i, xl, adding_gain);
- F (dr, i, xr, adding_gain);
- }
- }
- /* //////////////////////////////////////////////////////////////////////// */
- PortInfo
- Plate2x2::port_info [] =
- {
- {
- "in:l",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "in:r",
- INPUT | AUDIO,
- {BOUNDED, -1, 1}
- }, {
- "bandwidth",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0.005, .999} /* .9995 */
- }, {
- "tail",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_MID, 0, .749} /* .5 */
- }, {
- "damping",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, .0005, 1} /* .0005 */
- }, {
- "blend",
- INPUT | CONTROL,
- {BOUNDED | DEFAULT_LOW, 0, 1}
- }, {
- "out:l",
- OUTPUT | AUDIO,
- {0}
- }, {
- "out:r",
- OUTPUT | AUDIO,
- {0}
- }
- };
- template <> void
- Descriptor<Plate2x2>::setup()
- {
- UniqueID = 1795;
- Label = "Plate2x2";
- Properties = HARD_RT;
- Name = CAPS "Plate2x2 - Versatile plate reverb, stereo inputs";
- Maker = "Tim Goetze <tim@quitte.de>";
- Copyright = "GPL, 2004-7";
- /* fill port info and vtable */
- autogen();
- }
|