Bound queued audio data to prevent excessive latency

This commit is contained in:
Cameron Gutman 2019-05-07 20:39:45 -07:00
parent d5b950e5cf
commit 8da563b280
2 changed files with 12 additions and 3 deletions

View File

@ -168,8 +168,17 @@ public class AndroidAudioRenderer implements AudioRenderer {
}
@Override
public void playDecodedAudio(byte[] audioData) {
track.write(audioData, 0, audioData.length);
public void playDecodedAudio(short[] audioData) {
// Only queue up to 40 ms of pending audio data in addition to what AudioTrack is buffering for us.
if (MoonBridge.getPendingAudioFrames() < 8) {
// This will block until the write is completed. That can cause a backlog
// of pending audio data, so we do the above check to be able to bound
// latency at 40 ms in that situation.
track.write(audioData, 0, audioData.length);
}
else {
LimeLog.info("Too many pending audio frames: " + MoonBridge.getPendingAudioFrames());
}
}
@Override

@ -1 +1 @@
Subproject commit 39c6a3c8b10ff7c705f33d49e2217728ff9772c1
Subproject commit 9f409da618424136c50bd4c8b6185841be857353