CUGL 2.1
Cornell University Game Library
Classes | Public Member Functions | List of all members
cugl::audio::AudioNodeQueue Class Reference

#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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AudioNodeQueue()

cugl::audio::AudioNodeQueue::AudioNodeQueue ( )

Creates an empty player queue

◆ ~AudioNodeQueue()

cugl::audio::AudioNodeQueue::~AudioNodeQueue ( )

Disposes of the player queue, releasing all resources

Member Function Documentation

◆ clear()

void cugl::audio::AudioNodeQueue::clear ( )

Clears all elements in this queue.

This method is thread-safe

◆ empty()

bool cugl::audio::AudioNodeQueue::empty ( ) const
inline

Returns true if the queue is empty.

This method is atomic and thread-safe

Returns
true if the queue is empty.

◆ fill()

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).

Parameters
containerthe container to store the values
Returns
true if the operation was successful

◆ peek()

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

Parameters
nodethe pointer to store the audio node
loopthe pointer to store the number of loops
Returns
true if the operation was successful

◆ pop()

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

Parameters
nodethe pointer to store the audio node
loopthe pointer to store the number of loops
Returns
true if the operation was successful

◆ push()

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

Parameters
nodeThe node to be scheduled
loopsThe number of times to loop the audio

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