Problem with CocosDenshion in release mode on device

Forums Programming sound engine: CocosDenshion et al Problem with CocosDenshion in release mode on device

This topic contains 21 replies, has 7 voices, and was last updated by  SpriteLogic 1 year, 2 months ago.

Viewing 22 posts - 1 through 22 (of 22 total)
Author Posts
Author Posts
October 8, 2011 at 5:39 am #235908


Hi all,

I’m working on a project that is complete except for adding sounds. I’m now running into some problems integrating CocosDenshion. Does anyone know what the following console error message might mean?

Catchpoint 2 (throw)
Catchpoint 2 (exception thrown).(gdb) bt
#0 0x3415fbc8 in __cxa_throw ()
#1 0x328e26fc in ExtAudioFile::Open ()
#2 0x328e69f4 in ExtAudioFileOpenURL ()
#3 0x000267d0 in CDloadCafAudioData (inFileURL=0x2478c0, outDataSize=0x2fffe74c, outDataFormat=0x2fffe750, outSampleRate=0x2fffe748) at ../ProjectName/libs/CocosDenshion/CDOpenALSupport.m:135
#4 0x000269ec in CDGetOpenALAudioData (inFileURL=0x247660, outDataSize=0x2fffe74c, outDataFormat=0x2fffe750, outSampleRate=0x2fffe748) at ../ProjectName/libs/CocosDenshion/CDOpenALSupport.m:247
#5 0x00028864 in -[CDSoundEngine loadBuffer:filePath:] (self=0x223b60, _cmd=0x383d3934, soundId=0, filePath=0xffffffff) at ../ProjectName/libs/CocosDenshion/CocosDenshion.m:599
#6 0x000264b4 in -[CDBufferManager bufferForFile:create:] (self=0x246f30, _cmd=0x383d3934, filePath=0x965e8, create=96 '
') at ../ProjectName/libs/CocosDenshion/CDAudioManager.m:855
#7 0x0002ae2c in -[SimpleAudioEngine preloadEffect:] (self=0x2478c0, _cmd=0x383d3934, filePath=0x0) at ../ProjectName/libs/CocosDenshion/SimpleAudioEngine.m:147
#8 0x00002f74 in -[ProjectNameAppDelegate applicationDidFinishLaunching:] (self=<variable not found>, _cmd=0x383d3934, application=0x0) at ../ProjectName/Classes/ProjectNameAppDelegate.m:99
#9 0x00002f74 in -[ProjectNameAppDelegate applicationDidFinishLaunching:] (self=<variable not found>, _cmd=0x383d3934, application=0x0) at ../ProjectName/Classes/ProjectNameAppDelegate.m:99
#10 0x331b6e90 in -[UIApplication _performInitializationWithURL:sourceBundleID:] ()
#11 0x331b6a68 in -[UIApplication _runWithURL:sourceBundleID:] ()
#12 0x33207e00 in -[UIApplication handleEvent:withNewEvent:] ()
#13 0x3320763c in -[UIApplication sendEvent:] ()
#14 0x33207094 in _UIApplicationHandleEvent ()
#15 0x342ea7e4 in PurpleEventCallback ()
#16 0x3244f52a in CFRunLoopRunSpecific ()
#17 0x3244ec1e in CFRunLoopRunInMode ()
#18 0x331b5c08 in -[UIApplication _run] ()
#19 0x331b4230 in UIApplicationMain ()
#20 0x000028ec in main (argc=1, argv=0x2ffff5ac) at ../ProjectName/main.m:13

I’m using XCode 3.2.5, Cocos2d 1.0.1, and deploying to a 2nd gen iPod touch running 3.1.3.

The project runs correctly in the simulator.

Code example of how I am initializing the sounds:


#import "SimpleAudioEngine.h"


- (void) applicationDidFinishLaunching:(UIApplication*)application
// Preload sounds
[[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume:0.1f];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:0.2f];

[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic:@"backgroundmusic.caf"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"effect1.caf"];


October 8, 2011 at 5:42 am #350502


I dont understand enough of cocosdenshion to figure it out, but try with a *.wav sound just to check. If it works then there is some issue with your sound file.

October 8, 2011 at 6:00 am #350503


Thanks for the quick reply Zaaroth.

I tried removing all of my preload code and adding a single preload for a .wav file. The preload didn’t fail over.

And… on the next scene, where my .caf files are first played, there were no issues.

Must be something wrong with the preload code?

Unless I find any issues with my game when not preloading sounds I’ll just keep it working and not preloading.

Thanks again.

October 8, 2011 at 6:06 am #350504


Spoke too soon…

After continuing on to another scene from the scene that loaded the sounds. The app/game crashes. The music should keep playing, since I’m not telling CocosDenshion to stop using

[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];

I get the following console error log:

(gdb) bt
#0 0x3415fbc8 in __cxa_throw ()
#1 0x330d09d4 in ACAACEncoder_IOA2::ACAACEncoder_IOA2 ()
#2 0x330d0ad4 in ACAACEncoder_IOA2::IsAvailable ()
#3 0x330a56bc in RegisterExternalAudioCodecs ()
#4 0x327c1aac in RegisterEmbeddedAudioCodecs ()
#5 0x327ca858 in AudioComponentManager::FindNext ()
#6 0x327ca54c in AudioComponentFindNext ()
#7 0x327eb8d0 in ConverterRegistry::FindFormats ()
#8 0x327eb6a0 in ConverterRegistry::GetInputFormatsSet ()
#9 0x327eb430 in ConverterRegistry::GetInputFormatsSize ()
#10 0x327ea4d8 in AudioFormatGetPropertyInfo ()
#11 0x328e2134 in ExtAudioFile::GetExistingFileInfo ()
#12 0x328e271c in ExtAudioFile::Open ()
#13 0x328e69f4 in ExtAudioFileOpenURL ()
#14 0x000267f0 in CDloadCafAudioData (inFileURL=0x24e7a0, outDataSize=0x2fffe4ac, outDataFormat=0x2fffe4b0, outSampleRate=0x2fffe4a8) at ../ProjectName/libs/CocosDenshion/CDOpenALSupport.m:135
#15 0x00026a0c in CDGetOpenALAudioData (inFileURL=0x217800, outDataSize=0x2fffe4ac, outDataFormat=0x2fffe4b0, outSampleRate=0x2fffe4a8) at ../ProjectName/libs/CocosDenshion/CDOpenALSupport.m:247
#16 0x00028884 in -[CDSoundEngine loadBuffer:filePath:] (self=0x223d30, _cmd=0x385c0dfc, soundId=0, filePath=0x21646174) at ../ProjectName/libs/CocosDenshion/CocosDenshion.m:599
#17 0x000264d4 in -[CDBufferManager bufferForFile:create:] (self=0x2470e0, _cmd=0x385c0dfc, filePath=0x969a8, create=48 '0') at ../ProjectName/libs/CocosDenshion/CDAudioManager.m:855
gdb stack crawl at point of internal error:
0 gdb-arm-apple-darwin 0x0013216e internal_vproblem + 316

October 8, 2011 at 6:20 am #350505


I’ve now tested this same code against an iPad2 running 4.3.5, and didn’t have any issues.

It looks like the sound failures are either due to the device or the version. I might have to try another solution other than CocosDenshion if it doesn’t support older iOS versions.

October 8, 2011 at 6:26 am #350506


I’m still digging, and will just post anything I find. In case I solve this and anyone else can benefit.

I’ve checked into the SimpleAudioEngine.h and this is the minimum specs it says it supports:


A wrapper to the CDAudioManager object.

This is recommended for basic audio requirements. If you just want to play some sound fx

and some background music and have no interest in learning the lower level workings then

this is the interface to use.


- Firmware: OS 2.2 or greater

- Files: SimpleAudioEngine.*, CocosDenshion.*

- Frameworks: OpenAL, AudioToolbox, AVFoundation

@since v0.8


@interface SimpleAudioEngine

October 8, 2011 at 6:37 am #350507


Well, I’m a bit stumped.

Also, in case anyone is more familiar with this. Here is my audio file format information:

<<geidsvig>> :~$ afinfo Desktop/sound/soundtest.caf
File: Desktop/sound/soundtest.caf
File type ID: caff
Data format: 2 ch, 44100 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
no channel layout.
estimated duration: 34.000000 sec
audio bytes: 5997600
audio packets: 1499400
audio 1499400 valid frames + 0 priming + 0 remainder = 1499400
bit rate: 1411200 bits per second
packet size upper bound: 4
audio data file offset: 4096
source bit depth: I16
sound check:
approximate duration in seconds 34

Which was converted by:

afconvert -f caff -d LEI16 Desktop/sound/filename.mp3 Desktop/sound/soundtest.caf

As stated by Apple here:

October 8, 2011 at 4:17 pm #350508


I am a bit lazy now to read the whole thread again. Have you tried with waves? In case you did, what was the outcome?

October 8, 2011 at 6:22 pm #350509


I’ve replaced all .caf files with .wav files. Using only .wav files works.

thanks zaaroth!

So then why doesn’t .caf work?

I read through

Looks like this is the correct way to convert to .caf :

afconvert -f caff -d ima4 mysound.wav

So the suggested format on Apple doesn’t match. ie. LEI16 versus ima4.

Fixed! :)

October 8, 2011 at 11:21 pm #350510


This thread helped me a lot! Except i went in the opposite direction as you :)

I had a project working fine in ios4 from xcode3, and i was creating my caf’s with: afconvert -f caff -d ima4 mysound.wav

but when i switched to ios5 and xcode4, i started getting the same exception as you.

switching to apples recommendation you pointed to fixed it: afconvert -f caff -d LEI16 Desktop/sound/filename.mp3 Desktop/sound/soundtest.caf

so if anyone lands on this thread having problems porting over to ios5, change over to LEI16 in your compression script

October 24, 2011 at 8:41 pm #350511


FYI, I have a similar problem and I’m wondering if it’s related to my previous issue ( ). Our app has been working more or less fine since release (August) but with a somewhat unusual number of reports of people with sounds cutting out. For all the people who had sound cutting out, rebooting their phone fixed it and the problem did not recur. This happened two times with users I trust did not make stupid mute button errors or whatever.

Now, today, I upgraded to Xcode 4.2 and attempted to compile and test on my iOS5 device and get consistent crashes on my sound files. It’s on this line in CDloadCafAudioData():

status = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat);

My caf files were creating using this:

/usr/bin/afconvert -f caff -d ima4 -c 1 $f

(where $f is the filename, naturally).

I haven’t yet testing reconverting with afconvert to a different format, but wanted to post that there seems to be some kind of underlying issue here with caf files.

Anyone else having problems?

October 24, 2011 at 10:22 pm #350512


To follow up on my previous post.

Using the same wav file:

IMA4: Convert to caf via ima4, using this command:

/usr/bin/afconvert -f caff -d ima4 -c 1 -v

Which results in this verbose output:

Input:   1 ch,  44100 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer<br />
Output: 1 ch, 44100 Hz, 'ima4' (0x00000000) 0 bits/channel, 34 bytes/packet, 64 frames/packet, 0 bytes/frame

(Is that 0 bits and 0 bytes weird?)

When I try to play this file (again, this same file used to work prior to upgrade):

2011-10-24 18:09:19.544 MonkeyMath[550:707] Denshion::CDSoundEngine - mixer output rate set to 44100.00<br />
AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved<br />
2011-10-24 18:09:19.770 MonkeyMath[550:707] Denshion::CDBufferManager generating new buffer id 0<br />
2011-10-24 18:09:19.773 MonkeyMath[550:707] Denshion::CDSoundEngine - Loading openAL buffer 0 v_mms_title3.caf

…and then the crash on line 173 of CDOpenAlSupport.m

LEI16: Now, all else the same, but convert using this convert command:

/usr/bin/afconvert -f caff -d LEI16 -c 1

…and the file plays fine without issue.

HOWEVER! The original wav is 340 kb, my ima4 is 94KB, and the LEI16 is 344kb. I tried using LEI16@16000 and it was smaller (170kb) but sounded terrible.

I’m stumped here, how do I do compressed audio with cocos2d now? :(

October 24, 2011 at 11:49 pm #350513

Steffen Altwiese

Try aac or mp3. Maybe Apple screwed up IMA4 support in iOS5, they normally break something audio related in every major release.

FYI caf is just a wrapper so you can have a caf file containing aac audio.

October 25, 2011 at 3:53 pm #350514


Steve: Thanks for the reply!

As a test I reconverted all my files using aac ( again via afconvert ) and I still get the same exact error. Crashes out on the same line number on the first sound it is asked to preload.

I then testing again reencoding all the sounds using LEI16. Since this time I had all my sounds converted, I was able to go further. But in this case the sound crashed on the third file instead of the first.

So my problem is apparently that no sounds will work.

Again, this was code that all compiled and ran fine prior to ios5/xcode 4.2 upgrade. In fact, the same code and files still (mostly) works fine on ios5. I just can’t compile a new version that works.


I’ve been poking around the Apple Developer forums (login required) and it appears there are some issues with openAL and ios5. It’s mostly over my head, but I have to note the one guy who says this “A ton of other OAL audio engines are broken, if that is even a consolation to anyone :-|”. Thread I’m discussing is here: — developer login needed, natch. I don’t think I’m allowed to repost anything outside that forum or I’d post here (or does that not apply now that ios5 is public?).

Like I said, I can’t tell if that’s related since I’m out of my depth, but it doesn’t look good.

October 26, 2011 at 2:03 am #350515

Steffen Altwiese

@malphigian – That forum thread has nothing to do with this issue, the issue being discussed there shouldn’t even have an impact on CocosDenshion as CocosDenshion doesn’t stream buffers.

Based on what others have reported there seems to be an issue with IMA4. Beyond that it seems you are the only person experiencing the problem you are having. Have you considered the possibility that you may have memory corruption in your app? Do you use C style arrays?

October 26, 2011 at 2:34 pm #350516


Ah well, back to square one I guess. No C style arrays, and as I said this same exact code and files compiled and ran fine on XCode 4.0. Looks like I’m stuck.

October 26, 2011 at 4:14 pm #350517

Steffen Altwiese

…as I said this same exact code and files compiled and ran fine on XCode 4.0

That is why I suggested memory corruption, it can be caused by things other than C style arrays but that is the most common i.e. writing beyond the end of an array.

You seem to be experiencing lots of weird behaviour. For example, the fact that your app crashes on loading the 3rd LE16 file doesn’t really make any sense to me. When things behave inexplicably I always look for memory corruption.

One thing you can try is using wave files, CocosDenshion uses a different loading strategy for files that end with .wav.

I’d also seriously consider using a commercial sound engine. I highly recommend Bass I’ve been using it since Apple broke OpenAL pitch shifting back in 4.x.

October 26, 2011 at 4:41 pm #350518


Steve, did you look at FMOD before choosing Bass? I went with FMOD and it works great but price is $500/game. Looks like Bass is actually more expensive unless you do shareware.

October 26, 2011 at 4:48 pm #350519

Steffen Altwiese

@CJ – yeah I looked at FMOD but it was too expensive for me. The Bass license is a bit confusing but basically individual developers pay 125 Euro for unlimited projects provided they don’t sell their products for more than 10 Euro. FMOD has the advantage that it is available for Android but there is an Android 2.3+ version of Bass in the works.

October 26, 2011 at 6:39 pm #350520


Thanks for the tips on the other sound engines, I’ll look into them. The 125 euro option seems pretty reasonable and looks like it applies to most iOS apps.

I’ll take a closer look at possible memory corruption as an issue as well.

November 1, 2011 at 8:27 pm #350521


I poked around with both fmod and un4seen Bass, and both were terribly underdocumented for iOS.  Fmod much better than Bass (which has nothing but a thread), but both were missing the critical “hey, here’s how to get this working in Xcode!” tutorial that I generally seem to require.   I’m sure I can get them working, but they both feel vastly over engineered for what I’m trying to do (play sounds, occasional pitch shift).

On a whim, I decided to grab the latest CocosDenshion from GIT and just try that.  I did so, and now all my sounds seem to play fine.   I wish I knew what changed, because this feels like magic right now.

February 7, 2013 at 2:54 am #350522


I am surprised how little information there is for this particular issue. I have wasted a few hours on this and found something that is worth sharing.

I also ran into the issue at the following line of CDloadCafAudioData():

status = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat);

I am using XCode 4.5.2. wav file is fine. caf file with ima4 has the problem. lei16 has even a larger file size than wav so I did not even bother to try.

But what I found was that this is not a crash. It’s an internal exception caught by XCode. I had a break point for “All Exceptions”. The exception is actually handled/rethrown a few times. But ExtAudioFileSetProperty eventually returns with no error and the sound plays fine too. ExtAudioFileSetProperty used exception internally to controlled their internal logic. There is no bug or anything. So if you don’t have break point for “All exceptions”, you don’t even notice this problem. I guess not many people set this break point and that is probably why I had a hard time searching for solutions on the internet.

So if you want to use ima4 to reduce file size and still keep the “All Exceptions” break point, I found you could edit this break point and let it break only on Object C exceptions.

Hope this is useful for someone in the future.



Viewing 22 posts - 1 through 22 (of 22 total)

You must be logged in to reply to this topic.