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

MDF (Multi-Delay block Frequency) echo cancellation with stream API. More...

#include <MDFEchoCancellationStream.h>

Inheritance diagram for MDFEchoCancellationStream< Allocator >:
AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 MDFEchoCancellationStream (Stream &in, int filterLength, AudioFFTBase &fftDriver, const Allocator &alloc=Allocator())
 Constructor (single channel)
 
 MDFEchoCancellationStream (Stream &in, int filterLength, AudioFFTBase &fftDriver, const Allocator &alloc=Allocator())
 Constructor (multiple channels)
 
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
 
MDFEchoCancellation< Allocator > & getEchoCanceller ()
 Get underlying MDF echo canceller instance.
 
int getFilterLen ()
 Get filter length.
 
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 (using buffered playback)
 
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 echo canceller state.
 
void setAudioInfo (AudioInfo info) override
 Defines the input AudioInfo.
 
void setFilterLen (int len)
 Set filter length (number of filter blocks)
 
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

int getFrameSize ()
 Get frame size from FFT configuration.
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
MDFEchoCancellation< Allocatorcanceller
 
AudioInfo info
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
AudioFFTBasep_fft = nullptr
 
Streamp_io = nullptr
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

template<typename Allocator = std::allocator<uint8_t>>
class audio_tools::MDFEchoCancellationStream< Allocator >

MDF (Multi-Delay block Frequency) echo cancellation with stream API.

This class wraps MDFEchoCancellation and provides a stream-based interface for easy integration with AudioTools streaming pipelines. It processes audio using the high-performance MDF algorithm.

Template Parameters
AllocatorCustom allocator for memory management (default: std::allocator)

Constructor & Destructor Documentation

◆ MDFEchoCancellationStream() [1/2]

template<typename Allocator = std::allocator<uint8_t>>
MDFEchoCancellationStream ( Stream in,
int  filterLength,
AudioFFTBase fftDriver,
const Allocator alloc = Allocator() 
)
inline

Constructor (single channel)

Parameters
inReference to the input stream (microphone or audio input)
filterLengthLength of echo cancellation filter in samples
fftDriverFFT driver instance from AudioFFT
allocAllocator instance (optional)

◆ MDFEchoCancellationStream() [2/2]

template<typename Allocator = std::allocator<uint8_t>>
MDFEchoCancellationStream ( Stream in,
int  filterLength,
AudioFFTBase fftDriver,
const Allocator alloc = Allocator() 
)
inline

Constructor (multiple channels)

Parameters
inReference to the input stream
filterLengthLength of echo cancellation filter in samples
nbMicNumber of microphone channels
nbSpeakersNumber of speaker channels
fftDriverFFT driver instance from AudioFFT
allocAllocator instance (optional)

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.

◆ getEchoCanceller()

template<typename Allocator = std::allocator<uint8_t>>
MDFEchoCancellation< Allocator > & getEchoCanceller ( )
inline

Get underlying MDF echo canceller instance.

Returns
Reference to MDFEchoCancellation object

◆ getFilterLen()

template<typename Allocator = std::allocator<uint8_t>>
int getFilterLen ( )
inline

Get filter length.

Returns
Current filter length

◆ getFrameSize()

template<typename Allocator = std::allocator<uint8_t>>
int getFrameSize ( )
inlineprotected

Get frame size from FFT configuration.

Returns
Frame size in samples

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

template<typename Allocator = std::allocator<uint8_t>>
size_t readBytes ( uint8_t *  buf,
size_t  len 
)
inlineoverridevirtual

Read input and remove echo (using buffered playback)

Parameters
bufPointer to buffer to store processed input
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()

template<typename Allocator = std::allocator<uint8_t>>
void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

Defines the input AudioInfo.

Reimplemented from AudioStream.

◆ setFilterLen()

template<typename Allocator = std::allocator<uint8_t>>
void setFilterLen ( int  len)
inline

Set filter length (number of filter blocks)

Parameters
lenLength of the adaptive filter in blocks

◆ write() [1/2]

template<typename Allocator = std::allocator<uint8_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
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: