[openal] example code request for Echo and other effects?

Chris Robinson chris.kcat at gmail.com
Fri Aug 14 10:30:43 EDT 2020


On Fri, 14 Aug 2020 14:44:21 +0300
Sean <s.tolstoyevski at gmail.com> wrote:

> Hi all,
> 
> I can't learn anything from the sample review. Since I am actively 
> coding in Python, I find it very difficult to understand OpenAL's C
> API.
> 
> Can you send me sample code for effects like Echo?
> 
> I read the reverb from example.
> But I could not find any other example of effect.

Hi.

Using the echo effect is very similar to using the reverb effect. Given
the LoadEffect function in examples/alreverb.c, it can be easily changed
to use the echo effect:

static ALuint LoadEffect(void)
{
    ALuint effect = 0;
    ALenum err;

    /* Create the effect object and set the echo type. */
    alGenEffects(1, &effect);
    alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_ECHO);

    /* Check if an error occured, and clean up if so. */
    err = alGetError();
    if(err != AL_NO_ERROR)
    {
        fprintf(stderr, "OpenAL error: %s\n", alGetString(err));
        if(alIsEffect(effect))
            alDeleteEffects(1, &effect);
        return 0;
    }

    return effect;
}

That will create an echo effect with the default parameters. To change
the echo parameters, set them after setting the echo type:

alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_ECHO);
/* Note the 'f' on these functions, not 'i' like above */
alEffectf(effect, AL_ECHO_DELAY, ...); /* 0.0f ... 0.207f */
alEffectf(effect, AL_ECHO_LRDELAY ...); /* 0.0f ... 0.404f */
alEffectf(effect, AL_ECHO_DAMPING ...); /* 0.0f ... 0.99f */
alEffectf(effect, AL_ECHO_FEEDBACK ...); /* 0.0f ... 1.0f */
alEffectf(effect, AL_ECHO_SPREAD ...); /* -1.0f ... 1.0f */

I don't use Python myself so unfortunately I can't make a Python
example, but if you were able to work through the alreverb example,
it's not very different. If you still have any questions, feel free to
ask.


More information about the openal mailing list