Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: recommended bufferSizeInBytes value in AudioRecord

I'm using the AudioRecord class which constructor is:

AudioRecord(
    int audioSource, int sampleRateInHz,
    int channelConfig, int audioFormat, int bufferSizeInBytes)

In all (or in the most) of the tutorials and examples I find on the Internet it's recommed to set bufferSizeInBytes like follows:

bufferSizeInBytes= getMinBufferSize (
    int sampleRateInHz, int channelConfig, int audioFormat) 

Could anyone tell me the reason?

I need to make the correlation between the values I'm recording and a pattern. This pattern is longer than MinBufferSize. So, should I just increase bufferSizeInBytes to the value I prefer, or is that going to worsen the performance of AudioRecord.

like image 309
Ignacio Alorre Avatar asked Sep 15 '13 17:09

Ignacio Alorre


1 Answers

Could anyone tell me the reason?

Because what getMinBufferSize returns for a given configuration is the smallest buffer size you'll be allowed to specify when creating you AudioRecord.

Why would you want the smallest possible buffer size? To get the lowest possible latency.
Imagine that you're doing something like an SPL meter; you wouldn't want there to be a one-second delay before your UI reacts to a change in the sound pressure.

The buffer size doesn't determine how much data you can request from read(), though. It's ok to request more data than the size of the AudioRecord's buffer; read() simply won't return until all the data you've requested has been read.

like image 180
Michael Avatar answered Oct 29 '22 19:10

Michael