Question

I'd like to check whether device supports particular sample rate.

I've tried the following (which should work according http://developer.android.com/reference/android/media/AudioRecord.html#getMinBufferSize(int, int, int) ) but doesn't (it never gets AudioRecord.ERROR_BAD_VALUE):

    int bufferSize8000 = AudioRecord.getMinBufferSize(90000000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);

    if(bufferSize8000 != (AudioRecord.ERROR_BAD_VALUE | AudioRecord.ERROR ))    {
        Log.v("samplerate", String.valueOf(bufferSize8000));
    } else {

        Log.v("samplerate", "NOTsupported");
    }
Was it helpful?

Solution

(AudioRecord.ERROR_BAD_VALUE | AudioRecord.ERROR )

Means -2 | -1, which equals -1, which equals AudioRecord.ERROR, which is why you're never getting the result you expect.

So this

if(bufferSize8000 != (AudioRecord.ERROR_BAD_VALUE | AudioRecord.ERROR ))    {

Should be

if (bufferSize8000 != Audiorecord.ERROR_BAD_VALUE && bufferSize8000 != AudioRecord.ERROR) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top