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

Header file for audio signal handling and processing classes. More...

Classes

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::ringbuffer_t
 A ringbuffer class for time domain audio signal, which makes no assumptions with respect to fragment size. More...
 
class  MHASignal::hilbert_t
 Hilbert transformation of a waveform segment. More...
 
class  MHASignal::minphase_t
 Minimal phase function. More...
 
class  MHASignal::stat_t
 
class  MHASignal::delay_wave_t
 Delayline containing wave fragments. More...
 
class  MHASignal::delay_spec_t
 
class  MHASignal::async_rmslevel_t
 Class for asynchronous level metering. 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  MHASignal::schroeder_t
 Schroeder tone complex class. More...
 
class  MHASignal::quantizer_t
 Simple simulation of fixpoint quantization. More...
 
class  MHASignal::loop_wavefragment_t
 Copy a fixed waveform fragment to a series of waveform fragments of other size. More...
 
class  MHASignal::delay_t
 Class to realize a simple delay of waveform streams. More...
 
class  MHASignal::subsample_delay_t
 implements subsample delay in spectral domain. More...
 

Namespaces

 MHASignal
 Namespace for audio signal handling and processing classes.
 

Macros

#define M_PI   3.14159265358979323846
 
#define mha_round(x)   (int)((float)x+0.5)
 

Functions

void MHASignal::for_each (mha_wave_t *s, mha_real_t(*fun)(mha_real_t))
 Apply a function to each element of a mha_wave_t. More...
 
mha_real_t MHASignal::lin2db (mha_real_t x, mha_real_t eps)
 Conversion from linear scale to dB (no SPL reference) More...
 
mha_real_t MHASignal::lin2db (mha_real_t x)
 Conversion from linear scale to dB (no SPL reference) More...
 
mha_real_t MHASignal::db2lin (mha_real_t x)
 Conversion from dB scale to linear (no SPL reference) More...
 
mha_real_t MHASignal::sq2db (mha_real_t x, mha_real_t eps=0.0f)
 conversion from squared values to dB (no SPL reference) More...
 
mha_real_t MHASignal::db2sq (mha_real_t x)
 conversion from dB to squared values (no SPL reference) More...
 
mha_real_t MHASignal::pa2dbspl (mha_real_t x, mha_real_t eps)
 Conversion from linear Pascal scale to dB SPL. More...
 
mha_real_t MHASignal::pa2dbspl (mha_real_t x)
 Conversion from linear Pascal scale to dB SPL. More...
 
mha_real_t MHASignal::dbspl2pa (mha_real_t x)
 Conversion from dB SPL to linear Pascal scale. More...
 
mha_real_t MHASignal::pa22dbspl (mha_real_t x, mha_real_t eps=0.0f)
 Conversion from squared Pascal scale to dB SPL. More...
 
mha_real_t MHASignal::dbspl2pa2 (mha_real_t x)
 conversion from dB SPL to squared Pascal scale More...
 
mha_real_t MHASignal::smp2sec (mha_real_t n, mha_real_t srate)
 conversion from samples to seconds More...
 
mha_real_t MHASignal::sec2smp (mha_real_t sec, mha_real_t srate)
 conversion from seconds to samples 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 mha_min_1 (unsigned int a)
 
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_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_tvalue (mha_wave_t *s, unsigned int fr, unsigned int ch)
 Access an element of a waveform structure. More...
 
const mha_real_tvalue (const mha_wave_t *s, unsigned int fr, unsigned int ch)
 Constant access to an element of a waveform structure. More...
 
mha_real_tvalue (mha_wave_t *s, unsigned int k)
 
mha_complex_tvalue (mha_spec_t *s, unsigned int k)
 
mha_complex_tvalue (mha_spec_t *s, unsigned int fr, unsigned int ch)
 Access to an element of a spectrum. More...
 
const mha_complex_tvalue (const mha_spec_t *s, unsigned int fr, unsigned int ch)
 Constant access to an element of a spectrum. More...
 
mha_real_tvalue (mha_wave_t &s, unsigned int fr, unsigned int ch)
 Access to an element of a waveform structure. More...
 
const mha_real_tvalue (const mha_wave_t &s, unsigned int fr, unsigned int ch)
 Constant access to an element of a waveform structure. More...
 
mha_complex_tvalue (mha_spec_t &s, unsigned int fr, unsigned int ch)
 Access to an element of a spectrum. More...
 
const mha_complex_tvalue (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_toperator+= (mha_wave_t &, const mha_real_t &)
 Addition operator. More...
 
mha_wave_toperator+= (mha_wave_t &, const mha_wave_t &)
 Addition operator. More...
 
mha_wave_toperator-= (mha_wave_t &, const mha_wave_t &)
 Subtraction operator. More...
 
mha_spec_toperator-= (mha_spec_t &, const mha_spec_t &)
 Subtraction operator. More...
 
mha_wave_toperator*= (mha_wave_t &, const mha_real_t &)
 Element-wise multiplication operator. More...
 
mha_wave_toperator*= (mha_wave_t &, const mha_wave_t &)
 Element-wise multiplication operator. More...
 
mha_spec_toperator*= (mha_spec_t &, const mha_real_t &)
 Element-wise multiplication operator. More...
 
mha_spec_toperator*= (mha_spec_t &, const mha_wave_t &)
 Element-wise multiplication operator. More...
 
mha_spec_toperator*= (mha_spec_t &, const mha_spec_t &)
 Element-wise multiplication operator. More...
 
mha_spec_toperator/= (mha_spec_t &, const mha_spec_t &)
 Element-wise division operator. More...
 
mha_wave_toperator/= (mha_wave_t &, const mha_wave_t &)
 Element-wise division operator. More...
 
mha_spec_toperator+= (mha_spec_t &, const mha_spec_t &)
 Addition operator. More...
 
mha_spec_toperator+= (mha_spec_t &, const mha_real_t &)
 Addition operator. More...
 
void set_minabs (mha_spec_t &, const mha_real_t &)
 
mha_spec_tsafe_div (mha_spec_t &self, const mha_spec_t &v, mha_real_t eps)
 In-Place division with lower limit on divisor. More...
 
mha_wave_toperator^= (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 MHASignal::scale (mha_spec_t *dest, const mha_wave_t *src)
 
void MHASignal::limit (mha_wave_t &s, const mha_real_t &min, const mha_real_t &max)
 Limit the singal in the waveform buffer to the range [min, max]. More...
 
mha_complex_tset (mha_complex_t &self, mha_real_t real, mha_real_t imag=0)
 Assign real and imaginary parts to a mha_complex_t variable. More...
 
mha_complex_t mha_complex (mha_real_t real, mha_real_t imag=0)
 Create a new mha_complex_t with specified real and imaginary parts. More...
 
mha_complex_tset (mha_complex_t &self, const std::complex< mha_real_t > &stdcomplex)
 Assign a mha_complex_t variable from a std::complex. More...
 
std::complex< mha_real_tstdcomplex (const mha_complex_t &self)
 Create a std::complex from mha_complex_t. More...
 
mha_complex_texpi (mha_complex_t &self, mha_real_t angle)
 replaces the value of the given mha_complex_t with exp(i*b). More...
 
double angle (const mha_complex_t &self)
 Computes the angle of a complex number in the complex plane. More...
 
mha_complex_toperator+= (mha_complex_t &self, const mha_complex_t &other)
 Addition of two complex numbers, overwriting the first. More...
 
mha_complex_t operator+ (const mha_complex_t &self, const mha_complex_t &other)
 Addition of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator+= (mha_complex_t &self, mha_real_t other_real)
 Addition of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator+ (const mha_complex_t &self, mha_real_t other_real)
 Addition of a complex and a real number, result is a temporary object. More...
 
mha_complex_toperator-= (mha_complex_t &self, const mha_complex_t &other)
 Subtraction of two complex numbers, overwriting the first. More...
 
mha_complex_t operator- (const mha_complex_t &self, const mha_complex_t &other)
 Subtraction of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator-= (mha_complex_t &self, mha_real_t other_real)
 Subtraction of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator- (const mha_complex_t &self, mha_real_t other_real)
 Subtraction of a complex and a real number, result is a temporary object. More...
 
mha_complex_toperator*= (mha_complex_t &self, const mha_complex_t &other)
 Multiplication of two complex numbers, overwriting the first. More...
 
mha_complex_t operator* (const mha_complex_t &self, const mha_complex_t &other)
 Multiplication of two complex numbers, result is a temporary object. More...
 
mha_complex_toperator*= (mha_complex_t &self, mha_real_t other_real)
 Multiplication of a complex and a real number, overwriting the complex. More...
 
mha_complex_texpi (mha_complex_t &self, mha_real_t angle, mha_real_t factor)
 replaces (!) the value of the given mha_complex_t with a * exp(i*b) More...
 
mha_complex_t operator* (const mha_complex_t &self, mha_real_t other_real)
 Multiplication of a complex and a real number, result is a temporary object. More...
 
mha_real_t abs2 (const mha_complex_t &self)
 Compute the square of the absolute value of a complex value. More...
 
mha_real_t abs (const mha_complex_t &self)
 Compute the absolute value of a complex value. More...
 
mha_complex_toperator/= (mha_complex_t &self, mha_real_t other_real)
 Division of a complex and a real number, overwriting the complex. More...
 
mha_complex_t operator/ (const mha_complex_t &self, mha_real_t other_real)
 Division of a complex and a real number, result is a temporary object. More...
 
mha_complex_tsafe_div (mha_complex_t &self, const mha_complex_t &other, mha_real_t eps, mha_real_t eps2)
 Safe division of two complex numbers, overwriting the first. More...
 
mha_complex_toperator/= (mha_complex_t &self, const mha_complex_t &other)
 Division of two complex numbers, overwriting the first. More...
 
mha_complex_t operator/ (const mha_complex_t &self, const mha_complex_t &other)
 Division of two complex numbers, result is a temporary object. More...
 
mha_complex_t operator- (const mha_complex_t &self)
 Unary minus on a complex results in a negative temporary object. More...
 
bool operator== (const mha_complex_t &x, const mha_complex_t &y)
 Compare two complex numbers for equality. More...
 
bool operator!= (const mha_complex_t &x, const mha_complex_t &y)
 Compare two complex numbers for inequality. More...
 
void conjugate (mha_complex_t &self)
 Replace (!) the value of this mha_complex_t with its conjugate. More...
 
void conjugate (mha_spec_t &self)
 Replace (!) the value of this mha_spec_t with its conjugate. More...
 
mha_complex_t _conjugate (const mha_complex_t &self)
 Compute the cojugate of this complex value. More...
 
void reciprocal (mha_complex_t &self)
 Replace the value of this complex with its reciprocal. More...
 
mha_complex_t _reciprocal (const mha_complex_t &self)
 compute the reciprocal of this complex value. More...
 
void normalize (mha_complex_t &self)
 Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle). More...
 
void normalize (mha_complex_t &self, mha_real_t margin)
 Divide a complex by its absolute value, thereby normalizing it (projecting onto the unit circle), with a safety margin. More...
 
bool almost (const mha_complex_t &self, const mha_complex_t &other, mha_real_t times_epsilon=1e2)
 Compare two complex numbers for equality except for a small relative error. More...
 
bool operator< (const mha_complex_t &x, const mha_complex_t &y)
 Compares the absolute values of two complex numbers. More...
 
std::ostream & operator<< (std::ostream &o, const mha_complex_t &c)
 ostream operator for mha_complex_t More...
 
std::istream & operator>> (std::istream &i, mha_complex_t &c)
 preliminary istream operator for mha_complex_t without error checking More...
 
mha_fft_t mha_fft_new (unsigned int n)
 Create a new FFT handle. More...
 
void mha_fft_free (mha_fft_t h)
 Destroy an FFT handle. More...
 
void mha_fft_wave2spec (mha_fft_t h, const mha_wave_t *in, mha_spec_t *out)
 Tranform waveform segment into spectrum. More...
 
void mha_fft_wave2spec (mha_fft_t h, const mha_wave_t *in, mha_spec_t *out, bool swaps)
 Tranform waveform segment into spectrum. More...
 
void mha_fft_spec2wave (mha_fft_t h, const mha_spec_t *in, mha_wave_t *out)
 Tranform spectrum into waveform segment. More...
 
void mha_fft_spec2wave (mha_fft_t h, const mha_spec_t *in, mha_wave_t *out, unsigned int offset)
 Tranform spectrum into waveform segment. More...
 
void mha_fft_forward (mha_fft_t h, mha_spec_t *sIn, mha_spec_t *sOut)
 Complex to complex FFT (forward). More...
 
void mha_fft_backward (mha_fft_t h, mha_spec_t *sIn, mha_spec_t *sOut)
 Complex to complex FFT (backward). More...
 
void mha_fft_forward_scale (mha_fft_t h, mha_spec_t *sIn, mha_spec_t *sOut)
 Complex to complex FFT (forward). More...
 
void mha_fft_backward_scale (mha_fft_t h, mha_spec_t *sIn, mha_spec_t *sOut)
 Complex to complex FFT (backward). More...
 
void mha_fft_wave2spec_scale (mha_fft_t h, const mha_wave_t *in, mha_spec_t *out)
 Tranform waveform segment into spectrum. More...
 
void mha_fft_spec2wave_scale (mha_fft_t h, const mha_spec_t *in, mha_wave_t *out)
 Tranform spectrum into waveform segment. More...
 
template<class elem_type >
elem_type MHASignal::kth_smallest (elem_type array[], unsigned n, unsigned k)
 Fast search for the kth smallest element of an array. More...
 
template<class elem_type >
elem_type MHASignal::median (elem_type array[], unsigned n)
 Fast median search. More...
 
template<class elem_type >
elem_type MHASignal::mean (const std::vector< elem_type > &data, elem_type start_val)
 Calculate average of elements in a vector. More...
 
template<class elem_type >
std::vector< elem_type > MHASignal::quantile (std::vector< elem_type > data, const std::vector< elem_type > &p)
 Calculate quantile of elements in a vector. More...
 
void MHASignal::saveas_mat4 (const mha_spec_t &data, const std::string &varname, FILE *fh)
 Save a openMHA spectrum as a variable in a Matlab4 file. More...
 
void MHASignal::saveas_mat4 (const mha_wave_t &data, const std::string &varname, FILE *fh)
 Save a openMHA waveform as a variable in a Matlab4 file. More...
 
void MHASignal::saveas_mat4 (const std::vector< mha_real_t > &data, const std::string &varname, FILE *fh)
 Save a float vector as a variable in a Matlab4 file. More...
 
void MHASignal::copy_permuted (mha_wave_t *dest, const mha_wave_t *src)
 Copy contents of a waveform to a permuted waveform. More...
 

Variables

unsigned long int MHASignal::signal_counter = 0
 Signal counter to produce signal ID strings. More...
 

Detailed Description

Header file for audio signal handling and processing classes.

The classes for waveform, spectrum and filterbank signals defined in this file are "intelligent" versions of the basic waveform, spectrum and filterbank structures used in the C function calls.

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846

◆ mha_round

#define mha_round (   x)    (int)((float)x+0.5)

Function Documentation

◆ mha_min_1()

unsigned int mha_min_1 ( unsigned int  a)
inline

◆ value() [1/2]

mha_real_t& value ( mha_wave_t s,
unsigned int  k 
)
inline

◆ value() [2/2]

mha_complex_t& value ( mha_spec_t s,
unsigned int  k 
)
inline

◆ set_minabs()

void set_minabs ( mha_spec_t self,
const mha_real_t m 
)

◆ safe_div()

mha_spec_t& safe_div ( mha_spec_t self,
const mha_spec_t v,
mha_real_t  eps 
)

In-Place division with lower limit on divisor.

◆ operator<<()

std::ostream& operator<< ( std::ostream &  o,
const mha_complex_t c 
)
inline

ostream operator for mha_complex_t

◆ operator>>()

std::istream& operator>> ( std::istream &  i,
mha_complex_t c 
)
inline

preliminary istream operator for mha_complex_t without error checking