Android Audio - Streaming sine-tone generator odd behaviour

前端 未结 1 1716
情歌与酒
情歌与酒 2020-12-30 11:08

first time poster here. I usually like to find the answer myself (be it through research or trial-and-error), but I\'m stumped here.

What I\'m trying to do:<

相关标签:
1条回答
  • 2020-12-30 11:36

    I've found it!

    It turns out the problem has nothing to do with buffers or threading.

    It sounds fine in the first couple of seconds, because the angle of the computation is relatively small. As the program runs and the angle grows, Math.sin(_currentAngle) begins to produce unreliable values.

    So, I replaced Math.sin() with FloatMath.sin().

    I also replaced _currentAngle = _currentAngle + _angleIncrement;

    with

    _currentAngle = ((_currentAngle + _angleIncrement) % (2.0f * (float) Math.PI));, so the angle is always < 2*PI.

    Works like a charm! Thanks very much for your help, praetorian droid!

    0 讨论(0)
提交回复
热议问题