Phaser.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Phaser.h
  3. Copyright 2002-5 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. Standard and fractal-modulated phaser units.
  6. */
  7. /*
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. 02111-1307, USA or point your web browser to http://www.gnu.org.
  20. */
  21. #ifndef _PHASER_H_
  22. #define _PHASER_H_
  23. #include "dsp/Sine.h"
  24. #include "dsp/Lorenz.h"
  25. #include "dsp/Delay.h"
  26. /* all-pass as used by the phaser. */
  27. class PhaserAP
  28. {
  29. public:
  30. sample_t a, m;
  31. PhaserAP()
  32. {
  33. a = m = 0.;
  34. }
  35. void set (double delay)
  36. {
  37. a = (1 - delay) / (1 + delay);
  38. }
  39. sample_t process (sample_t x)
  40. {
  41. register sample_t y = -a * x + m;
  42. m = a * y + x;
  43. return y;
  44. }
  45. };
  46. class PhaserI
  47. : public Plugin
  48. {
  49. public:
  50. PhaserAP ap[6];
  51. DSP::Sine lfo;
  52. sample_t rate;
  53. sample_t y0;
  54. struct {
  55. double bottom, range;
  56. } delay;
  57. template <sample_func_t>
  58. void one_cycle (int frames);
  59. int blocksize, remain;
  60. public:
  61. static PortInfo port_info [];
  62. void init()
  63. {
  64. blocksize = 32;
  65. }
  66. void activate()
  67. {
  68. y0 = 0.;
  69. remain = 0;
  70. delay.bottom = 400. / fs;
  71. delay.range = 2200. / fs;
  72. rate = -1; /* force lfo reset in one_cycle() */
  73. }
  74. void run (int n)
  75. {
  76. one_cycle<store_func> (n);
  77. }
  78. void run_adding (int n)
  79. {
  80. one_cycle<adding_func> (n);
  81. }
  82. };
  83. /* same as above, but filter sweep is controlled by a Lorenz fractal */
  84. class PhaserII
  85. : public Plugin
  86. {
  87. public:
  88. double fs;
  89. PhaserAP ap[6];
  90. DSP::Lorenz lorenz;
  91. sample_t rate;
  92. sample_t y0;
  93. struct {
  94. double bottom, range;
  95. } delay;
  96. template <sample_func_t>
  97. void one_cycle (int frames);
  98. int blocksize, remain;
  99. public:
  100. static PortInfo port_info [];
  101. void init()
  102. {
  103. blocksize = 32;
  104. lorenz.init();
  105. }
  106. void activate()
  107. {
  108. y0 = 0.;
  109. remain = 0;
  110. delay.bottom = 400. / fs;
  111. delay.range = 2200. / fs;
  112. rate = -1; /* force lfo reset in one_cycle() */
  113. }
  114. void run (int n)
  115. {
  116. one_cycle<store_func> (n);
  117. }
  118. void run_adding (int n)
  119. {
  120. one_cycle<adding_func> (n);
  121. }
  122. };
  123. #endif /* _PHASER_H_ */