Sound Class C++

Started by
3 comments, last by mmakrzem 12 years, 10 months ago
Hello, I'm planning on integrating sound into my OpenGL engine and was wondering what a good class would be. I am planning on using OpenAL for sound, but the example i saw implied on loading every sound at initialization. how would i go about having a "sound manager" at run time? Maybe at initialization i would have an array of all the sounds needed in a level, and each object (ship, laser, level for music) would tell it when to load the sound, and also when to bind and play the sound. How long does this stuff take? I'm trying to discover a context here, the OpenAL windows example was great, but i dont know how much memory i have to load sounds, how many sounds i can bind at once, how many i can play? im thinking i have an RTS that will have shooting, music, explosions, and unit orders and ships flying around...... phew.... anyways.... can someone link me to an article that will enlighten me some more? haha thanks!!!!

------------------------------

redwoodpixel.com

Advertisement
I posted about the Crown and Cutlass resource system a while ago. Since then, we have implemented a sound system that makes use of the post-rewrite resource system. The basic idea is that we have a wrapper around the sound resource objects (a sound "resource" is basically an OpenAL buffer). When you create one of the wrapper objects, it acquires the resource and does all the OpenAL work to get it set up. When you play it, it just calls the OpenAL functions to play that buffer. The idea is pretty simple. We also have pushed our sound system into another thread, so our "wrappers" really just fire off events to the other thread to play or stop or whatever the audio. Unfortunately, that complicated the implementation significantly. If you want to see the code, look at the SoundSubSystem (.h / .cpp / doc) and SoundBuffer (.h / .cpp / doc) classes. You should be able to follow links to everything involved from there.

Note that our resource manager does not do any kind of memory usage limitation, although that may be able to be added without too much trouble. However, we do ensure that only the sounds that are being used are actually loaded. Also, the sound system creates a fixed number of OpenAL sources because certain AL implementation have a fixed number of sources they support. The sound system handles managing those so that when a sound is played it acquires an OpenAL source and revokes the source from the least recently played sound if necessary. We also do not currently support 3D sound positioning. However, I think it would be easy to just pass an event with the new 3D attributes to the sound system to do that.

I'm not sure you would want to use our code directly, but here is the Crown and Cutlass license, just in case. Hopefully that will help you get some ideas though. I'm in a rush at the moment, but if any of that doesn't make sense let me know and I can try to explain it more. Also, if you see issues with that code, I would be happy to hear about it. Good luck with your system.
wow thank you.... this is a good start.

------------------------------

redwoodpixel.com

Here is a class which implements openAL and provides a means of management:

http://elevatedpixels.com/?p=117
On my website, I create a video tutorial series that explans how to create an Audio manager for OpenAL. The video's step you through the entire process of how to create listeners, sources and streams, and also shows you how to load and playback WAV and OGG files.

This topic is closed to new replies.

Advertisement