Phaser.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. Phaser.cc
  3. Copyright 2002-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. One simple mono phaser, 6 all-pass lines, the usual controls.
  6. Another unit in the same vein with the filter modulation controlled by
  7. a Lorenz fractal.
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. 02111-1307, USA or point your web browser to http://www.gnu.org.
  22. */
  23. #include "basics.h"
  24. #include "Phaser.h"
  25. #include "Descriptor.h"
  26. template <sample_func_t F>
  27. void
  28. PhaserI::one_cycle (int frames)
  29. {
  30. sample_t * s = ports[0];
  31. if (rate != *ports[1])
  32. {
  33. rate = getport(1);
  34. lfo.set_f (max (.001, rate * (double) blocksize), fs, lfo.get_phase());
  35. }
  36. double depth = getport(2);
  37. double spread = 1 + getport(3);
  38. double fb = getport(4);
  39. sample_t * dst = ports[5];
  40. while (frames)
  41. {
  42. if (remain == 0) remain = 32;
  43. int n = min (remain, frames);
  44. double d = delay.bottom + delay.range * (1. - fabs (lfo.get()));
  45. for (int j = 5; j >= 0; --j)
  46. {
  47. ap[j].set (d);
  48. d *= spread;
  49. }
  50. for (int i = 0; i < n; ++i)
  51. {
  52. sample_t x = s[i];
  53. sample_t y = x + y0 * fb + normal;
  54. for (int j = 5; j >= 0; --j)
  55. y = ap[j].process (y);
  56. y0 = y;
  57. F (dst, i, x + y * depth, adding_gain);
  58. }
  59. s += n;
  60. dst += n;
  61. frames -= n;
  62. remain -= n;
  63. }
  64. }
  65. /* //////////////////////////////////////////////////////////////////////// */
  66. PortInfo
  67. PhaserI::port_info [] =
  68. {
  69. {
  70. "in",
  71. INPUT | AUDIO,
  72. {BOUNDED, -1, 1}
  73. }, {
  74. "rate (Hz)",
  75. INPUT | CONTROL,
  76. {BOUNDED | DEFAULT_1, 0, 10}
  77. }, {
  78. "depth",
  79. INPUT | CONTROL,
  80. {BOUNDED | DEFAULT_HIGH, 0, 1}
  81. }, {
  82. "spread",
  83. INPUT | CONTROL,
  84. {BOUNDED | DEFAULT_LOW, 0, M_PI}
  85. }, {
  86. "feedback",
  87. INPUT | CONTROL,
  88. {BOUNDED | DEFAULT_HIGH, 0, .999}
  89. }, {
  90. "out",
  91. OUTPUT | AUDIO,
  92. {0}
  93. }
  94. };
  95. template <> void
  96. Descriptor<PhaserI>::setup()
  97. {
  98. UniqueID = 1775;
  99. Label = "PhaserI";
  100. Properties = HARD_RT;
  101. Name = CAPS "PhaserI - Mono phaser";
  102. Maker = "Tim Goetze <tim@quitte.de>";
  103. Copyright = "GPL, 2002-7";
  104. /* fill port info and vtable */
  105. autogen();
  106. }
  107. /* //////////////////////////////////////////////////////////////////////// */
  108. template <sample_func_t F>
  109. void
  110. PhaserII::one_cycle (int frames)
  111. {
  112. sample_t * s = ports[0];
  113. lorenz.set_rate (getport(1) * .08);
  114. double depth = getport(2);
  115. double spread = 1 + getport(3);
  116. double fb = getport(4);
  117. sample_t * dst = ports[5];
  118. while (frames)
  119. {
  120. if (remain == 0) remain = 32;
  121. int n = min (remain, frames);
  122. double d = delay.bottom + delay.range * (.3 * lorenz.get());
  123. for (int j = 5; j >= 0; --j)
  124. {
  125. ap[j].set (d);
  126. d *= spread;
  127. }
  128. for (int i = 0; i < n; ++i)
  129. {
  130. sample_t x = s[i];
  131. sample_t y = x + y0 * fb + normal;
  132. for (int j = 5; j >= 0; --j)
  133. y = ap[j].process (y);
  134. y0 = y;
  135. F (dst, i, x + y * depth, adding_gain);
  136. }
  137. s += n;
  138. dst += n;
  139. frames -= n;
  140. remain -= n;
  141. }
  142. }
  143. /* //////////////////////////////////////////////////////////////////////// */
  144. PortInfo
  145. PhaserII::port_info [] =
  146. {
  147. {
  148. "in",
  149. INPUT | AUDIO,
  150. {BOUNDED, -1, 1}
  151. }, {
  152. "rate",
  153. INPUT | CONTROL,
  154. {BOUNDED | DEFAULT_LOW, 0, 1}
  155. }, {
  156. "depth",
  157. INPUT | CONTROL,
  158. {BOUNDED | DEFAULT_HIGH, 0, 1}
  159. }, {
  160. "spread",
  161. INPUT | CONTROL,
  162. {BOUNDED | DEFAULT_LOW, 0, M_PI * .5}
  163. }, {
  164. "feedback",
  165. INPUT | CONTROL,
  166. {BOUNDED | DEFAULT_HIGH, 0, .999}
  167. }, {
  168. "out",
  169. OUTPUT | AUDIO,
  170. {0}
  171. }
  172. };
  173. template <> void
  174. Descriptor<PhaserII>::setup()
  175. {
  176. UniqueID = 2586;
  177. Label = "PhaserII";
  178. Properties = HARD_RT;
  179. Name = CAPS "PhaserII - Mono phaser modulated by a Lorenz fractal";
  180. Maker = "Tim Goetze <tim@quitte.de>";
  181. Copyright = "GPL, 2002-7";
  182. /* fill port info and vtable */
  183. autogen();
  184. }