nCine::IAudioPlayer class

Interface for an audio player.

Common base for AudioBufferPlayer and AudioStreamPlayer. Wraps a single OpenAL source and exposes playback control together with gain, pitch, low-pass and 3D positioning.

Base classes

class Object
Base class of all nCine objects.

Derived classes

class AudioBufferPlayer
Plays back a fully decoded AudioBuffer.
class AudioStreamPlayer
Plays back an AudioStream decoded on the fly.

Public types

enum class PlayerState { Initial = 0, Playing, Paused, Stopped }
Playback state.

Constructors, destructors, conversion operators

IAudioPlayer(ObjectType type)
~IAudioPlayer() override
IAudioPlayer(IAudioPlayer&&) defaulted

Public functions

auto operator=(IAudioPlayer&&) -> IAudioPlayer& defaulted
auto sourceId() const -> std::uint32_t
Returns the OpenAL id of the source.
auto bufferId() const -> std::uint32_t pure virtual
Returns the OpenAL id of the currently playing buffer.
auto bytesPerSample() const -> std::int32_t pure virtual
Returns the number of bytes per sample.
auto numChannels() const -> std::int32_t pure virtual
Returns the number of audio channels of the currently playing buffer.
auto frequency() const -> std::int32_t pure virtual
Returns the sample frequency of the currently playing buffer.
auto numSamples() const -> std::int32_t pure virtual
Returns the total number of samples.
auto duration() const -> float pure virtual
Returns the duration in seconds.
auto bufferSize() const -> std::int32_t pure virtual
Returns the size of the currently playing buffer in bytes.
auto sampleOffset() const -> std::int32_t virtual
Returns the current playback position in samples.
void setSampleOffset(std::int32_t offset) virtual
Sets the current playback position in samples.
void play() pure virtual
Starts or resumes playback.
void pause() pure virtual
Pauses playback at the current position.
void stop() pure virtual
Stops playback and rewinds to the beginning.
auto state() const -> PlayerState
Returns the current playback state.
auto isPlaying() const -> bool
Returns true if the player is currently playing.
auto isPaused() const -> bool
Returns true if the player is paused.
auto isStopped() const -> bool
Returns true if the player is stopped.
auto isLooping() const -> bool
Returns true if the player is looping.
void setLooping(bool value) virtual
Sets whether the player should loop.
auto isSourceRelative() const -> bool
Returns true if the position is relative to the listener.
void setSourceRelative(bool value) virtual
Sets whether the position is relative to the listener.
auto isAs2D() const -> bool
Returns true if the player is forced to behave as a 2D source.
void setAs2D(bool value) virtual
Sets whether the player should behave as a 2D source.
auto gain() const -> float
Returns the player gain.
void setGain(float gain) virtual
Sets the player gain.
auto pitch() const -> float
Returns the player pitch.
void setPitch(float pitch) virtual
Sets the player pitch.
auto lowPass() const -> float
Returns the player low-pass amount.
void setLowPass(float value) virtual
Sets the player low-pass amount.
auto position() const -> Vector3f
Returns the player position.
void setPosition(const Vector3f& position) virtual
Sets the player position.

Protected functions

void updateState() pure virtual
Updates the player state once the source has finished playing.
void updateFilters() virtual
auto getAdjustedPosition(IAudioDevice& device, const Vector3f& pos, bool isSourceRelative, bool isAs2D) -> Vector3f virtual
void setPositionInternal(const Vector3f& position)

Enum documentation

enum class nCine::IAudioPlayer::PlayerState

Playback state.

Enumerators
Initial

Created but never played

Playing

Currently playing

Paused

Paused, can be resumed from the current position

Stopped

Stopped and rewound to the beginning

Function documentation

void nCine::IAudioPlayer::updateState() pure virtual protected

Updates the player state once the source has finished playing.

Called every frame by IAudioDevice. In stream players it is also responsible for queueing and unqueueing buffers.