![]() |
CUGL 1.2
Cornell University Game Library
|
#include <CUAudioMixer.h>
Public Member Functions | |
AudioMixer () | |
~AudioMixer () | |
virtual bool | init () override |
bool | init (Uint8 width) |
virtual bool | init (Uint8 channels, Uint32 rate) override |
bool | init (Uint8 width, Uint8 channels, Uint32 rate) |
virtual void | dispose () override |
std::shared_ptr< AudioNode > | attach (Uint8 slot, const std::shared_ptr< AudioNode > &input) |
std::shared_ptr< AudioNode > | detach (Uint8 slot) |
virtual Uint32 | read (float *buffer, Uint32 frames) override |
float | getKnee () const |
void | setKnee (float knee) |
![]() | |
AudioNode () | |
virtual | ~AudioNode () |
Uint8 | getChannels () const |
Uint32 | getRate () const |
float | getGain () |
virtual void | setGain (float gain) |
const std::string & | getName () const |
void | setName (const std::string &name) |
void | setName (const char *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 () |
virtual bool | completed () |
virtual bool | mark () |
virtual bool | unmark () |
virtual bool | reset () |
virtual Sint64 | advance (Uint32 frames) |
virtual Sint64 | getPosition () const |
virtual Sint64 | setPosition (Uint32 position) |
virtual double | getElapsed () const |
virtual double | setElapsed (double time) |
virtual double | getRemaining () const |
virtual double | setRemaining (double time) |
Static Public Member Functions | |
static std::shared_ptr< AudioMixer > | alloc (Uint8 width=8) |
static std::shared_ptr< AudioMixer > | alloc (Uint8 width, Uint8 channels, Uint32 rate) |
Static Public Attributes | |
static const Uint8 | DEFAULT_WIDTH |
static const float | DEFAULT_KNEE |
![]() | |
static const Uint32 | DEFAULT_CHANNELS |
static const Uint32 | DEFAULT_SAMPLING |
Additional Inherited Members | |
![]() | |
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 |
![]() | |
std::string | _classname |
![]() | |
void | notify (const std::shared_ptr< AudioNode > &node, Action action) |
![]() | |
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 |
size_t | _hashOfName |
This class represents an audio mixer.
This mixer can take (a fixed number of) input streams and combine them together into a single output stream. The input streams must all have the same number of channels and sample rate as this node.
Mixing works by adding together all of the streams. This means that the results may exceed the range [-1,1], causing clipping. The mixer provides a "soft-knee" option (disabled by default) for confining the results to the range [-1,1]. When a knee k is specified, all values [-k,k] will not be effected, but values outside of this range will asymptotically bend to the range [-1,1].
The audio graph should only be accessed in the main thread. In addition, no methods marked as AUDIO THREAD ONLY should ever be accessed by the user.
This class does not support any actions for the AudioNode#setCallback.
cugl::audio::AudioMixer::AudioMixer | ( | ) |
Creates a degenerate mizer that takes no inputs
The mixer has no width and therefore cannot accept any inputs. The mixer must be initialized to be used.
|
inline |
Deletes this mixer, disposing of all resources.
|
inlinestatic |
Returns a newly allocated mixer with default stereo settings
The number of channels is two, for stereo output. The sample rate is CD standard 44100 HZ.
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
|
inlinestatic |
Returns a newly allocated mixer with the given number of channels and sample rate
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
channels | The number of audio channels |
rate | The sample rate (frequency) in HZ |
std::shared_ptr<AudioNode> cugl::audio::AudioMixer::attach | ( | Uint8 | slot, |
const std::shared_ptr< AudioNode > & | input | ||
) |
Attaches an input node to this mixer.
The input is attached at the given slot. Any input node previously at that slot is removed (and returned by this method).
slot | The slot for the input node |
input | The input node to attach |
std::shared_ptr<AudioNode> cugl::audio::AudioMixer::detach | ( | Uint8 | slot | ) |
Detaches the input node at the given slot.
The input node detached is returned by this method.
slot | The slot for the input node |
|
overridevirtual |
Disposes any resources allocated for this mixer
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.
float cugl::audio::AudioMixer::getKnee | ( | ) | const |
Returns the "soft knee" of this mixer, or -1 if not set
The soft knee is used to ensure that the results fit in the range [-1,1]. If the knee is k, then values in the range [-k,k] are unaffected, but values outside of this range are asymptotically clamped to the range [-1,1], using the formula (x-k+k*k)/x.
If the value is 0, then this mixer will hard clamp to [-1,1]. If it is negative, all inputs will be mixed exactly with no distortion.
|
overridevirtual |
Initializes the mixer with default stereo settings
The number of channels is two, for stereo output. The sample rate is CD standard 44100 HZ.
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
Reimplemented from cugl::audio::AudioNode.
bool cugl::audio::AudioMixer::init | ( | Uint8 | width | ) |
Initializes the mixer with default stereo settings
The number of channels is two, for stereo output. The sample rate is CD standard 44100 HZ.
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
|
overridevirtual |
Initializes the mixer with the given number of channels and sample rate
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
channels | The number of audio channels |
rate | The sample rate (frequency) in HZ |
Reimplemented from cugl::audio::AudioNode.
bool cugl::audio::AudioMixer::init | ( | Uint8 | width, |
Uint8 | channels, | ||
Uint32 | rate | ||
) |
Initializes the mixer with the given number of channels and sample rate
These values determine the buffer the structure for all read operations. In addition, they also detemine exactly which audio nodes are supported by this mixer. A mixer can only mix nodes that agree on both sample rate and frequency.
width | The number of audio nodes that may be attached to this mixer |
channels | The number of audio channels |
rate | The sample rate (frequency) in HZ |
|
overridevirtual |
Reads up to the specified number of frames into the given buffer
AUDIO THREAD ONLY: Users should never access this method directly, unless part of a custom audio graph node.
The buffer should have enough room to store frames * channels elements. The channels are interleaved into the output buffer.
Reading the buffer has no affect on the read position. You must manually move the frame position forward. This is to allow for a frame window to be reread if necessary.
buffer | The read buffer to store the results |
frames | The maximum number of frames to read |
Reimplemented from cugl::audio::AudioNode.
void cugl::audio::AudioMixer::setKnee | ( | float | knee | ) |
Sets the "soft knee" of this mixer.
The soft knee is used to ensure that the results fit in the range [-1,1]. If the knee is k, then values in the range [-k,k] are unaffected, but values outside of this range are asymptotically clamped to the range [-1,1], using the formula (x-k+k*k)/x
If the value is 0, then this mixer will hard clamp to [-1,1]. If it is negative, all inputs will be mixed exactly with no distortion.
knee | the "soft knee" of this mixer |
|
static |
The standard knee value for preventing clipping
|
static |
The default number of inputs supported (typically 8)