Does the engine support multiple sound listeners at once? I think I already know the answer but maybe there is a reason why there isn’t such support for it at the moment. The problem is with the splitscreen local multiplayer, since there could be only 1 sound listener, sounds will be generated only for one player and the rest of them will be playing in the “quiet” mode.
Multiple sound listeners
Currently the Audio class only supports one SoundListener.
void Audio::SetListener(SoundListener* listener)
{
listener_ = listener;
}
You should only require one sound listener, as there is no association between players and the audio system - simply put, the soundlistener is not owned by any player, it is owned by the application, and so can play any sound sources, regardless of ‘who made the sound happen’.
Well i don’t think the problem could be solved by more than one sound listeners. Just imagine a scenario of an explosion sound and two players. How would you handle the 3d sound if you have two listeners but your hardware has only ONE output (speakers) ? Some games achieve this by using the adventages of the stereo output and simply split the audio into L and R. But to be honest i don’t think there is any simple solution for this.
I would simply avoid using 3d sounds altogether in a split screen game…
Thanks for the explanation. That makes a lot of sense. Will try to avoid using 3D sounds altogether in my splitscreen project.
one 3d listener, the computer, can hear sounds from both players
please do not avoid 3d sound, its super easy and works in your bubble
It can’t… A listener is attached to a player (or camera) and the gain is calculated from a distance between a listener (player) and a sound source. It is impossble to hear the same sound from two different positions if you have only one speaker.
How would you play an explosion sound if one player stands closer and the other is far away ?
there are always ways to cheat the system, in this example, we could feed two sound streams into a mixer under sdl2 audio
most things worth doing are not easy, but thats what makes them interesting
nothing i know of, is impossible, except theoretical shit that doesnt fly yet
Yes there are some workarounds. The same issue is mentioned here :
https://answers.unity.com/questions/1030856/in-a-split-screen-game-how-to-deliver-different-3d.html
But wouldn’t that mean playing the same sound twice ? I don’t see a point of doing this.
no, it means the same audio inputs are mixed, into a final output hardware buffer player to the speaker(s)
we’re able to mix sounds before we play it
think like a DJ, with a mixing bench
What about using multiple sound listeners but only use the nearest listener to the sound source to calculate the volume of the actual sound + disabling the stereo effect?
When you’re working with 3D sound sources, you don’t need stereo sounds - all your 3D sounds should be mono! As for switching between Listeners, what’s the difference between that, and just moving the one Listener on demand?
Pretty sure I have 3D sound worked out, been doing this stuff for a while.
A 3D sound source comes from a place, so we don’t need two channels of audio information, we just need a mono sound, coming from some 3D place.
2D sounds on the other hand, like background music, can and should be stereo.
The implication is that 3D sounds exist in a virtual 3D space, while the more boring 2D sounds exist in the application space. It is fairly easy to make decisions about which space sounds should live in.