The Open Master Hearing Aid (openMHA)
openMHA
Open community platform for hearing aid algorithm research
|
The vector and matrix processing toolbox consists of a number of classes defined in the namespace MHASignal, and many functions and operators for use with the structures mha_wave_t and mha_spec_t. More...
Classes | |
struct | mha_wave_t |
Waveform signal structure. More... | |
struct | mha_audio_descriptor_t |
Description of an audio fragment (planned as a replacement of mhaconfig_t). More... | |
struct | mha_audio_t |
An audio fragment in the openMHA (planned as a replacement of mha_wave_t and mha_spec_t). More... | |
class | MHASignal::spectrum_t |
a signal processing class for spectral data (based on mha_spec_t) More... | |
class | MHASignal::waveform_t |
signal processing class for waveform data (based on mha_wave_t) More... | |
class | MHASignal::doublebuffer_t |
Double-buffering class. More... | |
class | MHASignal::hilbert_t |
Hilbert transformation of a waveform segment. More... | |
class | MHASignal::minphase_t |
Minimal phase function. More... | |
class | MHASignal::uint_vector_t |
Vector of unsigned values, used for size and index description of n-dimensional matrixes. More... | |
class | MHASignal::matrix_t |
n-dimensional matrix with real or complex floating point values. More... | |
class | MHAParser::window_t |
MHA configuration interface for a window function generator. More... | |
class | MHASignal::delay_wave_t |
Delayline containing wave fragments. More... | |
class | MHASignal::async_rmslevel_t |
Class for asynchronous level metering. More... | |
Typedefs | |
typedef float | mha_real_t |
openMHA type for real numbers More... | |
Functions | |
mha_wave_t | range (mha_wave_t s, unsigned int k0, unsigned int len) |
Return a time interval from a waveform chunk. More... | |
mha_spec_t | channels (mha_spec_t s, unsigned int ch_start, unsigned int nch) |
Return a channel interval from a spectrum. More... | |
mha_real_t | MHASignal::bin2freq (mha_real_t bin, unsigned fftlen, mha_real_t srate) |
conversion from fft bin index to frequency More... | |
mha_real_t | MHASignal::freq2bin (mha_real_t freq, unsigned fftlen, mha_real_t srate) |
conversion from frequency to fft bin index More... | |
mha_real_t | MHASignal::smp2rad (mha_real_t samples, unsigned bin, unsigned fftlen) |
conversion from delay in samples to phase shift More... | |
mha_real_t | MHASignal::rad2smp (mha_real_t phase_shift, unsigned bin, unsigned fftlen) |
conversion from phase shift to delay in samples More... | |
template<class elem_type > | |
std::vector< elem_type > | MHASignal::dupvec (std::vector< elem_type > vec, unsigned n) |
Duplicate last vector element to match desired size. More... | |
template<class elem_type > | |
std::vector< elem_type > | MHASignal::dupvec_chk (std::vector< elem_type > vec, unsigned n) |
Duplicate last vector element to match desired size, check for dimension. More... | |
bool | equal_dim (const mha_wave_t &a, const mha_wave_t &b) |
Test for equal dimension of waveform structures. More... | |
bool | equal_dim (const mha_wave_t &a, const mhaconfig_t &b) |
Test for match of waveform dimension with mhaconfig structure. More... | |
bool | equal_dim (const mha_spec_t &a, const mha_spec_t &b) |
Test for equal dimension of spectrum structures. More... | |
bool | equal_dim (const mha_spec_t &a, const mhaconfig_t &b) |
Test for match of spectrum dimension with mhaconfig structure. More... | |
bool | equal_dim (const mha_wave_t &a, const mha_spec_t &b) |
Test for equal dimension of waveform/spectrum structures. More... | |
bool | equal_dim (const mha_spec_t &a, const mha_wave_t &b) |
Test for equal dimension of waveform/spectrum structures. More... | |
void | integrate (mha_wave_t &s) |
Numeric integration of a signal vector (real values) More... | |
void | integrate (mha_spec_t &s) |
Numeric integration of a signal vector (complex values) More... | |
unsigned int | size (const mha_wave_t &s) |
Return size of a waveform structure. More... | |
unsigned int | size (const mha_spec_t &s) |
Return size of a spectrum structure. More... | |
unsigned int | size (const mha_wave_t *s) |
Return size of a waveform structure. More... | |
unsigned int | size (const mha_spec_t *s) |
Return size of a spectrum structure. More... | |
void | clear (mha_wave_t &s) |
Set all values of waveform to zero. More... | |
void | clear (mha_wave_t *s) |
Set all values of waveform to zero. More... | |
void | clear (mha_spec_t &s) |
Set all values of spectrum to zero. More... | |
void | clear (mha_spec_t *s) |
Set all values of spectrum to zero. More... | |
void | assign (mha_wave_t self, mha_real_t val) |
Set all values of waveform 'self' to 'val'. More... | |
void | assign (mha_wave_t self, const mha_wave_t &val) |
Set all values of waveform 'self' to 'val'. More... | |
void | assign (mha_spec_t self, const mha_spec_t &val) |
Set all values of spectrum 'self' to 'val'. More... | |
void | timeshift (mha_wave_t &self, int shift) |
Time shift of waveform chunk. More... | |
mha_real_t & | value (mha_wave_t *s, unsigned int fr, unsigned int ch) |
Access an element of a waveform structure. More... | |
const mha_real_t & | value (const mha_wave_t *s, unsigned int fr, unsigned int ch) |
Constant access to an element of a waveform structure. More... | |
mha_complex_t & | value (mha_spec_t *s, unsigned int fr, unsigned int ch) |
Access to an element of a spectrum. More... | |
const mha_complex_t & | value (const mha_spec_t *s, unsigned int fr, unsigned int ch) |
Constant access to an element of a spectrum. More... | |
mha_real_t & | value (mha_wave_t &s, unsigned int fr, unsigned int ch) |
Access to an element of a waveform structure. More... | |
const mha_real_t & | value (const mha_wave_t &s, unsigned int fr, unsigned int ch) |
Constant access to an element of a waveform structure. More... | |
mha_complex_t & | value (mha_spec_t &s, unsigned int fr, unsigned int ch) |
Access to an element of a spectrum. More... | |
const mha_complex_t & | value (const mha_spec_t &s, unsigned int fr, unsigned int ch) |
Constant access to an element of a spectrum. More... | |
std::vector< float > | std_vector_float (const mha_wave_t &) |
Converts a mha_wave_t structure into a std::vector<float> (interleaved order). More... | |
std::vector< std::vector< float > > | std_vector_vector_float (const mha_wave_t &) |
Converts a mha_wave_t structure into a std::vector< std::vector<float> > (outer vector represents channels). More... | |
std::vector< std::vector< mha_complex_t > > | std_vector_vector_complex (const mha_spec_t &) |
Converts a mha_spec_t structure into a std::vector< std::vector<mha_complex_t> > (outer vector represents channels). More... | |
mha_wave_t & | operator+= (mha_wave_t &, const mha_real_t &) |
Addition operator. More... | |
mha_wave_t & | operator+= (mha_wave_t &, const mha_wave_t &) |
Addition operator. More... | |
mha_wave_t & | operator-= (mha_wave_t &, const mha_wave_t &) |
Subtraction operator. More... | |
mha_spec_t & | operator-= (mha_spec_t &, const mha_spec_t &) |
Subtraction operator. More... | |
mha_wave_t & | operator*= (mha_wave_t &, const mha_real_t &) |
Element-wise multiplication operator. More... | |
mha_wave_t & | operator*= (mha_wave_t &, const mha_wave_t &) |
Element-wise multiplication operator. More... | |
mha_spec_t & | operator*= (mha_spec_t &, const mha_real_t &) |
Element-wise multiplication operator. More... | |
mha_spec_t & | operator*= (mha_spec_t &, const mha_wave_t &) |
Element-wise multiplication operator. More... | |
mha_spec_t & | operator*= (mha_spec_t &, const mha_spec_t &) |
Element-wise multiplication operator. More... | |
mha_spec_t & | operator/= (mha_spec_t &, const mha_spec_t &) |
Element-wise division operator. More... | |
mha_wave_t & | operator/= (mha_wave_t &, const mha_wave_t &) |
Element-wise division operator. More... | |
mha_spec_t & | operator+= (mha_spec_t &, const mha_spec_t &) |
Addition operator. More... | |
mha_spec_t & | operator+= (mha_spec_t &, const mha_real_t &) |
Addition operator. More... | |
mha_wave_t & | operator^= (mha_wave_t &self, const mha_real_t &arg) |
Exponent operator. More... | |
void | MHASignal::copy_channel (mha_spec_t &self, const mha_spec_t &src, unsigned sch, unsigned dch) |
Copy one channel of a source signal. More... | |
void | MHASignal::copy_channel (mha_wave_t &self, const mha_wave_t &src, unsigned src_channel, unsigned dest_channel) |
Copy one channel of a source signal. More... | |
mha_real_t | MHASignal::rmslevel (const mha_spec_t &s, unsigned int channel, unsigned int fftlen) |
Return RMS level of a spectrum channel. More... | |
mha_real_t | MHASignal::colored_intensity (const mha_spec_t &s, unsigned int channel, unsigned int fftlen, mha_real_t *sqfreq_response=nullptr) |
Colored spectrum intensity. More... | |
mha_real_t | MHASignal::maxabs (const mha_spec_t &s, unsigned int channel) |
Find maximal absolute value. More... | |
mha_real_t | MHASignal::rmslevel (const mha_wave_t &s, unsigned int channel) |
Return RMS level of a waveform channel. More... | |
mha_real_t | MHASignal::maxabs (const mha_wave_t &s, unsigned int channel) |
Find maximal absolute value. More... | |
mha_real_t | MHASignal::maxabs (const mha_wave_t &s) |
Find maximal absolute value. More... | |
mha_real_t | MHASignal::max (const mha_wave_t &s) |
Find maximal value. More... | |
mha_real_t | MHASignal::min (const mha_wave_t &s) |
Find minimal value. More... | |
mha_real_t | MHASignal::sumsqr_channel (const mha_wave_t &s, unsigned int channel) |
Calculate sum of squared values in one channel. More... | |
mha_real_t | MHASignal::sumsqr_frame (const mha_wave_t &s, unsigned int frame) |
Calculate sum over all channels of squared values. More... | |
void | conjugate (mha_spec_t &self) |
Replace (!) the value of this mha_spec_t with its conjugate. More... | |
The vector and matrix processing toolbox consists of a number of classes defined in the namespace MHASignal, and many functions and operators for use with the structures mha_wave_t and mha_spec_t.
typedef float mha_real_t |
openMHA type for real numbers
This type is expected to be allways the C-type 'float' (IEEE 754 single).
mha_wave_t range | ( | mha_wave_t | s, |
unsigned int | k0, | ||
unsigned int | len | ||
) |
Return a time interval from a waveform chunk.
A waveform chunk containing a time intervall of a larger waveform chunk is returned. The number of channels remains constant. The data of the output waveform structure points to the data of the input structure, i.e., write access to the output waveform chunk modifies the corresponding entries in the input chunk.
s | Waveform structure |
k0 | Index of first value in output |
len | Number of frames in output |
mha_spec_t channels | ( | mha_spec_t | s, |
unsigned int | ch_start, | ||
unsigned int | nch | ||
) |
Return a channel interval from a spectrum.
s | Input spectrum |
ch_start | Index of first channel in output |
nch | Number of channels in output |
|
inline |
conversion from fft bin index to frequency
bin | index of fft bin, index 0 has dc |
fftlen | FFT length |
srate | sampling frequency / Hz |
|
inline |
conversion from frequency to fft bin index
freq | frequency / Hz |
fftlen | FFT length |
srate | sampling frequency / Hz |
|
inline |
conversion from delay in samples to phase shift
Compute phase shift that needs to be applied to fft spectrum to achieve the desired delay.
samples | delay in samples. Positive delay: shift current signal to future. |
bin | index of fft bin, index 0 has dc (index 0 and nyqvist bin cannot be delayed) |
fftlen | FFT length |
|
inline |
conversion from phase shift to delay in samples
Compute delay in samples that is achieved by a phase shift.
phase_shift | phase shift in radiant |
bin | index of fft bin, index 0 has dc (index 0 and nyqvist bin cannot be delayed) |
fftlen | FFT length |
std::vector<elem_type> MHASignal::dupvec | ( | std::vector< elem_type > | vec, |
unsigned | n | ||
) |
Duplicate last vector element to match desired size.
vec | Input vector. |
n | Target number of elements. |
Resized | vector. |
std::vector<elem_type> MHASignal::dupvec_chk | ( | std::vector< elem_type > | vec, |
unsigned | n | ||
) |
Duplicate last vector element to match desired size, check for dimension.
The input dimension can be either 1 or the target length.
vec | Input vector. |
n | Target number of elements. |
Resized | vector. |
|
inline |
Test for equal dimension of waveform structures.
|
inline |
Test for match of waveform dimension with mhaconfig structure.
|
inline |
Test for equal dimension of spectrum structures.
|
inline |
Test for match of spectrum dimension with mhaconfig structure.
|
inline |
Test for equal dimension of waveform/spectrum structures.
|
inline |
Test for equal dimension of waveform/spectrum structures.
void integrate | ( | mha_wave_t & | s | ) |
Numeric integration of a signal vector (real values)
s | Input signal vector |
void integrate | ( | mha_spec_t & | s | ) |
Numeric integration of a signal vector (complex values)
s | Input signal vector |
|
inline |
Return size of a waveform structure.
|
inline |
Return size of a spectrum structure.
|
inline |
Return size of a waveform structure.
|
inline |
Return size of a spectrum structure.
|
inline |
Set all values of waveform to zero.
|
inline |
Set all values of waveform to zero.
|
inline |
Set all values of spectrum to zero.
|
inline |
Set all values of spectrum to zero.
|
inline |
Set all values of waveform 'self' to 'val'.
self | Waveform to be modified. |
val | Value to be assigned to all entries of waveform. |
void assign | ( | mha_wave_t | self, |
const mha_wave_t & | val | ||
) |
Set all values of waveform 'self' to 'val'.
self | Waveform to be modified. |
val | Source waveform structure. |
void assign | ( | mha_spec_t | self, |
const mha_spec_t & | val | ||
) |
Set all values of spectrum 'self' to 'val'.
self | Spectrum to be modified. |
val | Source spectrum. |
void timeshift | ( | mha_wave_t & | self, |
int | shift | ||
) |
Time shift of waveform chunk.
Shifted areas are filled with zeros.
self | Waveform chunk to be shifted |
shift | Shift amount, positive values shift to later times |
|
inline |
Access an element of a waveform structure.
s | Waveform structure |
fr | Frame number |
ch | Channel number |
|
inline |
Constant access to an element of a waveform structure.
s | Waveform structure |
fr | Frame number |
ch | Channel number |
|
inline |
Access to an element of a spectrum.
s | Spectrum structure |
fr | Bin number |
ch | Channel number |
|
inline |
Constant access to an element of a spectrum.
s | Spectrum structure |
fr | Bin number |
ch | Channel number |
|
inline |
Access to an element of a waveform structure.
s | Waveform structure |
fr | Frame number |
ch | Channel number |
|
inline |
Constant access to an element of a waveform structure.
s | Waveform structure |
fr | Frame number |
ch | Channel number |
|
inline |
Access to an element of a spectrum.
s | Spectrum structure |
fr | Bin number |
ch | Channel number |
|
inline |
Constant access to an element of a spectrum.
s | Spectrum structure |
fr | Bin number |
ch | Channel number |
std::vector<float> std_vector_float | ( | const mha_wave_t & | w | ) |
Converts a mha_wave_t structure into a std::vector<float> (interleaved order).
std::vector<std::vector<float> > std_vector_vector_float | ( | const mha_wave_t & | w | ) |
Converts a mha_wave_t structure into a std::vector< std::vector<float> > (outer vector represents channels).
std::vector<std::vector<mha_complex_t> > std_vector_vector_complex | ( | const mha_spec_t & | w | ) |
Converts a mha_spec_t structure into a std::vector< std::vector<mha_complex_t> > (outer vector represents channels).
mha_wave_t& operator+= | ( | mha_wave_t & | self, |
const mha_real_t & | v | ||
) |
Addition operator.
mha_wave_t& operator+= | ( | mha_wave_t & | self, |
const mha_wave_t & | v | ||
) |
Addition operator.
mha_wave_t& operator-= | ( | mha_wave_t & | self, |
const mha_wave_t & | v | ||
) |
Subtraction operator.
mha_spec_t& operator-= | ( | mha_spec_t & | self, |
const mha_spec_t & | v | ||
) |
Subtraction operator.
mha_wave_t& operator*= | ( | mha_wave_t & | self, |
const mha_real_t & | v | ||
) |
Element-wise multiplication operator.
mha_wave_t& operator*= | ( | mha_wave_t & | self, |
const mha_wave_t & | v | ||
) |
Element-wise multiplication operator.
mha_spec_t& operator*= | ( | mha_spec_t & | self, |
const mha_real_t & | v | ||
) |
Element-wise multiplication operator.
mha_spec_t& operator*= | ( | mha_spec_t & | self, |
const mha_wave_t & | v | ||
) |
Element-wise multiplication operator.
mha_spec_t& operator*= | ( | mha_spec_t & | self, |
const mha_spec_t & | v | ||
) |
Element-wise multiplication operator.
mha_spec_t& operator/= | ( | mha_spec_t & | self, |
const mha_spec_t & | v | ||
) |
Element-wise division operator.
mha_wave_t& operator/= | ( | mha_wave_t & | self, |
const mha_wave_t & | v | ||
) |
Element-wise division operator.
mha_spec_t& operator+= | ( | mha_spec_t & | self, |
const mha_spec_t & | v | ||
) |
Addition operator.
mha_spec_t& operator+= | ( | mha_spec_t & | self, |
const mha_real_t & | v | ||
) |
Addition operator.
mha_wave_t& operator^= | ( | mha_wave_t & | self, |
const mha_real_t & | arg | ||
) |
Exponent operator.
void MHASignal::copy_channel | ( | mha_spec_t & | self, |
const mha_spec_t & | src, | ||
unsigned | sch, | ||
unsigned | dch | ||
) |
Copy one channel of a source signal.
self | Destination. |
src | Source |
sch | Source channel number |
dch | Destination channel number |
void MHASignal::copy_channel | ( | mha_wave_t & | self, |
const mha_wave_t & | src, | ||
unsigned | src_channel, | ||
unsigned | dest_channel | ||
) |
Copy one channel of a source signal.
self | Destination. |
src | Source |
src_channel | Source channel number |
dest_channel | Destination channel number |
mha_real_t MHASignal::rmslevel | ( | const mha_spec_t & | s, |
unsigned int | channel, | ||
unsigned int | fftlen | ||
) |
Return RMS level of a spectrum channel.
Computes the RMS level of the signal in Pascal in the given channel.
Takes into account the the negative frequency bins that are not stored (Central Calibration).
s | Input spectrum |
channel | Channel number to be tested |
fftlen | FFT length (to correctly count the level of the Nyquist bin) |
mha_real_t MHASignal::colored_intensity | ( | const mha_spec_t & | s, |
unsigned int | channel, | ||
unsigned int | fftlen, | ||
mha_real_t * | sqfreq_response = nullptr |
||
) |
Colored spectrum intensity.
computes the squared sum of the spectrum after filtering with the frequency response. Takes into account the negative frequency bins that are not stored (Central Calibration).
s | Input spectrum |
channel | Channel number to be tested |
fftlen | FFT length (to correctly count the level of the Nyquist bin) |
sqfreq_response | An array with one squared weighting factor for every fft bin. Array length must be equal to s->num_frames. nullptr can be given for equal weighting of all frequencies. |
mha_real_t MHASignal::maxabs | ( | const mha_spec_t & | s, |
unsigned int | channel | ||
) |
Find maximal absolute value.
s | Input signal |
channel | Channel to be tested |
mha_real_t MHASignal::rmslevel | ( | const mha_wave_t & | s, |
unsigned int | channel | ||
) |
Return RMS level of a waveform channel.
s | Input waveform signal |
channel | Channel number to be tested |
mha_real_t MHASignal::maxabs | ( | const mha_wave_t & | s, |
unsigned int | channel | ||
) |
Find maximal absolute value.
s | Input signal |
channel | Channel to be tested |
mha_real_t MHASignal::maxabs | ( | const mha_wave_t & | s | ) |
Find maximal absolute value.
s | Input signal |
mha_real_t MHASignal::max | ( | const mha_wave_t & | s | ) |
Find maximal value.
s | Input signal |
mha_real_t MHASignal::min | ( | const mha_wave_t & | s | ) |
Find minimal value.
s | Input signal |
mha_real_t MHASignal::sumsqr_channel | ( | const mha_wave_t & | s, |
unsigned int | channel | ||
) |
Calculate sum of squared values in one channel.
s | Input signal |
channel | Channel |
mha_real_t MHASignal::sumsqr_frame | ( | const mha_wave_t & | s, |
unsigned int | frame | ||
) |
Calculate sum over all channels of squared values.
s | Input signal |
frame | Frame number |
|
inline |
Replace (!) the value of this mha_spec_t with its conjugate.