Yiya.Hao Yiya.Hao - 3 months ago 42
Android Question

Replace Default MIC using OpenSL ES(Native-audio in Android)

I am new to Android Native audio using OpenSL ES and I need your help.

Now I wanna write an app to do real-time recording and playing back. In recording part, we have to configure the audio source firstly when we are creating an audio recorder. Like this.

SLDataSource audioSrc = {&loc_dev, NULL};

The SL_DEFAULTDEVICEID_AUDIOINPUT is the address of Default microphones. I wanna use other MICs on the android phone(I am using Nexus 6 which has three different MICs), but I cannot find other MICs' addresses.

Appreciate any response!


From OpenSLES.h we've got some types of IODevices which are..

/** IODevice-types */
#define SL_IODEVICE_AUDIOINPUT  ((SLuint32) 0x00000001)
#define SL_IODEVICE_LEDARRAY    ((SLuint32) 0x00000002)
#define SL_IODEVICE_VIBRA       ((SLuint32) 0x00000003)
#define SL_IODEVICE_RESERVED4   ((SLuint32) 0x00000004)
#define SL_IODEVICE_RESERVED5   ((SLuint32) 0x00000005)

You can try each of these to check if these satisfy your need.

You can also have a look at OpenSLES_AndroidConfiguration.h. While initializing your AudioRecorder you've some Android configuration here to set the input type.

/* Android AudioRecorder configuration                                       */

/** Audio recording preset */
/** Audio recording preset key */
#define SL_ANDROID_KEY_RECORDING_PRESET ((const SLchar*) "androidRecordingPreset")
/** Audio recording preset values */
/**   preset "none" cannot be set, it is used to indicate the current settings
 *     do not match any of the presets. */
#define SL_ANDROID_RECORDING_PRESET_NONE                ((SLuint32) 0x00000000)
/**   generic recording configuration on the platform */
#define SL_ANDROID_RECORDING_PRESET_GENERIC             ((SLuint32) 0x00000001)
/**   uses the microphone audio source with the same orientation as the camera
 *     if available, the main device microphone otherwise */
#define SL_ANDROID_RECORDING_PRESET_CAMCORDER           ((SLuint32) 0x00000002)
/**   uses the main microphone tuned for voice recognition */
/**   uses the main microphone tuned for audio communications */

These are mainly for trial and error. I don't have any exact solution.