Audio Library Design
Eric Stock <[email protected]>
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <[email protected]> |
Hello, I have written a simple sound library for a windows video game. I am
providing functions for loading and playing a sound and also for streaming a
sound. I am supporting Ogg and Wave files.
here is an example of how the library can be used to load and play a sound:
handle = audioManger::Instance().PlaySound(const char* p_strSound); //load
and play
audioManger::Instance().SetVolume(handle, MAX_VOLUME); //the handle can
be used to manage the playback parameters of the sound
once the sound has finished playing, the handle becomes invalid and the
resources associated with that sound( AL_Buffers and AL_Sources) are
released back to the manager.
My problem is that every time I want to load and play a sound I have to
load it from disk. This seems like a very poor design if I want to play a
sound effect many times during part of my application.
Here are 3 alternatives I have thought of :
1) Keep everything the way it is, and load the sound in a separate thread.
This should avoid any frame rate drops when loading.
2) a
Change the interface to be as follows:
handle = audioManager::Instance().LoadSound(const char* p_strSound);
//Loading would place the pcm data into an open AL buffer associated with
the sound
audioManager::Instance().PlaySound(handle); //The sound would be played as
expected
audioManager::Instance().DeleteSound(handle); //The buffer would be
returned to the audio manager
2) b
handle = audioManager::Instance().LoadSound(const char* p_strSound); //
pcm data would be placed in main memory
audioManager::Instance().PlaySound(handle); //an AL_Buffer would be
assigned to the sound, and the pcm data from memory would be loaded into the
AL_Buffer
//once
the sound completed playback, the AL_Buffer would be returned to the audio
manager so it can be used by other sources
audioManager::Instance().DeleteSound(handle); //The main memory where the
pcm data was stored would be freed.
I look forward to getting some feedback on these designs. Note, I am only
talking about load and play sounds here. I think I understand how to handle
the streaming of an ogg file, by loading the compressed data into memory and
then decompressing and streaming from the location in memory.
Regards,
Eric Stock
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal