The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
gtfb_simd.cpp File Reference

Gammatone Filterbank Analyzer Plugin using SIMD. More...

Classes

class  gtfb_simd_cfg_t
 
class  gtfb_simd_t
 

Macros

#define add4f(a, b)   __builtin_ia32_addps(a,b)
 
#define sub4f(a, b)   __builtin_ia32_subps(a,b)
 
#define mul4f(a, b)   __builtin_ia32_mulps(a,b)
 
#define MXCSR_DAZ   (1 << 6) /* Enable denormals are zero mode */
 
#define MXCSR_FTZ   (1 << 15) /* Enable flush to zero mode */
 
#define check_alignment(ptr, alignment)
 Checks alignment of pointer address. More...
 

Functions

void filter_sisd_complex (const unsigned bands, const unsigned order, const mha_complex_t *inputs, mha_complex_t *outputs, const mha_complex_t *coefficients, mha_complex_t *states)
 Filters one sample per band, using SISD operations and the mha_complex operations. More...
 
void filter_sisd_real (const unsigned bands, const unsigned order, const mha_complex_t *inputs, mha_complex_t *outputs, const mha_complex_t *coefficients, mha_complex_t *states)
 Filters one sample per band, using SISD operations and real operations (operating on real and imaginary part as necessary). More...
 
void filter_simd (const unsigned bands, const unsigned order, const mha_real_t *rinputs, const mha_real_t *iinputs, mha_real_t *routputs, mha_real_t *ioutputs, const mha_real_t *rcoefficients, const mha_real_t *icoefficients, mha_real_t *rstates, mha_real_t *istates)
 Filters one sample per band, using simd operations on float32 To process more than one sample, the function must be called repeatedly in correct order (from oldest sample to newest sample), and the calling function must preserve the filter state (parameters rstates and istates). More...
 

Detailed Description

Gammatone Filterbank Analyzer Plugin using SIMD.

A single-instruction-multiple-data (SIMD) implementation of a gammatone filterbank (GTFB)

Not all functions in this file are actually used. Read the functions in this file as a path to convert an algorithm, here complex-valued gammatone filtering as introduced in Hohmann 2002, from a single-instruction-single-data (SISD) implementation that uses complex arithmetic operations to a SIMD implementation of the same, splitting the complex arithmetic operations into their defining real operations, i.e (a+b).real==a.real+b.real, (a+b).imag==a.imag+b.imag, (a*b).real==a.real*b.real-a.imag*b.imag, (a*b).imag==a.real*b.imag+a.imag*b.real.

Macro Definition Documentation

◆ add4f

#define add4f (   a,
 
)    __builtin_ia32_addps(a,b)

◆ sub4f

#define sub4f (   a,
 
)    __builtin_ia32_subps(a,b)

◆ mul4f

#define mul4f (   a,
 
)    __builtin_ia32_mulps(a,b)

◆ MXCSR_DAZ

#define MXCSR_DAZ   (1 << 6) /* Enable denormals are zero mode */

◆ MXCSR_FTZ

#define MXCSR_FTZ   (1 << 15) /* Enable flush to zero mode */

◆ check_alignment

#define check_alignment (   ptr,
  alignment 
)

Checks alignment of pointer address.

Parameters
ptrpointer to check
alignmentrequired alignment
Exceptions
MHA_Errorif ptr is not aligned as required.

Function Documentation

◆ filter_sisd_complex()

void filter_sisd_complex ( const unsigned  bands,
const unsigned  order,
const mha_complex_t inputs,
mha_complex_t outputs,
const mha_complex_t coefficients,
mha_complex_t states 
)

Filters one sample per band, using SISD operations and the mha_complex operations.

To process more than one sample, the function must be called repeatedly in correct order (from oldest sample to newest sample), and the calling function must preserve the filter state (parameter states).

This function is not actually used in this plugin, but can be used for testing. It implements the Hohmann 2002 filtering in the most readable form, and is translated towards a SIMD implementation in the following functions.

Parameters
bandsNumber of total bands to compute (i.e. input_channels * num_frequencies)
orderGammatone filter order
inputsPointer to array of complex input samples, only 1 sample per band
outputsPointer to array with space for output samples, 1 complex sample per band
coefficientsPointer to array of recursive filter coefficient, 1 coefficient per band. The same coefficient is reused for all filter orders.
statesPointer to array of complex filter states. Array size is bands*order. Initialize all elements with zeros before filtering the first sample. Filter state values will be modified by the function. For filtering the next sample, this function needs the filter state array from filtering the previous sample again, unmodified. The filter state of band b, order o can be found at index [b+o*bands]

◆ filter_sisd_real()

void filter_sisd_real ( const unsigned  bands,
const unsigned  order,
const mha_complex_t inputs,
mha_complex_t outputs,
const mha_complex_t coefficients,
mha_complex_t states 
)
inline

Filters one sample per band, using SISD operations and real operations (operating on real and imaginary part as necessary).

To process more than one sample, the function must be called repeatedly in correct order (from oldest sample to newest sample), and the calling function must preserve the filter state (parameter states).

This function is not actually used in this plugin, but can be used for testing. It reimplements filter_sisd_complex, but expands the complex operations into real arithmetics.

Parameters
bandsNumber of total bands to compute (i.e. input_channels * num_frequencies)
orderGammatone filter order
inputsPointer to array of complex input samples, only 1 sample per band
outputsPointer to array with space for output samples, 1 complex sample per band
coefficientsPointer to array of recursive filter coefficient, 1 coefficient per band. The same coefficient is reused for all filter orders.
statesPointer to array of complex filter states. Array size is bands*order. Initialize all elements with zeros before filtering the first sample. Filter state values will be modified by the function. For filtering the next sample, this function needs the filter state array from filtering the previous sample again, unmodified. The filter state of band b, order o can be found at index [b+o*bands]

◆ filter_simd()

void filter_simd ( const unsigned  bands,
const unsigned  order,
const mha_real_t rinputs,
const mha_real_t iinputs,
mha_real_t routputs,
mha_real_t ioutputs,
const mha_real_t rcoefficients,
const mha_real_t icoefficients,
mha_real_t rstates,
mha_real_t istates 
)
inline

Filters one sample per band, using simd operations on float32 To process more than one sample, the function must be called repeatedly in correct order (from oldest sample to newest sample), and the calling function must preserve the filter state (parameters rstates and istates).

This reimplements filter_sisd_real, but uses the CPU's vector registers for the arithmetics, and is actually used by this plugin.

Parameters
bandsNumber of total bands to compute (i.e. input_channels * num_frequencies) bands is also the size of the arrays pointed to by rinputs, iinputs, routputs, ioutputs, rcoefficients, icoefficients.
orderGammatone filter order
rinputsPointer to array of the real part of input samples
iinputsPointer to array of the imaginary part of input samples
routputsPointer to array with space for the real parts of the output samples
routputsPointer to array with space for the real parts of the output samples
rcoefficientsPointer to array of the real parts of the recursive filter coefficients
icoefficientsPointer to array of the imaginary parts of the filter coefficients
rstatesPointer to array of real parts of filter states. Array size is bands*order. Initialize all elements with zeros before filtering the first sample. Filter state values will be modified by the function. For filtering the next sample, this function needs the filter state arrays from filtering the previous sample again, unmodified. The real part of the filter state of band b, order o can be found at index [b+o*bands]
istatesPointer to array of imaginary parts of filter states. Array size is bands*order. Initialize all elements with zeros before filtering the first sample. Filter state values will be modified by the function. For filtering the next sample, this function needs the filter state arrays from filtering the previous sample again, unmodified. The imaginary part of the filter state of band b, order o can be found at index [b+o*bands]