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.

159 lines
4.7KB

  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. ==============================================================================
  23. */
  24. #ifndef __JUCETICE_VEXCCHORUS_HEADER__
  25. #define __JUCETICE_VEXCCHORUS_HEADER__
  26. #ifdef CARLA_EXPORT
  27. #include "juce_audio_basics.h"
  28. #else
  29. #include "../StandardHeader.h"
  30. #endif
  31. class VexChorus
  32. {
  33. public:
  34. VexChorus(const float* const p)
  35. : lfo1(0.0f),
  36. lfo2(0.0f),
  37. lastlfo1(0.0f),
  38. lastlfo2(0.0f),
  39. parameters(p),
  40. sampleRate(44100.0f),
  41. cycle(44100 / 32),
  42. iRead(cycle * 0.5f),
  43. iWrite(0),
  44. buffer(2, cycle)
  45. {
  46. lfoS[0] = 0.5f;
  47. lfoS[1] = 0.0f;
  48. buffer.clear();
  49. }
  50. void updateParameterPtr(const float* const p)
  51. {
  52. parameters = p;
  53. }
  54. void setSampleRate(const float s)
  55. {
  56. if (sampleRate == s)
  57. return;
  58. sampleRate = s;
  59. cycle = int(sampleRate / 32);
  60. iRead = int(cycle * 0.5f);
  61. iWrite = 0;
  62. buffer.setSize(2, cycle, false, false, true);
  63. buffer.clear();
  64. }
  65. void processBlock(AudioSampleBuffer* const outBuffer)
  66. {
  67. processBlock(outBuffer->getSampleData(0, 0), outBuffer->getSampleData(1, 0), outBuffer->getNumSamples());
  68. }
  69. void processBlock(float* const outBufferL, float* const outBufferR, const int numSamples)
  70. {
  71. #ifdef CARLA_EXPORT
  72. const float depth = parameters[0] * 0.2f;
  73. const float speed = parameters[1] * parameters[1];
  74. #else
  75. const float depth = parameters[77] * 0.2f;
  76. const float speed = parameters[76] * parameters[76];
  77. #endif
  78. const int delay = int(cycle * 0.5f);
  79. const float lfoC = 2.0f * sinf(float_Pi * (speed * 5.0f) / sampleRate);
  80. float* const bufferL = buffer.getSampleData(0, 0);
  81. float* const bufferR = buffer.getSampleData(1, 0);
  82. float a, b, alpha, readpoint;
  83. int rp;
  84. for (int i = 0; i < numSamples ; ++i)
  85. {
  86. // LFO
  87. lfoS[0] = lfoS[0] - lfoC*lfoS[1];
  88. lfoS[1] = lfoS[1] + lfoC*lfoS[0];
  89. lastlfo1 = lfo1;
  90. lastlfo2 = lfo2;
  91. lfo1 = (lfoS[0] + 1) * depth;
  92. lfo2 = (lfoS[1] + 1) * depth;
  93. // Write to buffer
  94. bufferL[iWrite] = outBufferL[i];
  95. bufferR[iWrite] = outBufferR[i];
  96. iWrite++; //inc and cycle the write index
  97. iWrite = iWrite % cycle;
  98. iRead = iWrite + delay; //cycle the read index
  99. iRead = iRead % cycle;
  100. // Read left
  101. readpoint = cycle * lfo1 * 0.5f;
  102. rp = roundFloatToInt(readpoint - 0.5f);
  103. alpha = readpoint - rp;
  104. a = bufferL[(iRead + rp -1) % cycle];
  105. b = bufferL[(iRead + rp) % cycle];
  106. outBufferL[i] = a + alpha * (b - a);
  107. // Read right
  108. readpoint = cycle * lfo2 * 0.5f;
  109. rp = roundFloatToInt(readpoint - 0.5f);
  110. alpha = readpoint - rp;
  111. a = bufferR[(iRead + rp -1) % cycle];
  112. b = bufferR[(iRead + rp) % cycle];
  113. outBufferR[i] = a + alpha * (b - a);
  114. }
  115. }
  116. private:
  117. float lfo1, lfo2, lastlfo1, lastlfo2;
  118. float lfoS[2];
  119. const float* parameters;
  120. float sampleRate;
  121. int cycle;
  122. int iRead, iWrite;
  123. AudioSampleBuffer buffer;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexChorus)
  125. };
  126. #endif