CUGL 2.1
Cornell University Game Library
|
#include <CUAudioScheduler.h>
Public Member Functions | |
AudioNodeQueue () | |
~AudioNodeQueue () | |
bool | empty () const |
void | push (const std::shared_ptr< AudioNode > &node, Sint32 loops=0) |
bool | peek (std::shared_ptr< AudioNode > &node, Sint32 &loop) const |
bool | pop (std::shared_ptr< AudioNode > &node, Sint32 &loop) |
bool | fill (std::deque< std::shared_ptr< AudioNode >> &container) const |
void | clear () |
This class provides is a lock free producer-consumer queue,
This queue allows us to add buffers to the source node without interrupting playback. Its implementation is taken from
http://www.drdobbs.com/parallel/writing-lock-free-code-a-corrected-queue/210604448
This queue is only designed to support two threads. The producer is the main thread, while the consumer is the audio thread.
This queue does not have a lot of bells and whistles because it is only intended for thread synchronization. We expect the user to maintain what has and has not been appended to the queue.
cugl::audio::AudioNodeQueue::AudioNodeQueue | ( | ) |
Creates an empty player queue
cugl::audio::AudioNodeQueue::~AudioNodeQueue | ( | ) |
Disposes of the player queue, releasing all resources
void cugl::audio::AudioNodeQueue::clear | ( | ) |
Clears all elements in this queue.
This method is thread-safe
|
inline |
Returns true if the queue is empty.
This method is atomic and thread-safe
bool cugl::audio::AudioNodeQueue::fill | ( | std::deque< std::shared_ptr< AudioNode >> & | container | ) | const |
Stores all values in the provided dequeue.
This method only stores the values, not the loop settings. If the queue is empty, the deque is not altered and this method returns false.
This method is thread-safe ASSUMING that push is only ever called in the same thread (e.g. this is a producer method).
container | the container to store the values |
bool cugl::audio::AudioNodeQueue::peek | ( | std::shared_ptr< AudioNode > & | node, |
Sint32 & | loop | ||
) | const |
Looks at the front element this queue.
The element will be stored in the (shared) pointer result. If there is nothing to see, the pointer will store null and the method will return false.
This method is thread-safe
node | the pointer to store the audio node |
loop | the pointer to store the number of loops |
bool cugl::audio::AudioNodeQueue::pop | ( | std::shared_ptr< AudioNode > & | node, |
Sint32 & | loop | ||
) |
Removes an entry from the front of this queue.
The element will be stored in the (shared) pointer result. If there is nothing to remove, the pointer will store null and the method will return false.
This method is thread-safe
node | the pointer to store the audio node |
loop | the pointer to store the number of loops |
void cugl::audio::AudioNodeQueue::push | ( | const std::shared_ptr< AudioNode > & | node, |
Sint32 | loops = 0 |
||
) |
Adds an entry to the end of this queue.
The loop value is an integer. If it is 0, the audio node will not be looped. If it is positive, it will loop the audio that many (additional) times. If it is negative, the audio node will be looped indefinitely until it is stopped.
This method is thread-safe
node | The node to be scheduled |
loops | The number of times to loop the audio |