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. Calculate Open GL Coordinate system X and Y values by using wndow x and y values

Hi ,

I am new to android .Recently we started some game application on Open
GL.But problem is while drawing any thing it will be based on
Coordinate system.How can we calculate x-units and y-units depends
upon window .Again when we change landscape to portrait, it is
affecting to
my code at drawing positions.Finally how to control coordinate
system values and all if Any body knows please suggest me if any links
available or code.

Thanks & Regards,
Madhusudhan D


2. Shop Stats ready for open signups!


I posted a while back about a web service I created for Android sales
stats (

3. Question about intent filters for NFC tags (tech)

4. How to disable global search key when dialog is shown?

5. LVL and new SDKs


7. OK for one Service to bind to another?