You’re incrementing startSample
on each iteration of the loop per sample. You might find it easier to reason about what’s going on if your for
loop is
for (int i = 0; i < numSamples; ++i)
Then just offset i
every time you use it to write the output e.g.,
outputBuffer.setSample (channel, i + startSample, sum);