TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Audio::AudioController Class Reference

#include <tb_audio_controller.h>

Public Member Functions

 AudioController (const AudioHandle &audioHandle=kInvalidAudio)
 
 AudioController (const AudioController &other)
 
 ~AudioController (void)
 
void Play (const bool isLooping=false)
 
void Pause (void)
 
void Stop (void)
 
void StopLooping (void)
 
float GetPitch (void) const
 
void SetPitch (const float pitch)
 
float GetVolume (void) const
 
void SetVolume (const float volume)
 
void FadeVolumeTo (const float desiredVolume, const tbCore::uint32 timeInMilliseconds)
 
void SetLoopPoints (const tbCore::uint32 startSample, const tbCore::uint32 endSample)
 
bool IsComplete (void) const
 

Friends

class AudioManager
 

Detailed Description

The AudioController gives control over an effect or music piece played by AudioManager::PlaySound() or AudioManager::PlayEvent(). This allows programmatically changing volume, pitch, play/pause/stop etc.

Constructor & Destructor Documentation

TurtleBrains::Audio::AudioController::AudioController ( const AudioHandle audioHandle = kInvalidAudio)
explicit

Constructs an AudioController, this may change and should be considered an implementation detail of TurtleBrains.

Parameters
audioHandleHandle to the audio that will be played/controlled by this controller.
TurtleBrains::Audio::AudioController::AudioController ( const AudioController other)

Constructs an AudioController from another AudioController as a copy constructor would.

TurtleBrains::Audio::AudioController::~AudioController ( void  )

Cleans up and destroys the AudioController, once destroyed the audio channel/sound effect it had been controlling cannot be stopped or modified. Make sure to stop looping audio as necessary before losing control of the controller.

Member Function Documentation

void TurtleBrains::Audio::AudioController::FadeVolumeTo ( const float  desiredVolume,
const tbCore::uint32  timeInMilliseconds 
)

Changes the volume of the effect/music that is playing over some amount of time.

Parameters
desiredVolumeHow loud the audio should play where 0.0 is silent and 1.0 is full volume. If a value is out of that range it will be clamped. A value of 1.2 will become 1.0.
timeInMillisecondsHow long to take in milliseconds before the desiredVolume is reached.
float TurtleBrains::Audio::AudioController::GetPitch ( void  ) const

Gets the pitch from the effect/music that is attached to a channel and returns that value, 0.5 being half speed, 1.0 being normal pith and 2.0 being twice as fast. If the effect/music is not attached to a channel then 0.0 will be returned.

float TurtleBrains::Audio::AudioController::GetVolume ( void  ) const

Gets the volume from the effect/music that is attached to a channel and returns that value, 0.0 being silent and 1.0 being full volume. If the effect/music is not attached to a channel then 0.0 will be returned.

bool TurtleBrains::Audio::AudioController::IsComplete ( void  ) const

Checks to see if the effect/music has finished completed and returns true if it is completed or not playing / attached to a channel.

void TurtleBrains::Audio::AudioController::Pause ( void  )

Abruptly stops the sound or music from playing, but will not reset to the start of the sound/music when Play is called. This will also keep the channel for the sound effect.

void TurtleBrains::Audio::AudioController::Play ( const bool  isLooping = false)

Continues playing the music/effect where it was last at if paused, or restarts from the beginning if it was stopped/not played yet.

Parameters
isLoopingWhen the end of the music/effect is reached it will restart from the beginning if this is set to true, otherwise will finish and free the channel once completed.
void TurtleBrains::Audio::AudioController::SetLoopPoints ( const tbCore::uint32  startSample,
const tbCore::uint32  endSample 
)

Setup custom sample points to loop between on a streaming audio effect/music allowing an intro, loop, exit. The controllers audio handle must be a streaming effect and an OGG file format.

Parameters
startSampleThe sample offset of the start point of the loop. 0 would be the start of the audio and is the default.
endSampleThe offset of the end of the loop, when reached the audio will jump back to startSample. This must be greater-than or equal-to startSample or an error condition will be triggered. If both startSample and endSample are equal, the entire audio data will be used for looping.
Note
If the audio player is already playing beyond the endSample, the audio player will not loop and will instead reach the end.
void TurtleBrains::Audio::AudioController::SetPitch ( const float  pitch)

Changes the pitch, 'speed / frequency' of the sound and how it plays. 1.0 plays at normal pitch while 0.5 plays at what seems to be half speed, much slower. 2.0 should be twice as fast as normal.

void TurtleBrains::Audio::AudioController::SetVolume ( const float  volume)

Changes the volume of the effect/music playing.

Parameters
volumeHow loud the audio should play where 0.0 is silent and 1.0 is full volume. If a value is out of that range it will be clamped. A value of 1.2 will become 1.0.
void TurtleBrains::Audio::AudioController::Stop ( void  )

Abruptly stops the sound or music from playing and when Play is called again it will start from the beginning of the effect/music. This also frees the channel to be used by other effects.

void TurtleBrains::Audio::AudioController::StopLooping ( void  )

Removes a looping flag from the sound so it will continue to play through until it finishes and then it will stop playing. Does not abruptly stop the sound.