arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EchoCancellation< T > Class Template Reference

Echo cancellation with adaptive LMS filtering for microcontrollers. More...

#include <EchoCancellation.h>

Inheritance diagram for EchoCancellation< T >:
AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 EchoCancellation (Stream &in, size_t lag_samples=0, size_t buffer_size=512, size_t filter_len=32, float mu=0.001f)
 Constructor.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
size_t readBytes (uint8_t *buf, size_t len) override
 Read input and remove echo (subtract output signal with lag)
 
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.
 
void reset ()
 Reset the internal buffer and lag state.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setFilterLen (size_t len)
 Set the filter length for the adaptive filter.
 
void setLag (size_t lag_samples)
 Set the lag (delay) in samples for echo cancellation.
 
void setMu (float mu)
 Set the adaptation rate (mu) for the LMS algorithm.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *buf, size_t len) override
 Store the output signal (sent to speaker)
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
float adaptation_rate = 0.01f
 
size_t buffer_size
 
Vector< float > filter
 
size_t filter_len
 
AudioInfo info
 
bool is_notify_active = true
 
size_t lag
 
Vector< AudioInfoSupport * > notify_vector
 
Streamp_io = nullptr
 
RingBuffer< T > ring_buffer {0}
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

template<typename T = int16_t>
class audio_tools::EchoCancellation< T >

Echo cancellation with adaptive LMS filtering for microcontrollers.

This class implements echo cancellation using an adaptive FIR filter (LMS algorithm). It estimates the echo path and subtracts the estimated echo from the microphone input.

Constructor & Destructor Documentation

◆ EchoCancellation()

template<typename T = int16_t>
EchoCancellation ( Stream in,
size_t  lag_samples = 0,
size_t  buffer_size = 512,
size_t  filter_len = 32,
float  mu = 0.001f 
)
inline

Constructor.

Parameters
inReference to the input stream (microphone or audio input)
lag_samplesNumber of samples to delay the echo subtraction (default: 0)
buffer_sizeSize of the internal ring buffer (default: 512)

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin()

virtual bool begin ( )
inlinevirtualinherited

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

Reimplemented from Print.

Reimplemented in ResampleStream, BufferedTaskStream, and BufferedStream.

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

template<typename T = int16_t>
size_t readBytes ( uint8_t *  buf,
size_t  len 
)
inlineoverridevirtual

Read input and remove echo (subtract output signal with lag)

Parameters
bufPointer to buffer to store processed input (T*)
lenNumber of bytes to read
Returns
Number of bytes read from input

Reimplemented from AudioStream.

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setFilterLen()

template<typename T = int16_t>
void setFilterLen ( size_t  len)
inline

Set the filter length for the adaptive filter.

Parameters
lenLength of the adaptive filter

◆ setLag()

template<typename T = int16_t>
void setLag ( size_t  lag_samples)
inline

Set the lag (delay) in samples for echo cancellation.

Parameters
lag_samplesNumber of samples to delay the echo subtraction

◆ setMu()

template<typename T = int16_t>
void setMu ( float  mu)
inline

Set the adaptation rate (mu) for the LMS algorithm.

Parameters
muAdaptation rate

◆ write() [1/2]

template<typename T = int16_t>
size_t write ( const uint8_t *  buf,
size_t  len 
)
inlineoverridevirtual

Store the output signal (sent to speaker)

Parameters
bufPointer to PCM data sent to the speaker (T*)
lenNumber of bytes in buf
Returns
Number of bytes processed

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Reimplemented in BufferedTaskStream, and BufferedStream.


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