Hi there,
I’ve been trying to get audio working in my game for days, without success, both effects and background music.
Initial setup in AppDelegate:
#define USE_SIMPLE_AUDIO_ENGINE 1
…
auto audio = SimpleAudioEngine::getInstance();
audio->preloadEffect("/sound/hit.wav");
audio->preloadBackgroundMusic("/sound/music.mp3");
In game:
SimpleAudioEngine::getInstance()->playEffect("/sound/hit.wav");
SimpleAudioEngine::getInstance()->playBackgroundMusic("/sound/music.mp3");
With playEffect, it fails in SimpleAudioEngine_objc.m:
-(ALuint) playEffect:(NSString*) filePath loop:(BOOL) loop pitch:(Float32) pitch pan:(Float32) pan gain:(Float32) gain
{
int soundId = [bufferManager bufferForFile:filePath create:YES];
if (soundId != kCDNoBuffer) {
return [soundEngine playSound:soundId sourceGroupId:0 pitch:pitch pan:pan gain:gain loop:loop];
} else {
return CD_MUTE;
}
}
because soundId == -1, or kCDNoBuffer. Something wrong with the file, I thought, so I tried other different files, different formats like caf. Nothing works.
With playBackgroundMusic, it fails in CDAudioManager.m:
-(void) play {
if (enabled_) {
systemPaused = NO;
paused = NO;
stopped = NO;
[audioSourcePlayer play];
} else {
CDLOGINFO(@“Denshion::CDLongAudioSource long audio source didn’t play because it is disabled”);
}
}
because audioSourcePlayer == nil
Very confused as to what might be the problem. The location of the sound folder (Resources/sound) seems to be correct- if I change it, I get console errors saying file can’t be found. No other errors related to sound in the console. Tried different devices, same problem. Is there some initial setup that needs to be done that I’m missing, beyond defining USE_SIMPLE_AUDIO_ENGINE? Any sample projects I can look at?

