Search code examples
openal

OpenAL global sounds


Is it possible to create sound sources that are "global", meaning that their volume and pitch are not affected by the listener's position and velocity at all?

I want both system sounds (not affected by listener) and 3 dimensional sounds in my application and I could not find any solution.


Solution

  • If your sounds are stereo then you may place them anywhere, they are not affected by relative distance nor rotation nor velocity.

    But if they are mono, you need to do some more work:

    All audio sources have position & velocity relative to listener flag. Turn it on and leave your source coordinates at default position, {0,0,0}, with zero velocity.

    alSourcei(source, AL_SOURCE_RELATIVE, 1); // This turns on the flag
    

    This will only work if you use one of the clamped distance models. Clamped inverse distance is default, so you should not have any problems with it. (A distance model is an equation which determines in what way sound volume changes when distance to listener changes. You can select one of these models with an OpenAL function. A clamped distance model is a such model in which a sound won't get infinitely loud when it's placed exactly on the listener. So, volume is clamped to some max value.) But if you use a non-clamped distance model, then you should turn on the flag and place your sound exactly one reference distance away from the listener. So, it will be at, for example, at {ref_distance,0,0}. Default reference distance is 1.0, but you can change it with an OpenAL function. (Reference distance is a distance at which sound has it's volume equal to 1.)