Results 1 to 10 of 21

Thread: Adding Audio Effects in android

Hybrid View

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    13

    Adding Audio Effects in android

    Hi Erik

    The OpenSL document specifies Interfaces for audio effects such as equalizer, bass boost, preset reverberation, stereo widening etc. OpenSL ES supports bass boost via SLBassBoostItf. So I used this interface but i'm not getting any effect..so pls resolve the problem..

  2. #2
    Super Moderator
    Join Date
    Mar 2009
    Location
    Sweden
    Posts
    48
    Hi Bitfield,

    I am assuming that you've read sections 4.5.1 and 8.13 of the (OpenSL ES 1.1) specification . Using the BassBoostItf is fairly straight forward.

    The SLBassBoost interface is an optional interface, so you have to start by checking that it's supported by your device and your object. You didn't mention if you are using it on the audio player or the output mix object, but the method is the same:
    res = (*player)->GetInterface(player, SL_IID_BASSBOST, (void *)&BassBoostItf);
    if ( res != SL_RESULT_SUCCESS ) exit -1;

    If the result doesn't equal SL_RESULT_SUCCESS, the interface cannot be used, and the value in BassBoostItf is undefined. Note that the system may return a previous handle to an interface and may accept calls but fail internally.

    Now that you have your interface, you will need to enable the bass boost and set the strength. The result value will be key to debugging:
    res = (*BassBoostItf)->SetEnabled(BassBoostItf, SL_BOOLEAN_TRUE);
    res = (*BassBoostItf)->IsEnabled(BassBoostItf, &isEnabled); /* Verify bass boost is enabled */

    res = (*BassBoostItf)->IsStrengthSupported(BassBoostItf, &isSupported); /* Is strength supported? */
    if(isSupported == SL_BOOLEAN_TRUE)
    {
    res = (*BassBoostItf)->SetStrength(BassBoostItf, 1000); /* Max strength */
    res = (*BassBoostItf)->GetRoundedStrength(BassBoostItf, &roundedStrength); /*Check to see what the system set */
    }

    Hope this helps

    Erik
    Last edited by Erik; 08-27-2013 at 12:24 AM. Reason: Code fix
    Erik Noreke,
    Work Group Chair OpenSL ES, OpenMAX AL

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    13

    Question

    Hi Erik,

    Thanks for your reply,I did the same thing previously i debugged and checked it I am getting SL_RESULT_SUCCESS.I have attached BassBoost Inteface to output mix i tried it with audio player also,but still there is no effect.I checked it on HTC oneX,Samsung NOTE2,NOTE1.I am not getting any errors..but there is no effect.My project depends on this issue.

    Expecting for your reply,

    Thanks & Regards
    Bitfield.

  4. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    13
    Hi Erik,
    I am waiting for your reply.The actual bass effect check it in power amp music player there the bass will be extreme..but by using opensl es in android i am not getting that effect.

  5. #5
    Super Moderator
    Join Date
    Mar 2009
    Location
    Sweden
    Posts
    48
    Bitfield,

    Without seeing the code in question it's hard to say why it is failing. The code snippet I provided has been successfully tested on a conformant implementation and worked, but I haven't tested it on Android. Remember, there may be other things running on the device which affect the results. Do you have other effects working and it's only the bass boost which isn't working, or is this the first effect you are trying?

    If you haven't done so already, I suggest writing a small test application which only tests that portion of code - bass boost on playback without any other effects. Once you get a small application working, then take a look at what's different between the two.

    Sorry I can't be of more help at this point, but without details it's going to be hard to help you resolve the issue.

    Erik
    Erik Noreke,
    Work Group Chair OpenSL ES, OpenMAX AL

  6. #6
    Junior Member
    Join Date
    Aug 2013
    Posts
    13
    Hi Erik,
    Thanks for your reply,I am providing the code what i did..yes it is impossible to say why it is failing..sorry for the inconvenience. Here i am using asset audio player i am exposing bassboost to this player.Previously i checked with reverb effect.Reverb is the first effect i tried i did not got any effect so i tried of checking with bassboost..so for this i faced the same problem no effect.So please resolve the issue by checking the code(don't check about reverb problem).The red color code is where I exposed BassBoost.The bassboost effect is easy to identify..so i exposed directly to player and i played the music after exposing to player. previously i maintained a status based on the status i enabling or disabling bassboost but in this case also i did not got any effect.



    #include <assert.h>
    #include <jni.h>
    #include <string.h>

    // for __android_log_print(ANDROID_LOG_INFO, "YourApp", "formatted message");
    // #include <android/log.h>

    // for native audio
    #include <SLES/OpenSLES.h>
    #include <SLES/OpenSLES_Android.h>

    // for native asset manager
    #include <sys/types.h>
    #include <android/asset_manager.h>
    #include <android/asset_manager_jni.h>
    #include <android/log.h>


    // engine interfaces
    static SLObjectItf engineObject = NULL;
    static SLEngineItf engineEngine;

    // output mix interfaces
    static SLObjectItf outputMixObject = NULL;
    static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;

    // buffer queue player interfaces
    static SLObjectItf bqPlayerObject = NULL;
    static SLPlayItf bqPlayerPlay;
    static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
    static SLEffectSendItf bqPlayerEffectSend;
    static SLMuteSoloItf bqPlayerMuteSolo;
    static SLVolumeItf bqPlayerVolume;
    SLBassBoostItf bassboost;

    // aux effect on the output mix, used by the buffer queue player
    static const SLEnvironmentalReverbSettings reverbSettings =
    SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;

    // URI player interfaces
    static SLObjectItf uriPlayerObject = NULL;
    static SLPlayItf uriPlayerPlay;
    static SLSeekItf uriPlayerSeek;
    static SLMuteSoloItf uriPlayerMuteSolo;
    static SLVolumeItf uriPlayerVolume;

    // file descriptor player interfaces
    static SLObjectItf fdPlayerObject = NULL;
    static SLPlayItf fdPlayerPlay;
    static SLSeekItf fdPlayerSeek;
    static SLMuteSoloItf fdPlayerMuteSolo;
    static SLVolumeItf fdPlayerVolume;
    SLEqualizerItf equalizer;
    SLVirtualizerItf virtualizer;
    // recorder interfaces
    static SLObjectItf recorderObject = NULL;
    static SLRecordItf recorderRecord;
    static SLAndroidSimpleBufferQueueItf recorderBufferQueue;

    // synthesized sawtooth clip
    #define SAWTOOTH_FRAMES 8000
    static short sawtoothBuffer[SAWTOOTH_FRAMES];

    // 5 seconds of recorded audio at 16 kHz mono, 16-bit signed little endian
    #define RECORDER_FRAMES (16000 * 5)
    static short recorderBuffer[RECORDER_FRAMES];
    static unsigned recorderSize = 0;
    static SLmilliHertz recorderSR;


    // create the engine and output mix objects
    void Java_com_example_nativeaudio_NativeAudio_createEng ine(JNIEnv* env,jclass clazz)
    {
    SLresult result;

    // create engine
    result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // realize the engine
    result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // get the engine interface, which is needed in order to create other objects

    result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE,&engineEngine);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // create output mix, with environmental reverb specified as a non-required interface

    const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
    const SLboolean req[1] = { SL_BOOLEAN_FALSE };
    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject,1, ids, req);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // realize the output mix
    result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    }






    // create asset audio player
    jboolean Java_com_example_nativeaudio_NativeAudio_createAss etAudioPlayer(JNIEnv* env, jclass clazz, jobject assetManager, jstring filename)
    {
    SLresult result;

    // convert Java string to UTF-8

    const char *utf8 = (*env)->GetStringUTFChars(env, filename, NULL);
    assert(NULL != utf;

    // use asset manager to open asset by filename

    AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
    assert(NULL != mgr);
    AAsset* asset = AAssetManager_open(mgr, utf8, AASSET_MODE_UNKNOWN);

    // release the Java string and UTF-8

    (*env)->ReleaseStringUTFChars(env, filename, utf;

    // the asset might not be found
    if (NULL == asset)
    {
    return JNI_FALSE;
    }

    // open asset as file descriptor
    off_t start, length;
    int fd = AAsset_openFileDescriptor(asset, &start, &length);
    assert(0 <= fd);
    AAsset_close(asset);

    // configure audio source
    SLDataLocator_AndroidFD loc_fd = { SL_DATALOCATOR_ANDROIDFD, fd, start,length };

    SLDataFormat_MIME format_mime = { SL_DATAFORMAT_MIME, NULL,SL_CONTAINERTYPE_UNSPECIFIED };
    SLDataSource audioSrc = { &loc_fd, &format_mime };

    // configure audio sink
    SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX,outputMixObject };
    SLDataSink audioSnk = { &loc_outmix, NULL };

    // create audio player
    const SLInterfaceID ids[4] = { SL_IID_SEEK, SL_IID_MUTESOLO, SL_IID_VOLUME,SL_IID_BASSBOOST};
    const SLboolean req[4] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE,SL_BOOLEAN_TRUE};

    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &fdPlayerObject,&audioSrc, &audioSnk, 5, ids, req);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // realize the player
    result = (*fdPlayerObject)->Realize(fdPlayerObject, SL_BOOLEAN_FALSE);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // get the play interface
    result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_PLAY,&fdPlayerPlay);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // get the seek interface
    result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_SEEK,&fdPlayerSeek);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // get the mute/solo interface
    result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_MUTESOLO,&fdPlayerMuteSolo);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    // get the volume interface
    result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_VOLUME,&fdPlayerVolume);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    result = (*fdPlayerObject)->GetInterface(fdPlayerObject, SL_IID_BASSBOOST,(void *) &bassboost);


    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo", "result not sucess");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo", "result sucess");

    result = (*bassboost)->SetEnabled(bassboost, SL_BOOLEAN_TRUE);

    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result not set enabled sucess");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result set enabled sucess");

    SLboolean isEnabled, isSupported;
    result = (*bassboost)->IsEnabled(bassboost, &isEnabled); /* Verify bass boost is enabled */

    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result not enabled sucess");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result enabled sucess");

    result = (*bassboost)->IsStrengthSupported(bassboost, &isSupported); /* Is strength supported? */

    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result is strength not supported");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result is strength supported");


    result = (*bassboost)->SetStrength(bassboost, 1000); /* Max strength */

    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result set strength not supported");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result set strength supported");

    SLint32 roundedStrength = 0;
    result = (*bassboost)->GetRoundedStrength(bassboost, &roundedStrength); /*Check to see what the system set */

    if (result != SL_RESULT_SUCCESS)
    __android_log_print(ANDROID_LOG_DEBUG, "demo","result no round strength supported");
    else
    __android_log_print(ANDROID_LOG_DEBUG, "demo", "The value is %d",
    roundedStrength);


    result = (*fdPlayerSeek)->SetLoop(fdPlayerSeek, SL_BOOLEAN_TRUE, 0,
    SL_TIME_UNKNOWN);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;

    return JNI_TRUE;
    }


    // set the playing state for the asset audio player
    void Java_com_example_nativeaudio_NativeAudio_setPlayin gAssetAudioPlayer(
    JNIEnv* env, jclass clazz, jboolean isPlaying) {
    SLresult result;

    // make sure the asset audio player was created
    if (NULL != fdPlayerPlay) {

    // set the player's state
    result = (*fdPlayerPlay)->SetPlayState(fdPlayerPlay,
    isPlaying ? SL_PLAYSTATE_PLAYING : SL_PLAYSTATE_PAUSED);
    assert(SL_RESULT_SUCCESS == result);
    (void) result;
    }

    }

    }

    Thanks & Regards
    Bitfield
    Last edited by bitfield; 08-28-2013 at 05:40 AM.

  7. #7
    Super Moderator
    Join Date
    Mar 2009
    Location
    Sweden
    Posts
    48
    Bitfield,

    I noticed you aren't using the SLEffectSendItf interface on the player. SLEffectSendItf controls how much an effect from a player contributes to the overall audio chain. See section 8.16 in the 1.0.1 spec.

    Since an effect can be used both on the player and on the output mix, the effect on the player is considered an auxiliary effect to the output mix effect. The SLEfectSendItf controls how much the auxiliary effect will contribute. The default level is 0.

    If that doesn't resolve the issue, I would separate out initializing the player with setting up your effects. Then try turning your effect on and off while playing a continuous steady sound so that you can easily hear if turning the effect on and off has any effect on the audio.
    Erik Noreke,
    Work Group Chair OpenSL ES, OpenMAX AL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •