void SamplesBuffer::set(const SamplesBuffer &buffer, int bufferChannelOffset, int channelsToCopy) { if (buffer.channels <= 0 || channels <= 0) return; int framesToCopy = std::min(buffer.getFrameLenght(), (int)frameLenght); int channelsToProcess = std::min(channelsToCopy, std::min(buffer.getChannels(), (int)channels)); if (channelsToProcess + bufferChannelOffset <= buffer.getChannels()) {// avoid invalid channel index int bytesToCopy = framesToCopy * sizeof(float); for (int c = 0; c < channelsToProcess; ++c) memcpy((void *)getSamplesArray(c), buffer.getSamplesArray( c + bufferChannelOffset), bytesToCopy); } }
void SamplesBuffer::set(const SamplesBuffer &buffer, int bufferChannelOffset, int channelsToCopy) { if (buffer.channels == 0 || channels == 0) return; int framesToCopy = std::min(buffer.getFrameLenght(), frameLenght); int channelsToProcess = std::min(channelsToCopy, std::min(buffer.getChannels(), static_cast<int>(channels))); if (channelsToProcess + bufferChannelOffset > buffer.getChannels()) return; // avoid crash acessing invalid memory int bytesToCopy = framesToCopy * sizeof(float); for (int c = 0; c < channelsToProcess; ++c) { memcpy((void *)getSamplesArray(c), buffer.getSamplesArray(c + bufferChannelOffset), bytesToCopy); } }
void LooperLayer::mixTo(SamplesBuffer &outBuffer, uint samplesToMix, uint intervalPosition, float looperMainGain) { bool canMix = samplesToMix > 0 && (muteState == LooperLayer::Unmuted || muteState == LooperLayer::WaitingToMute); if (canMix) { float *internalChannels[] = {&(leftChannel[0]), &(rightChannel[0])}; const uint secondChannelIndex = (outBuffer.isMono()) ? 0 : 1; float *bufferChannels[] = {outBuffer.getSamplesArray(0), outBuffer.getSamplesArray(secondChannelIndex)}; uint channels = outBuffer.getChannels(); const float mainGain = looperMainGain * gain; const float finalLeftGain = mainGain * leftGain; const float finalRightGain = mainGain * rightGain; float gains[] = {finalLeftGain, finalRightGain}; for (uint c = 0; c < channels; ++c) { for (uint s = 0; s < samplesToMix; ++s) { const uint offset = s + intervalPosition; bufferChannels[c][s] += internalChannels[c][offset] * gains[c]; } } } }