jpaguerre
jpaguerre

Reputation: 1150

Android - Audio Record - Sample rates

I developed a game for android that uses Audio Record to get the mic input.

You can have a glance at https://play.google.com/store/apps/details?id=fixappmedia.micro

The thing is that I'm using the following function to get the sample rates available on the phone:

public int getValidSampleRates() {
            int r=8000;
            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_MONO, AudioFormat.ENCODING_PCM_16BIT);
                if (bufferSize > 0) {
                    r= rate;
                }
            }
            return r;
        }

I tested it initially on my phone (Samsung Galaxy Vibrant) and it worked pretty well... but today I tested it on a Samsung Galaxy Ace and the sample rate didn't work...

Any ideas on why?

Upvotes: 2

Views: 9871

Answers (2)

mnaa
mnaa

Reputation: 424

from the docs http://developer.android.com/reference/android/media/AudioRecord.html

the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices.

Also noticed you are using AudioFormat.CHANNEL_CONFIGURATION_MONO which is deprecated according to the docs http://developer.android.com/reference/android/media/AudioFormat.html

This constant was deprecated in API level 5. use CHANNEL_OUT_MONO or CHANNEL_IN_MONO instead

Good luck

Upvotes: 1

I'm the developer of voice recording app (Hi-Q MP3 Voice Recorder), and I found out that all phones supports either 44100 Hz, 48000 Hz, or both.

Looking at your code, you missed out 48000.

Upvotes: 1

Related Questions