Skip to content

Commit 60a2c28

Browse files
committed
fix resample mode generation
1 parent 8502220 commit 60a2c28

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

‎Source/Node/nodes/sampler/SamplerNode.cpp‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,16 +1131,55 @@ void SamplerNode::SamplerNote::run()
11311131

11321132
if (autoKeyAlgorithm == SamplerNode::RESAMPLE)
11331133
{
1134-
const int srcNeeded = jmax(numSamples + 16, (int)(numSamples * safeShift) + 16);
1134+
const int outSamples = (int)(numSamples / safeShift);
1135+
1136+
const int loopFadeSamples = loopFadeEnabled
1137+
? jmin(jmax(0, numSamples - 1), fadeNumSamples)
1138+
: 0;
1139+
1140+
const int paddedInputSamples = numSamples + loopFadeSamples;
1141+
const int outLoopFadeSamples = (int)(loopFadeSamples / safeShift);
1142+
const int totalOutSamples = outSamples + outLoopFadeSamples;
1143+
1144+
// Provide enough source samples plus interpolation margin
1145+
const int srcNeeded = paddedInputSamples + 16;
11351146
AudioBuffer<float> extSrc(numChannels, srcNeeded);
1147+
extSrc.clear();
11361148
for (int ch = 0; ch < numChannels; ++ch)
1137-
for (int i = 0; i < srcNeeded; ++i)
1138-
extSrc.setSample(ch, i, i < numSamples ? sourceCopy.getSample(ch, i) : 0.0f);
1149+
{
1150+
for (int i = 0; i < numSamples; ++i)
1151+
extSrc.setSample(ch, i, sourceCopy.getSample(ch, i));
1152+
if (loopFadeEnabled && loopFadeSamples > 0)
1153+
for (int i = 0; i < loopFadeSamples; ++i)
1154+
extSrc.setSample(ch, numSamples + i, sourceCopy.getSample(ch, i));
1155+
}
1156+
1157+
pitchedFull.setSize(numChannels, outSamples);
1158+
pitchedFull.clear();
1159+
1160+
AudioBuffer<float> totalOutput(numChannels, totalOutSamples);
1161+
totalOutput.clear();
11391162

11401163
for (int ch = 0; ch < numChannels; ++ch)
11411164
{
11421165
CatmullRomInterpolator resampler;
1143-
resampler.process(safeShift, extSrc.getReadPointer(ch), pitchedFull.getWritePointer(ch), numSamples);
1166+
resampler.process(safeShift, extSrc.getReadPointer(ch), totalOutput.getWritePointer(ch), totalOutSamples);
1167+
}
1168+
1169+
for (int ch = 0; ch < numChannels; ++ch)
1170+
{
1171+
pitchedFull.copyFrom(ch, 0, totalOutput, ch, 0, outSamples);
1172+
}
1173+
1174+
renderedNumSamples = outSamples;
1175+
1176+
if (loopFadeEnabled && outLoopFadeSamples > 0)
1177+
{
1178+
loopContinuation.setSize(numChannels, outLoopFadeSamples);
1179+
for (int ch = 0; ch < numChannels; ++ch)
1180+
{
1181+
loopContinuation.copyFrom(ch, 0, totalOutput, ch, outSamples, outLoopFadeSamples);
1182+
}
11441183
}
11451184
}
11461185
else

0 commit comments

Comments
 (0)