This project is read-only.

CCSimpleAudioEngine - PlayEffect produces no sound but PlayBackgroundMusic does

Topics: Cocos Builder, iOS
Mar 4, 2014 at 1:44 AM
I am running into an issue with CCSimpleAudioEngine. When I use it to create a sound effect using an mp3 file, I hear no sound being made and no errors or exceptions being generated. When I use PlayBackgroundMusic method instead, the sound file plays fine. Below is the code i'm using:

Load Method:
    CCSimpleAudioEngine soundEngine = new CCSimpleAudioEngine ();
    soundEngine.PreloadEffect ("Sounds/tap.mp3");
    soundEngine.EffectsVolume = 1f;
When a tap on screen is done:
    soundEngine.PlayEffect ("Sounds/tap.mp3");
If I replace PlayEffect with PlayBackground music, it works fine (On iOS simulator or on my iOS device). I cannot figure out what the issue can be. I'm using the cocos2d project available on GitHub: and also using Xamarin IDE if that makes a difference.

Any help would be appreciated.
Mar 4, 2014 at 6:10 AM
Sound effects only work with wav files.
Mar 4, 2014 at 11:01 AM
totallyevil wrote:
Sound effects only work with wav files.
I've tried with Wav files as well but still get the same issue.
Mar 4, 2014 at 2:52 PM
One other thing to mention. I tried setting the properties of my Wav file to use as content or bundleresource but neither of those seem to make it work.
Mar 4, 2014 at 4:28 PM
The WAV files must be encoded using the XNA restrictions, which is something like 44 kHz and mono (not stereo), I think.

Make sure that they are in your Content/Sounds folder, so your project hierarchy should be Project/Content/Sounds/tap.wav and the output will be bin/Debug/Content/Sounds/tap.wav

Next, preload your sounds. If the tap is a long tap then the sound effect loader and audio preprocessor will take a little bit of time to initialize. OpenAL can be slow. I've seen a few times where our initial play of wav files is delayed, and then it catches up once the memory buffers are initialized.
Mar 4, 2014 at 5:53 PM
Do you have any sample wave files I can use that follow this XNA restriction? If not, do you suggest any conversion tools I can use?

I've made sure that my sound files are under Content/Sounds. I'll ensure it shows up properly under debug.

The effect is preloaded prior to my game starting. The tap is pretty quick and doesn't happen too often.
Mar 4, 2014 at 6:06 PM
Edited Mar 4, 2014 at 6:07 PM
I use goldwave to do my sound editing and conversions.

The "effect1.wav" file in the GitHub repository is a good example. It should work. That one is PCM unsigned 8 bit mono, but it is 11025 Hz, or 11 kHz. I think the lower sampling rate is okay, it's the higher sampling rates that don't seem to work. Anything beyond 44 kHz will not work in my experience.

Edit: cocos2d-xna\tests\testsContent\Sounds -> this is the location of that wav file
Mar 5, 2014 at 12:25 AM
I tried the "effect1.wav" file thats available in the cocos2d-xna project. I still get the same issue where no sound is played.

I checked bin/Debug/iPhone/Content/Sounds and the file is there. I tried setting the file properties as "Content" and "BundleResource" and "None" but that didnt work either. I also tried just preloading the effect and playing it when its done (rather than waiting for a tap) but that also didnt work. Any other advice?
Mar 5, 2014 at 12:34 AM
Open the xcode device log viewer and see what error is printed to the console when you try to play the effect...... post that error ....
Mar 5, 2014 at 12:56 AM
Nothing in the console gets printed. Under device log viewer, no log gets created either.
Mar 5, 2014 at 12:59 AM
You are running this in debug mode right? It always has a log. I've never seen it not produce a log for an ios device.
Mar 5, 2014 at 1:09 AM
I'm in debug mode. I had to reconnect the device to display the console output, which I have put here: in the mean time. I'm still checking as to why I do not see any device logs...
Mar 5, 2014 at 1:40 AM
Ok i think i will not get any device logs until the app actually crashes, which in this case it does not. Is the console output i sent in the pastebin enough?
Mar 5, 2014 at 5:20 AM
yeah, the console output is what I meant by the device log.

I don't see much cocos2d output in the console trace. ... I don't see any OpenAL output either. it's as if you are using a release build of MonoGame..
Mar 5, 2014 at 8:15 AM
Strange i'm not sure why this would happen. I'm using the latest MonoGame project which I got here:

I am certainly in debug mode as well. I guess i'm stuck where i'm at currently. Is there any sample project out in the wild that is just playing a sound effect using Simple Audio Engine that I can look at?
Mar 5, 2014 at 4:22 PM
The problem is that you are on master. You need to be on MonoGame "DEVELOP"
Mar 5, 2014 at 4:42 PM
Edited Mar 5, 2014 at 4:44 PM
I changed the references in my main project and in cocos2d project to use MonoGame-develop instead:

I'm still not seeing any reference to OpenAL....

Edit: I downloaded MonoGame-develop from
Mar 5, 2014 at 4:44 PM
The Master branch of MonoGame is pretty old. You should always work from the develop branch when you see any problems with MonoGame related capabilities.

I never use the master branch.

Our fork of MonoGame in the cocos2d-xna repository is designed to work with cocos2d-xna. It has some changes that are not merged into the main MG repo.
Mar 5, 2014 at 4:54 PM
Edited Mar 5, 2014 at 4:59 PM
Is your fork of MonoGame in cocos2d-xna available on github? I tried looking into getting it on NuGet but from what I can tell it is not available on Mac, but please correct me if i'm wrong.

Edit: I just noticed that the cocos2d project i'm using is actually from master, so could this be why we aren't seeing any console logs?
Mar 5, 2014 at 4:59 PM
Nuget for the Mac? I didn't think that existed yet.

Yeah, when you clone our repo and then update the submodules you will get our MonoGame.
clone cocos2d-xna
submodule update on cocos2d-xna
cd into MonoGame
submodule update on MonoGame to get the rest of the libs and such
Thatsssssssssit! All of our games are produced using that repository and nothing else.

That's our official fork.
Mar 5, 2014 at 5:10 PM
Okay i'm now using the Cocos2dxna fork of Monogame. I updated the references in my game and in the Cocos2d project reference. I checked the console log again but I'm still not seeing any real debug output (esp for OpenAL). Is it because i'm using the master cocos2d project? On github I dont see a develop branch to download...
Mar 5, 2014 at 5:17 PM
The master cc2dxna branch is correct. If you open a Git Bash on the MonoGame directory under cocos2d-xna you should see that it is on the develop branch (it will be printed in the path, e.g. (develop))

You're still not getting any sound?
Mar 5, 2014 at 5:23 PM
Still no sound after getting the proper MonoGame branch....trying to get the cc2dxna develop branch now.
Mar 5, 2014 at 5:35 PM
cocos2d-xna : master
monogame : develop
kungfubannana : master
dependencies : master

only MonoGame is on a special branch. All others are on master.
Mar 5, 2014 at 5:38 PM
Apologies but i'm having some trouble finding the develop branch for cc2d under MonoGame directory. Can you point me in the right direction?
Mar 5, 2014 at 5:40 PM
totallyevil wrote:
cocos2d-xna : master
monogame : develop
kungfubannana : master
dependencies : master

only MonoGame is on a special branch. All others are on master.
Okay, since I have cocos2d-xna master downloaded, how can I enable it to print the debug information we require?
Mar 5, 2014 at 5:42 PM
The debug output will automatically appear when the build is set to Debug.

All of the output is #ifdef'd around DEBUG being enabled. In release mode you won't get much of any output except errors/exceptions.

When OpenAL is initialized and it has a problem, it should report some kind of error or warning about encoding or buffer failures.
Mar 5, 2014 at 5:54 PM
totallyevil wrote:
The debug output will automatically appear when the build is set to Debug.

All of the output is #ifdef'd around DEBUG being enabled. In release mode you won't get much of any output except errors/exceptions.

When OpenAL is initialized and it has a problem, it should report some kind of error or warning about encoding or buffer failures.
I'm definitely in Debug mode. I am not so sure it's an OpenAL problem since I can play background music just fine unless that portion doesn't use OpenAL. Maybe I can somehow hardcore debug enabled in the monogame project?
Mar 5, 2014 at 6:07 PM
Try doing a step-in session and go all the way down into monogame when you play the sound effect.
Mar 5, 2014 at 6:27 PM
Edited Mar 5, 2014 at 6:49 PM
Eventually I get to the following:

        return Play (MasterVolume, 0.0f, 0.0f);  -- MasterVolume is set to 1.
I then get to:

        soundState = SoundState.Playing; -- Sound state is set to "Playing"
        TryPlay() returns true back to Microsoft.Xna.Framework.Audio.SoundEffect.Play() which then goes to CCEffectPlayer.

I actually get as far as the below method in OpenALSoundController class. I can't go any deeper since AL.SourcePlay is coming from an OpenTK library reference in Mono.
    public void PlaySound (OALSoundBuffer soundBuffer)
        if (!CheckInitState())
        lock (playingSourcesCollection)
            playingSourcesCollection.Add (soundBuffer);
        AL.SourcePlay (soundBuffer.SourceId);
Mar 5, 2014 at 9:46 PM
Did the soundbuffer have a valid SourceId ??
Mar 5, 2014 at 10:11 PM
Yes it did.
Mar 5, 2014 at 10:15 PM
Edited Mar 5, 2014 at 10:19 PM
Do you see any issues with using SystemSound class from MonoTouch.AudioToolBox? This allows me to use any of the sound files I have and i'm not really seeing a difference in performance?

Edit: One down fall is i can't modify the volume of the sound, I'd have to modify the sound file manually...
Mar 5, 2014 at 10:22 PM
Hmmm. Is there a limit to the number of concurrent sounds you can run using AudioToolBox?

I don't see any reason not to use AudioToolBox except for the volume control. Does it work with background music playing?
Mar 5, 2014 at 10:45 PM
I tried 2 concurrent sounds while using background music from simple audio engine. It seems to work. Its unfortunate I can't get PlayEffect working but I feel as though we spent too much time looking at this. I appreciate the help still though. Thanks!