Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EffectLFO.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. EffectLFO.cpp - Stereo LFO used by some effects
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "EffectLFO.h"
  18. #include "../Misc/Util.h"
  19. #include <cmath>
  20. #include "globals.h"
  21. EffectLFO::EffectLFO(float srate_f, float bufsize_f)
  22. :Pfreq(40),
  23. Prandomness(0),
  24. PLFOtype(0),
  25. Pstereo(64),
  26. xl(0.0f),
  27. xr(0.0f),
  28. ampl1(RND),
  29. ampl2(RND),
  30. ampr1(RND),
  31. ampr2(RND),
  32. lfornd(0.0f),
  33. samplerate_f(srate_f),
  34. buffersize_f(bufsize_f)
  35. {
  36. updateparams();
  37. }
  38. EffectLFO::~EffectLFO() {}
  39. //Update the changed parameters
  40. void EffectLFO::updateparams(void)
  41. {
  42. float lfofreq = (powf(2.0f, Pfreq / 127.0f * 10.0f) - 1.0f) * 0.03f;
  43. incx = fabsf(lfofreq) * buffersize_f / samplerate_f;
  44. if(incx > 0.49999999f)
  45. incx = 0.499999999f; //Limit the Frequency
  46. lfornd = Prandomness / 127.0f;
  47. lfornd = (lfornd > 1.0f) ? 1.0f : lfornd;
  48. if(PLFOtype > 1)
  49. PLFOtype = 1; //this has to be updated if more lfo's are added
  50. lfotype = PLFOtype;
  51. xr = xl + (Pstereo - 64.0f) / 127.0f + 1.0f;
  52. xr -= floorf(xr);
  53. }
  54. //Compute the shape of the LFO
  55. float EffectLFO::getlfoshape(float x)
  56. {
  57. float out;
  58. switch(lfotype) {
  59. case 1: //EffectLFO_TRIANGLE
  60. if((x > 0.0f) && (x < 0.25f))
  61. out = 4.0f * x;
  62. else
  63. if((x > 0.25f) && (x < 0.75f))
  64. out = 2.0f - 4.0f * x;
  65. else
  66. out = 4.0f * x - 4.0f;
  67. break;
  68. //when adding more, ensure ::updateparams() gets updated
  69. default:
  70. out = cosf(x * 2.0f * PI); //EffectLFO_SINE // TODO: use M_PI ?
  71. }
  72. return out;
  73. }
  74. //LFO output
  75. void EffectLFO::effectlfoout(float *outl, float *outr)
  76. {
  77. float out;
  78. out = getlfoshape(xl);
  79. if((lfotype == 0) || (lfotype == 1))
  80. out *= (ampl1 + xl * (ampl2 - ampl1));
  81. xl += incx;
  82. if(xl > 1.0f) {
  83. xl -= 1.0f;
  84. ampl1 = ampl2;
  85. ampl2 = (1.0f - lfornd) + lfornd * RND;
  86. }
  87. *outl = (out + 1.0f) * 0.5f;
  88. out = getlfoshape(xr);
  89. if((lfotype == 0) || (lfotype == 1))
  90. out *= (ampr1 + xr * (ampr2 - ampr1));
  91. xr += incx;
  92. if(xr > 1.0f) {
  93. xr -= 1.0f;
  94. ampr1 = ampr2;
  95. ampr2 = (1.0f - lfornd) + lfornd * RND;
  96. }
  97. *outr = (out + 1.0f) * 0.5f;
  98. }