lucadestudios team mailing list archive
-
lucadestudios team
-
Mailing list archive
-
Message #00002
OpenAL sound system for LuceneStudios project
Gents,
I've written down a few notes on the sound system for the LucadeStudios project. I thought I'd post them up for review.
Let me know if you have any queries or suggestions, this is just rough plan at this stage.
OBJECTIVE
Sound library, providing a high-level interface to the OpenAL library with a focus on games development.
Based on concepts from KALEngine, OGRE and Unity:
http://techbase.kde.org/Development/Tutorials/Games/KALEngine
http://www.ogre3d.org/wiki/index.php/OpenAL
http://unity3d.com/support/documentation/Manual/Sound.html
COMPONENTS
=== Manager ===
High-level controller for the sound system. In normal circumstances only one instance is needed. Sources are added to this before they can be played, and are made accessible by a user-defined key (stored in a hash map).
Future consideration: At a later stage it may be desirable to include a "addFromConfig()" call; to build the sound sources from declarations in the config_reader. This could be available in addition to the manual addSource() method.
init()
shutdown()
addSource(key, source)
getSource(key)
play(key)
stop(key)
pause(key)
=== Source Streams ===
- ogg_stream
- wav_stream
Sound sources, a source is initialised with a file name and passed to the manager with a key string. The associated file in a source stream is immutable, but other characteristics can be modified at any time (position, looping, volume, etc). As well as using the play() operation through the manager interface, you can also retrieve a reference to the stream and play it directly. By default, the sound data will be decompressed and loaded into a buffer on demand (when play() is invoked). This behaviour will be modifiable per sound stream, so that frequently triggered sounds can be available decompressed in memory.
Future consideration: In the first pass, sound sources will be able to have a position, but will be static. We should work out a mechanism for setting a direction and velocity as a next phase.
play()
stop()
pause()
storeInBuffer(bool)
setLooping(bool)
setPosition(float, float, float)
dropPosition()
=== Sound API Service ===
OpenAL will be abstracted from the manager, so we can support other API's in the future (e.g. to support a platform that is incompatible with OpenAL). Currently, it will be the default and only service available to the engine's sound system.
EXAMPLE USAGE
// Initialise the sound system
sound_manager mgr();
mgr.init();
// Add some sources, the keys can be any string - format is down to the caller
mgr.add_source("/global/menu/itemclick", new ogg_stream("beep.ogg"));
mgr.add_source("/enemy/actions/fireweapon", new ogg_stream("bang.ogg"));
// The sounds can be triggered from the manager
mgr.play("/global/menu/itemclick");
// Or, alternatively, a source can be retrieved later on, to manipulate it and/or play it directly
ogg_stream* _fire_weapon_sound = mgr.get_source("/enemy/actions/fireweapon");
_fire_weapon_sound->setPosition(50, 50, 0);
_fire_weapon_sound->play();
// Shut down the sound system when you're finished
// We could possibly make this automatic by applying a scoped_ptr to the openal_service, I'll follow whatever the standard convention in the project is...
mgr.shutdown();