Search code examples
audioopenallwjgl

Disable surround sound with openAL


I'm french so sorry for my english.

I'm currently making a splitscreen 2D game with LWJGL. I'm using the openAL API which is given with LWJGL. Everything seems to works perfectly. Well, too perfectly to be honest : because I'm making a splitscreen game and because I can't have 2 listener sharing the same context, I want to get rid of the left/right panning.

Sound attenuation work well. I change the position of sound depending on the closest player. The listener doesn't change, always at (0,0,0). The sound position is (soundPosition - closestPlayerPosition).

So how do I get rid of the surround thing ? I want to keep sound attenuation over distance, of course. I could simply put the sound on the Z-axis depending on the distance but this seem a bit silly (I have to compute the distance every time I have to update a sound position).

Thanks !


Solution

  • When you calculate the sound's position (soundPosition - closestPlayerPosition) take the length of the vector returned by that and then put that sound directly down the z axis that distance away from the player.

    Example:

    soundPosition = (1.4,0,1.4) closestPlayerPosition = (0,0,0)

    soundDirection = soundPosition - closestPlayerPosition = (1.4,0,1.4)

    soundDistance = soundDirection.Length()

    And finally, the final position of your sound:

    finalSoundPosition = (0,0,soundDistance) = (0,0,2)

    Edit: I didn't notice you already suggested this. To be honest I think this is fine, and its the only way to solve your problem beyond rewriting stuff internal to openAL