There's a fair bit of redundant stuff in there. Where are channelcount and samplecount defined? Are they constant, or incoming parameters? And is the audio actually meant to be
four channels, each being a single sinewave? The "interleaved" feels like the audio could be far-more-common stereo ie
two channels.
Also, whilst you've done a beautiful translation of the 1.0f use into B4X, you could go one step further in that:
... frequencyPerChannel(ch)
* (one/samplerate
) ...
can be replaced by:
... frequencyPerChannel(ch) / samplerate ...
ie no need for Float one. Sorry
I suspect that the reason for the original style was to force optimization of replacing the division by multiplication of a constant reciprocal.
Which you can still do, if you really, truly need to save cycles. Add "
Dim DivideBySampleRate As Float = 1 / samplerate"
before the loop (so it only gets done once) and then replace the "
/ samplerate" with "
* DivideBySampleRate"