Can麓t create an AudioRecor der object

by HeHe » Mon, 08 Mar 2010 01:16:04 GMT

Sponsored Links
 what is the value of the variable SAMPLE_RATE?


Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Mon, 08 Mar 2010 02:06:15 GMT


On 7 mar, 14:15, HeHe <> wrote:


Sponsored Links

Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Mon, 08 Mar 2010 02:06:50 GMT

 AMPLE_RATE = 8000;

On 7 mar, 14:15, HeHe <> wrote:


Can麓t create an AudioRecor der object

by Gabriel Sim玫es » Thu, 11 Mar 2010 10:29:35 GMT

 ell, after spending my free time for the last 5 days working on the
AudioRecord class Im here again to post my findings.
But first let me make myself clear:

- What Im about to write is the result of my tests and findings after
having a lot of trouble to use the basic routines of the class. I
found a lot of forums posts over the internet about the same problems
so my idea here is to help people so they dont face the same problems
Ive faced.

- It may be beginners stuff, but a lot of people have faced or are
facing the same problems.

- If something here is wrong please dont come here just to say it,
share your knowledge with us and post not only whats wrong but how to
do it right.

- Ive done all tests on the EMULATOR provided by google. Also Im
using the sdk 2.1 (build 7)

Ok, lets go.

Creating an AudioRecord object:

When you create a new instance of AudioRecord there are two ways of
finding out if it was created properly (the device can handle the
audio parameters and resources were trully allocated to your object):
by catching an exception or by verifying the return of the getState()

- Handling the IllegalArgumentException : Well, tricky is what I can
say. Exceptions will only be thrown if any of the parameters you have
used are NOT acceptable by the CLASS (not if the device cant handle
it). For example, a sample rate = 12345 is not a standard value and
then the class will throw an exception. If SR = 44100 is not supported
by the DEVICE, the object will be created and no exception will be
* An interesting thing is that the official documentation says:
"sampleRateInHz the sample rate expressed in Hertz. Examples of rates
are (but not limited to) 44100, 22050 and 11025."
If you try SR = 11025 the system will throw an exception as it
considers this an illegal parameter. Strange, huh?

- Then ok, you have created an instance of AudioRecord but you dont
know if the parameters you have set are available in an specific
device. What you do? Verify AudioRecord.getState(), right?
Ok then, it works. But if you find out your instance is not ok and
then you have to create a new AudioRecord object you will be in
trouble. Why? Even after running AudioRecord.release() the resources
for the audio input you are interested in will keep being in use and
you wont be abble to recreate your object in a way it would work.
To verify this create an instace of AudioRecord with parameters that
are known not to work on the emulator (ex. SR = 44100). Then verify
the errors on logcat. After that call release() and then try to create
another instance of AudioRecorder with the parameters that work (sr =
8000, mono channel, pcm 16 bits) and check the first error line.

Then how should you find out which parameters the device will allow
you to use? Say with me: AudioRecord.getMinBufferSize() is my
Loop checking from the best combination of parameters to the worst. If
it returns -2, you should try another combination, if it returns -1
the audio input source is already being in use or isnt even available
for the specific device. If it returns something > 0 then youre ok
and can proceed creating a new AudioRecord object.

AudioRecord notification:

YES, IT WORKS! Believe me. The trick is: the notification will only be
called AFTER you call read() for the first time! And not only one time
(Oo). After a periodic notification you need to read from the audio

Other Threads

1. cant fetch

i am using windows vista, i turn on force to download from setting it
works fine now


2. LogCat reports"Could not find method foo"

I am trying to use the library.  I wonder
if I have the library configured correctly.

Here's what I did in Eclipse 3.5:

1) Created Android project.
2) Added backport-android-bluetooth2.jar to my reference libraries
3) Wrote some code that called
4) Compiled successfully
5) Did "Run as..." so it was running on my G1 device
6) Saw this error in LogCat

How is it that I can compile successfully, but can't find a method at
run time?  (I have >10 years low level programming experience, but am
new to Java)


3. Is there a normal human way to copy image from one folder to another?

4. Passing MOTION EVENTS up while transitioning between activities

5. List of existing ACTIONS and Component names

6. Best use of MediaPlayer?

7. Android app. crashes after exiting settings...