SDK1.5 AudioRecord sample rate problem

by szabolcs » Fri, 24 Apr 2009 03:32:20 GMT

Sponsored Links
 I was trying to record sound using the MIC with the AudioRecord class:

mRecord = new AudioRecord(

This call results in:

ERROR/AudioRecord(1120): Recording parameters are not supported:
sampleRate 11025, channelCount 1, format 1
ERROR/AudioRecord-JNI(1120): Error creating AudioRecord instance:
initialization check failed.
ERROR/AudioRecord-Java(1120): [ ] Error code
-20 when initializing native AudioRecord object.

whenever the SAMPLE_RATE is some value other than
AudioRecord::DEFAULT_SAMPLE_RATE (8000) declared in ./frameworks/base/
include/media/AudioRecord.h from GIT.
The documentation says 11025/22050/44100 should be ok too.

Am I missing something?

Thank you for your help,



SDK1.5 AudioRecord sample rate problem

by Steven_T » Fri, 24 Apr 2009 16:28:34 GMT

 you can try this code:

private static final int AUDIO_SAMPLE_FREQ = 8000;
private static final int AUDIO_BUFFER_SIZE = 200000;
private AudioRecord recorder;
         // init recorder
         recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
 catch (IllegalArgumentException e)


Sponsored Links

SDK1.5 AudioRecord sample rate problem

by szabolcs » Fri, 24 Apr 2009 18:25:24 GMT


Thank you for your reply.

I know AudioRecord works with a sample frequency of 8000Hz. In my
initial post I was asking why this frequency is the ONLY frequency
that works?!

BTW, there is no exception thrown when the initialization of
AudioRecord fails. I figured you are supposed to check that yourself
by something like:
if(mRecord.getState()==AudioRecord.STATE_INITIALIZED), not a try-catch

So again: the question is, why does the initialization fail, if I
supply the constructor with AUDIO_SAMPLE_FREQ= 11025 || 22050 ||

Thank you,



SDK1.5 AudioRecord sample rate problem

by Dave Sparks » Sat, 25 Apr 2009 04:42:29 GMT

 Is this on the emulator? If so, it may be a limitation of the


SDK1.5 AudioRecord sample rate problem

by Yoni » Sat, 25 Apr 2009 06:04:14 GMT

 Make sure you're using 16 bit samples. 8 bit samples seem to just not
work. Don't use the default anythings - actually set it to MIC,
PCM_16BIT, 11025, MONO. Then once that works you can try tweaking
other options. Also, make sure your buffer is big enough - you can use
AudioRecord.getMinBufferSize to set up your recorder with a value with
minimal latency.

The way AudioRecord fails is really gross and uninformative. Hopefully
they'll fix that (and 8-bit recording) before 1.5 final...


SDK1.5 AudioRecord sample rate problem

by szabolcs » Sun, 26 Apr 2009 05:37:06 GMT

 Dave, Yoni,

Thank you for replying.

Yes, I experienced the problem using the 1.5 prerelease SDK emulator.
I dont know how the G1 would behave.

I have tried pretty much ALL permutations of the different parameters,
including PCM_16BIT, with no DEFAULTS. Still, Recording works only
with a sample rate of 8000Hz.

emulator that will get fixed into the final version. Dave, is it
enough that you know about this issue, or am I supposed to fill out a
bugreport somewhere?

Best regards,



SDK1.5 AudioRecord sample rate problem

by niko20 » Mon, 27 Apr 2009 16:23:47 GMT


The documentation for AudioRecord specifies that the constructor may
fail based on what the hardware supports. The format of the data will
depend on if the hardware supports it. Since the current android
emulator is like a G1 type phone, and phone systems are usually
8000hz, the hardware probably only supports that frequency.


SDK1.5 AudioRecord sample rate problem

by Dave Sparks » Tue, 28 Apr 2009 05:42:27 GMT

 I believe this is a known limitation of the emulator. There is a
feature request to allow for more sample rates, but no one is actively
working on it. The source code is available if someone wants to take
it on.


SDK1.5 AudioRecord sample rate problem

by Yoni » Tue, 28 Apr 2009 12:55:46 GMT

 > Since the current android

Nope. My actual G1 seems to record just fine at 11025 or 22050 hz
(running The Dude's 0.8 cupcake build from xda-developers). But those
sample rates are not guaranteed for every device, so the best strategy
is probably aim for the quality you'd like, try/catch and eventually
settle on the quality you can get out of the hardware you happen to
have, whether that's a G1 at 44100 hz/16-bit or the emulator at 8000
hz or some new piece of unknown hardware that does 8-bit/11025 only.
Of course, a code sample in the SDK to show best practices there would
have been nice, since the exceptions thrown by AudioRecord are fairly

Other Threads

1. Samsung launches I7500, The Compan y鈥檚 First Android-Powered Mobile Phone

Samsung has done a press release on their first Android powered mobile
phone, out in June in Europe according to the PR ...


2. Why not build an installer for android on WM phones?

I was wondering.. I've been following the android development for
quite a time now.. I am certainly not an developer but why doesn't the
android group bring out an application with wich u can simpel install
android over your current windows mobile..

I know that there are lot's of things that may give error like unkown
hardware and stuff.. But if there is an application made that you can
run on your pc (win,mac,linux) witch can detect what sort of hardware
your phone has and if its capitble of running android (1.5) then it
would over you to install it from your desktop..

And the software alsof should backup the original windows mobile rom

I was suprised they didn't do this already because it wouild be a
great change for Android to really steal some of the windows mobile

Is there any changes such an idea is possible?

(sorry for my rubbish English)


3. How To Load Previous Activity

4. Android and OpenJDK

5. NotePadv1 Example!!

6. Switching Between Multiple Views

7. How to config G1 to make both browser and MMS work?