There's some code where it creates a float array like this:
mData = new float[channelCount * maxFrames];
then it does
memcpy(&mData[sampleIndex],
buffer,
(numSamples * sizeof(float)));
What does &mData[sampleIndex] mean? Well, we have a float array, we take an element of that array, and then take the address of that element. Wouldn't the address of that element be mData + sampleIndex?
What if I wanted to change memcpy by a for loop? I did this and it worked:
for (int i=0; i< numSamples * sizeof(float); i++) {
(&mData[sampleIndex])[i] = buffer[i];
}
but I don't know what (&mData[sampleIndex])[i] means. Should it be mData + sampleIndex + i?
This code is supposed to work to record microfone wav data, so we should be able to store things in multiple channels. How this code manages such channels?
for (int i=0; i< numSamples; i++)since you are assigning wholefloats and not individual bytes, assumingbuffer[]is an array offloatto match thatmDatais an array offloat.memcpy(&mData[sampleIndex], buffer, (numSamples * sizeof(float)));is useful when you want tomemcpydata into the middle of an array.