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


 000

On 7 mar, 14:15, HeHe <cnm...@gmail.com> 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 <cnm...@gmail.com> 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()
method.

- 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
launched.
* 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
solution!
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
bu



Other Threads

1. Kang lucky in action @htc wildfire launching

Mantabhh presentasinya... Salut utk kang lucky bisa membuat orang media dan 
HTCnya terbengong2 ketika present mengenai android


@hendy_kurniawan
www.jeruknipis.com

-- 
"Indonesian Android Community [id-android]" 

2. SamsungFirmwares.com: No Official Froyo Updates For Spica

Dah saya komenin Om... balesannya "gak seratus 100% katanya"

berharap ke Kang LeshaK dengan samdroid nya... :)




-- 
"Indonesian Android Community [id-android]" 

3. How can I find unneeded permission?

4. CheckBox in ListView

5. (Share) pMessenger

6. ListView, with Header, Trackball Scrolling Problem

7. Android Library Broken