Audio in 3D games

What are 3D game writers doing about audio?

All that cocos2d-x’s own audio support is lacking to provide fairly reasonable 3d audio is to be able to control pan in addition to gain. Annoyingly, although SimpleAudioEngine does allow pan and gain to be set when issuing an effect, you cannot then adjust either while the effect is playing. AudioEngine, on the other hand, has setVolume which lets you adjust the gain of an effect while it plays, but it has no support for setting pan at all. It’s so close to being a perfectly usable API, but it isn’t quite.

I see recommendations for using fmod, but my game is written in Lua and see no information on driving fmod from a Lua-based game.

I noticed your post in the other thread, regarding adding FMOD to Cocos2d-x, but I don’t think that is possible given the licensing terms. FMOD is a commercial product, and while certain open source programs do use it for free, they do so because they comply with the licensing requirements.

Other than that, is there anything stopping you from adding the LUA bindings for FMOD yourself? Given LUA is already used in Cocos2d-x, there should be plenty of examples in the code on how to create the relevant bindings to FMOD, along with much information online on how to achieve this.

I guess not, other than it’s a whole lot of extra areas of the code to learn, with limited time. (I get to spend a day on this project every couple of months or so). I imagine using FMOD at all isn’t trivial, if you want it to work on several platforms. It’s a shame to have to delve into that level of things when everything else so far has been achievable through existing Lua APIs. All the more, FMOD seems the wrong approach when it’s just pan that is missing in AudioEngine.

I might implement just mono sound for now in my game, and hope that later I have the time to add support for pan in AudioEngine myself.

That’s fair enough. If you do want to give it a shot at some point, then this may help serve as a starting point: https://github.com/apscodes/fluamod-fmod-lua-wrapper

1 Like

One thing about Android.
cocos2d is related on OpenSL es on low level. I tried to extend cocos binding to use 3D interfaces from OpenSL, but had the following error on my phone:


I stopped further experiments after that.
It was some time ago - may be last Android OS and devices already support 3D sounds.

The method I was looking to use doesn’t need to utilize the 3D audio features on the device. It’s not difficult, within the game code, to keep track of the distance and direction of each sound source w.r.t. the camera and repeatedly adjust the volume and stereo position (gain and pan) appropriately for each. I’ve done this in the cocos2d-iphone version of my game and it works very well. The show stopper is not having any way to control the strereo position of sounds.

@Glidos You’re right, I tried almost the same for Android, but considered only the distance between source and camera.