e2d::audio::Sound Class Reference

List of all members.

Detailed Description

A sound can be either a music or a sound effect, or any other kind of sound you may come up with. You can load a sound file from your disk, and play/pause/stop it with this class.

You can set a relative volume for this sound, so it can differentiate itself in volume from other sounds in the same group. For example, if this song is in group SOUND_GROUP_SFX, and the volume set for this group is 0.5, you can set a relative volume of 0.3 for this sound to end up with a volume of 0.8. Note that volume will always be between 0 and 1, so if the group volume is 0.3 and you set a relative volume of -0.5, the final volume for this sound will be 0.

Public Member Functions

 Sound (int group)
void CalculateVolume ()
 Calculates actual volume for this sound.
int GetGroup ()
 Returns the group assigned to this sound.
float GetRelativeVolume ()
 Returns the relative volume set for this sound.
audiere::OutputStreamPtr GetStream ()
 Gets a reference to Audiere's sound stream.
void Load (char *filename, bool streaming)
 Loads a sound file.
void Pause ()
 Pause or resume play.
void Play (bool repeat=false)
 Plays the sound.
void SetRelativeVolume (float volume)
 Sets the relative volume for this sound.
void Stop ()
 Stops the sound from playing.

Static Public Attributes

static const int SOUND_GROUP_SFX = 0
 Sound group for sound effects.
static const int SOUND_GROUP_MUSIC = 1
 Sound group for songs.

Constructor & Destructor Documentation

e2d::audio::Sound::Sound ( int  group  ) 

On this constructor you must define what group this sound belongs to. When you create an instance of this class, it is automatically added to its correspondent group in AudioManager. Note that there is no default constructor, so it is mandatory to define a group. The group can be any of the constants defined on this class, or any other int of your choice (this will create a separate group).

group sound group.

Member Function Documentation

void e2d::audio::Sound::CalculateVolume (  ) 

This method is used internally by Easy2D to set this sound's volume by using its relative volume and the volume set for its group in AudioManager. You don't need to call it.

int e2d::audio::Sound::GetGroup (  ) 

the group assigned to this sound.

float e2d::audio::Sound::GetRelativeVolume (  ) 

relative volume set for this sound.

audiere::OutputStreamPtr e2d::audio::Sound::GetStream (  ) 

With this method you can have direct access to Audiere's stream. You really must know what you are doing if you intend to call this method.

void e2d::audio::Sound::Load ( char *  filename,
bool  streaming 

Loads a sound. The file format can be any format supported by Audiere (http://audiere.sourceforge.net/). You can choose between loading the whole file to memory (recommended for sound effects), or streaming it from the disk (recommended for songs). If you choose to stream it but Audiere can't stream that file, then it will load it entirely instead of streaming it.

filename Path of the sound file.
streaming true to stream the file from disk, false to load it entirely into memory.
e2d::core::Exception if the file could not be opened. You may want to catch this exception and handle it, so your program does not terminate if a sound is not loaded (most games run nice without music).

void e2d::audio::Sound::Pause (  ) 

If Audiere recognizes this sound as "seekable", you may pause it, and you can resume playing from pause with this very method just by calling it again. If the sound is not seekable, or the sound is stopped, this method does nothing.

void e2d::audio::Sound::Play ( bool  repeat = false  ) 

Plays this sound.

repeat whether or not to loop.

void e2d::audio::Sound::SetRelativeVolume ( float  volume  ) 

Sets the relative volume for this sound.

volume the relative volume.

void e2d::audio::Sound::Stop (  ) 

Stops playing this sound.

Generated on Tue Dec 8 10:32:44 2009 for Easy2D by  doxygen 1.5.6