AudioRecord.getMinBufferSize
does not support PCM_8BIT
(see the AudioRecord source code), and will return ERROR_BAD_VALUE
(-2) if you pass a PCM_8BIT
format to it.
One solution would be to switch to using PCM_16BIT
encoding. Another possibility (which I haven't verified whether it works) is to ask for a minimum buffer size based on PCM_16BIT
and divide the returned size by 2 when constructing the AudioRecord
instance.