xyginext  0.2.0
Second generation of xygine game creation framework
Public Types | Public Member Functions | Friends | List of all members
xy::AudioEmitter Class Referencefinal

Audio emitter component. Audio emitter provide points within the scene to play audio, either one shot effects or streaming music. If the buffer used to supply the audio is monothen the AudioEmitter will be panned spatially relative to the current listener (usually the active scene camera), unless it has been set to absolute positioning. Requires a scene to have an AudioSystem. More...

#include <AudioEmitter.hpp>

Public Types

enum  Status { Stopped = 0, Paused, Playing }
 

Public Member Functions

 AudioEmitter ()
 Constructor. When AudioEmitters are first created they are in an invalid state, and will not play any sound until setSource() has been called to assign a valid sound source.
 
 AudioEmitter (AudioEmitter &&)=default
 Move constructor. AudioEmitters are moveable but non-copyable.
 
AudioEmitteroperator= (AudioEmitter &&)=default
 
 AudioEmitter (const AudioEmitter &)=delete
 
AudioEmitteroperator= (const AudioEmitter &)=delete
 
void setSource (const sf::SoundBuffer &)
 Sets the source of the emitter to a buffer shared between one or more emitters to play sounds fully loaded in memory. This is usually applied to short sounds used as sfx. This will remove any existing audio source, including any which are loaded as streaming sources.
 
bool setSource (const std::string &path)
 Sets the source of the emitter to stream a file at a given path. Usually longer audio such as music should be streamed rather than loading it entirely into memory. This will remove any existing sound source, even if loading fails. More...
 
bool hasSource () const
 Returns true if the emitter has been initialised with a sound source.
 
void play ()
 Plays the emitter's sound source if there is one.
 
void pause ()
 Pauses any currently playing audio.
 
void stop ()
 Stops any playing audio, and rewinds the audio to the beginning if it is playing or paused.
 
void setPitch (float)
 
void setVolume (float)
 
void setPosition (sf::Vector3f)
 Set the 3D position of the emitter in world coordinates. This is automatically overriden if the entity to which this emitter is attached also has a Transform component and exists in a scene that contains an AudioSystem. This also has no effect if the source for this component is stereo.
 
void setRelativeTolistener (bool)
 Sets whether or not this sound is panned relatively to the active listener. Does not affect stereo sound sources.
 
void setMinDistance (float)
 Sets the minimum distance at which the emitter starts to fade, when relative to the active listener.
 
void setAttenuation (float)
 Sets the rolloff, ie how quickly the sound fades with distance from the listener.
 
void setLooped (bool)
 Sets whether or not this sound should be played looped.
 
void setChannel (sf::Uint8)
 Sets the channel in the Audio mixer. Emitters can be assigned mixer channels which in turn affect the volume of all sounds assigned to the channel. For example you may wish to assign all sound effects to channel 2, and UI sounds to channel 3. This way sound effects can have their volume adjusted independently of UI effects. By default all emitters are assigned to channel 0. More...
 
void setPlayingOffset (sf::Time)
 Set the playing offset in Time since the beginning.
 
float getPitch () const
 Returns the current playback pitch of the emitter.
 
float getVolume () const
 Returns the current playback volume of the emitter.
 
sf::Vector3f getPosition () const
 Returns the current 3D position of the emitter in world coordinates This only applies to mono sounds which are not automatically panned by their entitiy's transform component.
 
bool isRelativeToListener () const
 Returns whether or not this emitter is set tot be panned relatively to the active listener.
 
float getMinDistance () const
 Returns the minimum distance from the listener at which the emitter's volume starts to fade.
 
float getAttenuation () const
 Returns the current attentuaton value.
 
bool isLooped () const
 Returns whether or not this emitter's sound is set to play looped.
 
sf::Uint8 getChannel () const
 Returns the current mixer channel assignment.
 
Status getStatus () const
 Returns the current status of the sound. Can be Playing, Paused or Stopped.
 
sf::Time getDuration () const
 Returns the total duration of the audio associated with this emitter.
 
sf::Time getPlayingOffset () const
 Returns the current playing offset from the beginning of the audio associated with this emitter.
 
void applyMixerSettings (float multiplier=1.f)
 Applies the current mixer channel settings. Generally only used by audio systems which need to update an emitter with any changes in the mixer panel. More...
 
bool isStreaming () const
 Returns true if the audio is from a streaming source, else returns false.
 
void update ()
 Used by AudioSystem to update the internal state. Calling this else where will probably have no effect, however should be called once per frame by any custom audio systems.
 

Friends

class AudioSystem
 

Detailed Description

Audio emitter component. Audio emitter provide points within the scene to play audio, either one shot effects or streaming music. If the buffer used to supply the audio is monothen the AudioEmitter will be panned spatially relative to the current listener (usually the active scene camera), unless it has been set to absolute positioning. Requires a scene to have an AudioSystem.

Member Function Documentation

◆ applyMixerSettings()

void xy::AudioEmitter::applyMixerSettings ( float  multiplier = 1.f)

Applies the current mixer channel settings. Generally only used by audio systems which need to update an emitter with any changes in the mixer panel.

Parameters
multiplierUsed to multiply the final output of the emitter audio for fade or dimming effects

◆ setChannel()

void xy::AudioEmitter::setChannel ( sf::Uint8  )

Sets the channel in the Audio mixer. Emitters can be assigned mixer channels which in turn affect the volume of all sounds assigned to the channel. For example you may wish to assign all sound effects to channel 2, and UI sounds to channel 3. This way sound effects can have their volume adjusted independently of UI effects. By default all emitters are assigned to channel 0.

See also
Mixer

◆ setSource()

bool xy::AudioEmitter::setSource ( const std::string &  path)

Sets the source of the emitter to stream a file at a given path. Usually longer audio such as music should be streamed rather than loading it entirely into memory. This will remove any existing sound source, even if loading fails.

Returns
true if the source was opened successfully, else false