Saturday, July 31, 2010

[android-developers] Record audio problem on the LG Ally

Hi guys

I have a music recognition app (Tunepal) that records 12 seconds of
audio @ 22KHz (in one second chunks). After each second, the audio is
copied from a byte array into a float array and eventually I perform
some DSP on the float array.

My app is available on the Android Marketplace and is selling ok. I
have tested it on lots of different phones, such as the HTC Desire/
Hero/Motorola Droid etc and everything is fine.

One of my users has an Lg Ally (running Android 2.1 I believe) and the
recording is not working. In fact it's crashing the app. I have
developed a test program that just records some audio and I think I
have isolated the problem. The test program records audio of various
durations and sample rates and then plays it back. This is the crucial
bit of code:

protected Void doInBackground(Void... arg0)
{
System.out.println("Recording started");
audioRecord = null;
System.gc();
int totalBytes = bufferSize;
try
{
buffer = new byte[bufferSize];
audioRecord = new
AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, totalBytes);
audioRecord.startRecording();

int bufferReadResult = audioRecord.read(buffer, 0,
bufferSize);
if (bufferReadResult ==
AudioRecord.ERROR_INVALID_OPERATION)
{
message = "ERROR_INVALID_OPERATION returned";
error = true;
}
if (bufferReadResult == AudioRecord. ERROR_BAD_VALUE)
{
message = "ERROR_BAD_VALUE returned";
error = true;
}
if (bufferReadResult != bufferSize)
{
message = "Requested " + bufferSize + " bytes but read
" + bufferReadResult + " bytes";
error = true;
}
}
catch (Exception e)
{
message = e.getMessage();
error = true;
}


if (! isCancelled())
{
doneRecording();
}

return null;
}

This code works fine on my HTC Desire, but on the LG Ally, no matter
what the buffer size or sample rate is set to, bufferReadResult always
returns 2048. In other words, the call to:

audioRecord.read(buffer, 0, bufferSize);

Always reads just 1024 samples of audio. Actually I havent tested to
see if the buffer contains anything useful.

I can possibly get around this in my app with a bit of work, but I was
wondering if anyone else has encountered this problem and if there is
a better way to get around it than reading the audio in 2K chunks.

You can try out the test app for yourself here:

http://tunepal.org/tunepal/android/RecordTest.apk

Rotations will screw it up BTW, so keep your phone orientated in
portrait for the test.

Bryan

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate