Fun engineering problem I am currently facing: Generate a very long sine wave in...

@azonenberg@ioc.exchange

Fun engineering problem I am currently facing: Generate a very long sine wave in ngscopeclient, accurately and in parallel, using only single-precision floating point and 32-bit integer math.

The current implementation, used in both the "sine" and "downconvert" filter, looks basically like (pseudocode with some stuff like scaling and offsets removed for simplicity)

double rate;
uint depth;

for GPU thread i in 0...depth-1
double tmp = (i * rate) mod 2*pi
out[i] = sin( (float) tmp)

The problem is the use of the float64 intermediate, which breaks on platforms (most notably apple silicon) that do not have native fp64 support.

Naively having rate and tmp be float32 causes loss-of-precision errors and waveform distortion with deep memory.

Anybody have ideas on some clever numerical method to do this with only float32 temporaries?