i’m working a lot with the AudioSampleBuffer class and i’ve discovered most of the time i need to copyFrom two buffer while still applying a volume (ramped or linear) in the same loop (thus not requiring an additional loop only for setting volume).
void AudioSampleBuffer::copyFrom (const int destChannel,
const int destStartSample,
const float* source,
int numSamples,
float gain) throw()
{
jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
jassert (source != 0);
if (gain != 0.0f && numSamples > 0)
{
float* d = channels [destChannel] + destStartSample;
if (gain != 1.0f)
{
while (--numSamples >= 0)
*d++ = gain * *source++;
}
else
{
copyFrom (destChannel,
destStartSample,
source,
numSamples);
}
}
}
void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
const int destStartSample,
const float* source,
int numSamples,
float startGain,
float endGain) throw()
{
jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
jassert (source != 0);
if (startGain == endGain)
{
copyFrom (destChannel,
destStartSample,
source,
numSamples,
startGain);
}
else
{
if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
{
const float increment = (endGain - startGain) / numSamples;
float* d = channels [destChannel] + destStartSample;
while (--numSamples >= 0)
{
*d++ = startGain * *source++;
startGain += increment;
}
}
}
}
can you consider adding those functions ?