GePlaySnd Class Reference

#include <lib_snd.h>

Detailed Description

A class for playing sounds.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Normally one want to use the BaseSound class for the actual sound, as in this example:

return false;
if (!sound) return false;
if (!sound->Load(fn)) return false;
GeSndInfo sndinfo(sound);
if (!playsound) return false;
playsound->Open(sound);
playsound->Scrub(0, sndinfo.GetLength().Get());
while(playsound->IsPlaying())
{
}
playsound->Close();

Private Member Functions

 GePlaySnd ()
 
 ~GePlaySnd ()
 

Alloc/Free

static GePlaySndAlloc ()
 
static void Free (GePlaySnd *&data)
 

Miscellaneous

Bool Open (const BaseSound *snd)
 
Bool Open (Int32 stream_cnt, const BaseSound **streams, const Float *start_offsets, Float max_length)
 
void Close (void)
 
void StartAt (Float64 start)
 
void Scrub (Float64 start, Float64 duration)
 
void Stop (void)
 
Bool IsPlaying (void)
 
Float64 GetPositionEstimate (void)
 
void SetScale (Float64 scale)
 
Float64 GetScale (void)
 

Constructor & Destructor Documentation

◆ GePlaySnd()

GePlaySnd ( )
private

◆ ~GePlaySnd()

~GePlaySnd ( )
private

Member Function Documentation

◆ Alloc()

static GePlaySnd* Alloc ( )
static

Allocates a GePlaySnd instance. Destroy the allocated GePlaySnd instance with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated GePlaySnd instance, or nullptr if the allocation failed.

◆ Free()

static void Free ( GePlaySnd *&  data)
static

Destructs GePlaySnd instances allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]dataThe GePlaySnd instance to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Open() [1/2]

Bool Open ( const BaseSound snd)

The audio data referenced by the BaseSound will be kept in memory until Close() is called.

Parameters
[in]sndThe sound to use for playback. The caller owns the pointed sound.
Returns
true if successful, otherwise false.

◆ Open() [2/2]

Bool Open ( Int32  stream_cnt,
const BaseSound **  streams,
const Float start_offsets,
Float  max_length 
)

Opens an audio device with multiple BaseSounds that will be mixed. The audio data referenced by the BaseSounds will be kept in memory until Close() is called.

Parameters
[in]stream_cntThe number of sounds to be mixed.
[in]streamsThe array with the sounds.
[in]start_offsetsThe array with start time offsets in seconds (this is the audible sound data when StartAt(0) is called).
[in]max_lengthThe maximum length of the audio data in seconds (relative to StartAt(0)).
Returns
true if successful, otherwise false.

◆ Close()

void Close ( void  )

Closes the audio device.

Note
If the sounds used for Open() have been deleted in the meantime, their audio data will be released.

◆ StartAt()

void StartAt ( Float64  start)

Starts audio output.

Parameters
[in]startThe position relative to the start of the audio data in seconds.

◆ Scrub()

void Scrub ( Float64  start,
Float64  duration 
)
Parameters
[in]startThe position relative to the start of the audio data in seconds.
[in]durationThe scrub duration in seconds after which the audio device will be stopped.

◆ Stop()

void Stop ( void  )

Stops audio output.

◆ IsPlaying()

Bool IsPlaying ( void  )

Checks if the audio device is running

Returns
true if if audio is playing, otherwise false.

◆ GetPositionEstimate()

Float64 GetPositionEstimate ( void  )

Gets an estimate audio position.

Returns
The currently audible position in seconds.

◆ SetScale()

void SetScale ( Float64  scale)

Sets the playback time scale.

Parameters
[in]scaleThe playback scale value: 1.0 means real time, 2.0 means twice as fast, 0.5 means half the speed, 0.0 is invalid.

◆ GetScale()

Float64 GetScale ( void  )

Gets the current playback time scale.

Returns
The playback scale value: 1.0 means real time, 2.0 means twice as fast, 0.5 means half the speed, 0.0 is invalid.