Scape.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. Scape.cc
  3. Copyright 2004-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. */
  6. /*
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  18. 02111-1307, USA or point your web browser to http://www.gnu.org.
  19. */
  20. #include "basics.h"
  21. #include "Scape.h"
  22. #include "Descriptor.h"
  23. void
  24. Scape::activate()
  25. {
  26. time = 0;
  27. fb = 0;
  28. for (int i = 0; i < 4; ++i)
  29. svf[i].reset(),
  30. svf[i].set_out (SVF::Band),
  31. hipass[i].set_f (250. / fs);
  32. svf[3].set_out (SVF::Low),
  33. delay.reset();
  34. period = 0;
  35. }
  36. static double
  37. dividers [] = {
  38. 1 /* 0 sentinel */,
  39. 1, 0.5, 0.66666666666666666667, 0.75
  40. };
  41. float
  42. frandom2()
  43. {
  44. float f = frandom();
  45. return f * f * f;
  46. }
  47. template <sample_func_t F>
  48. void
  49. Scape::one_cycle (int frames)
  50. {
  51. sample_t * s = ports[0];
  52. // double one_over_n = 1 / (double) frames;
  53. /* delay times */
  54. double t1 = fs * 60. / getport(1);
  55. int div = (int) getport(2);
  56. double t2 = t1 * dividers[div];
  57. fb = getport(3);
  58. double dry = getport(4);
  59. dry = dry * dry;
  60. double blend = getport(5);
  61. sample_t * dl = ports[6];
  62. sample_t * dr = ports[7];
  63. DSP::FPTruncateMode truncate;
  64. while (frames)
  65. {
  66. /* flip 'renormal' addition constant */
  67. normal = -normal;
  68. /* retune filters */
  69. if (period <= 1)
  70. {
  71. period = t2 * .5;
  72. float f, q;
  73. f = frandom2();
  74. svf[0].set_f_Q (300 + 300 * f / fs, .3);
  75. svf[3].set_f_Q (300 + 600 * 2 * f / fs, .6);
  76. f = frandom2();
  77. q = f;
  78. svf[1].set_f_Q (400 + 2400 * f / fs, q);
  79. q = 1 - f;
  80. svf[2].set_f_Q (400 + 2400 * f / fs, q);
  81. }
  82. int n = min ((int) period, frames);
  83. if (n < 1)
  84. {
  85. /* not reached */
  86. #ifdef DEBUG
  87. fprintf (stderr, "Scape: %d - %d/%d frames, t2 = %.3f?!?\n", (int) period, n, frames, t2);
  88. #endif
  89. return;
  90. }
  91. /* sample loop */
  92. for (int i = 0; i < n; ++i)
  93. {
  94. sample_t x = s[i] + normal;
  95. sample_t x1 = delay.get_at (t1);
  96. sample_t x2 = delay.get_at (t2);
  97. delay.put (x + fb * x1 + normal);
  98. x = dry * x + .2 * svf[0].process (x) + .6 * svf[3].process(x);
  99. x1 = svf[1].process (x1 - normal);
  100. x2 = svf[2].process (x2 - normal);
  101. x1 = hipass[1].process (x1);
  102. x2 = hipass[2].process (x2);
  103. sample_t x1l, x1r, x2l, x2r;
  104. x1l = fabs (lfo[0].get());
  105. x1r = 1 - x1l;
  106. x2r = fabs (lfo[1].get());
  107. x2l = 1 - x2r;
  108. F (dl, i, x + blend * (x1 * x1l + x2 * x2l), adding_gain);
  109. F (dr, i, x + blend * (x2 * x2r + x1 * x1r), adding_gain);
  110. }
  111. frames -= n;
  112. period -= n;
  113. s += n;
  114. dl += n;
  115. dr += n;
  116. }
  117. }
  118. /* //////////////////////////////////////////////////////////////////////// */
  119. PortInfo
  120. Scape::port_info [] =
  121. {
  122. {
  123. "in",
  124. INPUT | AUDIO,
  125. {BOUNDED, -1, 1}
  126. }, {
  127. "bpm",
  128. INPUT | CONTROL,
  129. {BOUNDED | DEFAULT_LOW, 30, 240}
  130. }, {
  131. "divider",
  132. INPUT | CONTROL,
  133. {BOUNDED | INTEGER | DEFAULT_MIN, 2, 4}
  134. }, {
  135. "feedback",
  136. INPUT | CONTROL,
  137. {BOUNDED | DEFAULT_LOW, 0, 1}
  138. }, {
  139. "dry",
  140. INPUT | CONTROL,
  141. {BOUNDED | DEFAULT_LOW, 0, 1}
  142. }, {
  143. "blend",
  144. INPUT | CONTROL,
  145. {BOUNDED | DEFAULT_HIGH, 0, 1}
  146. }, {
  147. "out:l",
  148. OUTPUT | AUDIO,
  149. {0}
  150. }, {
  151. "out:r",
  152. OUTPUT | AUDIO,
  153. {0}
  154. }
  155. };
  156. template <> void
  157. Descriptor<Scape>::setup()
  158. {
  159. UniqueID = 2588;
  160. Label = "Scape";
  161. Properties = HARD_RT;
  162. Name = CAPS "Scape - Stereo delay + Filters";
  163. Maker = "Tim Goetze <tim@quitte.de>";
  164. Copyright = "GPL, 2004-7";
  165. /* fill port info and vtable */
  166. autogen();
  167. }