3

As the update of Android 5.0L mentioned (http://geeknizer.com/audio-improvements-in-android-5-0-l-audiophile/), Android starts to support 96000Hz sampling rate. However when I try to do this on my Galaxy S6:

void checkAvailableSampleRate(){
    for (int rate : new int[] {44100, 48000, 96000}) {  // add the rates you wish to check against
        int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
        if (bufferSize > 0) {
            // buffer size is valid, Sample rate supported
            Log.d(C.LOG_TAG,"Sample rate "+rate+" is supportted");
            // just used for debugging
            AudioRecord temp = new AudioRecord(MediaRecorder.AudioSource.MIC, rate, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
            Log.d(C.LOG_TAG,"make audioRecord successfully ");
        }
    }
}

I am unable to make 96000Hz work....

Here is the output I got:

Sample rate 44100 is supportted
Make audioRecord successfully
Sample rate 48000 is supportted
Make audioRecord successfully
Sample rate 96000 is supportted

My app crashes here so it means I can get the minBuffer when sample rate is set to 96000Hz but unable to create a AudioRecord instance.

and here is the error:

java.lang.IllegalArgumentException: 96000Hz is not a supported sample rate.

It is weird to me that AudioRecord.getMinBufferSize() works fine with 96000Hz but app crashes when I try to create a 96000Hz AudioRecord.

Has anyone has tried to record 96000Hz audio in Android?

-------------------------------------

Here is the update of my gradle setting:

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "edu.umich.cse.echotag"
        minSdkVersion 21
        targetSdkVersion 21
        ndk {
            moduleName "detection"
        }
    } ....
Yu-Chih Tung
  • 81
  • 1
  • 9

1 Answers1

0

The OS may support 96k but the hardware also needs to support 96k to make that work.

getMinBufferSize may not be a robust way to check the hardware supported sample rates. see here How can I find out what Sampling rates are supported on my tablet?

AudioManager can query native parameters for the device. If you want to check for whether 96k is supported, this might be useful.

        AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
        Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
        Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));
        Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND));
        Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND));

more reading http://geeknizer.com/audio-improvements-in-android-5-0-l-audiophile/

Hope it can help you.

Community
  • 1
  • 1
Syi
  • 108
  • 1
  • 6