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.

161 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2008 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2008 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU Lesser General Public License, as published by the Free Software
  9. Foundation; either version 2 of the License, or (at your option) any later
  10. version.
  11. JUCE and JUCETICE are distributed in the hope that they will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  17. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. Boston, MA 02111-1307 USA
  19. ==============================================================================
  20. @author rockhardbuns
  21. @tweaker Lucio Asnaghi
  22. @tweaker falkTX
  23. ==============================================================================
  24. */
  25. #ifndef DISTRHO_VEX_CHORUS_HEADER_INCLUDED
  26. #define DISTRHO_VEX_CHORUS_HEADER_INCLUDED
  27. #ifndef CARLA_EXPORT
  28. #define CARLA_EXPORT
  29. #endif
  30. #ifdef CARLA_EXPORT
  31. #include "juce_audio_basics.h"
  32. #else
  33. #include "../StandardHeader.h"
  34. #endif
  35. class VexChorus
  36. {
  37. public:
  38. VexChorus(const float* const p)
  39. : lfo1(0.0f),
  40. lfo2(0.0f),
  41. lastlfo1(0.0f),
  42. lastlfo2(0.0f),
  43. parameters(p),
  44. sampleRate(0.0f),
  45. cycle(0),
  46. iRead(0),
  47. iWrite(0),
  48. buffer(2, 0)
  49. {
  50. lfoS[0] = 0.5f;
  51. lfoS[1] = 0.0f;
  52. setSampleRate(44100.0f);
  53. }
  54. void updateParameterPtr(const float* const p)
  55. {
  56. parameters = p;
  57. }
  58. void setSampleRate(const float s)
  59. {
  60. if (sampleRate == s)
  61. return;
  62. sampleRate = s;
  63. cycle = int(sampleRate / 32);
  64. iRead = int(cycle * 0.5f);
  65. iWrite = 0;
  66. buffer.setSize(2, cycle, false, false, true);
  67. buffer.clear();
  68. }
  69. void processBlock(AudioSampleBuffer& outBuffer)
  70. {
  71. processBlock(outBuffer.getWritePointer(0), outBuffer.getWritePointer(1), outBuffer.getNumSamples());
  72. }
  73. void processBlock(float* const outBufferL, float* const outBufferR, const int numSamples)
  74. {
  75. const float speed = parameters[76] * parameters[76];
  76. const float depth = parameters[77] * 0.2f + 0.01f;
  77. const int delay = int(cycle * 0.5f);
  78. const float lfoC = 2.0f * sinf(float_Pi * (speed * 5.0f) / sampleRate);
  79. float* const bufferL = buffer.getWritePointer(0);
  80. float* const bufferR = buffer.getWritePointer(1);
  81. float a, b, alpha, readpoint;
  82. int rp;
  83. for (int i = 0; i < numSamples ; ++i)
  84. {
  85. // LFO
  86. lfoS[0] = lfoS[0] - lfoC*lfoS[1];
  87. lfoS[1] = lfoS[1] + lfoC*lfoS[0];
  88. lastlfo1 = lfo1;
  89. lastlfo2 = lfo2;
  90. lfo1 = (lfoS[0] + 1) * depth;
  91. lfo2 = (lfoS[1] + 1) * depth;
  92. // Write to buffer
  93. bufferL[iWrite] = outBufferL[i];
  94. bufferR[iWrite] = outBufferR[i];
  95. iWrite++; //inc and cycle the write index
  96. iWrite = iWrite % cycle;
  97. iRead = iWrite + delay; //cycle the read index
  98. iRead = iRead % cycle;
  99. // Read left
  100. readpoint = cycle * lfo1 * 0.5f;
  101. rp = roundFloatToInt(readpoint - 0.5f);
  102. alpha = readpoint - rp;
  103. a = bufferL[(iRead + rp -1) % cycle];
  104. b = bufferL[(iRead + rp) % cycle];
  105. outBufferL[i] = a + alpha * (b - a);
  106. // Read right
  107. readpoint = cycle * lfo2 * 0.5f;
  108. rp = roundFloatToInt(readpoint - 0.5f);
  109. alpha = readpoint - rp;
  110. a = bufferR[(iRead + rp -1) % cycle];
  111. b = bufferR[(iRead + rp) % cycle];
  112. outBufferR[i] = a + alpha * (b - a);
  113. }
  114. }
  115. private:
  116. float lfo1, lfo2, lastlfo1, lastlfo2;
  117. float lfoS[2];
  118. const float* parameters;
  119. float sampleRate;
  120. int cycle;
  121. int iRead, iWrite;
  122. AudioSampleBuffer buffer;
  123. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexChorus)
  124. };
  125. #endif // DISTRHO_VEX_CHORUS_HEADER_INCLUDED