views:

179

answers:

1

Finch uses OpenAL. However, when I have an instance of Sound, and say -play, the sound plays. When I call -play multiple times one after another in a fast paced way, every -play makes the current sound playback of that sound stop and restart it.

That's not what I want. Would I have to create multiple sources or buffers to get that working? Or would I just instantiate multiple Sounds with the same file?

+2  A: 

There’s a RevolverSound class exactly for this use case. It’s very simple, it allocates a number of Sound instances beforehand and then plays them in rotation:

- (void) play
{
    [[sounds objectAtIndex:current] play];
    current = (current + 1) % [sounds count];
}

This means that there is a hard limit of the sounds that can play simultaneously and the memory usage goes up with that limit. I didn’t find that to be a big problem in practice, because when there are five or more sounds playing at once, there’s already such a sonic chaos that you generally won’t notice that the first one did not play to the very end before starting again.

zoul
my fault. I misinterpreted the example. You don't tell how many times that "revolver" has to fire. It does overlap nicely. Cool thing. Thanks Tomáš!
dontWatchMyProfile
How much bigger is the overhead of using an instance of RevolverSound rather than Sound, generally? Does it hurt if I always use RevolverSound for anything, just for the case I may want to overlap?
dontWatchMyProfile