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(
                        MediaRecorder.AudioSource.MIC,
                        SAMPLE_RATE,
                        AudioFormat.CHANNEL_CONFIGURATION_DEFAULT,
                        AudioFormat.ENCODING_DEFAULT,
                        BUFFERSIZE
                        );

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): [ android.media.AudioRecord ] 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,

-Szabolcs

--~--~---------~--~----~------------~-------~--~----~



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;
 try
 {
         // init recorder
         recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
                         AUDIO_SAMPLE_FREQ,
                         AudioFormat.CHANNEL_CONFIGURATION_MONO,
                         AudioFormat.ENCODING_PCM_16BIT,
                         AUDIO_BUFFER_SIZE);
 }
 catch (IllegalArgumentException e)
 {
        e.printStackTrace();
 }




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


SDK1.5 AudioRecord sample rate problem

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


 Steven,

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
block.

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

Thank you,

-Szabolcs

--~--~---------~--~----~------------~-------~--~----~



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
emulator.



--~--~---------~--~----~------------~-------~--~----~



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,

-szabolcs

--~--~---------~--~----~------------~-------~--~----~



SDK1.5 AudioRecord sample rate problem

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


 Hi,

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
uninformative.
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Password Security / Encryption / Decompile?

I am developing an app that uploads files to an FTP server, and the
app will have the ftp user name / password in the code. I'm
investigating making the FTP user name and password as secure as
possible (including an encrypted value for each in a strings.xml and
decrypting in the app when it needs to connect to the FTP server).

My concern is this is not actually secure at all, it seems someone
could unzip the .apk, decompile it, view the strings.xml and java code
that decrypts it - and thereby obtain the ftp login info.

So my question is.. am I approaching this wrong way? Is there a
standard method of ensuring passwords that are hard coded into an app
can be secure? (note - in this case this is not a password a user of
the app would enter, the FTP password is universal to all that install
it so it is included in the app).

Apologies if this is a noob question but I don't know my way around
this whole decompiling / hacking android apps thing. Any input would
be greatly appreciated!

-- 

2. Headset Detection

Hi,

i hope somebody can help me. i have developed a service to detect a
connected headset at the mobile using following constant

http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG

The definition of this constant defines two extra values which will be
available in the resulting intent.

Now, the question:

What does the extra value "name" describes?
Is this the product name of the connected headset?

When i connect the htc headset or adapter this extra value contains
the string "Headset" and i'm not smarter than before.

It would be great when someone can help me!

Cheers
Gerby
--~--~---------~--~----~------------~-------~--~----~

3. TimeStamp to record Start and Stop times!

4. Capturing HEADSET_PLUG (android.intent.action.HEADSET_PLUG)

5. ProgressDialog question

6. Galley of thumbnails from the web running out of memory

7. executing a shell script from Android application