Panning Stereo sounds using MojoAL (Extension?)
Hi,
We have been looking into panning sounds. In OpenAL, it looks like it's only possible to do so using mono sounds.
For stereo sounds, it seems there's an alternative way discussed here : https://github.com/kcat/openal-soft/issues/194
But we had some trouble actually following the suggested workaround when using MojoAL. This is discussed a bit here: https://github.com/adventuregamestudio/ags/issues/1637
Would an extension to provide a way to do so in MonoAL be acceptable?
I'm not against the idea if you want to throw together a PR for it. Just going to CC @kcat here, in case we want to talk about a formal extension.
(the extension can be as simple as "the spec says stereo sounds don't spatialize, but with this extension they will with the following characteristics." Those characteristics could be as simple as "the AL will convert the audio data to mono and then follow standard spatialization rules" or "it will pan each channel with the following equation" or whatever.)
This might need a new source property or an alEnable() enum or something, so apps that put a stereo buffer onto a reused source object that was previously positioned away from the Listener don't get a surprise without opting in first.
When it comes to OpenAL, there's a distinction to be had between "panning" (ala DirectSound's SetPan where you control the volume level of the left output vs right output of a sound), and 3D spatialization (placing a sound source in 3D space and OpenAL uses a method to create the impression of the sound at that location given the available speakers).
OpenAL Soft has the AL_SOFT_source_spatialize extension to allow 3D spatialization of multi-channel sources. Setting a given source's AL_SOURCE_SPATIALIZE_SOFT property to AL_TRUE allows multi-channel sounds to be spatialized by having them downmix to a single point in space, essentially becoming mono and letting it move around and attenuate like a mono source (and things like doppler and directional cones affect it also). Setting it to AL_FALSE makes multi-channel sounds behave normal, while mono sounds also stop spatializing (it won't move around with position or orientation changes, and doppler and directional cones no longer affect it). Setting it to AL_AUTO_SOFT (default) gives standard behavior; a mono sound spatializes, a multi-channel sound doesn't.
downmix to a single point in space, essentially becoming mono
Uhm, this means any stereoness from the original sound is lost?
Essentially I would like to pass all sounds through MojoAL, this would include in-game sounds and sounds that simply happen, and those could be panned (and stereo) - if this were graphics, it would be like rendering GUI and Game through the same pipeline. The advantage for doing so is only maintaining a single backend and API.
Uhm, this means any stereoness from the original sound is lost?
When it's at some point out in space away from the listener, yes. If it's at the same position as the listener (or at 0,0,0 with AL_SOURCE_RELATIVE on), it maintains stereo separation. This is because sources have no size, they're infinitely small, so there's no width to determine how to separate the left and right channels when it's somewhere away from the listener.
There is a separate AL_EXT_SOURCE_RADIUS extension that gives a size to sources, and one of the things I'd like to do is have the stereo sound narrow as it moves away given it's size. Although there is no defined behavior for the interaction of these two extensions, so it's up to the implementation to do what it thinks is best.