1
votes

On an Android 2.1 device (Samsung Galexy S), I am trying to record audio data using the following code.


int frequency = 16000;

int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding); AudioRecord audioRecord = new AudioRecord( MediaRecorder.AudioSource.MIC, frequency, channelConfiguration, audioEncoding, bufferSize); short [] buffer = new short[bufferSize];

isAdIdle = false; audioRecord.startRecording();

while( isRecording ) { int bufferReadResult = audioRecord.read(buffer, 0, bufferSize); // save buffer data

}

This code worked well on other devices, such as nexus one, but on the Samsung Galexy S, I have the following error message:


AFCCreateReSampler: avAFCInfo->bUsed[0] in SampleRate[44100] outSampleRate[16000] nChannel[2] outBitDepth[16]

What is the problem? Could anyone help me to resolve this one?

Thanks in advance~ YI Kim.

3

3 Answers

2
votes

If you are still interested in it, I found several things to do to make audio record functional on Galaxy S (and all devices with alsa on the top of the driver).

  1. Don't trust getMinBufferSize ! Here some code that seems to work on all devices :
if(inputBuffSizeRec <= 4096){
   inputBuffSizeRec = 4096 * 3/2;
}

This will already helps a lot, but you'll still observe some lost frames

  1. Don't read in continuously.

You must add get current timestamp before each read method; compare it to the previous value and if delay between last frame and frame you want to read is more than the frame size, you should wait (sleep) before reading. The goal is to not call the read method while buffer (audio driver buffer) have not been feed with things you'll request.

Note that I read chunks with a size lower than buffer size (I think that's better too).

I found the solution on another android opensource sip application (sipdroid). Integrated in mine, and sounds to works fine. Don't know if there is still the error (warning?) in logs, but ... I eared a voice mail recorder from galaxy S with my app and sound is perfect.

1
votes

I'm also facing this problem. For reference here is the open issue on my project : http://code.google.com/p/csipsimple/issues/detail?id=89#c6

Unfortunately I have no device to test on.

Did you is to with another audio format and another sample rate? I guess that using 44100 as frequency will remove the error since according to its name it's related to re-sampler creation.

Besides I would be really interesting if you can say me what you observe as audio data? Is it choppy sound/ incomplete? Nothing? Works well but cpu is overloaded while recording?

0
votes

I have tried to record with different sampling rates, 8000 and 44100 Hz. But failed!

On 8000 Hz, an AudioRecord object was created successfully, but the data read from it was choppy and incomplete! This is the same result with 16000 Hz recording.

On 44100 Hz setting, the creation of AudioRecord object was failed and throw an execption.

The recorded data (saved after bit swapping) is just like this: (in binary) (address 0h) 80 07 80 07 ... (same pattern) ...
... (same pattern) ... (address 210h) 07 80 07 80 08 80 FD 82 FF 87 5C 8D ... ... (different noisy pattern) ...

I think the CPU load is very low and almost idle.

Now I am trying to test other settings of AudioRecord~ And looking for an help from the community!

Thanks for your help and interest

YI Kim.