CUGL 2.1
Cornell University Game Library
|
#include <CUAudioPlayer.h>
Public Member Functions | |
AudioPlayer () | |
~AudioPlayer () | |
bool | init (const std::shared_ptr< AudioSample > &source) |
virtual void | dispose () override |
std::shared_ptr< AudioSample > | getSource () |
virtual Uint32 | read (float *buffer, Uint32 frames) override |
virtual bool | completed () override |
virtual bool | mark () override |
virtual bool | unmark () override |
virtual bool | reset () override |
virtual Sint64 | advance (Uint32 frames) override |
virtual Sint64 | getPosition () const override |
virtual Sint64 | setPosition (Uint32 position) override |
virtual double | getElapsed () const override |
virtual double | setElapsed (double time) override |
virtual double | getRemaining () const override |
virtual double | setRemaining (double time) override |
Public Member Functions inherited from cugl::audio::AudioNode | |
AudioNode () | |
virtual | ~AudioNode () |
virtual bool | init () |
virtual bool | init (Uint8 channels, Uint32 rate) |
Uint8 | getChannels () const |
Uint32 | getRate () const |
float | getGain () |
virtual void | setGain (float gain) |
const std::string & | getClassName () const |
const std::string & | getName () const |
void | setName (const std::string name) |
Sint32 | getTag () const |
void | setTag (Sint32 tag) |
virtual std::string | toString (bool verbose=false) const |
operator std::string () const | |
Callback | getCallback () |
void | setCallback (Callback callback) |
virtual bool | isPaused () |
virtual bool | pause () |
virtual bool | resume () |
Static Public Member Functions | |
static std::shared_ptr< AudioPlayer > | alloc (const std::shared_ptr< AudioSample > &sample) |
Protected Attributes | |
std::shared_ptr< AudioSample > | _source |
std::shared_ptr< AudioDecoder > | _decoder |
std::atomic< Uint64 > | _offset |
std::atomic< Uint64 > | _marked |
float * | _buffer |
float * | _chunker |
Uint32 | _chksize |
Uint32 | _chklimt |
Uint32 | _chklast |
std::atomic< bool > | _dirty |
Protected Attributes inherited from cugl::audio::AudioNode | |
Uint8 | _channels |
Uint32 | _sampling |
bool | _booted |
std::atomic< float > | _ndgain |
std::atomic< bool > | _paused |
std::atomic< bool > | _polling |
Callback | _callback |
std::atomic< bool > | _calling |
Sint32 | _tag |
std::string | _localname |
std::string | _classname |
size_t | _hashOfName |
Additional Inherited Members | |
Public Types inherited from cugl::audio::AudioNode | |
enum | Action : int { COMPLETE = 0, INTERRUPT = 1, FADE_OUT = 2, FADE_IN = 3, FADE_DIP = 4, LOOPBACK = 5 } |
typedef std::function< void(const std::shared_ptr< AudioNode > &node, Action type)> | Callback |
Static Public Attributes inherited from cugl::audio::AudioNode | |
const static Uint32 | DEFAULT_CHANNELS |
const static Uint32 | DEFAULT_SAMPLING |
Protected Member Functions inherited from cugl::audio::AudioNode | |
void | notify (const std::shared_ptr< AudioNode > &node, Action action) |
This class represents a playback instance for AudioPlayback.
A single sound asset may have multiple instances playing simultaneously, particularly in the case of sound effects. This node allows us to keep the playback distinct for each instance.
A player can be reset and can jump to anywhere in the sounds. However, it cannot be set to loop or sequence two sound assets together. To do that you should combine this node with AudioScheduler.
This class is medium-weight, and has a lot of buffers to support stream decoding (when appropriate). In practice, it may be best to create a memory pool of preallocated players (which are reinitialized) than to construct them on the fly.
A player is always associated with a node in the audio graph. As such, it should only be accessed in the main thread. In addition, no methods marked as AUDIO THREAD ONLY should ever be accessed by the user. The only exception to this rule is by another (custom) audio graph node in its audio thread methods.
This class does not support any actions for the AudioNode#setCallback. Fade in/out and scheduling have been refactored into other nodes to provide proper audio patch support.
cugl::audio::AudioPlayer::AudioPlayer | ( | ) |
Creates a degenerate audio player with no associated source.
The player has no channels or source file, so read options will do nothing. The player must be initialized to be used.
|
inline |
Deletes this audio player, disposing of all resources.
|
overridevirtual |
Advances the stream by the given number of frames.
This method only advances the read position, it does not actually read data into a buffer.
frames | The number of frames to advace |
Reimplemented from cugl::audio::AudioNode.
|
inlinestatic |
Returns a newly allocated player for the given audio sample.
The player will either be streamed or buffered, depending on the type of audio sample. We do not require separate players for each type.
sample | the audio sample to be played. |
|
overridevirtual |
Returns true if this audio node has no more data.
A completed audio node is one that will return 0 (no frames read) on subsequent threads read.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Disposes any resources allocated for this player
The state of the node is reset to that of an uninitialized constructor. Unlike the destructor, this method allows the node to be reinitialized.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Returns the elapsed time in seconds.
The value returned is always measured from the start of the steam, regardless of the presence of any marks.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Returns the current frame position of this audio node
The value returned will always be the absolute frame position regardless of the presence of any marks.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Returns the remaining time in seconds.
The remaining time is duration from the current read position to the end of the sample. It is not effected by any fade-out.
Reimplemented from cugl::audio::AudioNode.
|
inline |
Returns the source for this instance
bool cugl::audio::AudioPlayer::init | ( | const std::shared_ptr< AudioSample > & | source | ) |
Initializes a player for the given audio sample.
The player will be set for a single playthrough of this given sample. However the player may be reset or reinitialized.
source | The audio sample to be played. |
|
overridevirtual |
Marks the current read position in the audio steam.
This method is used by reset() to determine where to restore the read position.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Reads up to the specified number of frames into the given buffer
AUDIO THREAD ONLY: Users should never access this method directly. The only exception is when the user needs to create a custom subclass of this AudioNode.
The buffer should have enough room to store frames * channels elements. The channels are interleaved into the output buffer.
This method will always forward the read position after reading. Reading again may return different data.
buffer | The read buffer to store the results |
frames | The maximum number of frames to read |
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Resets the read position to the marked position of the audio stream.
If no mark is set, this will reset to the player to the beginning of the audio sample.
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Sets the read position to the elapsed time in seconds.
The value returned is always measured from the start of the steam, regardless of the presence of any marks.
time | The elapsed time in seconds. |
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Sets the current frame position of this audio node.
The value set will always be the absolute frame position regardless of the presence of any marks.
position | the current frame position of this audio node. |
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Sets the remaining time in seconds.
This method will move the read position so that the distance between it and the end of the same is the given number of seconds.
time | The remaining time in seconds. |
Reimplemented from cugl::audio::AudioNode.
|
overridevirtual |
Clears the current marked position.
Clearing the mark in a player is equivelent to setting the mark at the beginning of the audio asset. Future calls to reset() will return to the start of the audio stream.
Reimplemented from cugl::audio::AudioNode.
|
protected |
A reference to the underlying data buffer (IN-MEMORY ACCESS)
|
protected |
The number of the last read frame in the chunk
|
protected |
The pointer to the last available frame in the chunk
|
protected |
The size of a single chunk in frames
|
protected |
A buffer for storing each chunk as we need it
|
protected |
The decoder for the current asset
|
protected |
Whether or not we need to reposition (STREAMING ACCESS)
|
protected |
The last marked position (starts at 0)
|
protected |
The current read position
|
protected |
The original source for this instance