Guest User

Untitled

a guest
Nov 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. void Delay::processBlock(const AudioSourceChannelInfo& bufferToFill)
  2. {
  3. auto levelParam = parameters.at("level");
  4. auto lengthParam = parameters.at("length");
  5.  
  6. if (!levelParam->getIsOn()) { return; }
  7.  
  8. int numSamples = delayBuffer.getNumSamples();
  9. float delayLength = lengthParam->getVal() * (float) numSamples;
  10.  
  11. int writePos = 0;
  12.  
  13. for (int chan = 0; chan < bufferToFill.buffer->getNumChannels(); chan++)
  14. {
  15. auto channelData = bufferToFill.buffer->getWritePointer(chan);
  16. auto delayData = delayBuffer.getWritePointer(chan);
  17.  
  18. writePos = delayPosition;
  19.  
  20. for (int i = 0; i < bufferToFill.numSamples; i++)
  21. {
  22. float readPos = (float) writePos - delayLength;
  23.  
  24. if (readPos < 0.0) { readPos += numSamples; }
  25.  
  26. int baseIndex = (int) std::floor(readPos);
  27. float fraction = readPos - (float) baseIndex;
  28.  
  29. auto in = channelData[i];
  30.  
  31. // Linearly interpolate between two samples
  32. auto output = delayData[baseIndex] + ((delayData[baseIndex + 1] - delayData[baseIndex]) * fraction);
  33. channelData[i] += output;
  34.  
  35. // Write output back into delay line
  36. delayData[writePos] = (in + output) * levelParam->getVal();
  37.  
  38. writePos++;
  39. if (writePos >= numSamples)
  40. {
  41. writePos = 0;
  42. }
  43. }
  44. }
  45. delayPosition = writePos;
  46. }
Add Comment
Please, Sign In to add comment