Hello,
I am sorry, I am still newbie in the routines on bytes etc, so my question will probably sound not professional.
In my project I use in MyAudioProcessor::processBlock()
the for loop through each sample in the buffer, like that:
void MyAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
// some code
// let's say I have only one channel so I don't need loop through the channels
for(int s=0; s<buffer.getNumSamples(); ++s)
{
// some operations
}
}
And I need to copy all data from buffer
to another buffer (and in that case it doesn’t matter if it’s output or input). So after my “through each sample loop” I could call:
myAudioBuffer.copyFrom(0, 0, buffer.getReadPointer(0), buffer.getNumSamples());
As far as I know it uses memcpy
which is very fast routine. And it would copy whole block of data. But I wonder if inside of memcpy
it is the same for
loop through each sample?
If yes, then the question is: wouldn’t it be more efficient if I use my own loop which already exist, and instead calling copyFrom
, maybe it would be better to call inside my loop something like that:
void MyAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
// some code
auto bufferReadPointer = buffer.getReadPointer(0);
auto myBufferWritePointer = myAudioBuffer.getWritePointer(0);
for(int s=0; s<buffer.getNumSamples(); ++s)
{
// some operations
myBufferPointer[s] = bufferReadPointer[s];
}
}
Then I have only one loop. So wouldn’t it be more efficient?
Sorry if stupid question. But it is very interesting for me and I am not sure how to exactly test those two scenarios and get comparable data about efficiency?
For any help great thanks in advance.
Best Regards