Reserved sources is the number if sources that OALSimpleAudio reserves for itself. There is a limited number of sources available. Typically it’s 32, but that’s implementation dependent. If you try to use too many, the app will crash.
You only need to set it lower if you plan on manually creating your own sources.
A buffer is a loaded sound file, ready to be played by the sound system.
3. I have many simultaneous sounds (explosions) in my game. I notice sometimes that an unrelated sound (firing) will stop working when there are a large number of effects played around the same time. Im pretty sure this why this is happening but I need to conduct more tests to be sure. Why would an unrelated sound stop playing? anyone experienced this? What could I do to prevent it other than the obvious "play less sounds”
ObjectAL uses the concept of sound channels. A channel is made up of many sources, but has the same interface as a source. If you tell it to play a sound, it will find an idle source from its pool and instruct it to play the sound. If all of the sound sources are busy playing a sound already, it behaves according to its interruptible property:
1. Interruptible: Pick a source from its pool and force it to stop playing so that it can play the new sound.
2. Not interruptible: Refuse to play the sound.
Once your game crosses into complicated territory, OALSimpleAudio won’t solve all of your problems, and you’ll need to start manually creating channels to avoid things like long running effects getting cancelled due to rapid fire sounds. The best way to do this is to reduce the number of reserved sources in OALSimpleAudio and create your own channel for small sounds. Basically:
[OALSimpleAudio sharedInstance].reservedSources = 10; // Leaves 22 sources for stuff you want to do manually
firingChannel = [OALChannelSource channelWithSources:5]; // Use however many makes it sound nice when you’re playing tons of lasers
// So at this point, you’ve taken 10+5=15 sources and there are 17 unused.
Make it interruptible or not (your choice):
firingChannel.interruptible = true;
Now load your buffers and keep references to them. You can just use OALSimpleAudio’s preloadEffect, which will also cache the buffer:
fire1Sound = [[OALSimpleAudio sharedInstance] preloadEffect:@“fire1.caf”];
fire2Sound = [[OALSimpleAudio sharedInstance] preloadEffect:@“fire2.caf”];
Alternatively you can load buffers without caching:
fire1Sound = [[OpenALManager sharedInstance] bufferFromFile:@“fire1.caf”];
Then use the channel to play the fire sound:
[firingChannel play:fire1Sound];
…
[firingChannel play:fire2Sound];
…
[firingChannel play:fire2Sound];
…
[firingChannel play:fire2Sound];
…
[firingChannel play:fire1Sound];
The rest of the sounds you can play using OALSimpleAudio like you did before:
[[OALSimpleAudio sharedInstance] playEffect:@“dont_interrupt_me_bro.caf”];
The channels demo has more code to look at.
Basically, OALSimpleAudio is a convenience layer on top of all of this stuff. You can go as deep or as shallow as your needs require.