Re: playing when many simultaneous sounds, other sounds stop playing

107 views
Skip to first unread message

Robert Eickmann

unread,
Jan 23, 2015, 7:31:19 PM1/23/15
to objectal-...@googlegroups.com

1. You should preload if at all possible. (Blocks are your friends for file system operations like this...) 
Yes. it will reload the file each time.... The file system is very slow. (And honestly, it feels like an new iPad is slower than old one in file system access). 

2. A buffer is just a chunk of memory, that contains part of the audio file. 

3. Its been a while since I did a lot with openAL there was a limit for the number of simultaneous sounds (32). 
My recommendation is build a quick demo app, that plays your sound files and check it in instruments. 

-Rob 





On Fri, Jan 23, 2015 at 4:06 PM, Tameem Hamoui <tame...@gmail.com> wrote:
Let me preface by saying I have read documentation and looked at examples but I'm finding myself lost. I have many questions:

1. Do I need to preload effects if I don't notice any slowdown in my app?  If I have a function that preloads and then plays a sound will it keep preloading the same sound each time my function is called?

2. Is setting reserved sources important in oalsimpleaudio.sharedinstance? What is a reserved source exactly?  What is a buffer?

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"

--
You received this message because you are subscribed to the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-ip...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karl Stenerud

unread,
Jan 23, 2015, 7:32:05 PM1/23/15
to objectal-...@googlegroups.com
1. Do I need to preload effects if I don't notice any slowdown in my app?  If I have a function that preloads and then plays a sound will it keep preloading the same sound each time my function is called?

If you’re using OALSimpleAudio, it will only load a sound once and then cache it. You can manually uncache it if you need to.
If you didn’t preload first, OALSimpleAudio will attempt to load the first time you play it through that interface.


2. Is setting reserved sources important in oalsimpleaudio.sharedinstance? What is a reserved source exactly?  What is a buffer?

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.

Tameem Hamoui

unread,
Jan 23, 2015, 7:55:32 PM1/23/15
to objectal-...@googlegroups.com
Thanks to both of you for the responses and clarification. So a channel is a group of sources that can be set as interruptible or not? And source is an empty slot for a sound effect to play. Right?

My explosion sound effects would be using many of those sources.. But once they stop playing I notice my firing sound never comes back. My firing sound is a single sound being looped every fifth of a second while the player holds the button.

Based on what you've told me there may not be enough sources available for my firing effect to play during explosions.. but after my explosions stop then those sources should become available right? This is unfortunately not the case. The firing sounds never work again thereafter

Karl Stenerud

unread,
Jan 23, 2015, 8:05:07 PM1/23/15
to objectal-...@googlegroups.com
Yes, a channel is basically a group of sources. In fact, OALSimpleAudio is basically composed of one interruptible sound channel, and setting reservedSources adjusts how many sources it has in its channel.

So if I understand correctly, you have a single firing sound and multiple explosion sounds. In that case, you should play the explosion sounds in a separate, interruptible channel.
You might even want to create a single ALSource to use for your firing sound. It could make things simpler.

firingSource = [ALSource source];
firingSource.buffer = [[OALSimpleAudio sharedInstance] preloadEffect:@“laser_loop.wav”];
firingSource.looping = YES;

[firingSource play];
[firingSource stop];


Tameem Hamoui

unread,
Jan 23, 2015, 10:01:52 PM1/23/15
to objectal-...@googlegroups.com
None of them are single sounds being looped or anything like that. The fire sound is a short sound effect being played from a fire method. The fire method is called in an outside loop as the player holds down the button. The explosions follow a similar design. They're short sounds being played rapidly for each explosion animation. Alsource with a loop wouldn't really be suitable for either one. Would your channel advice still apply to this case? These are all short sound effects playing in quick succession, not a looped source. So I should try putting my explosions on an interruptible channel? Sorry for all the questions. Just want to make sure I'm getting it right

Karl Stenerud

unread,
Jan 23, 2015, 10:17:54 PM1/23/15
to objectal-...@googlegroups.com
Yeah, from that description, you’d be best making a fire channel and an explosion channel, both interruptible.

On Jan 23, 2015, at 7:01 PM, Tameem Hamoui <tame...@gmail.com> wrote:

> None of them are single sounds being looped or anything like that. The fire sound is a short sound effect being played from a fire method. The fire method is called in an outside loop as the player holds down the button. The explosions follow a similar design. They're short sounds being played rapidly for each explosion animation. Alsource with a loop wouldn't really be suitable for either one. Would your channel advice still apply to this case? These are all short sound effects playing in quick succession, not a looped source. So I should try putting my explosions on an interruptible channel? Sorry for all the questions. Just want to make sure I'm getting it right
>

Tameem Hamoui

unread,
Jan 23, 2015, 11:38:02 PM1/23/15
to objectal-...@googlegroups.com
thanks for the lesson karl!  really appreciate it!
> To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-iphone+unsub...@googlegroups.com.

Alex Cannon

unread,
Feb 11, 2015, 11:22:15 PM2/11/15
to objectal-...@googlegroups.com
Can anyone point me in the direction of a working ObjectAL demo for iOS 8? The ones included in the Github repo seem to be defunct...
Reply all
Reply to author
Forward
0 new messages