In practice, the system captures audio samples by blocks of 1024 samples. Remplace the hardcoded value of 5 milliseconds (240 samples), and let AudioRecord fill the input buffer provided by MediaCodec (or by AudioRawRecorder), with a maximum size of 1024 samples (just in case).