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.

VexDelay.h 3.8KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_DELAY_HEADER_INCLUDED
  26. #define DISTRHO_VEX_DELAY_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 VexDelay
  36. {
  37. public:
  38. VexDelay(const float* const p)
  39. : parameters(p),
  40. sampleRate(0.0f),
  41. bufferSize(0),
  42. iRead(0),
  43. iWrite(0),
  44. buffer(2, 0)
  45. {
  46. buffer.clear();
  47. setSampleRate(44100.0f);
  48. }
  49. void updateParameterPtr(const float* const p)
  50. {
  51. parameters = p;
  52. }
  53. void setSampleRate(const float s)
  54. {
  55. if (sampleRate == s)
  56. return;
  57. sampleRate = s;
  58. bufferSize = sampleRate * 2;
  59. iRead = 0;
  60. iWrite = 0;
  61. buffer.setSize(2, bufferSize, false, false, true);
  62. buffer.clear();
  63. }
  64. void processBlock(AudioSampleBuffer* const outBuffer, double bpm)
  65. {
  66. processBlock(outBuffer->getSampleData(0, 0), outBuffer->getSampleData(1, 0), outBuffer->getNumSamples(), bpm);
  67. }
  68. void processBlock(float* const outBufferL, float* const outBufferR, const int numSamples, double bpm)
  69. {
  70. bpm = jlimit(10.0, 500.0, bpm);
  71. const int delay = jmin(int(parameters[73] * 8.0f) * int(((60.0 / bpm) * sampleRate) / 4.0), 44100);
  72. const float feedback = parameters[74];
  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 // DISTRHO_VEX_DELAY_HEADER_INCLUDED