Whew ! If you’re looking for “fast”, you’re not going about it the right way.
-
Nested loops are bad.
-
A file open, and close every cycle on the outer loop ? Is that really necessary ? Big time performance hit.
-
spintf() as I recall is a fairly slow function.
A few things you can do to fix these issues.
Remove the nested loops and replace with a, if/else control block. Make the conditions checks that are most likely to pass more often - first. Also, simplify your math. If the numbers are going to be consistent, and non changing. Hard code the values. Multiplication and division on fast moving code will slow you down. Especially if done on floating point numbers. So unless I missed an assignment somewhere . . .
``while(io->DRam[0] < (bStep+1) * bsSize && io->DRam[0] > bStep * bsSize) {
…
}
if bsStep which seems to be left unassigned ( 0 ) + 1 = 1
1 * is going to be that . . . Some compilers may optimize this out, but why ? It also makes the code less readable.
Also . . .
fwrite(io->Adc->Value, sizeof(uint16), 16000, oFile);
Is a potential performance hit. Quite honestly I am not sure if sizeof(uint16) would be checked once at compile time, or if it would be checked every cycle at run time. But you can “fix” this simply by hard coding the value. Make it a constant if you feel it makes the code more readable.
Open the file once before the loop, and close it after the loop is done. That is, if at all possible. Also there is a “trap for new players”, in that if the application exits abnormally, the file may still be left opened. So a check when the application first starts may be in order.
As an aside, you can simplify the whole application by just gathering raw data, and shifting it out to the the general purpose processor ( ARM ). Which then the main processor can be made to do all the heavy math “lifting”.
Anyway I hope this is useful information, and my posting is not meant to demean, or otherwise come across as “smart-ass”.