cgv
Loading...
Searching...
No Matches
cgv::audio::OALSource Class Reference

This class describes a sound source in the scene. More...

#include <al_context.h>

Public Member Functions

 OALSource (const OALSource &)=delete
 
 OALSource (OALSource &&)=default
 
OALSourceoperator= (const OALSource &)=delete
 
OALSourceoperator= (OALSource &&)=default
 
bool init (OALContext &ctx, std::string sound_name="")
 This function links a source to a context.
 
void clear ()
 destruct source and restore uninitialized state
 
bool append_sound (std::string sound_name)
 Append buffer of named sound to source's playback list.
 
void set_position (cgv::math::fvec< float, 3 > pos)
 Sets the source position.
 
void set_velocity (cgv::math::fvec< float, 3 > vel)
 Sets the source velocity.
 
void set_pitch (float pitch)
 Sets the source pitch.
 
void set_gain (float gain)
 Sets the source gain.
 
void set_looping (bool should_loop)
 Sets the looping property of the source.
 
cgv::math::fvec< float, 3 > get_position () const
 Gets the source position.
 
cgv::math::fvec< float, 3 > get_velocity () const
 Gets the source velocity.
 
float get_pitch () const
 Gets the source pitch.
 
float get_gain () const
 Gets the source gain.
 
bool is_looping () const
 Determines if the source has the looping property.
 
bool is_playing () const
 Determines if the source is playing.
 
OALSourceState get_state () const
 returns state of this source
 
void play ()
 Commences the playback of the sound buffer.
 
void pause ()
 Pauses the playback of the sound buffer without moving the playhead.
 
void play_pause (bool should_play)
 Explicitly toggles between pausing and playing the sound buffer.
 
void stop ()
 Stops the playback of the sound buffer and moves the playhead to the beginning.
 
void rewind ()
 Moves the playhead to the beginning of the buffer.
 

Protected Member Functions

bool append_sound_impl (std::string sound_name)
 

Detailed Description

This class describes a sound source in the scene.

Definition at line 254 of file al_context.h.

Constructor & Destructor Documentation

◆ ~OALSource()

cgv::audio::OALSource::~OALSource ( )

Definition at line 247 of file al_context.cxx.

Member Function Documentation

◆ append_sound()

bool cgv::audio::OALSource::append_sound ( std::string  sound_name)

Append buffer of named sound to source's playback list.

Parameters
[in]sound_nameThe sounds symbolic name
Returns
True if attachment was successful, False otherwise.
Warning
Failes if source is playing or paused and not stopped.
See also
OALContext::load_sample()
OALContext::load_samples()

Definition at line 263 of file al_context.cxx.

References cgv::audio::OALContext::get_native_context().

◆ append_sound_impl()

bool cgv::audio::OALSource::append_sound_impl ( std::string  sound_name)
protected

Definition at line 269 of file al_context.cxx.

◆ clear()

void cgv::audio::OALSource::clear ( )

destruct source and restore uninitialized state

Definition at line 237 of file al_context.cxx.

References get_state(), and stop().

◆ get_gain()

float cgv::audio::OALSource::get_gain ( ) const

Gets the source gain.

Returns
The current gain of the source.

Definition at line 319 of file al_context.cxx.

◆ get_pitch()

float cgv::audio::OALSource::get_pitch ( ) const

Gets the source pitch.

Returns
The current pitch of the source.

Definition at line 312 of file al_context.cxx.

◆ get_position()

cgv::math::fvec< float, 3 > cgv::audio::OALSource::get_position ( ) const

Gets the source position.

Returns
The current position of the source.

Definition at line 298 of file al_context.cxx.

References cgv::math::fvec< T, N >::data().

◆ get_state()

OALSourceState cgv::audio::OALSource::get_state ( ) const

returns state of this source

Definition at line 340 of file al_context.cxx.

Referenced by clear().

◆ get_velocity()

cgv::math::fvec< float, 3 > cgv::audio::OALSource::get_velocity ( ) const

Gets the source velocity.

Returns
The current velocity of the source.

Definition at line 305 of file al_context.cxx.

References cgv::math::fvec< T, N >::data().

◆ init()

bool cgv::audio::OALSource::init ( OALContext ctx,
std::string  sound_name = "" 
)

This function links a source to a context.

Parameters
ctx_ptrThe OpenAL context
[in]sound_nameOptionally a named sound whose buffer to append
Returns
True if initialization was successful, False otherwise.
Warning
An internal reference to the given context is made. You need to make sure, that this object does not outlive the context.
See also
OALContext::load_sample()
OALContext::load_samples()

Definition at line 252 of file al_context.cxx.

References cgv::audio::OALContext::get_native_context(), and cgv::audio::OALContext::is_no_error().

◆ is_looping()

bool cgv::audio::OALSource::is_looping ( ) const

Determines if the source has the looping property.

Returns
True if the source is looping its buffer, False otherwise.

Definition at line 326 of file al_context.cxx.

◆ is_playing()

bool cgv::audio::OALSource::is_playing ( ) const

Determines if the source is playing.

Returns
True if the source is currently playing, False otherwise.

Definition at line 333 of file al_context.cxx.

◆ pause()

void cgv::audio::OALSource::pause ( )

Pauses the playback of the sound buffer without moving the playhead.

Definition at line 349 of file al_context.cxx.

Referenced by play_pause().

◆ play()

void cgv::audio::OALSource::play ( )

Commences the playback of the sound buffer.

Definition at line 347 of file al_context.cxx.

Referenced by play_pause().

◆ play_pause()

void cgv::audio::OALSource::play_pause ( bool  should_play)

Explicitly toggles between pausing and playing the sound buffer.

Parameters
[in]should_playTrue if the source should play, False if it should be paused.
Remarks
This function is provided as convenience to directly control the source with a boolean argument.

Definition at line 351 of file al_context.cxx.

References pause(), and play().

◆ rewind()

void cgv::audio::OALSource::rewind ( )

Moves the playhead to the beginning of the buffer.

Definition at line 363 of file al_context.cxx.

◆ set_gain()

void cgv::audio::OALSource::set_gain ( float  gain)

Sets the source gain.

Parameters
[in]gainThe new gain of the source

Definition at line 291 of file al_context.cxx.

◆ set_looping()

void cgv::audio::OALSource::set_looping ( bool  should_loop)

Sets the looping property of the source.

Parameters
[in]should_loopTrue if the source buffer should be looped, False otherwise.

Definition at line 293 of file al_context.cxx.

◆ set_pitch()

void cgv::audio::OALSource::set_pitch ( float  pitch)

Sets the source pitch.

Parameters
[in]pitchThe new pitch of the source

Definition at line 289 of file al_context.cxx.

◆ set_position()

void cgv::audio::OALSource::set_position ( cgv::math::fvec< float, 3 >  pos)

Sets the source position.

Parameters
[in]posThe new position of the source

Definition at line 285 of file al_context.cxx.

References cgv::math::fvec< T, N >::data().

◆ set_velocity()

void cgv::audio::OALSource::set_velocity ( cgv::math::fvec< float, 3 >  vel)

Sets the source velocity.

Parameters
[in]velThe new velocity of the source

Definition at line 287 of file al_context.cxx.

References cgv::math::fvec< T, N >::data().

◆ stop()

void cgv::audio::OALSource::stop ( )

Stops the playback of the sound buffer and moves the playhead to the beginning.

Definition at line 361 of file al_context.cxx.

Referenced by clear().


The documentation for this class was generated from the following files: