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.

131 lines
3.8KB

  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_VEXCDELAY_HEADER__
  25. #define __JUCETICE_VEXCDELAY_HEADER__
  26. #ifdef CARLA_EXPORT
  27. #include "juce_audio_basics.h"
  28. #else
  29. #include "../StandardHeader.h"
  30. #endif
  31. class VexDelay
  32. {
  33. public:
  34. VexDelay(const float* const p)
  35. : parameters(p),
  36. sampleRate(44100),
  37. bufferSize(sampleRate*2),
  38. iRead(0),
  39. iWrite(0),
  40. buffer(2, bufferSize)
  41. {
  42. buffer.clear();
  43. }
  44. void updateParameterPtr(const float* const p)
  45. {
  46. parameters = p;
  47. }
  48. void setSampleRate(const float s)
  49. {
  50. if (sampleRate == s)
  51. return;
  52. sampleRate = s;
  53. bufferSize = sampleRate * 2;
  54. iRead = 0;
  55. iWrite = 0;
  56. buffer.setSize(2, bufferSize, false, false, true);
  57. buffer.clear();
  58. }
  59. void processBlock(AudioSampleBuffer* const outBuffer, double bpm)
  60. {
  61. processBlock(outBuffer->getSampleData(0, 0), outBuffer->getSampleData(1, 0), outBuffer->getNumSamples(), bpm);
  62. }
  63. void processBlock(float* const outBufferL, float* const outBufferR, const int numSamples, double bpm)
  64. {
  65. bpm = jlimit(10.0, 500.0, bpm);
  66. #ifdef CARLA_EXPORT
  67. const int delay = jmin(int(parameters[0]) * int(((60.0 / bpm) * sampleRate) / 4.0), 44100);
  68. const float feedback = parameters[1]/100.0f;
  69. #else
  70. const int delay = jmin(int(parameters[73] * 8.0) * int(((60.0 / bpm) * sampleRate) / 4.0), 44100);
  71. const float feedback = parameters[74];
  72. #endif
  73. float* const bufferL = buffer.getSampleData(0, 0);
  74. float* const bufferR = buffer.getSampleData(1, 0);
  75. for (int i = 0; i < numSamples; ++i)
  76. {
  77. iRead = iWrite - delay;
  78. if (iRead < 0)
  79. iRead += (int)sampleRate;
  80. bufferL[iWrite] = outBufferL[i];
  81. bufferR[iWrite] = outBufferR[i];
  82. bufferR[iWrite] += bufferL[iRead] * feedback;
  83. bufferL[iWrite] += bufferR[iRead] * feedback;
  84. jassert(i < numSamples);
  85. jassert(iRead < bufferSize);
  86. jassert(iWrite < bufferSize);
  87. outBufferL[i] = bufferL[iRead];
  88. outBufferR[i] = bufferR[iRead];
  89. if (++iWrite == sampleRate)
  90. iWrite = 0;
  91. }
  92. }
  93. private:
  94. const float* parameters;
  95. float sampleRate;
  96. int bufferSize, iRead, iWrite;
  97. AudioSampleBuffer buffer;
  98. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexDelay)
  99. };
  100. #endif