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

3 Band Equalizer with per-channel frequency and gain control Allows independent frequency and gain settings for each audio channel. Each channel can have different low/high frequency cutoffs and different gain values for low, medium, and high frequency bands. More...

#include <Equalizer3Bands.h>

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

Classes

struct  EQSTATE

Public Member Functions

 Equalizer3BandsPerChannelT (AudioOutput &out)
 Equalizer3BandsPerChannelT (AudioStream &stream)
 Equalizer3BandsPerChannelT (Print &out)
 Equalizer3BandsPerChannelT (Stream &in)
 ~Equalizer3BandsPerChannelT ()
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 (ConfigEqualizer3Bands &config)
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
ConfigEqualizer3Bands & config ()
ConfigEqualizer3Bands defaultConfig ()
void end () override
void flush () override
bool getChannelFrequencies (int channel, int &freq_low_val, int &freq_high_val)
bool getChannelGains (int channel, float &gain_low_val, float &gain_medium_val, float &gain_high_val)
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 ()
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 info) override
void setChannelFrequencies (int channel, int freq_low_val, int freq_high_val)
void setChannelGains (int channel, float gain_low_val, float gain_medium_val, float gain_high_val)
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 &out) 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)
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 allocateChannelArrays (int num_channels)
void ensureChannelArraysAllocated ()
 Ensures that per-channel arrays are allocated and properly sized.
void filterSamples (const uint8_t *data, size_t len)
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().
T sample (int channel, T sample_val)

Protected Attributes

int _timeout = 10
ConfigEqualizer3Bands cfg
 Default configuration instance.
Vector< int > freq_high
 High frequency cutoffs per channel (Hz).
Vector< int > freq_low
 Low frequency cutoffs per channel (Hz).
Vector< float > gain_high
 High frequency gains per channel.
Vector< float > gain_low
 Low frequency gains per channel.
Vector< float > gain_medium
 Medium frequency gains per channel.
AudioInfo info
bool is_active = false
bool is_notify_active = true
int max_state_count = 0
 Maximum number of allocated channel states.
Vector< AudioInfoSupport * > notify_vector
ConfigEqualizer3Bands * p_cfg = &cfg
 Pointer to active configuration.
Stream * p_io = nullptr
 Input/output stream for read operations.
Print * p_out = nullptr
 Output stream for write operations.
struct audio_tools::Equalizer3BandsPerChannelT::EQSTATE * state = nullptr
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
const T vsa = EqDenormalGuard<T>::value()
 Denormal-avoidance offset.
int write_buffer_size = 8

Detailed Description

template<typename T = float>
class audio_tools::Equalizer3BandsPerChannelT< T >

3 Band Equalizer with per-channel frequency and gain control Allows independent frequency and gain settings for each audio channel. Each channel can have different low/high frequency cutoffs and different gain values for low, medium, and high frequency bands.

Template Parameters
TArithmetic type used for the filter state and coefficients; see Equalizer3BandsT for details. Equalizer3BandsPerChannel (no template argument) is a float-based alias kept for backwards compatibility.
Author
pschatzmann

Constructor & Destructor Documentation

◆ Equalizer3BandsPerChannelT() [1/4]

template<typename T = float>
Equalizer3BandsPerChannelT ( Print & out)
inline

Constructor with Print output

Parameters
outPrint stream for output

◆ Equalizer3BandsPerChannelT() [2/4]

template<typename T = float>
Equalizer3BandsPerChannelT ( Stream & in)
inline

Constructor with Stream input

Parameters
inStream for input

◆ Equalizer3BandsPerChannelT() [3/4]

template<typename T = float>
Equalizer3BandsPerChannelT ( AudioOutput & out)
inline

Constructor with AudioOutput

Parameters
outAudioOutput for output with automatic audio change notifications

◆ Equalizer3BandsPerChannelT() [4/4]

template<typename T = float>
Equalizer3BandsPerChannelT ( AudioStream & stream)
inline

Constructor with AudioStream

Parameters
streamAudioStream for input/output with automatic audio change notifications

◆ ~Equalizer3BandsPerChannelT()

template<typename T = float>
~Equalizer3BandsPerChannelT ( )
inline

Member Function Documentation

◆ 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.

◆ allocateChannelArrays()

template<typename T = float>
void allocateChannelArrays ( int num_channels)
inlineprotected

Allocates and initializes per-channel frequency and gain arrays

Parameters
num_channelsNumber of channels to allocate arrays for

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available()

template<typename T = float>
int available ( )
inlineoverridevirtual

Get available data for reading

Returns
Number of bytes available for reading

Reimplemented from BaseStream.

◆ availableForWrite()

template<typename T = float>
int availableForWrite ( )
inlineoverridevirtual

Get available space for writing

Returns
Number of bytes available for writing

Reimplemented from BaseStream.

◆ begin() [1/2]

template<typename T = float>
bool begin ( )
inlinevirtual

Initialize the equalizer using the current configuration

Returns
true if initialization was successful

Reimplemented from BaseStream.

◆ begin() [2/2]

template<typename T = float>
bool begin ( ConfigEqualizer3Bands & config)
inline

Initialize the equalizer with the given configuration

Parameters
configConfiguration settings for the equalizer
Returns
true if initialization was successful

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ config()

template<typename T = float>
ConfigEqualizer3Bands & config ( )
inline

◆ defaultConfig()

template<typename T = float>
ConfigEqualizer3Bands defaultConfig ( )
inline

◆ end()

template<typename T = float>
void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ ensureChannelArraysAllocated()

template<typename T = float>
void ensureChannelArraysAllocated ( )
inlineprotected

Ensures that per-channel arrays are allocated and properly sized.

◆ filterSamples()

template<typename T = float>
void filterSamples ( const uint8_t * data,
size_t len )
inlineprotected

Applies per-channel 3-band equalization to audio samples

Parameters
dataPointer to audio data buffer
lenLength of the data buffer in bytes

◆ flush()

template<typename T = float>
void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ getChannelFrequencies()

template<typename T = float>
bool getChannelFrequencies ( int channel,
int & freq_low_val,
int & freq_high_val )
inline

Get frequency parameters for a specific channel

Parameters
channelChannel index (0-based)
freq_low_valReference to store the low frequency cutoff
freq_high_valReference to store the high frequency cutoff
Returns
true if successful, false if channel index is invalid

◆ getChannelGains()

template<typename T = float>
bool getChannelGains ( int channel,
float & gain_low_val,
float & gain_medium_val,
float & gain_high_val )
inline

Get gain parameters for a specific channel

Parameters
channelChannel index (0-based)
gain_low_valReference to store the low frequency gain
gain_medium_valReference to store the medium frequency gain
gain_high_valReference to store the high frequency gain
Returns
true if successful, false if channel index is invalid

◆ 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]

◆ readBytes()

template<typename T = float>
size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Read and process audio data through the per-channel equalizer

Parameters
dataBuffer to store processed audio data
lenMaximum number of bytes to read
Returns
Number of bytes actually read and processed

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.

◆ sample()

template<typename T = float>
T sample ( int channel,
T sample_val )
inlineprotected

Processes a single sample through the 3-band equalizer for a specific channel

Parameters
channelThe channel number to process
sample_valThe input sample value
Returns
The processed sample value with per-channel equalization applied

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

template<typename T = float>
virtual void setAudioInfo ( AudioInfo info)
inlineoverridevirtual

◆ setChannelFrequencies()

template<typename T = float>
void setChannelFrequencies ( int channel,
int freq_low_val,
int freq_high_val )
inline

Set frequency parameters for a specific channel

Parameters
channelChannel index (0-based)
freq_low_valLow frequency cutoff in Hz
freq_high_valHigh frequency cutoff in Hz

◆ setChannelGains()

template<typename T = float>
void setChannelGains ( int channel,
float gain_low_val,
float gain_medium_val,
float gain_high_val )
inline

Set gain parameters for a specific channel

Parameters
channelChannel index (0-based)
gain_low_valGain multiplier for low frequencies (0.0-2.0)
gain_medium_valGain multiplier for medium frequencies (0.0-2.0)
gain_high_valGain multiplier for high frequencies (0.0-2.0)

◆ 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<typename T = float>
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<typename T = float>
void setStream ( Stream & io)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ write() [1/2]

◆ write() [2/2]

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

Process and write audio data through the per-channel equalizer

Parameters
dataPointer to audio data buffer
lenLength of data in bytes
Returns
Number of bytes written

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

◆ cfg

template<typename T = float>
ConfigEqualizer3Bands cfg
protected

Default configuration instance.

◆ freq_high

template<typename T = float>
Vector<int> freq_high
protected

High frequency cutoffs per channel (Hz).

◆ freq_low

template<typename T = float>
Vector<int> freq_low
protected

Low frequency cutoffs per channel (Hz).

◆ gain_high

template<typename T = float>
Vector<float> gain_high
protected

High frequency gains per channel.

◆ gain_low

template<typename T = float>
Vector<float> gain_low
protected

Low frequency gains per channel.

◆ gain_medium

template<typename T = float>
Vector<float> gain_medium
protected

Medium frequency gains per channel.

◆ info

AudioInfo info
protectedinherited

◆ is_active

template<typename T = float>
bool is_active = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ max_state_count

template<typename T = float>
int max_state_count = 0
protected

Maximum number of allocated channel states.

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ p_cfg

template<typename T = float>
ConfigEqualizer3Bands* p_cfg = &cfg
protected

Pointer to active configuration.

◆ p_io

template<typename T = float>
Stream* p_io = nullptr
protected

Input/output stream for read operations.

◆ p_out

template<typename T = float>
Print* p_out = nullptr
protected

Output stream for write operations.

◆ state

template<typename T = float>
struct audio_tools::Equalizer3BandsPerChannelT::EQSTATE* state = nullptr
protected

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ vsa

template<typename T = float>
const T vsa = EqDenormalGuard<T>::value()
protected

Denormal-avoidance offset.

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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