I have simple mappings between actions and animations and I will probably duplicate this for sound (sure, not all actions may have a sound, but the general idea is there).
A maybe useful resource explaining how to play sounds the easy way: This link from iCodeBlog – unfortunately the ’system sounds’ approach doesn’t allow playing more than one sound simultaneously or even tuning volume(!)
AVAudioPlayer
AVAudioPlayer (apple docs link). Not hard to use; documented; allows simultaneous sound playback, volume control and other features. Link to the iPhone Programming Guide AVAudioPlayer introduction.
OK, I’ve been looking for an example that simply demonstrates how to use this. Check the Metronome example from iPhone dev connection (do Find > Find in Project with ‘AVAudioPlayer’). An immediate concern – how to convert a file path to a URL:
NSURL *soundURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"sound" ofType:@"caf"]];
Getting files from the main bundle is exactly what I want in this case because files imported into XCode projects end up inside the so called main bundle.
Expected issues:
- Converting files to .caf. – sure apple does provide a converter, but that’ll take a bit of time to look into. Leave for later as other formats are supported and using them might just be OK.
- Memory issues – initializing AVAudioPlayer with a URL doesn’t really tell me how sound gets loaded / unloaded.
- Performance issues – again, initializing from a URL could mean that I experience delays playing back sound.
Now the next part is putting the code together and integrating with my proto-framework.
Open AL?
Later, I might want to upgrade to OpenAL, but like realtime 3D, this maybe more appropriate for a second game. After all, I want to cover basic ground (fun, gameplay, story…) before I worry about even moderately complex technology. I had a quick look at the OpenAL programming guide and the apple example, It would probably take a good week for an experienced programmer to get to grips with this thing (although a good tutorial would probably help). No time for doing this now (admittingly, I’m not thrilled by the prospect either).


Comments