What is the difference between these two?
for (int i = 0; i < numSamples; i++) {
mData[sampleIndex++] = *buffer++ * (1.0f / 32768);
}
and
memcpy(&mData[sampleIndex], buffer, (numSamples * sizeof(float)));
If I understood correct, the first copies numSamples
float
values to mData
, one by one. The second one, copies numSamples*sizeof(float)
bytes to mData
. Since we're copying numSaples
* number of bytes on float
, I think they do the same thing, but the first one actually multiplies things before passing to mData
.
So, is there a way to transform the memcpy
into a for
? Something like:
for (int i = 0; i < numSamples * sizeof(float); i++) {
//What to put here?
}
Context:
const int32_t mChannelCount;
const int32_t mMaxFrames;
int32_t sampleIndex;
float *mData;
float *buffer;
question from:
https://stackoverflow.com/questions/65945183/how-to-transform-this-memcpy-into-a-for 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…