kingston
kingston

Reputation: 11419

RecorderObject in OpenSL does not implement the interface to set the volume or configure on Android

I tried to get the SLDeviceVolumeItf interface of the RecorderObject on Android but I got the error: SL_RESULT_FEATURE_UNSUPPORTED.

I read that the Android implementation of OpenSL ES does not support volume setting for the AudioRecorder. Is that true?

If yes is there a workaround? I have a VOIP application that does not worl well on Galaxy Nexus because of the very high mic gain.

I also tried to get the SL_IID_ANDROIDCONFIGURATION to set the streamType to the new VOICE_COMMUNINCATION audio-source but again I get error 12 (not supported).

   // create audio recorder
const SLInterfaceID id[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION };
const SLboolean    req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };

result = (*engine)->CreateAudioRecorder(engine, &recorderObject, &audioSrc,  &audioSnk, 2, id, req);
if (SL_RESULT_SUCCESS != result) {
    return false;
}

SLAndroidConfigurationItf recorderConfig;   
result = (*recorderObject)->GetInterface(recorderObject, SL_IID_ANDROIDCONFIGURATION, &recorderConfig);
if(result != SL_RESULT_SUCCESS) {
    error("failed to get SL_IID_ANDROIDCONFIGURATION interface. e == %d", result);
}

The recorderObject is created but I can't get the SL_IID_ANDROIDCONFIGURATION interface. I tried it on Galaxy Nexus (ICS), HTC sense (ICS) and Motorola Blur (Gingerbread). I'm using NDK version 6.

Upvotes: 5

Views: 2905

Answers (4)

Shrish
Shrish

Reputation: 729

Even i tried to find a way to change the gain in OpenSL, looks like there is no api/interface for that. i implemented a work around by implementing a simple shift gain multiplier

void multiply_gain(void *buffer, int bytes, int gain_val) { int i = 0, j = 0;

    short *buffer_samples = (short*)buffer;

    for(i = 0, j = 0; i < bytes; i+=2,j++)
    {
       buffer_samples[j] = (buffer_samples[j] >> gain_val);
    }

}

But here the gain is multiplied/divided (based on << or >>) by a factor or 2. if you need a smoother gain curve, you need to write a more complex digital gain function.

Upvotes: 0

foolmelon
foolmelon

Reputation: 1

    apiLvl = (*env)->GetStaticIntField(env, versionClass, sdkIntFieldID);

SLint32 streamType = SL_ANDROID_RECORDING_PRESET_GENERIC;
    if(apiLvl > 10){
        streamType = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
        I("set SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION");
    }

    result = (*recorderConfig)->SetConfiguration(recorderConfig, SL_ANDROID_KEY_RECORDING_PRESET, &streamType, sizeof(SLint32));
    if (SL_RESULT_SUCCESS != result) {
        return 0;
    }

Upvotes: 0

Andrew Prock
Andrew Prock

Reputation: 7107

I ran into a similar problem. My results were returning the error code for not implemented. However, my problem was that I wasn't creating the recorder with the SL_IID_ANDROIDCONFIGURATION interface flag.

Upvotes: 0

kingston
kingston

Reputation: 11419

Now I can get the interface. I had to use NDK 8 and target-14. When I tried to use 10 as a target, I had an error compiling the native code (dirent.h was not found). I had to use target-platform-14.

Upvotes: 1

Related Questions