Sin.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Sin.cc
  3. Copyright 2002-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. simple sin() generator.
  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. #include "basics.h"
  22. #include "Sin.h"
  23. #include "Descriptor.h"
  24. void
  25. Sin::init()
  26. {
  27. sin.set_f (f = .005, fs, 0);
  28. gain = 0;
  29. }
  30. template <sample_func_t F>
  31. void
  32. Sin::one_cycle (int frames)
  33. {
  34. if (f != *ports[0])
  35. sin.set_f (f = getport(0), fs, sin.get_phase());
  36. double g = (gain == *ports[1]) ?
  37. 1 : pow (getport(1) / gain, 1. / (double) frames);
  38. sample_t * d = ports[2];
  39. for (int i = 0; i < frames; ++i)
  40. {
  41. F (d, i, gain * sin.get(), adding_gain);
  42. gain *= g;
  43. }
  44. gain = getport(1);
  45. }
  46. /* //////////////////////////////////////////////////////////////////////// */
  47. PortInfo
  48. Sin::port_info [] =
  49. {
  50. {
  51. "f",
  52. INPUT | CONTROL,
  53. {BOUNDED | LOG | DEFAULT_100, 0.0001, 20000}
  54. }, {
  55. "volume",
  56. INPUT | CONTROL,
  57. {BOUNDED | DEFAULT_MID, MIN_GAIN, 1}
  58. }, {
  59. "out",
  60. OUTPUT | AUDIO,
  61. {0}
  62. }
  63. };
  64. template <> void
  65. Descriptor<Sin>::setup()
  66. {
  67. UniqueID = 1781;
  68. Label = "Sin";
  69. Properties = HARD_RT;
  70. Name = CAPS "Sin - Sine wave generator";
  71. Maker = "Tim Goetze <tim@quitte.de>";
  72. Copyright = "GPL, 2004-7";
  73. /* fill port info and vtable */
  74. autogen();
  75. }