CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::audio::AlgorithmicReverb Class Reference

#include <CUAlgorithmicReverb.h>

Inheritance diagram for cugl::audio::AlgorithmicReverb:
cugl::audio::AudioNode

Public Member Functions

 AlgorithmicReverb ()
 
 ~AlgorithmicReverb ()
 
virtual bool init () override
 
virtual bool init (Uint8 channels, Uint32 rate) override
 
bool init (const std::shared_ptr< AudioNode > &input)
 
virtual void dispose () override
 
bool attach (const std::shared_ptr< AudioNode > &node)
 
std::shared_ptr< AudioNodedetach ()
 
std::shared_ptr< AudioNodegetInput ()
 
void clear ()
 
virtual void setReadSize (Uint32 size) override
 
virtual Uint32 read (float *buffer, Uint32 frames) override
 
void setRoomSize (float value)
 
float getRoomSize ()
 
void setDamp (float value)
 
float getDamp ()
 
void setWet (float value)
 
float getWet ()
 
void setDry (float value)
 
float getDry ()
 
void setWidth (float value)
 
float getWidth ()
 
void setTail (double duration)
 
double getTail ()
 
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)
 
virtual void dispose ()
 
Uint8 getChannels () const
 
Uint32 getRate () const
 
float getGain ()
 
virtual void setGain (float gain)
 
Uint32 getReadSize () const
 
virtual void setReadSize (Uint32 size)
 
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 ()
 
virtual bool completed ()
 
virtual Uint32 read (float *buffer, Uint32 frames)
 
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< AlgorithmicReverballoc ()
 
static std::shared_ptr< AlgorithmicReverballoc (Uint8 channels, Uint32 rate)
 
static std::shared_ptr< AlgorithmicReverballoc (const std::shared_ptr< AudioNode > &input)
 

Protected Member Functions

void initFilter ()
 
- Protected Member Functions inherited from cugl::audio::AudioNode
void notify (const std::shared_ptr< AudioNode > &node, Action action)
 

Protected Attributes

std::shared_ptr< AudioNode_input
 
std::mutex _mutex
 
std::atomic< float > _ingain
 
std::atomic< float > _wet
 
std::atomic< float > _dry
 
std::atomic< float > _roomsize
 
std::atomic< float > _damp
 
std::atomic< float > _width
 
std::atomic< bool > _dirty
 
ATK_AlgoReverb * _reverb
 
Sint64 _outmark
 
Uint64 _fadeout
 
bool _outdone
 
- 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
 
Uint32 _readsize
 
std::string _localname
 
std::string _classname
 
size_t _hashOfName
 
bool _locked
 

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
static const Uint32 DEFAULT_CHANNELS
 
static const Uint32 DEFAULT_SAMPLING
 

Detailed Description

This class provides an algorithmic implementation of audio reverb.

The implementation is modeled after the the open source Schroeder reverberator, Freeverb. It is tunable with several attributes, including wet/dry mix, damping, and room size. All of attributes except tail should be between 0 and 1. More information about the algorithm can be found at:

https://ccrma.stanford.edu/~jos/pasp/Freeverb.html

Constructor & Destructor Documentation

◆ AlgorithmicReverb()

cugl::audio::AlgorithmicReverb::AlgorithmicReverb ( )

Creates a degenerate reverb node with no associated input.

The node has no settings and so will not provide any reverb.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate a graph node on the heap, use one of the static constructors instead.

◆ ~AlgorithmicReverb()

cugl::audio::AlgorithmicReverb::~AlgorithmicReverb ( )
inline

Deletes this node, disposing of all resources.

Member Function Documentation

◆ advance()

virtual Sint64 cugl::audio::AlgorithmicReverb::advance ( Uint32  frames)
overridevirtual

Advances the stream by the given number of frames.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

This method only advances the read position, it does not actually read data into a buffer. This method is generally not supported for nodes with real-time input like AudioInput.

Parameters
framesThe number of frames to advace
Returns
the actual number of frames advanced; -1 if not supported

Reimplemented from cugl::audio::AudioNode.

◆ alloc() [1/3]

static std::shared_ptr< AlgorithmicReverb > cugl::audio::AlgorithmicReverb::alloc ( )
inlinestatic

Returns a newly allocated reverb with the default stereo settings

The number of channels is two, for stereo output. The sample rate is the modern standard of 48000 HZ. Any input node must agree with these settings.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Returns
a newly allocated reverb node with the default stereo settings

◆ alloc() [2/3]

static std::shared_ptr< AlgorithmicReverb > cugl::audio::AlgorithmicReverb::alloc ( const std::shared_ptr< AudioNode > &  input)
inlinestatic

Returns a newly allocated reverb for the given input node.

This node acquires the channels and sample rate of the input. If input is nullptr, this method will fail.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Parameters
inputThe audio node to fade
Returns
a newly allocated reverb node for the given input node.

◆ alloc() [3/3]

static std::shared_ptr< AlgorithmicReverb > cugl::audio::AlgorithmicReverb::alloc ( Uint8  channels,
Uint32  rate 
)
inlinestatic

Returns a newly allocated reverb 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 whether this node can serve as an input to other nodes in the audio graph.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Parameters
channelsThe number of audio channels
rateThe sample rate (frequency) in HZ
Returns
a newly allocated reverb node with the given number of channels and sample rate

◆ attach()

bool cugl::audio::AlgorithmicReverb::attach ( const std::shared_ptr< AudioNode > &  node)

Attaches an audio node to this reverb node.

This method will fail if the channels of the audio node do not agree with this node.

Parameters
nodeThe audio node to add reverb to
Returns
true if the attachment was successful

◆ clear()

void cugl::audio::AlgorithmicReverb::clear ( )

Clears all filters in the reverb subgraph.

◆ completed()

virtual bool cugl::audio::AlgorithmicReverb::completed ( )
overridevirtual

Returns true if this audio node has no more data.

An audio node is typically completed if it return 0 (no frames read) on subsequent calls to read(). However, for infinite-running audio threads, it is possible for this method to return true even when data can still be read; in that case the node is notifying that it should be shut down.

Returns
true if this audio node has no more data.

Reimplemented from cugl::audio::AudioNode.

◆ detach()

std::shared_ptr< AudioNode > cugl::audio::AlgorithmicReverb::detach ( )

Detaches an audio node from this reverb node.

If the method succeeds, it returns the audio node that was removed.

Returns
The audio node to detach (or null if failed)

◆ dispose()

virtual void cugl::audio::AlgorithmicReverb::dispose ( )
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.

◆ getDamp()

float cugl::audio::AlgorithmicReverb::getDamp ( )

Returns the damping associated with each comb filter.

This value should be between 0 and 1 for best effects.

Returns
the damping as a float.

◆ getDry()

float cugl::audio::AlgorithmicReverb::getDry ( )

Returns the dryness scale for the reverb.

This should be a value between 0 and 1. A value of 0 will mean that only the wet mix (reverb) is played.

Returns
the dryness scale for the reverb.

◆ getElapsed()

virtual double cugl::audio::AlgorithmicReverb::getElapsed ( ) const
overridevirtual

Returns the elapsed time in seconds.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

In some nodes like AudioInput, this method is only supported if mark() is set. In that case, the times will be the number of seconds since the mark. Other nodes like AudioPlayer measure from the start of the stream.

Returns
the elapsed time in seconds.

Reimplemented from cugl::audio::AudioNode.

◆ getInput()

std::shared_ptr< AudioNode > cugl::audio::AlgorithmicReverb::getInput ( )
inline

Returns the input node of this reverb node.

Returns
the input node of this reverb node.

◆ getPosition()

virtual Sint64 cugl::audio::AlgorithmicReverb::getPosition ( ) const
overridevirtual

Returns the current frame position of this audio node

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

In some nodes like AudioInput, this method is only supported if mark() is set. In that case, the position will be the number of frames since the mark. Other nodes like AudioPlayer measure from the start of the stream.

Returns
the current frame position of this audio node.

Reimplemented from cugl::audio::AudioNode.

◆ getRemaining()

virtual double cugl::audio::AlgorithmicReverb::getRemaining ( ) const
overridevirtual

Returns the remaining time in seconds.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

In some nodes like AudioInput, this method is only supported if setRemaining() has been called. In that case, the node will be marked as completed after the given number of seconds. This may or may not actually move the read head. For example, in AudioPlayer it will skip to the end of the sample. However, in AudioInput it will simply time out after the given time.

Returns
the remaining time in seconds.

Reimplemented from cugl::audio::AudioNode.

◆ getRoomSize()

float cugl::audio::AlgorithmicReverb::getRoomSize ( )

Returns the room size associated with each comb filter.

This value should be between 0 and 1 for best effects.

Returns
the room size as a float.

◆ getTail()

double cugl::audio::AlgorithmicReverb::getTail ( )

Returns the fade-out tail for this reverb node

A reverb node is technically complete when its input node is complete. But for long enough echoes, this can cause the echo to be cut off. Therefore, it makes sense to add a tail where the echo is allowed to persist a little bit longer. This echo will linearly fade to 0 over the tail duration.

If this value is 0 or less, there will be no tail. You should not add a tail if you want this sound to be looped with the echo.

Returns
the fade-out tail for this reverb node

◆ getWet()

float cugl::audio::AlgorithmicReverb::getWet ( )

Returns the wetness scale for the reverb.

This should be a value between 0 and 1. A value of 0 will mean that no reverb is applied.

Returns
the wetness scale for the reverb.

◆ getWidth()

float cugl::audio::AlgorithmicReverb::getWidth ( )

Returns the width between the stereo channels

Returns
the width between the stereo channels

◆ init() [1/3]

virtual bool cugl::audio::AlgorithmicReverb::init ( )
overridevirtual

Initializes the node with default stereo settings

The number of channels is two, for stereo output. The sample rate is the modern standard of 48000 HZ.

These values determine the buffer the structure for all read operations. In addition, they also detemine whether this node can serve as an input to other nodes in the audio graph.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Returns
true if initialization was successful

Reimplemented from cugl::audio::AudioNode.

◆ init() [2/3]

bool cugl::audio::AlgorithmicReverb::init ( const std::shared_ptr< AudioNode > &  input)

Initializes reverb for the given input node.

This node acquires the channels and sample rate of the input. If input is nullptr, this method will fail.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Parameters
inputThe audio node to fade
Returns
true if initialization was successful

◆ init() [3/3]

virtual bool cugl::audio::AlgorithmicReverb::init ( Uint8  channels,
Uint32  rate 
)
overridevirtual

Initializes the node 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 whether this node can serve as an input to other nodes in the audio graph.

The reverb will be set with the default settings as defined by the public domain FreeVerb algorithm.

Parameters
channelsThe number of audio channels
rateThe sample rate (frequency) in HZ
Returns
true if initialization was successful

Reimplemented from cugl::audio::AudioNode.

◆ initFilter()

void cugl::audio::AlgorithmicReverb::initFilter ( )
protected

Initializes the reverb filter from the default settings.

◆ mark()

virtual bool cugl::audio::AlgorithmicReverb::mark ( )
overridevirtual

Marks the current read position in the audio steam.

DELEGATED METHOD: This method delegates its call to the input node. It returns false if there is no input node or if this method is unsupported in that node

This method is typically used by reset() to determine where to restore the read position. For some nodes (like AudioInput), this method may start recording data to a buffer, which will continue until reset() is called.

It is possible for reset() to be supported even if this method is not.

Returns
true if the read position was marked.

Reimplemented from cugl::audio::AudioNode.

◆ read()

virtual Uint32 cugl::audio::AlgorithmicReverb::read ( float *  buffer,
Uint32  frames 
)
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.

Parameters
bufferThe read buffer to store the results
framesThe maximum number of frames to read
Returns
the actual number of frames read

Reimplemented from cugl::audio::AudioNode.

◆ reset()

virtual bool cugl::audio::AlgorithmicReverb::reset ( )
overridevirtual

Resets the read position to the marked position of the audio stream.

DELEGATED METHOD: This method delegates its call to the input node. It returns false if there is no input node or if this method is unsupported in that node

When no mark() is set, the result of this method is node dependent. Some nodes (such as AudioPlayer) will reset to the beginning of the stream, while others (like AudioInput) only support a rest when a mark is set. Pay attention to the return value of this method to see if the call is successful.

Returns
true if the read position was moved.

Reimplemented from cugl::audio::AudioNode.

◆ setDamp()

void cugl::audio::AlgorithmicReverb::setDamp ( float  value)

Sets the damping associated with each comb filter.

This value should be between 0 and 1 for best effects.

Parameters
valuethe damping as a float.

◆ setDry()

void cugl::audio::AlgorithmicReverb::setDry ( float  value)

Sets the dryness scale for the reverb.

This should be a value between 0 and 1. A value of 0 will mean that only the wet mix (reverb) is played.

Parameters
valuethe amount of dry to mix as a float.

◆ setElapsed()

virtual double cugl::audio::AlgorithmicReverb::setElapsed ( double  time)
overridevirtual

Sets the read position to the elapsed time in seconds.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

In some nodes like AudioInput, this method is only supported if mark() is set. In that case, the new time will be meaured from the mark. Other nodes like AudioPlayer measure from the start of the stream.

Parameters
timeThe elapsed time in seconds.
Returns
the new elapsed time in seconds.

Reimplemented from cugl::audio::AudioNode.

◆ setPosition()

virtual Sint64 cugl::audio::AlgorithmicReverb::setPosition ( Uint32  position)
overridevirtual

Sets the current frame position of this audio node.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

In some nodes like AudioInput, this method is only supported if mark() is set. In that case, the position will be the number of frames since the mark. Other nodes like AudioPlayer measure from the start of the stream.

Parameters
positionthe current frame position of this audio node.
Returns
the new frame position of this audio node.

Reimplemented from cugl::audio::AudioNode.

◆ setReadSize()

virtual void cugl::audio::AlgorithmicReverb::setReadSize ( Uint32  size)
overridevirtual

Sets the typical read size of this node.

Some audio nodes need an internal buffer for operations like mixing or resampling. In that case, it helps to know the requested read size ahead of time. The capacity is the minimal required read amount of the AudioEngine and corresponds to AudioEngine#getReadSize.

It is not actually necessary to set this size. However for nodes with internal buffer, setting this value can optimize performance.

This method is not synchronized because it is assumed that this value will never change while the audio engine in running. The average user should never call this method explicitly. You should always call AudioEngine#setReadSize instead.

Parameters
sizeThe typical read size of this node.

Reimplemented from cugl::audio::AudioNode.

◆ setRemaining()

virtual double cugl::audio::AlgorithmicReverb::setRemaining ( double  time)
overridevirtual

Sets the remaining time in seconds.

DELEGATED METHOD: This method delegates its call to the input node. It returns -1 if there is no input node or if this method is unsupported in that node

If this method is supported, then the node will be marked as completed after the given number of seconds. This may or may not actually move the read head. For example, in AudioPlayer it will skip to the end of the sample. However, in AudioInput it will simply time out after the given time.

Parameters
timeThe remaining time in seconds.
Returns
the new remaining time in seconds.

Reimplemented from cugl::audio::AudioNode.

◆ setRoomSize()

void cugl::audio::AlgorithmicReverb::setRoomSize ( float  value)

Sets the room size associated with each comb filter.

This value should be between 0 and 1 for best effects.

Parameters
valuethe room size as a float.

◆ setTail()

void cugl::audio::AlgorithmicReverb::setTail ( double  duration)

Sets the fade-out tail for this reverb node

A reverb node is technically complete when its input node is complete. But for long enough echoes, this can cause the echo to be cut off. Therefore, it makes sense to add a tail where the echo is allowed to persist a little bit longer. This echo will linearly fade to 0 over the tail duration.

If this value is 0 or less, there will be no tail. You should not add a tail if you want this sound to be looped with the echo.

Parameters
durationThe fade-out tail in seconds

◆ setWet()

void cugl::audio::AlgorithmicReverb::setWet ( float  value)

Sets the wetness scale for the reverb.

This should be a value between 0 and 1. A value of 0 will mean that no reverb is applied.

Parameters
valuethe amount of wet to mix as a float.

◆ setWidth()

void cugl::audio::AlgorithmicReverb::setWidth ( float  value)

Sets the width between the stereo channels

Parameters
valuethe distance between channels

◆ unmark()

virtual bool cugl::audio::AlgorithmicReverb::unmark ( )
overridevirtual

Clears the current marked position.

DELEGATED METHOD: This method delegates its call to the input node. It returns false if there is no input node or if this method is unsupported in that node

If the method mark() started recording to a buffer (such as with AudioInput), this method will stop recording and release the buffer. When the mark is cleared, reset() may or may not work depending upon the specific node.

Returns
true if the read position was marked.

Reimplemented from cugl::audio::AudioNode.

Member Data Documentation

◆ _damp

std::atomic<float> cugl::audio::AlgorithmicReverb::_damp
protected

Amount that the wet mix is damped

◆ _dirty

std::atomic<bool> cugl::audio::AlgorithmicReverb::_dirty
protected

Whether the reverb settings have changed and need to be regenerated

◆ _dry

std::atomic<float> cugl::audio::AlgorithmicReverb::_dry
protected

Scales gain for the dry mix

◆ _fadeout

Uint64 cugl::audio::AlgorithmicReverb::_fadeout
protected

The amount of fade-out remaining

◆ _ingain

std::atomic<float> cugl::audio::AlgorithmicReverb::_ingain
protected

internal gain for producing wet mix

◆ _input

std::shared_ptr<AudioNode> cugl::audio::AlgorithmicReverb::_input
protected

The audio input node

◆ _mutex

std::mutex cugl::audio::AlgorithmicReverb::_mutex
protected

This class needs a proper lock guard; too many race conditions

◆ _outdone

bool cugl::audio::AlgorithmicReverb::_outdone
protected

Whether we have completed this node due to a fadeout

◆ _outmark

Sint64 cugl::audio::AlgorithmicReverb::_outmark
protected

The number of frames to fade-out; -1 if no active fade-out

◆ _reverb

ATK_AlgoReverb* cugl::audio::AlgorithmicReverb::_reverb
protected

The reverb filter from ATK

◆ _roomsize

std::atomic<float> cugl::audio::AlgorithmicReverb::_roomsize
protected

Sets the amount of feedback for the comb filters (wet tail length)

◆ _wet

std::atomic<float> cugl::audio::AlgorithmicReverb::_wet
protected

Scales gain for the wet mix (stereo)

◆ _width

std::atomic<float> cugl::audio::AlgorithmicReverb::_width
protected

distance between left and right channels


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