Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Delay::processBlock(const AudioSourceChannelInfo& bufferToFill)
- {
- auto levelParam = parameters.at("level");
- auto lengthParam = parameters.at("length");
- if (!levelParam->getIsOn()) { return; }
- int numSamples = delayBuffer.getNumSamples();
- float delayLength = lengthParam->getVal() * (float) numSamples;
- int writePos = 0;
- for (int chan = 0; chan < bufferToFill.buffer->getNumChannels(); chan++)
- {
- auto channelData = bufferToFill.buffer->getWritePointer(chan);
- auto delayData = delayBuffer.getWritePointer(chan);
- writePos = delayPosition;
- for (int i = 0; i < bufferToFill.numSamples; i++)
- {
- float readPos = (float) writePos - delayLength;
- if (readPos < 0.0) { readPos += numSamples; }
- int baseIndex = (int) std::floor(readPos);
- float fraction = readPos - (float) baseIndex;
- auto in = channelData[i];
- // Linearly interpolate between two samples
- auto output = delayData[baseIndex] + ((delayData[baseIndex + 1] - delayData[baseIndex]) * fraction);
- channelData[i] += output;
- // Write output back into delay line
- delayData[writePos] = (in + output) * levelParam->getVal();
- writePos++;
- if (writePos >= numSamples)
- {
- writePos = 0;
- }
- }
- }
- delayPosition = writePos;
- }
Add Comment
Please, Sign In to add comment