The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research

Namespace for audio signal handling and processing classes. More...

Classes

class  async_rmslevel_t
 Class for asynchronous level metering. More...
 
class  delay_spec_t
 
class  delay_t
 Class to realize a simple delay of waveform streams. More...
 
class  delay_wave_t
 Delayline containing wave fragments. More...
 
class  doublebuffer_t
 Double-buffering class. More...
 
class  fft_t
 
class  hilbert_fftw_t
 
class  hilbert_t
 Hilbert transformation of a waveform segment. More...
 
class  loop_wavefragment_t
 Copy a fixed waveform fragment to a series of waveform fragments of other size. More...
 
class  matrix_t
 n-dimensional matrix with real or complex floating point values. More...
 
class  minphase_t
 Minimal phase function. More...
 
class  quantizer_t
 Simple simulation of fixpoint quantization. More...
 
class  ringbuffer_t
 A ringbuffer class for time domain audio signal, which makes no assumptions with respect to fragment size. More...
 
class  schroeder_t
 Schroeder tone complex class. More...
 
class  spectrum_t
 a signal processing class for spectral data (based on mha_spec_t) More...
 
class  stat_t
 
class  subsample_delay_t
 implements subsample delay in spectral domain. More...
 
class  uint_vector_t
 Vector of unsigned values, used for size and index description of n-dimensional matrixes. More...
 
class  waveform_t
 signal processing class for waveform data (based on mha_wave_t) More...
 

Functions

void 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 lin2db (mha_real_t x, mha_real_t eps)
 Conversion from linear scale to dB (no SPL reference) More...
 
mha_real_t lin2db (mha_real_t x)
 Conversion from linear scale to dB (no SPL reference) More...
 
mha_real_t db2lin (mha_real_t x)
 Conversion from dB scale to linear (no SPL reference) More...
 
mha_real_t sq2db (mha_real_t x, mha_real_t eps=0.0f)
 conversion from squared values to dB (no SPL reference) More...
 
mha_real_t db2sq (mha_real_t x)
 conversion from dB to squared values (no SPL reference) More...
 
mha_real_t pa2dbspl (mha_real_t x, mha_real_t eps)
 Conversion from linear Pascal scale to dB SPL. More...
 
mha_real_t pa2dbspl (mha_real_t x)
 Conversion from linear Pascal scale to dB SPL. More...
 
mha_real_t dbspl2pa (mha_real_t x)
 Conversion from dB SPL to linear Pascal scale. More...
 
mha_real_t pa22dbspl (mha_real_t x, mha_real_t eps=0.0f)
 Conversion from squared Pascal scale to dB SPL. More...
 
mha_real_t dbspl2pa2 (mha_real_t x)
 conversion from dB SPL to squared Pascal scale More...
 
mha_real_t smp2sec (mha_real_t n, mha_real_t srate)
 conversion from samples to seconds More...
 
mha_real_t sec2smp (mha_real_t sec, mha_real_t srate)
 conversion from seconds to samples More...
 
mha_real_t bin2freq (mha_real_t bin, unsigned fftlen, mha_real_t srate)
 conversion from fft bin index to frequency More...
 
mha_real_t freq2bin (mha_real_t freq, unsigned fftlen, mha_real_t srate)
 conversion from frequency to fft bin index More...
 
mha_real_t smp2rad (mha_real_t samples, unsigned bin, unsigned fftlen)
 conversion from delay in samples to phase shift More...
 
mha_real_t 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 > 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 > dupvec_chk (std::vector< elem_type > vec, unsigned n)
 Duplicate last vector element to match desired size, check for dimension. More...
 
void copy_channel (mha_spec_t &self, const mha_spec_t &src, unsigned sch, unsigned dch)
 Copy one channel of a source signal. More...
 
void 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 rmslevel (const mha_spec_t &s, unsigned int channel, unsigned int fftlen)
 Return RMS level of a spectrum channel. More...
 
mha_real_t 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 maxabs (const mha_spec_t &s, unsigned int channel)
 Find maximal absolute value. More...
 
mha_real_t rmslevel (const mha_wave_t &s, unsigned int channel)
 Return RMS level of a waveform channel. More...
 
mha_real_t maxabs (const mha_wave_t &s, unsigned int channel)
 Find maximal absolute value. More...
 
mha_real_t maxabs (const mha_wave_t &s)
 Find maximal absolute value. More...
 
mha_real_t max (const mha_wave_t &s)
 Find maximal value. More...
 
mha_real_t min (const mha_wave_t &s)
 Find minimal value. More...
 
mha_real_t sumsqr_channel (const mha_wave_t &s, unsigned int channel)
 Calculate sum of squared values in one channel. More...
 
mha_real_t sumsqr_frame (const mha_wave_t &s, unsigned int frame)
 Calculate sum over all channels of squared values. More...
 
void scale (mha_spec_t *dest, const mha_wave_t *src)
 
void 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...
 
template<class elem_type >
elem_type 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 median (elem_type array[], unsigned n)
 Fast median search. More...
 
template<class elem_type >
elem_type 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 > quantile (std::vector< elem_type > data, const std::vector< elem_type > &p)
 Calculate quantile of elements in a vector. More...
 
void 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 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 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 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 signal_counter = 0
 Signal counter to produce signal ID strings. More...
 

Detailed Description

Namespace for audio signal handling and processing classes.

Function Documentation

◆ for_each()

void MHASignal::for_each ( mha_wave_t s,
mha_real_t(*)(mha_real_t fun 
)
inline

Apply a function to each element of a mha_wave_t.

Parameters
sPointer to a mha_wave_t structure
funFunction to be applied (one argument)

◆ lin2db() [1/2]

mha_real_t MHASignal::lin2db ( mha_real_t  x,
mha_real_t  eps 
)
inline

Conversion from linear scale to dB (no SPL reference)

Parameters
xLinear input
epsminimum linear value (if x < eps --> convert eps instead), eps < 0 not allowed
Returns
NaN if x < 0 (log not defined for negative)
Exceptions
MHA_Errorif eps < 0

◆ lin2db() [2/2]

mha_real_t MHASignal::lin2db ( mha_real_t  x)
inline

Conversion from linear scale to dB (no SPL reference)

Parameters
xLinear input.
Returns
NaN if x < 0 (log not defined for negative)

◆ db2lin()

mha_real_t MHASignal::db2lin ( mha_real_t  x)
inline

Conversion from dB scale to linear (no SPL reference)

Parameters
xdB input.

◆ sq2db()

mha_real_t MHASignal::sq2db ( mha_real_t  x,
mha_real_t  eps = 0.0f 
)
inline

conversion from squared values to dB (no SPL reference)

Parameters
xsquared value input
epsminimum squared value (if x < eps --> convert eps instead), eps < 0 not allowed
Returns
NaN if x < 0 (log not defined for negative)
Exceptions
MHA_Errorif eps < 0

◆ db2sq()

mha_real_t MHASignal::db2sq ( mha_real_t  x)
inline

conversion from dB to squared values (no SPL reference)

Parameters
xdB input

◆ pa2dbspl() [1/2]

mha_real_t MHASignal::pa2dbspl ( mha_real_t  x,
mha_real_t  eps 
)
inline

Conversion from linear Pascal scale to dB SPL.

Parameters
xLinear input
epsminimum pascal value (if x < eps --> convert eps instead),
Precondition
eps >= 0
Returns
NaN if x < 0 (logarithm not defined for negative numbers)
Exceptions
MHA_Errorif eps < 0

◆ pa2dbspl() [2/2]

mha_real_t MHASignal::pa2dbspl ( mha_real_t  x)
inline

Conversion from linear Pascal scale to dB SPL.

Parameters
xLinear input
Returns
NaN if x < 0 (log not defined for negative)

◆ dbspl2pa()

mha_real_t MHASignal::dbspl2pa ( mha_real_t  x)
inline

Conversion from dB SPL to linear Pascal scale.

Parameters
xLinear input.

◆ pa22dbspl()

mha_real_t MHASignal::pa22dbspl ( mha_real_t  x,
mha_real_t  eps = 0.0f 
)
inline

Conversion from squared Pascal scale to dB SPL.

Parameters
xsquared pascal input
epsminimum squared-pascal value (if x < eps --> convert eps instead), eps < 0 not allowed
Returns
NaN if x < 0 (log not defined for negative)
Exceptions
MHA_Errorif eps < 0

◆ dbspl2pa2()

mha_real_t MHASignal::dbspl2pa2 ( mha_real_t  x)
inline

conversion from dB SPL to squared Pascal scale

Parameters
xdB SPL input

◆ smp2sec()

mha_real_t MHASignal::smp2sec ( mha_real_t  n,
mha_real_t  srate 
)
inline

conversion from samples to seconds

Parameters
nnumber of samples
sratesampling rate / Hz

◆ sec2smp()

mha_real_t MHASignal::sec2smp ( mha_real_t  sec,
mha_real_t  srate 
)
inline

conversion from seconds to samples

Parameters
sectime in seconds
sratesampling rate / Hz
Returns
number of samples, generally has non-zero fractional part

◆ scale()

void MHASignal::scale ( mha_spec_t dest,
const mha_wave_t src 
)

◆ limit()

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

Parameters
sThe signal to limit. The signal in this wave buffer is modified.
minlower limit
maxupper limit

◆ kth_smallest()

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.

The order of elements is altered, but not completely sorted. Using the algorithm from N. Wirth, published in "Algorithms + data structures = programs", Prentice-Hall, 1976

Parameters
arrayElement array
Postcondition
The order of elements in the array is altered. array[k] then holds the result.
Parameters
nnumber of elements in array
Precondition
n >= 1
Parameters
kThe k'th smalles element is returned: k = 0 returns the minimum, k = (n-1)/2 returns the median, k=(n-1) returns the maximum
Precondition
k < n
Returns
The kth smallest array element

◆ median()

template<class elem_type >
elem_type MHASignal::median ( elem_type  array[],
unsigned  n 
)
inline

Fast median search.

The order of elements is altered, but not completely sorted.

Parameters
arrayElement array
Postcondition
The order of elements in the array is altered. array[(n-1)/2] then holds the median.
Parameters
nnumber of elements in array
Precondition
n >= 1
Returns
The median of the array elements

◆ mean()

template<class elem_type >
elem_type MHASignal::mean ( const std::vector< elem_type > &  data,
elem_type  start_val 
)
inline

Calculate average of elements in a vector.

Parameters
dataInput vector
start_valValue for initialization of the return value before sum.
Returns
The average of the vector elements

◆ quantile()

template<class elem_type >
std::vector<elem_type> MHASignal::quantile ( std::vector< elem_type >  data,
const std::vector< elem_type > &  p 
)
inline

Calculate quantile of elements in a vector.

Parameters
dataInput vector
pVector of probability values.
Returns
Vector of quantiles of input data, one entry for each probability value.

◆ saveas_mat4() [1/3]

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.

Parameters
dataopenMHA spectrum to be saved.
varnameMatlab variable name (Matlab4 limitations on maximal length are not checked).
fhFile handle to Matlab4 file.

◆ saveas_mat4() [2/3]

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.

Parameters
dataopenMHA waveform to be saved.
varnameMatlab variable name (Matlab4 limitations on maximal length are not checked).
fhFile handle to Matlab4 file.

◆ saveas_mat4() [3/3]

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.

Parameters
dataFloat vector to be saved.
varnameMatlab variable name (Matlab4 limitations on maximal length are not checked).
fhFile handle to Matlab4 file.

◆ copy_permuted()

void MHASignal::copy_permuted ( mha_wave_t dest,
const mha_wave_t src 
)

Copy contents of a waveform to a permuted waveform.

Parameters
destDestination waveform
srcSource waveform

The total size of src and dest must be the same, num_frames and num_channels must be exchanged in dest.

Variable Documentation

◆ signal_counter

unsigned long int MHASignal::signal_counter = 0

Signal counter to produce signal ID strings.