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

7

16

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!

Echelon answered 26/1, 2011 at 16:59 Comment(0)
I
16

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.

Impressible answered 14/7, 2011 at 12:55 Comment(0)
D
9

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.

Deontology answered 7/6, 2011 at 0:8 Comment(3)
Note my answer above, my phone, also a Samsung Galaxy S, has a native layer that is picky about AudioRecord.release() being called.Impressible
had the same with a Galaxy S as well. Any ideas on how to ensure that i don't get this? O.oAiring
i got the same ,, when i restarted it began to work. what have to do that the problem dont repeatMunt
D
5

After using audio recorder, you must stop and release it. Then when you init the audio recorder the next time, it's ok.

Deuterogamy answered 31/1, 2012 at 9:21 Comment(0)
E
4

Hi I've had the very same issue while trying to initialize an AudioRecord object and the solution I've found was to test the configurtion parameter before actually trying to instantiate the current AudioRecord object. Here is the rouine I've used:

    /**
 * Scan for the best configuration parameter for AudioRecord object on this device.
 * Constants value are the audio source, the encoding and the number of channels.
 * That means were are actually looking for the fitting sample rate and the minimum
 * buffer size. Once both values have been determined, the corresponding program
 * variable are initialized (audioSource, sampleRate, channelConfig, audioFormat)
 * For each tested sample rate we request the minimum allowed buffer size. Testing the
 * return value let us know if the configuration parameter are good to go on this
 * device or not.
 * 
 * This should be called in at start of the application in onCreate().
 * 
 * */
public void initRecorderParameters(int[] sampleRates){

    for (int i = 0; i < sampleRates.length; ++i){
        try {
            Log.i(TAG, "Indexing "+sampleRates[i]+"Hz Sample Rate");
            int tmpBufferSize = AudioRecord.getMinBufferSize(sampleRates[i], 
                            AudioFormat.CHANNEL_IN_MONO,
                            AudioFormat.ENCODING_PCM_16BIT);

            // Test the minimum allowed buffer size with this configuration on this device.
            if(tmpBufferSize != AudioRecord.ERROR_BAD_VALUE){
                // Seems like we have ourself the optimum AudioRecord parameter for this device.
                AudioRecord tmpRecoder = new AudioRecord(MediaRecorder.AudioSource.MIC, 
                                                        sampleRates[i], 
                                                        AudioFormat.CHANNEL_IN_MONO,
                                                        AudioFormat.ENCODING_PCM_16BIT,
                                                        tmpBufferSize);
                // Test if an AudioRecord instance can be initialized with the given parameters.
                if(tmpRecoder.getState() == AudioRecord.STATE_INITIALIZED){
                    String configResume = "initRecorderParameters(sRates) has found recorder settings supported by the device:"  
                                        + "\nSource   = MICROPHONE"
                                        + "\nsRate    = "+sampleRates[i]+"Hz"
                                        + "\nChannel  = MONO"
                                        + "\nEncoding = 16BIT";
                    Log.i(TAG, configResume);

                    //+++Release temporary recorder resources and leave.
                    tmpRecoder.release();
                    tmpRecoder = null;

                    return;
                }                   
            }else{
                Log.w(TAG, "Incorrect buffer size. Continue sweeping Sampling Rate...");
            }
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "The "+sampleRates[i]+"Hz Sampling Rate is not supported on this device");
        }
    }
}

I Hop this help.

Dickwan

Eczema answered 6/3, 2011 at 12:49 Comment(0)
R
3

This is also affecting Sansung Galaxy tabs GT-P1000 and later 10.1 one

This bug is pretty hard to reproduce and a reboot is the only way I found to escape this bad state ...

Is there a bug tracker to follow at samsung ?

Rebuff answered 30/12, 2011 at 16:29 Comment(0)
D
3

If you did not take Record_Audio permission then take it even than you getting error then switch off your mobile than switch on again then run your app.

Deaconess answered 15/4, 2013 at 11:16 Comment(0)
B
0

I think the audio hardware cannot support up to 10 channels, which you set as input, so try to use 2 channels, and to see whether it can work.

Bred answered 7/7, 2011 at 1:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.