Java tutorial
//package com.java2s; //License from project: Open Source License import android.media.AudioRecord; public class Main { /** * Check correct buffer size for your AudioRecord instance * * @param audioSource * the audio source * @param fs * the fs * @param channelConfiguration * the channel configuration * @param audioEncoding * the audio encoding * @return the int */ public static int checkCorrectBufferSize(int audioSource, int fs, int channelConfiguration, int audioEncoding) { for (int buffer : new int[] { 256, 512, 1024, 2048, 4096 }) { // add the rates you wish to check against AudioRecord audioRecordTemp = new AudioRecord(audioSource, fs, channelConfiguration, audioEncoding, buffer); if (audioRecordTemp != null && audioRecordTemp.getState() == AudioRecord.STATE_INITIALIZED) { return buffer; } } return 0; } }