Yiya.Hao
Yiya.Hao

Reputation: 3

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.

SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE,SL_IODEVICE_AUDIOINPUT,SL_DEFAULTDEVICEID_AUDIOINPUT, NULL};
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!

Upvotes: 0

Views: 2550

Answers (1)

Reaz Murshed
Reaz Murshed

Reputation: 24211

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 */
#define SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION   ((SLuint32) 0x00000003)
/**   uses the main microphone tuned for audio communications */
#define SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION ((SLuint32) 0x00000004)

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

Upvotes: 2

Related Questions