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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. EffectLFO::EffectLFO(float srate_f, float bufsize_f)
  21. :Pfreq(40),
  22. Prandomness(0),
  23. PLFOtype(0),
  24. Pstereo(64),
  25. xl(0.0f),
  26. xr(0.0f),
  27. ampl1(RND),
  28. ampl2(RND),
  29. ampr1(RND),
  30. ampr2(RND),
  31. lfornd(0.0f),
  32. samplerate_f(srate_f),
  33. buffersize_f(bufsize_f)
  34. {
  35. updateparams();
  36. }
  37. EffectLFO::~EffectLFO() {}
  38. //Update the changed parameters
  39. void EffectLFO::updateparams(void)
  40. {
  41. float lfofreq = (powf(2.0f, Pfreq / 127.0f * 10.0f) - 1.0f) * 0.03f;
  42. incx = fabsf(lfofreq) * buffersize_f / samplerate_f;
  43. if(incx > 0.49999999f)
  44. incx = 0.499999999f; //Limit the Frequency
  45. lfornd = Prandomness / 127.0f;
  46. lfornd = (lfornd > 1.0f) ? 1.0f : lfornd;
  47. if(PLFOtype > 1)
  48. PLFOtype = 1; //this has to be updated if more lfo's are added
  49. lfotype = PLFOtype;
  50. xr = fmodf(xl + (Pstereo - 64.0f) / 127.0f + 1.0f, 1.0f);
  51. }
  52. //Compute the shape of the LFO
  53. float EffectLFO::getlfoshape(float x)
  54. {
  55. float out;
  56. switch(lfotype) {
  57. case 1: //EffectLFO_TRIANGLE
  58. if((x > 0.0f) && (x < 0.25f))
  59. out = 4.0f * x;
  60. else
  61. if((x > 0.25f) && (x < 0.75f))
  62. out = 2.0f - 4.0f * x;
  63. else
  64. out = 4.0f * x - 4.0f;
  65. break;
  66. //when adding more, ensure ::updateparams() gets updated
  67. default:
  68. out = cosf(x * 2.0f * PI); //EffectLFO_SINE
  69. }
  70. return out;
  71. }
  72. //LFO output
  73. void EffectLFO::effectlfoout(float *outl, float *outr)
  74. {
  75. float out;
  76. out = getlfoshape(xl);
  77. if((lfotype == 0) || (lfotype == 1))
  78. out *= (ampl1 + xl * (ampl2 - ampl1));
  79. xl += incx;
  80. if(xl > 1.0f) {
  81. xl -= 1.0f;
  82. ampl1 = ampl2;
  83. ampl2 = (1.0f - lfornd) + lfornd * RND;
  84. }
  85. *outl = (out + 1.0f) * 0.5f;
  86. out = getlfoshape(xr);
  87. if((lfotype == 0) || (lfotype == 1))
  88. out *= (ampr1 + xr * (ampr2 - ampr1));
  89. xr += incx;
  90. if(xr > 1.0f) {
  91. xr -= 1.0f;
  92. ampr1 = ampr2;
  93. ampr2 = (1.0f - lfornd) + lfornd * RND;
  94. }
  95. *outr = (out + 1.0f) * 0.5f;
  96. }