I need a fetch a new audio frame every 20ms, therefore i create a AudioTrack which has buffer size of 7528 bytes(Maximum of 2 Audio Buffers of 3764 byes each)
int minBufferSize = 7528;
mAudioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize , AudioTrack.MODE_STREAM);
mAudioTrack.setPlaybackPositionUpdateListener(CarMediaPlayer.this ,mMainThreadHandler );
mAudioTrack.setPositionNotificationPeriod(914); //Set a notification for every 20ms to get an Audio frame. This is got by Dividing 3764/4(framesize)
The problem i see is that the callback
@Override
public void onPeriodicNotification(AudioTrack track)
{
Log.i(TAG, "onPeriodicNotification ");
getAudioFrame();
}
Is not getting called for every 20ms. Sometimes it gets called very early and sometimes too late. It is not consistent but get called for every playback of frame of 3764 bytes.
Any idea how to make it consistent so that it get called for every 20ms?