Source

Simple OO wrapper around an OpenAL source, defines the interface used for Sample and Music.

Source is a template class and can not be used directly, use either Sample or Music.  Sample is for playing small files such as sound effects.  Music is for streaming files such as background music.

Operators

  • Source = Source
  • bool : True if source has loaded buffer, false if not.
  • ostream& << Source
Summary
Simple OO wrapper around an OpenAL source, defines the interface used for Sample and Music.
Default constructor, initalizes internal state of Source.
Copy constructor, copies another Source.
Initializing constructor, loads Source via call to open.
Destructor for source, frees the OpenAL source resource.
Opens an audio file, supported formats are WAV and Ogg.
Starts the playback of the sound attached to the source.
Stops the playback of the sound attached to the source.
Pauses the playback of the sound attached to the source.
Rewinds the position of the sound attached to the source.
Sets if the source’s sound is looping or is played only once.
Determine status of Source.
Determine if source is playing.
Determine if source is looping.
Define a new named resource.
Define a new unaliased resource.

(Con/ De)structors

Source

Source()

Default constructor, initalizes internal state of Source.

Source

Source(const Source &rhs)

Copy constructor, copies another Source.

Parameters

rhsSource to construct copy of.

Source

Source(const std::string &name)

Initializing constructor, loads Source via call to open.

Parameters

nameName of the Source <Resource> to open.

See Also

open

~Source

~Source()

Destructor for source, frees the OpenAL source resource.

General

open

void open(const std::string &name)

Opens an audio file, supported formats are WAV and Ogg.

Parameters

nameName of the Source <Resource> to open.

Source Control

play

void play()

Starts the playback of the sound attached to the source.

stop

void stop()

Stops the playback of the sound attached to the source.

pause

void pause()

Pauses the playback of the sound attached to the source.

rewind

void rewind()

Rewinds the position of the sound attached to the source.

setLooping

void setLooping(bool loop)

Sets if the source’s sound is looping or is played only once.

Parameters

loopIf true, will make sound loop, otherwise will play only once.

Accessors

isValid

bool isValid() const

Determine status of Source.

Returns

True if source is loaded, false if source is not loaded/initialized.

isPlaying

bool isPlaying() const

Determine if source is playing.

Returns

True if source is playing, false if source is stopped.

isLooping

bool isLooping() const

Determine if source is looping.

Returns

True if source is looping, false if source is not looping.

Resource Creation

addResource

static void addResource(const std::string &name,
const std::string &path)

Define a new named resource.  (Ex.  Image::addResource(“monkey”,”images/monkey.png”) would make it so that any attempts to load “monkey” would load the image images/monkey.png)

Parameters

nameName to give to resource.
pathPath of resource data file.

addResource

static void addResource(const std::string &path)

Define a new unaliased resource.  (name == path).  (Ex.  Image::addResource(“images/monkey.png”) is essentially the same as Image::addResource(“images/monkey.png”,”images/monkey.png”)

Parameters:. path - Path of resource data file.

Source()
Default constructor, initalizes internal state of Source.
void open(const std::string &name)
Opens an audio file, supported formats are WAV and Ogg.
~Source()
Destructor for source, frees the OpenAL source resource.
void play()
Starts the playback of the sound attached to the source.
void stop()
Stops the playback of the sound attached to the source.
void pause()
Pauses the playback of the sound attached to the source.
void rewind()
Rewinds the position of the sound attached to the source.
void setLooping(bool loop)
Sets if the source’s sound is looping or is played only once.
bool isValid() const
Determine status of Source.
bool isPlaying() const
Determine if source is playing.
bool isLooping() const
Determine if source is looping.
static void addResource(const std::string &name,
const std::string &path)
Define a new named resource.