The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHAFilter::iir_filter_t Class Reference

IIR filter class wrapper for integration into parser structure. More...

Inheritance diagram for MHAFilter::iir_filter_t:
Inheritance graph

Public Member Functions

 iir_filter_t (std::string help="IIR filter structure", std::string def_A="[1]", std::string def_B="[1]", unsigned int channels=1)
 Constructor of the IIR filter. More...
void filter (mha_wave_t *y, const mha_wave_t *x)
 The filter processes the audio signal. More...
mha_real_t filter (mha_real_t x, unsigned int ch)
 Filter a single audio sample. More...
void resize (unsigned int channels)
 Change the number of channels after object creation. More...
- Public Member Functions inherited from MHAParser::parser_t
 parser_t (const std::string &help_text="")
 Construct detached node to be used in the configuration tree. More...
 ~parser_t ()
void insert_item (const std::string &, base_t *)
 Register a parser item into this sub-parser. More...
void remove_item (const std::string &)
 Remove an item by name. More...
void force_remove_item (const std::string &)
 Remove an item by name. More...
void remove_item (const base_t *)
 Remove an item by address. More...
- Public Member Functions inherited from MHAParser::base_t
 base_t (const std::string &)
 Constructor for base class of all parser nodes. More...
 base_t (const base_t &)
 Copy constructor for base_t. More...
base_toperator= (const base_t &)=default
 base_t (base_t &&)=delete
base_toperator= (base_t &&)=delete
virtual ~base_t ()
virtual std::string parse (const std::string &)
 Causes this node to process a command in the openMHA configuration language. More...
virtual void parse (const char *, char *, unsigned int)
 This function parses a command and writes the parsing result into a C character array. More...
virtual void parse (const std::vector< std::string > &, std::vector< std::string > &)
virtual std::string query_perm (const std::string &)
virtual std::string query_range (const std::string &)
std::string query_version (const std::string &)
std::string query_id (const std::string &)
std::string query_subst (const std::string &)
std::string query_addsubst (const std::string &)
std::string query_help (const std::string &)
std::string query_cmds (const std::string &)
void set_node_id (const std::string &)
 Set the identification string of this parser node. More...
void set_help (const std::string &)
 Set the help comment of a variable or parser. More...
void add_parent_on_insert (parser_t *, std::string)
void rm_parent_on_remove (parser_t *)
const std::string & fullname () const
 Return the full dot-separated path name of this parser node in the openMHA configuration tree. More...

Private Member Functions

void update_filter ()
- Private Member Functions inherited from MHAPlugin::config_t< iir_filter_state_t >
 config_t ()
 ~config_t ()
iir_filter_state_t * poll_config ()
 Receive the latest run time configuration. More...
iir_filter_state_t * peek_config () const
 Receive the latest run time configuration without changing the configuration pointer. More...
void push_config (iir_filter_state_t *ncfg)
 Push a new run time configuration into the configuration fifo. More...
void cleanup_unused_cfg ()
 To be called by the push_config() for housekeeping. More...
void remove_all_cfg ()
 To be called on Plugin destruction, will delete all runtime configuration list nodes and objects regardless of their in_use flag. More...

Private Attributes

MHAParser::vfloat_t A
MHAParser::vfloat_t B
MHAEvents::patchbay_t< iir_filter_tconnector
unsigned int nchannels
- Private Attributes inherited from MHAPlugin::config_t< iir_filter_state_t >
iir_filter_state_t * cfg
 Pointer to the runtime configuration currently used by the signal processing thread. More...

Additional Inherited Members

- Public Attributes inherited from MHAParser::base_t
MHAEvents::emitter_t writeaccess
 Event emitted on write access. More...
MHAEvents::emitter_t valuechanged
 Event emitted if the value has changed. More...
MHAEvents::emitter_t readaccess
 Event emitted on read access. More...
MHAEvents::emitter_t prereadaccess
 Event emitted on read access, before the data field is accessed. More...
- Protected Member Functions inherited from MHAParser::parser_t
std::string op_subparse (expression_t &)
std::string op_setval (expression_t &)
std::string op_query (expression_t &)
std::string query_type (const std::string &)
std::string query_dump (const std::string &)
std::string query_entries (const std::string &)
std::string query_readfile (const std::string &)
std::string query_savefile (const std::string &)
std::string query_savefile_compact (const std::string &)
std::string query_savemons (const std::string &)
std::string query_val (const std::string &)
std::string query_listids (const std::string &)
void set_id_string (const std::string &)
bool has_entry (const std::string &)
- Protected Member Functions inherited from MHAParser::base_t
void activate_query (const std::string &, query_t)
void notify ()
- Protected Attributes inherited from MHAParser::base_t
query_map_t queries
bool data_is_initialized

Detailed Description

IIR filter class wrapper for integration into parser structure.

This class implements an infinite impulse response filter. Since it inherits from MHAParser::parser_t, it can easily be integrated in the openMHA configuration tree. It provides the configuration language variables "A" (vector of recursive filter coefficients) and "B" (vector of non-recursive filter coefficients).

The filter instance reacts to changes in filter coefficients through the openMHA configuration language, and uses the updated coefficients in the next invocation of the filter method.

Update of the coefficients is thread-safe and non-blocking. Simply add this subparser to your parser items and use the "filter" member function. Filter states are reset to all 0 on update.

Constructor & Destructor Documentation

◆ iir_filter_t()

MHAFilter::iir_filter_t::iir_filter_t ( std::string  help = "IIR filter structure",
std::string  def_A = "[1]",
std::string  def_B = "[1]",
unsigned int  channels = 1 

Constructor of the IIR filter.

Initialises the sub-parser structure and the memory for holding the filter's state.

helpThe help string for the parser that groups the configuration variables of this filter. Could be used to describe the purpose of this IIR filter.
def_AThe initial value of the vector of the recursive filter coefficients, represented as string.
def_BThe initial value of the vector of the non-recursive filter coefficients, represented as string.
channelsThe number of indipendent audio channels to process with this filter. Needed to allocate a state vector for each audio channel.

Member Function Documentation

◆ filter() [1/2]

void MHAFilter::iir_filter_t::filter ( mha_wave_t y,
const mha_wave_t x 

The filter processes the audio signal.

All channels in the audio signal are processed using the same filter coefficients. Indipendent state is stored between calls for each audio channel.

yPointer to output signal holder. The output signal is stored here. Has to have the same signal dimensions as the input signal x. In-place processing (y and x pointing to the same signal holder) is possible.
xPointer to input signal holder. Number of channels has to be the same as given to the constructor, or to the resize method.

◆ filter() [2/2]

mha_real_t MHAFilter::iir_filter_t::filter ( mha_real_t  x,
unsigned int  ch 

Filter a single audio sample.

xThe single audio sample
chZero-based channel index. Use and change the state of channel ch. ch has to be less than the number of channels given to the constructor or the resize method.
the filtered result sample.

◆ resize()

void MHAFilter::iir_filter_t::resize ( unsigned int  channels)

Change the number of channels after object creation.

channelsThe new number of channels. Old filter states are lost.

◆ update_filter()

void MHAFilter::iir_filter_t::update_filter ( )

Member Data Documentation

◆ A

MHAParser::vfloat_t MHAFilter::iir_filter_t::A

◆ B

MHAParser::vfloat_t MHAFilter::iir_filter_t::B

◆ connector

MHAEvents::patchbay_t<iir_filter_t> MHAFilter::iir_filter_t::connector

◆ nchannels

unsigned int MHAFilter::iir_filter_t::nchannels

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