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 2.9KB

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