Android AudioRecord Supported Sampling Rates

前端 未结 8 697
悲&欢浪女
悲&欢浪女 2020-11-28 22:47

I\'m trying to figure out what sampling rates are supported for phones running Android 2.2 and greater. We\'d like to sample at a rate lower than 44.1kHz and not have to re

8条回答
  •  被撕碎了的回忆
    2020-11-28 23:25

    The original poster has probably long since moved on, but I'll post this in case anyone else finds this question.

    Unfortunately, in my experience, each device can support different sample rates. The only sure way of knowing what sample rates a device supports is to test them individually by checking the result of AudioRecord.getMinBufferSize() is non negative (which means there was an error), and returns a valid minimum buffer size.

    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
    
            }
        }
    }
    

提交回复
热议问题