LWJGL
May 25, 2013, 04:58:58 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Sound creation efficiency  (Read 4956 times)
elias4444
Nerdus Imperius
*****
Posts: 636



WWW
« on: January 23, 2006, 10: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?
Logged

=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com
Matzon
Administrator
Demigod
*****
Posts: 2239



« Reply #1 on: January 23, 2006, 11: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
Logged

elias
Nerdus Imperius
*****
Posts: 899



WWW
« Reply #2 on: January 24, 2006, 08: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
Logged

elias4444
Nerdus Imperius
*****
Posts: 636



WWW
« Reply #3 on: January 24, 2006, 11: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?
Logged

=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com
tomb
Talks Too Much
***
Posts: 148


« Reply #4 on: January 24, 2006, 21: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.
Logged
elias4444
Nerdus Imperius
*****
Posts: 636



WWW
« Reply #5 on: January 25, 2006, 07: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.  :?
Logged

=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!