Hello Guest

Sound creation efficiency

  • 5 Replies
  • 9968 Views
Sound creation efficiency
« on: January 23, 2006, 18:24:28 »
So, how do some of you handle this:

In my game, there's a lot of sounds... and many of my sound files are used over and over again (and overlap quite often). That seems to rule out reusing the same OpenAL sound instance, since I have to set it's position and then replay (and hence you could only have one of that sound playing at a time, correct?).

SO, I've gone to caching the sound data, and then creating a new OpenAL sound for each event that occurs (so each can have a different position). And when the sound is finished playing, it's destroyed.

Is this efficient? Is there a better way I should be doing this?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline Matzon

  • *****
  • 2242
Sound creation efficiency
« Reply #1 on: January 23, 2006, 19:12:08 »
here is how I would do it YMMW:
1: Generate the amount of sources needed (dont go over 16 sources - probably stay somewhere around 12-14).
2: Prioritize the sources accordingly (1-3 for continous sound, rest for round-robin played sounds - perhaps pool based (2-4 sounds for shots, 2 for event sounds etc.))
3: Generate the buffers for sound always used - these stay resident until shutdown

for each level loaded
 Generate needed buffers
 Load data into buffer
 <play level>
 nuke buffers

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Re: Sound creation efficiency
« Reply #2 on: January 24, 2006, 16:50:57 »
Quote from: "elias4444"
So, how do some of you handle this:

In my game, there's a lot of sounds... and many of my sound files are used over and over again (and overlap quite often). That seems to rule out reusing the same OpenAL sound instance, since I have to set it's position and then replay (and hence you could only have one of that sound playing at a time, correct?).

SO, I've gone to caching the sound data, and then creating a new OpenAL sound for each event that occurs (so each can have a different position). And when the sound is finished playing, it's destroyed.

Is this efficient? Is there a better way I should be doing this?


I'm not sure I understand, but I'd like to point out that sound data is stored in OpenAL buffers, while sound playback is done through OpenAL sources. You can play a buffer through multiple sources.

 - elias

Sound creation efficiency
« Reply #3 on: January 24, 2006, 19:28:38 »
Right, and that's actually what I'm doing. First I load all the sounds in data buffers, and then I create a source for each instance of that sound. Only problem is that if I'm not good about clearing the source when I'm done using it, OpenAL clogs up after a while... am I doing that wrong? Or does it expect you to clear the source after it's finished?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline tomb

  • ***
  • 148
Sound creation efficiency
« Reply #4 on: January 25, 2006, 05:29:35 »
What do you mean by "clear the source". I can't remember there being any clear functions in OpenAL :wink:

...and what do you mean by "OpenAL clogs up after a while"? Be a bit more descriptive.

Now, if you are trying to say that you generate a new source every time you play a sound. And by clearing you mean that you don't delete the source, then you are doing it all terribly wrong.

What you need to do is generate (using alGenSources) as many sources as you need, or that are available, at the very beginning of your application. You will never generate or delete (using alDeleteSources) a source after the game is started. Got that?

When you need to play a sound you will iterate your sources to find one that is not playing. If there is none available you stop the least important sound and use it. Stopping a sound might introduce clicking so you can choose not to play the sound at all.

Sound creation efficiency
« Reply #5 on: January 25, 2006, 15:07:42 »
Meaning, I keep the sound data buffered, and use alSourcei and alSourcef to create a new source each time I need a sound. Once the sound is finished, I call alDeleteSources(sourceid) to clear it out. If I fail to call alDeleteSources(sourceid), the system hangs after a while. Sounds like I'm doing it wrong though. I did it that way because I like to attach a sound to each object created. Guess I'll need to find another way - maybe just attach a sound source and playtime to each object and then loop through to see which is the least important.  :?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com