attachAuxEffect and OpenSL ES

4
当在Android中使用AudioTrack时,您可以调用attachAuxEffect来附加音频效果。在使用OpenSL ES进行音频播放时是否有类似的方法或者途径呢?我似乎找不到类似的方法。
1个回答

0

在你的NDK-home/samples/native-audio目录下有一个示例,展示了如何使用OpenSL ES本地音频。

看一下这段代码片段(我们在这里应用了混响效果):

...
// create the engine and output mix objects
void Java_com_example_nativeaudio_NativeAudio_createEngine(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;

    // get the environmental reverb interface
    // this could fail if the environmental reverb effect is not available,
    // either because the feature is not present, excessive CPU load, or
    // the required MODIFY_AUDIO_SETTINGS permission was not requested and granted
    result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB,
            &outputMixEnvironmentalReverb);
    if (SL_RESULT_SUCCESS == result) {
        result = (*outputMixEnvironmentalReverb)->SetEnvironmentalReverbProperties(
                outputMixEnvironmentalReverb, &reverbSettings);
        (void)result;
    }
    // ignore unsuccessful result codes for environmental reverb, as it is optional for this example

}

请注意,Android OpenSL ES 实现是 OpenSL ES 的子集,而 OpenSL ES 又是 OpenSL 的子集:某些效果可能无法在所有设备上使用。关于这一方面的非常简要的说明可以在此处找到。

1
我熟悉这段代码,但是你提供的片段不能完成调用“attachAuxEffect”并传递效果ID的相同任务。 - William Seemann
@WilliamSeemann 我不这么认为。AudioTrack是一个高级API,它掩盖了底层音频框架的许多复杂性(如源到汇路径);这意味着OpensSL ES API可能会“不同”,但实现的是相同的功能。 - bonnyz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接