[Open Source!] AudioHelper : Making game audio less painful!

Hey there!

I just released another open source component, AudioHelper!

The AudioHelper class exists to allow you to have a single access point into the Cocos2d-x engine’s audio framework, with some neat optimisations in order to make adding audio simpler. The AudioHelper simply is a generic interface into the audio frameworks, with some extra icing on the top! It can also allow you to switch out your audio framework as and when you need to, without having to change any code within your main game, as the AudioHelper will be the only part of your project that will touch the audio framework itself!

Some great examples of why the AudioHelper is really helpful are (as copied from the GitHub description!):

  • Let’s say you have a background music track, and you can change the volume of the audio between 0% - 100%. You don’t want the music to be played if the volume is equal to 0, but you don’t want your code to be littered with calls to the audio framework checking the volume! Simply call playBackgroundMusic() with the track of your choosing, and the AudioHelper will check the volume for you, and if it’s above 0 it’ll play the music!

  • You may also have different audio formats depending on the platform, but don’t want the code to handle choosing the format suffix littered around your fancy game code. Simply call playEffect() with the effect of your choosing, and it will determine the correct format and play the effect (only if the effect volume is also above 0!)

  • You may also have adverts in your game, and want to disable the background music whenever they are shown and re-enable it when the advert disappears. AudioHelper carries this out of the box, call advertStarted() when an advert is successfully presented to stop the music and advertFinished() when it is dismissed. If the volume is above 0, the music is played again when the advert is dismissed!

  • You may decide one day to switch your current audio framework for another, but with your non-AudioHelper audio implementation you’ve got to change the framework references and implementations across your ENTIRE project. That sucks. With AudioHelper you’ve only got to change your references and implementation in one place, the AudioHelper. The functions provided to interface from your game to the AudioHelper are generic, allowing those to stay the same within your game while the audio framework gets switched out to another!

The AudioHelper class is incredibly easy to use, and when integrated will make game audio incredibly easy to manage!

Check it out here: https://github.com/ryanbourneuk/AudioHelper! :smiley:

Have a great evening, if anyone has any questions please do let me know! :slight_smile:


I have just updated AudioHelper with a brand new feature - painless switching between SimpleAudioEngine and AudioEngine!

Simply follow the new integration instructions on GitHub to get on the way to stress free game audio!

1 Like

Looking forward for FMOD wrapper for cocos2d-x that just works…

1 Like

I’ve actually been looking into FMOD… perhaps I’ll get an implementation of it made soon.

Only problem would then be getting FMOD integrated into projects - it isn’t as easy as switching between AudioEngine and SimpleAudioEngine and that’d most likely lead to some people getting rather confused! If I ever get enough time to sit down and make some extra-clear instructions for it to remove all, then I’ll get it put together :slight_smile:

Are you sure fmod lib is free to use?

FMOD is free for indie use (1 game per year, < $500k budget), above that you have to pay up.


So, really we don’t need any wrapper for current glitchy build in sound… we need professional lib, FMOD.

Cool, thanx

While I’m sure FMOD is incredible, personally I have found SimpleAudioEngine to fit the needs of my game perfectly. In the past 7-8 months I’ve been using it, it has certainly become more stable. AudioEngine itself is still very glitchy on iOS, hence I don’t use that, but a wrapper is provided for those who want it anyway. If you have integrated FMOD into one of your games, please feel free to submit a pull request with an implementation for FMOD! :slight_smile:

Dobryy vecher!

I know that the team made significant fixes to AudioEngine in version 3.15. Did you try this version
or your statement relate to an earlier experience?

Could you tell us what glitches you saw?
I ask because I did not “hear” audio glitches on my devices, but maybe I need to consider additional cases, or get additional devices.

My experience of AudioEngine is from both v3.15 and before. Before 3.15, background audio would not loop at all. Now, on v3.15, it will work perfectly on Android but stop midway through the 3rd-4th background music loop. I find that SimpleAudioEngine does what I need it too, it doesn’t lag at all and the background music loops perfectly. The AudioHelper is there for convenience, so I can manage all of the sounds in one place :slight_smile:

1 Like

I just don’t want to spent time with it… seriously. I just want a solid working solution. FMOD is, “free” and nice. So really it’s needed nice simple wrapper(play, pause, pitch et.c) or better just integration with cocos2d-x.

I’ll be working on a wrapper for FMOD soon, but there’s a few other things I’m working on first :slight_smile: Just keep checking back here for more details on when it’ll be released! :smiley:

Thank you! :slight_smile: Now I can reproduce it. But in my case I had to play for a long time.
Apparently SimpleAudioEngine is a good choice for me for now.

Do not get me wrong, I respect your efforts to develop SpriteBuilderX. But the cocos team made efforts to develop AudioEngine, and this guy made efforts to develop the wrapper, and now you come and say that it is not necessary and

Do not you think that this is somewhat wrong?

Everyone would like to hear a good feedback about their work, or at least constructive criticism.

As for AudioEngine, there is no perfect software, it will always have bags (if it’s not Hello World).
The best that we could do is test every new version of AudioEngine and create issues for the problems found.
Or do not use it, but please do not negative criticism in this case.

You calling this wrapper?

void AudioImpl::stopBackgroundMusic() {

void AudioImpl::pauseBackgroundMusic() {

void AudioImpl::resumeBackgroundMusic() {

void AudioImpl::playEffect(string track) {

You know what - AudioEngine or SimpleAudioEngine don’t need any wrapper, but FMOD needs for sure.

Thats very very bad strategy. You should ask users why your product is bad, until they can’t answer you anything.

Technically yes. Although I would prefer other implementation.

But this might be useful if you have a lot of code and often use Audio.
For example I’m going to use SimpleAudioEngine for the current project, but I’m also going to test the AudioEngine after some fixes. So changing the 4 lines of code for the test is much easier than searching and changing it in the all files.

This is a subjective opinion.
Why do not you write a wrapper for this in such a case?

Personally, I’m not interested in FMOD because the indie license is not what I need, and I prefer to use a free solution.
But if you write the wrapper, than you will also receive a Like from me, just because.

Firstly, please do not take my words out of context.
If you can not provide positive feedback and can not provide constructive criticism, then provide a negative criticism without clarifying is an even worse strategy.

We are not just users, we are developers as well. And as a developer I understand that there is no perfect code, besides the concept of good code is very relative, because we all think very differently.
In addition, many people take a painful view of the criticism of their code or project, not because they are bad or narcissistic people, no, it can be caused, for example, by psychological trauma, and harsh criticism can only worsen the situation.

I will give you two examples.

  • example 1

You (simplistically): FMOD is the best, SimpleAudioEngine/AudioEngine is bad.
Me (simplistically): Why? Did you test the new version?
You (simplistically): No.

Well, you can not answer anything specifically. Does it mean that the “product” is not bad anymore?

  • example 2

Some user: I like “Finger Spinner”.
Me (I’m a user, too): This game is for idiots.

And who is right? And what should the developer ask to correct the situation?

1 Like

Just gonna weigh in here:

This is literally the reason for the existence of the AudioHelper class. I wanted to be able to test both out, and didn’t want to have to change references everywhere in the project.

I also wanted to be able to switch audio off for adverts, and only switch it on if it was on before. The AudioHelper provides that.

I want to play sound effects throughout the game with only one-line function calls. AudioHelper provides that functionality, as it’ll check to see if sounds are enabled before playing effects.

I have different sound formats depending on the currently used platform, and I didn’t to have to check the audio format everywhere. AudioHelper provides a really nice way of handling it, as you pass in the filename, and it’ll decide the format.

AudioHelper may not suit everyone’s requirements, however it suits mine perfectly and if it ever helps anyone else, then I’ll be very happy indeed.

@anon98020523 Please feel free to make a merge request with a wrapper for FMOD, as I do think that’d be really cool :slight_smile:

It’s obviously very different things. FMOD made in very specific own way I can say, and so can be wrapped only by itself. It’s very powerful, so requires a lot of integration as I think. Soon I will start to integrate it into my game, will see…

However, using it just for play, stop, pause can be like replacement for current sound engine, but I need it for much more.