Android Audiorecord Supported Sampling Rates

How can I find out what Sampling rates are supported on my tablet?

Yes, Android does not provide an explicit method to check it but there is a work-around with AudioRecord class' getMinBufferSize function.

public void getValidSampleRates() {
for (int rate : new int[] {8000, 11025, 16000, 22050, 44100}) { // add the rates you wish to check against
int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize > 0) {
// buffer size is valid, Sample rate supported

}
}
}

If you checked the function description, it will return a negative value if one of the parameters entered are not supported. Assuming you enter all other inputs as valid, we are expecting it to return a negative buffersize if sample rate is not supported.

However, some people reported that it was returning positive even if sampling rate is not supported so an additional check could be done by trying to initialize an AudioRecord object, which will throw an IllegalArgumentException if it thinks it cannot deal with that sampling rate.

Finally, none of them provide a guaranteed check but using both increases your chances of getting the supported one.

Most of the time, 44100 and 48000 work for me but of course, it differs from device to device.

Can I record 24/48k audio using AudioRecord?

Surely it depends on the device you are trying to record from? The Hardware manufacturer has to configure a lot of this stuff in the HAL.

The audio_policy.confshould indicate the compatible sampling rates and formats, on the device you are on. You can examine the file- it's usually found on your android device, probably under system/etc/

Example:

audio_hw_modules {
primary {
outputs {
primary {
sampling_rates 44100|48000
channel_masks AUDIO_CHANNEL_OUT_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
devices AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_AUX_DIGITAL
flags AUDIO_OUTPUT_FLAG_PRIMARY
}
}
inputs {
primary {
sampling_rates 8000|11025|16000|22050|32000|44100|48000
channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET|AUDIO_DEVICE_IN_WIRED_HEADSET
}
}
}

In this particular case I would not be able to use 24-Bit Audio at 48 KHz, but 16 Bit would be fine.

Dynamic Sampling Rate for Audio Recording Android

What would you expect to happen when you change the sampling rate once it is recording? Setting the rate directly is not supported by AudioRecord, so that is a definite no.

Setting the rate directly with MediaRecorder is allowed, but is expected to be done before starting the recording. I would not expect all, if any, implementations of the Android OS to handle this.



Related Topics



Leave a reply



Submit