Hello! I’m attempting to combine two buffers in within the context of the SamplerPlugin
. What I want to do is combine the samples for SampledNote
s with the same note
value so I can process their buffers per-sound. The end result should be one buffer with the sound of the two clips playing simultaneously.
Here I am sorting through a list of notes to find SamplerNote
s that match the currentNote
that I, processing. I get the buffer with sn->addNectBlock
and then add it in to sampleAccumulator.
AudioSampleBuffer sampleAccumulator(fc.destBuffer->getNumChannels(), fc.destBuffer->getNumSamples());
sampleAccumulator.clear();
// Test to see if other sampled notes share a note property
for (int innerNote = 0; innerNote < playingNotes.size(); innerNote++)
{
if (playingNotes.getUnchecked(innerNote)->note == currentNote)
{
AudioSampleBuffer tempSampleBuffer(fc.destBuffer->getNumChannels(), fc.destBuffer->getNumSamples());
tempSampleBuffer.clear();
auto sn = playingNotes.getUnchecked(innerNote);
// Build the audio buffer containing the sampler note's data
sn->addNextBlock(tempSampleBuffer, fc.bufferStartSample, fc.bufferNumSamples);
// Add it to the sampleAccumulator
for (int channel = 0; channel < fc.destBuffer->getNumChannels(); channel++)
{
sampleAccumulator.addFrom(channel, fc.bufferStartSample, tempSampleBuffer, channel, fc.bufferStartSample, fc.bufferNumSamples);
}
for (int i = 0; i < sampleAccumulator.getNumSamples(); i++)
{
DBG("(" << i << ", " << sampleAccumulator.getSample(0, i) << ")");
}
}
}
for (int channel = 0; channel < fc.destBuffer->getNumChannels(); channel++)
{
fc.destBuffer->addFrom(channel, fc.bufferStartSample, sampleAccumulator, channel, fc.bufferStartSample, fc.bufferNumSamples);
}
My problem seems to be when I call sampleAccumulator.addFrom() with more than one source. If it’s filled with only one buffer’s worth of data it sounds fine, but given 2 or more it does not.
In this example my input is a clip of a 440hz sine wave. Here are the samples in sampleAccumulator
with one SamplerNote
in the list:
Here’s the two sets of samples I’m adding overlayed:
Here are the samples in sampleAccumulator
with two SamplerNote
s in the list, the second sample having been triggered to play slightly after the first:
As you might expect this sounds bad and is not what I want. What am I doing wrong here, or what intermediate step am I missing? How do I end up with a buffer that sounds like two audio clips playing simultaneously?