kcat / alure

Alure is a utility library for OpenAL, providing a C++ API and managing common tasks that include file loading, caching, and streaming
zlib License
70 stars 20 forks source link

feature request: direct modification of spatial locations #31

Open nathanleighsays opened 4 years ago

nathanleighsays commented 4 years ago

It would be amazing if there was something akin to source.setPosition that allowed you more direct control of the speaker outputs. i.e. the ability to assign a source to come only out of the center channel or sub channel, or hard panning of left and right.

kcat commented 4 years ago

OpenAL Soft and Rapture3D have the AL_EXT_DEDICATED extension, which would allow sources to play directly on the front-center or LFE channels when they exist. It shouldn't be too hard to add support for that. Hard panning for left and right can be done by putting the source directly left or directly right of the listener (with source.setRelative(true) so it automatically stays relative to the listener).

More directly controlling the speaker outputs would be a problem since there's no saying what speakers exist, if any. Some people may only have stereo speakers, some may have quad, others 5.1 or 7.1 (in the future there could also be 8-channel cube, or 7.4.4.1). With B-Format or HRTF output, there aren't even speakers to really think about, as sounds can be panned and mixed in arbitrary 3D space using speaker-agnostic or filtered output. This can also change over the course of the app lifetime.

nathanleighsays commented 4 years ago

Ahhh. That makes sense, though even just the ability to route to the center or sub would be a huge boon to the project I'm developing. I suppose this is a feature/notabug situation since that speaker configuration portability is what drew me to use Alure over other libraries in the first place. In that case, how difficult would it be to create a Device function that queries the number of available outputs for a given Device?

nathanleighsays commented 4 years ago

On further tinkering, I can't get sound to come out of Center or Sub at all regardless of where I position it. (It took longer than I'd like to admit to realize the Z-axis in setPosition = front / back). Is there a combination of positions / orientations that place sound in the Center of a 5.1 system? Or is presently the only way to access those channels through dealing directly with OpenAL Soft?

kcat commented 4 years ago

If it needs to be on the front-center speaker specifically, it needs to be done through the ALC_EXT_DEDICATED extension, which unfortunately Alure doesn't currently deal with, but I can look at adding when I get time to. As a workaround, you can simply set source.setRelative(true); and source.setPosition(0.0f, 0.0f, -1.0f); to pan it to the front-center position. This panning is what that extension would do anyway if a front-center speaker isn't available.