arduino-audio-tools
Loading...
Searching...
No Matches
AudioEffectStreamT< T > Class Template Reference

EffectsStreamT: the template class describes an input or output stream to which one or multiple effects are applied. Each channel is processed by its own independent clone of the effect chain (created via AudioEffect::clone()), so e.g. a stereo signal keeps its channel separation and effects that carry internal state (Delay's ring buffer, ADSRGain/Tremolo's envelope or oscillator phase, etc.) don't get confused by interleaved samples from different channels. addEffect() adds to a shared template chain that is cloned into every channel on begin() (and immediately cloned into all already-active channels if called afterwards); use addEffect(channel, effect) to register an effect directly on just one channel instead. Note that size()/operator[]/findEffect() operate on the template chain, not on the per-channel clones: mutating a pointer obtained from them after begin() has already cloned it does not retroactively change already-cloned per-channel copies. Currently only int16_t values are supported, so I recommend to use the AudioEffectStream class which is defined as using AudioEffectStream = AudioEffectStreamT<effect_t>;. More...

#include <AudioEffects.h>

Inheritance diagram for AudioEffectStreamT< T >:
ModifyingStream AudioStream AudioStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream

Public Member Functions

 AudioEffectStreamT ()=default
 AudioEffectStreamT (const AudioEffectStreamT &)=delete
 AudioEffectStreamT (Print &out)
 AudioEffectStreamT (Stream &io)
 ~AudioEffectStreamT ()
void addEffect (AudioEffect &effect)
 Adds an effect object (by reference) to the template chain: cloned into every channel.
void addEffect (AudioEffect *effect)
 Adds an effect using a pointer to the template chain: cloned into every channel.
void addEffect (int channel, AudioEffect &effect)
void addEffect (int channel, AudioEffect *effect)
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
int available () override
int availableForWrite () override
bool begin ()
bool begin (AudioInfo cfg)
int channelCount ()
 Provides the number of channels that have their own effect chain (valid after begin()).
AudioEffectCommon & channelEffects (int channel)
 Provides access to a single channel's own effect chain (valid after begin()).
void clear ()
 deletes all defined effects
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
AudioInfo defaultConfig ()
void end () override
AudioEffect * findEffect (int id)
 Finds an effect by id in the template chain.
void flush () override
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
virtual operator bool ()
virtual operator bool ()
AudioEffectStreamT & operator= (const AudioEffectStreamT &)=delete
AudioEffect * operator[] (int idx)
 gets an effect by index from the template chain
size_t readBytes (uint8_t *data, size_t len) override
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
virtual void setOutput (AudioOutput &out)
 Defines/Changes the output target and registers for audio change notifications.
void setOutput (Print &print) override
 Defines/Changes the output target.
virtual void setStream (AudioStream &io)
 Defines/Changes the input & output and registers for audio change notifications.
void setStream (Stream &io) override
 Defines/Changes the input & output.
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
size_t size ()
 Provides the actual number of defined effects in the template chain.
virtual size_t write (uint8_t ch) override
size_t write (const uint8_t *data, size_t len) override
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

void cloneInto (int ch, AudioEffect *effect)
 clones a single effect into a single channel's chain, tracking ownership
virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void setupChannels ()
 (re)builds channel_effects from the template effects chain

Protected Attributes

int _timeout = 10
bool active = false
Vector< T > buffer_out
Vector< AudioEffectCommon > channel_effects
AudioEffectCommon effects
AudioInfo info
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
Vector< AudioEffect * > owned_clones
Stream * p_io =nullptr
Print * p_out =nullptr
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
int write_buffer_size = 8

Detailed Description

template<class T>
class audio_tools::AudioEffectStreamT< T >

EffectsStreamT: the template class describes an input or output stream to which one or multiple effects are applied. Each channel is processed by its own independent clone of the effect chain (created via AudioEffect::clone()), so e.g. a stereo signal keeps its channel separation and effects that carry internal state (Delay's ring buffer, ADSRGain/Tremolo's envelope or oscillator phase, etc.) don't get confused by interleaved samples from different channels. addEffect() adds to a shared template chain that is cloned into every channel on begin() (and immediately cloned into all already-active channels if called afterwards); use addEffect(channel, effect) to register an effect directly on just one channel instead. Note that size()/operator[]/findEffect() operate on the template chain, not on the per-channel clones: mutating a pointer obtained from them after begin() has already cloned it does not retroactively change already-cloned per-channel copies. Currently only int16_t values are supported, so I recommend to use the AudioEffectStream class which is defined as using AudioEffectStream = AudioEffectStreamT<effect_t>;.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ AudioEffectStreamT() [1/4]

template<class T>
AudioEffectStreamT ( )
default

◆ AudioEffectStreamT() [2/4]

template<class T>
AudioEffectStreamT ( Stream & io)
inline

◆ AudioEffectStreamT() [3/4]

template<class T>
AudioEffectStreamT ( Print & out)
inline

◆ AudioEffectStreamT() [4/4]

template<class T>
AudioEffectStreamT ( const AudioEffectStreamT< T > & )
delete

◆ ~AudioEffectStreamT()

template<class T>
~AudioEffectStreamT ( )
inline

Member Function Documentation

◆ addEffect() [1/4]

template<class T>
void addEffect ( AudioEffect & effect)
inline

Adds an effect object (by reference) to the template chain: cloned into every channel.

◆ addEffect() [2/4]

template<class T>
void addEffect ( AudioEffect * effect)
inline

Adds an effect using a pointer to the template chain: cloned into every channel.

◆ addEffect() [3/4]

template<class T>
void addEffect ( int channel,
AudioEffect & effect )
inline

Adds an effect object (by reference) directly to a single channel's own chain (not cloned, not owned by this class). Requires begin() to have already been called.

◆ addEffect() [4/4]

template<class T>
void addEffect ( int channel,
AudioEffect * effect )
inline

Adds an effect using a pointer directly to a single channel's own chain (not cloned, not owned by this class). Requires begin() to have already been called.

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available()

template<class T>
int available ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite()

template<class T>
int availableForWrite ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [1/2]

template<class T>
bool begin ( )
inlinevirtual

Reimplemented from BaseStream.

◆ begin() [2/2]

template<class T>
bool begin ( AudioInfo cfg)
inline

◆ channelCount()

template<class T>
int channelCount ( )
inline

Provides the number of channels that have their own effect chain (valid after begin()).

◆ channelEffects()

template<class T>
AudioEffectCommon & channelEffects ( int channel)
inline

Provides access to a single channel's own effect chain (valid after begin()).

◆ clear()

template<class T>
void clear ( )
inline

deletes all defined effects

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ cloneInto()

template<class T>
void cloneInto ( int ch,
AudioEffect * effect )
inlineprotected

clones a single effect into a single channel's chain, tracking ownership

◆ defaultConfig()

template<class T>
AudioInfo defaultConfig ( )
inline

◆ end()

template<class T>
void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ findEffect()

template<class T>
AudioEffect * findEffect ( int id)
inline

Finds an effect by id in the template chain.

◆ flush()

template<class T>
void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ not_supported() [1/2]

virtual int not_supported ( int out,
const char * msg = "" )
inlineprotectedvirtualinherited

◆ not_supported() [2/2]

virtual int not_supported ( int out,
const char * msg = "" )
inlineprotectedvirtualinherited

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool() [1/2]

◆ operator bool() [2/2]

◆ operator=()

template<class T>
AudioEffectStreamT & operator= ( const AudioEffectStreamT< T > & )
delete

◆ operator[]()

template<class T>
AudioEffect * operator[] ( int idx)
inline

gets an effect by index from the template chain

◆ readBytes()

template<class T>
size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Provides the audio data by reading the assinged Stream and applying the effects on that input

Reimplemented from AudioStream.

◆ readSilence() [1/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ readSilence() [2/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer() [1/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ refillReadBuffer() [2/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setOutput() [1/2]

virtual void setOutput ( AudioOutput & out)
inlinevirtualinherited

Defines/Changes the output target and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setOutput() [2/2]

template<class T>
void setOutput ( Print & out)
inlineoverridevirtual

Defines/Changes the output target.

Implements ModifyingStream.

◆ setStream() [1/2]

virtual void setStream ( AudioStream & io)
inlinevirtualinherited

Defines/Changes the input & output and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setStream() [2/2]

template<class T>
void setStream ( Stream & in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setupChannels()

template<class T>
void setupChannels ( )
inlineprotected

(re)builds channel_effects from the template effects chain

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ size()

template<class T>
size_t size ( )
inline

Provides the actual number of defined effects in the template chain.

◆ write() [1/2]

◆ write() [2/2]

template<class T>
size_t write ( const uint8_t * data,
size_t len )
inlineoverridevirtual

Writes the samples passed in the buffer and applies the effects before writing the result to the output defined in the constructor. The processed block is written in a single call to the downstream Stream/Print (instead of one call per sample) to avoid the per-sample dispatch overhead that would otherwise starve a real-time producer such as a Bluetooth A2DP sink.

Reimplemented from AudioStream.

◆ writeSilence() [1/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

◆ writeSilence() [2/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ active

template<class T>
bool active = false
protected

◆ buffer_out

template<class T>
Vector<T> buffer_out
protected

◆ channel_effects

template<class T>
Vector<AudioEffectCommon> channel_effects
protected

◆ effects

template<class T>
AudioEffectCommon effects
protected

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ owned_clones

template<class T>
Vector<AudioEffect*> owned_clones
protected

◆ p_io

template<class T>
Stream* p_io =nullptr
protected

◆ p_out

template<class T>
Print* p_out =nullptr
protected

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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