How do you determine the audio latency (AudioTrack) on Android?

后端 未结 4 1163
情歌与酒
情歌与酒 2020-12-31 13:19

I have an app in which I use an AudioTrack in streaming mode to play dynamically generated audio. The app doesn\'t have to respond instantaneously to inputs, s

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 14:10

    Consider driver's latency. There's hidden function AudioManager.getOutputLatency(int) to get this.

    Call it like this:

    AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    try{
       Method m = am.getClass().getMethod("getOutputLatency", int.class);
       latency = (Integer)m.invoke(am, AudioManager.STREAM_MUSIC);
    }catch(Exception e){
    }
    

    I get about 45 - 50 ms on different devices. Use the result in your calculations.

提交回复
热议问题