Android AudioTrack buffering problems

前端 未结 3 1787
梦如初夏
梦如初夏 2021-01-31 11:25

Ok so I have a frequency generator which uses AudioTrack to send PCM data to the hardware. Here\'s the code I\'m using for that:

private class playSoundTask ext         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 12:08

    I think I've managed to solve the problem.

    ...
    samples[i] = (short)((float)Math.sin( angle )*Short.MAX_VALUE);
    angle += increment;
    angle = angle % (2.0f * (float) Math.PI); //added statement
    ...
    

    As stated before, it's not about buffers. It is about the angle variable, it increases continuously. After a while, the variable gets too large and does not support little steps.

    As the sine repeats after 2*PI, we need to take the modulus of angle.

    Hope this helps.

    edited: angle += increment is enough for the job.

提交回复
热议问题