[openal] Multiple Output Devices

Chris Robinson chris.kcat at gmail.com
Sat May 16 03:37:59 EDT 2020


On Fri, 15 May 2020 15:44:05 -0500
Patrick Baggett <baggett.patrick at gmail.com> wrote:

> I've been planning out a split-screen video game. I have a plan for
> supporting split-screen via a single sound card. Is whether it is
> possible to have OpenAL render sound to two different sound cards
> *simultaneously*.
> 
> Use case: split screen with two players each having headphones and
> hearing only *their* sounds.
> 
> There is a limit of one active context per process - but does that
> mean I can create only one context? Or does it mean that I can create
> multiple and I just need to constantly use alcMakeCurrent() to switch
> between them to issue commands? Or would making a context not-current
> disable all processing? Any idea of the overhead of constantly
> swapping contexts?

With OpenAL Soft, it's definitely possible to create multiple contexts,
with multiple devices. Changing the context would only change which one
commands are issued to, and doesn't stop processing/output for
non-current contexts. There's not too much overhead with changing
contexts, though it would be a good idea to minimize changes by
updating the sounds, environments, and listener for each player
together. e.g.

alcMakeContextCurrent(Player1Ctx);
updatePlayer1Sounds();
updatePlayer1Listener();

alcMakeContextCurrent(Player2Ctx);
updatePlayer2Sounds();
updatePlayer2Listener();

... etc ...

Just be aware each context with each device will be completely
separate. Each one will have its own list of sources and buffers and
the like, so if the same sound is heard by multiple players, each one
would need its own buffer to hold the sound and its own source to play
it.

> In my testing machine, I have two separate sound cards. The first is a
> Creative X-FI card that is supported by Creative's OpenAL hardware
> implementation. The second is an on-board Realtek chip that is
> supported by the OpenAL-soft (v1.20.1).

Using two separate implementations would depend on using the router. It
might still work with the router, but I'm not familiar enough with it's
or the hardware driver's inner workings to know for sure.


More information about the openal mailing list