How can I specify the input source for the AudioRecorder object?

android, android-ndk, opensl

Solution

Check out the functions and constants defined in `SLES/OpenSLES_Android.h` and `SLES/OpenSLES_AndroidConfiguration.h`. When you get your recording object from OpenSLES, use `GetInterface()` to get the interface pointer for `SL_IID_ANDROIDCONFIGURATION`. From there you can call `SetConfiguration()` using key `SL_ANDROID_KEY_RECORDING_PRESET` on the returned `SLAndroidConfigurationItf` pointer.

Problem

I'm porting an audio capture loop from Java (using `AudioRecord` class) to a native library using OpenSL. The reason for this is that after profiling, the capture loop is consuming in our test phones around 2% less CPU in OpenSL. That is a significative gain! The constructor for the Java AudioRecord class receives a `source` parameter that can be configured to several values (`MIC, CAMCORDER, VOICE_DOWNLINK`, etc.) So far, I haven't been able to find the equivalence (if there exists) for the source parameter in OpenSL. Does anybody know if there's a way to specify this Source parameter for the AudioRecorder object? Cheers!

Original source