Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<AudioRecord> "Could not get audio input for record source 1"

I've been having this issue with initializing AudioRecord for Android. I searched for quite a while on the web with no success.

For the phone, I'm using a Samsung GalaxyS on SDK version 7. For the AudioRecord initialization, I'm using 8000 as the sample rate, MONO for channel config, 16bit for audio format, and according to the log, the minBufferSize is set to be 4160. I have added the AUDIO_RECORD permission to the manifest.

My code for the initialization is as follows:

...
private static int SAMPLE_RATE = 8000;
private static int CHANNEL_CONFIG = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private static int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
// ??? Both 8Bit and Default are deemed illegal.

public MicVolumeManager() {
    this.bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE,
        CHANNEL_CONFIG, AUDIO_FORMAT);
    PhoneDebugger.debug("AUDIO-BUFFER-SIZE", 
        Integer.toString(this.bufferSize));

    this.recorder = new AudioRecord(AudioSource.MIC, SAMPLE_RATE,
        CHANNEL_CONFIG, AUDIO_FORMAT, this.bufferSize);

    this.audioBuffer = new byte[this.bufferSize];
}
...

However, the object (this.recorder) failed to be initialized. The following is from the log using DDMS:

AUDIO-BUFFER-SIZE(3253): 4160
AudioRecord(3253): set(): sampleRate 8000, channels 16, frameCount 2080
AudioPolicyManager(2175): getInput() inputSource 1, samplingRate 8000, format 1, channels 10, acoustics 0
AudioFlinger(2175): openInput() openInputStream returned input 0x0, SamplingRate 8000, Format 1, Channels 10, acoustics 0, status -17
AudioRecord(3253): Could not get audio input for record source 1
AudioRecord-JNI(3253): Error creating AudioRecord instance: initialization check failed.
AudioRecord-Java(3253): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.

Any help please? Many thanks!

like image 821
Gene Avatar asked Jan 26 '11 16:01

Gene


2 Answers

For me, the cause was failure to call AudioRecord.release() for a previous instance of AudioRecord; it tied up native resources in AudioFlinger and interfered with subsequent AudioRecord instances. Saw it on a Samsung Fascinate (Galaxy S) Android 2.1 (Eclair); either the Eclair or the Samsung implementation may be particularly intolerant.

like image 108
Liudvikas Bukys Avatar answered Nov 08 '22 02:11

Liudvikas Bukys


Had the same error, till I restarted the device.

It seems that on my Galaxy S the native impl is buggy: several times acquiring and releasing an AudioRecorder (during whole phone uptime) causes that error.

like image 9
java.is.for.desktop Avatar answered Nov 08 '22 03:11

java.is.for.desktop