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. Native Apps for Tasks, Reader, And Books?

Hey everyone, I was just wondering if anyone had any information on
whether Google was planning to release/create applications for the
Tasks/Reader/Books services that can be found online? I find it a bit
of a small inconvenience that in the event that I don't have
connectivity with my phone or say, laptop, that I won't be able to
have seamless syncing between notes/tasks/calendar services.

I don't know if there were legit apps created from and by Google
already because I have checked, so I come in here in hopes that
someone may have the answer.

Thank you kindly,



2. how to get android 1.6 source


According to the doc of

"*If you would like to check out a branch other than "master", specify it
with -b, like:*
*$ repo init** -u git:// -b

I need to download android source 1.6 which match the android sdk 1.6, I
guess the command should looks similar like above. Anyone can tell me what
exactly it should be ?

Thanks in advances.



3. Is there any event broadcasted when CPU is about to go to sleep mode on Android target

4. Refresh ImageView after setting Image

5. update and delete contact / contact details

6. PPTP VPN connection problems

7. Reg: Mobile Applications For Your Organization