nCine 2025.06.r503-24a4688
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
ncine::IAudioPlayer Class Referenceabstract

Audio player interface class. More...

#include <IAudioPlayer.h>

Inheritance diagram for ncine::IAudioPlayer:
Inheritance graph
[legend]
Collaboration diagram for ncine::IAudioPlayer:
Collaboration graph
[legend]

Public Types

enum class  PlayerState { INITIAL = 0 , PLAYING , PAUSED , STOPPED }
 Player state.
 
- Public Types inherited from ncine::Object
enum class  ObjectType {
  BASE = 0 , TEXTURE , SHADER , SCENENODE ,
  SPRITE , MESH_SPRITE , ANIMATED_SPRITE , PARTICLE ,
  PARTICLE_SYSTEM , FONT , TEXTNODE , AUDIOBUFFER ,
  AUDIOBUFFER_PLAYER , AUDIOSTREAM_PLAYER
}
 Object types.
 

Public Member Functions

 IAudioPlayer (ObjectType type, const char *name)
 
 IAudioPlayer (ObjectType type)
 
 IAudioPlayer (IAudioPlayer &&)=default
 Default move constructor.
 
IAudioPlayeroperator= (IAudioPlayer &&)=default
 Default move assignment operator.
 
bool hasSource () const
 Returns true if a valid OpenAL source is currently assigned to the player.
 
unsigned int sourceId () const
 Returns the OpenAL id of the player source.
 
virtual unsigned int bufferId () const =0
 Returns the OpenAL id of the currently playing buffer.
 
virtual int bytesPerSample () const =0
 Returns the number of bytes per sample.
 
virtual int numChannels () const =0
 Returns the number of audio channels of the currently playing buffer.
 
virtual int frequency () const =0
 Returns the samples frequency of the currently playing buffer.
 
virtual unsigned long int numSamples () const =0
 Returns the number of samples.
 
virtual float duration () const =0
 Returns the duration in seconds.
 
virtual unsigned long bufferSize () const =0
 Returns the size of the currently playing buffer in bytes.
 
int sampleOffset () const
 Returns the playback position expressed in samples.
 
void setSampleOffset (int offset)
 Sets the playback position expressed in samples.
 
bool isSourceLocked () const
 Returns true if the OpenAL source is locked.
 
void setSourceLocked (bool sourceLocked)
 Locks an OpenAL source so it is not released to the pool when the player stops.
 
virtual void play ()=0
 Starts playing.
 
virtual void pause ()=0
 Pauses playing.
 
virtual void stop ()=0
 Stops playing and rewinds.
 
PlayerState state () const
 Returns the state of the player.
 
bool isPlaying () const
 Returns true if the player is playing.
 
bool isPaused () const
 Returns true if the player is paused.
 
bool isStopped () const
 Returns true if the player is stopped.
 
bool isLooping () const
 Returns the looping property of the player.
 
void setLooping (bool isLooping)
 Sets the looping property of the player.
 
float gain () const
 Returns the player gain value.
 
void setGain (float gain)
 Sets the player gain value.
 
float pitch () const
 Returns the player pitch value.
 
void setPitch (float pitch)
 Sets the player pitch value.
 
Vector3f position () const
 Returns the player position vector.
 
void setPosition (const Vector3f &position)
 Sets the player position vector.
 
void setPosition (float x, float y, float z)
 Sets the player position vector through components.
 
Vector3f velocity () const
 Returns the player velocity vector.
 
void setVelocity (const Vector3f &velocity)
 Sets the player velocity vector.
 
void setVelocity (float x, float y, float z)
 Sets the player velocity vector through components.
 
Vector3f direction () const
 Returns the player direction vector.
 
void setDirection (const Vector3f &direction)
 Sets the player direction vector.
 
void setDirection (float x, float y, float z)
 Sets the player direction vector through components.
 
float coneInnerAngle () const
 Returns the player inside angle of the sound cone in degrees.
 
void setConeInnerAngle (float coneAngle)
 Sets the player inside angle of the sound cone in degrees.
 
float coneOuterAngle () const
 Returns the player outside angle of the sound cone in degrees.
 
void setConeOuterAngle (float coneAngle)
 Sets the player outside angle of the sound cone in degrees.
 
float coneOuterGain () const
 Returns the player multiplication factor to determine the gain outside the cone.
 
void setConeOuterGain (float gain)
 Sets the player multiplication factor to determine the gain outside the cone.
 
- Public Member Functions inherited from ncine::Object
 Object (ObjectType type)
 Constructs an object with a specified type and adds it to the index.
 
 Object (ObjectType type, const char *name)
 Constructs an object with a specified type and name and adds it to the index.
 
virtual ~Object ()
 Removes an object from the index and then destroys it.
 
 Object (Object &&other)
 Move constructor.
 
Objectoperator= (Object &&other)
 Move assignment operator.
 
unsigned int id () const
 Returns the object identification number.
 
ObjectType type () const
 Returns the object type (RTTI)
 
const char * name () const
 Returns the object name.
 
void setName (const char *name)
 Sets the object name.
 

Static Public Attributes

static const float MinGain = 0.0f
 
static const float DefaultGain = 1.0f
 
static const float MaxGain = 1.0f
 
static const float MinPitch = 0.5f
 
static const float DefaultPitch = 1.0f
 
static const float MaxPitch = 2.0f
 
static const float MinConeAngle = 0.0f
 
static const float DefaultConeAngle = 360.0f
 
static const float MaxConeAngle = 360.0f
 
static const float MinConeOuterGain = 0.0f
 
static const float DefaultConeOuterGain = 0.0f
 
static const float MaxConeOuterGain = 1.0f
 
static const float MinAirAbsorptionFactor = 0.0f
 
static const float DefaultAirAbsorptionFactor = 0.0f
 
static const float MaxAirAbsorptionFactor = 10.0f
 
static const float MinRoomRolloffFactor = 0.0f
 
static const float DefaultRoomRolloffFactor = 0.0f
 
static const float MaxRoomRolloffFactor = 10.0f
 
static const float MinConeOuterGainHF = 0.0f
 
static const float DefaultConeOuterGainHF = 0.0f
 
static const float MaxConeOuterGainHF = 1.0f
 
- Static Public Attributes inherited from ncine::Object
static const unsigned int MaxNameLength = 128
 Maximum length for an object name.
 

Protected Member Functions

virtual void updateState ()=0
 Updates the state of the player if the source has finished playing.
 
void applySourceProperties ()
 Applies source properties after registering a player.
 
- Protected Member Functions inherited from ncine::Object
 Object (const Object &other)
 Protected copy constructor used to clone objects.
 

Protected Attributes

unsigned int sourceId_
 The OpenAL source id.
 
bool sourceLocked_
 The flag indicating if an OpenAL source is locked and never released to the pool.
 
PlayerState state_
 Current player state.
 
bool isLooping_
 Looping status flag.
 
float gain_
 Player gain value.
 
float pitch_
 Player pitch value.
 
Vector3f position_
 Player position in space.
 
Vector3f velocity_
 Player velocity in space.
 
Vector3f direction_
 Player direction in space.
 
float coneInnerAngle_
 Inside angle of the sound cone in degrees.
 
float coneOuterAngle_
 Outside angle of the sound cone in degrees.
 
float coneOuterGain_
 Multiplication factor to determine the gain outside the cone.
 
float airAbsorptionFactor_
 Player air absorption factor value.
 
float roomRooloffFactor_
 Player room rolloff factor value.
 
float coneOuterGainHF_
 Player cone outer gain HF value.
 
unsigned int effectSlotId_
 The OpenAL effect slot id to use when playing.
 
unsigned int auxFilterId_
 The OpenAL auxiliary filter id to use when playing.
 
unsigned int directFilterId_
 The OpenAL direct filter id to use when playing.
 
- Protected Attributes inherited from ncine::Object
ObjectType type_
 Object type.
 

Friends

class ALAudioDevice
 

Additional Inherited Members

- Static Public Member Functions inherited from ncine::Object
static ObjectType sType ()
 Static method to return class type.
 
template<class T >
static T * fromId (unsigned int id)
 Returns a casted pointer to the object with the specified id, if any exists.
 

Detailed Description

Audio player interface class.

Member Function Documentation

◆ bufferId()

virtual unsigned int ncine::IAudioPlayer::bufferId ( ) const
pure virtual

Returns the OpenAL id of the currently playing buffer.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ bufferSize()

virtual unsigned long ncine::IAudioPlayer::bufferSize ( ) const
pure virtual

Returns the size of the currently playing buffer in bytes.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ bytesPerSample()

virtual int ncine::IAudioPlayer::bytesPerSample ( ) const
pure virtual

Returns the number of bytes per sample.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ duration()

virtual float ncine::IAudioPlayer::duration ( ) const
pure virtual

Returns the duration in seconds.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ frequency()

virtual int ncine::IAudioPlayer::frequency ( ) const
pure virtual

Returns the samples frequency of the currently playing buffer.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ numChannels()

virtual int ncine::IAudioPlayer::numChannels ( ) const
pure virtual

Returns the number of audio channels of the currently playing buffer.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ numSamples()

virtual unsigned long int ncine::IAudioPlayer::numSamples ( ) const
pure virtual

Returns the number of samples.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ pause()

virtual void ncine::IAudioPlayer::pause ( )
pure virtual

Pauses playing.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ play()

virtual void ncine::IAudioPlayer::play ( )
pure virtual

Starts playing.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ setDirection() [1/2]

void ncine::IAudioPlayer::setDirection ( const Vector3f direction)

Sets the player direction vector.

Note
Setting all components to zero will make the player omnidirectional

◆ setDirection() [2/2]

void ncine::IAudioPlayer::setDirection ( float  x,
float  y,
float  z 
)

Sets the player direction vector through components.

Note
Setting all components to zero will make the player omnidirectional

◆ setSourceLocked()

void ncine::IAudioPlayer::setSourceLocked ( bool  sourceLocked)

Locks an OpenAL source so it is not released to the pool when the player stops.

Note
Locking an OpenAL source can be useful to retain source, effect, and filter properties

◆ stop()

virtual void ncine::IAudioPlayer::stop ( )
pure virtual

Stops playing and rewinds.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

◆ updateState()

virtual void ncine::IAudioPlayer::updateState ( )
protectedpure virtual

Updates the state of the player if the source has finished playing.

It is called every frame by the IAudioDevice class and it is also responsible for buffer queueing/unqueueing in stream players.

Implemented in ncine::AudioBufferPlayer, and ncine::AudioStreamPlayer.

Member Data Documentation

◆ coneInnerAngle_

float ncine::IAudioPlayer::coneInnerAngle_
protected

Inside angle of the sound cone in degrees.

Note
The default value of 360 means that the inner angle covers the entire world.

◆ coneOuterAngle_

float ncine::IAudioPlayer::coneOuterAngle_
protected

Outside angle of the sound cone in degrees.

Note
The default value of 360 means that the outer angle covers the entire world.

◆ direction_

Vector3f ncine::IAudioPlayer::direction_
protected

Player direction in space.

Note
If all components are zero the player is omnidirectional

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