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

Runtime configuration class for plugin wave2spec. More...

Inheritance diagram for wave2spec_t:
Inheritance graph

Public Member Functions

 wave2spec_t (unsigned int nfft, unsigned int nwnd_, unsigned int nwndshift_, unsigned int nch, mha_real_t wndpos, const MHAWindow::base_t &window, MHA_AC::algo_comm_t &ac, std::string algo)
 Constructor computes window and zeropadding, allocates storage and FFT plan. More...
 
void publish_ac_variables ()
 Insert two AC variables into AC space: More...
 
mha_spec_tprocess (mha_wave_t *wave_in)
 Perform signal shift, windowing, zero-padding and FFT. More...
 
 ~wave2spec_t ()
 Destructor removes AC variables from AC space and deallocates memory. More...
 
unsigned get_zeropadding (bool after) const
 Getter method to read zeropadding computed for the STFT configuration parameters. More...
 
- Public Member Functions inherited from MHA_AC::spectrum_t
 spectrum_t (algo_comm_t &ac, const std::string &name, unsigned int bins, unsigned int channels, bool insert_now)
 Initialize memory and metadata of the AC variable. More...
 
 ~spectrum_t ()
 Destroy the AC variable: deallocate its memory. More...
 
void insert ()
 Insert or re-insert AC variable into AC space. More...
 
void remove ()
 Remove the AC variable by reference from the AC variable space. More...
 
- Public Member Functions inherited from MHASignal::spectrum_t
 spectrum_t (const unsigned int &frames, const unsigned int &channels)
 constructor of spectrum class More...
 
 spectrum_t (const mha_spec_t &)
 Copy constructor. More...
 
 spectrum_t (const MHASignal::spectrum_t &)
 Copy constructor. More...
 
 spectrum_t (const std::vector< mha_complex_t > &)
 
mha_complex_toperator() (unsigned int f, unsigned int ch)
 Access to element. More...
 
mha_complex_toperator[] (unsigned int k)
 Access to a single element, direct index into data buffer. More...
 
mha_complex_tvalue (unsigned int f, unsigned int ch)
 Access to element. More...
 
void copy (const mha_spec_t &)
 copy all elements from a spectrum More...
 
void copy_channel (const mha_spec_t &s, unsigned sch, unsigned dch)
 Copy one channel of a given spectrum signal to a target channel. More...
 
void export_to (mha_spec_t &)
 copy elements to spectrum structure More...
 
void scale (const unsigned int &, const unsigned int &, const unsigned int &, const mha_real_t &)
 scale section [a,b) in channel "ch" by "val" More...
 
void scale_channel (const unsigned int &, const mha_real_t &)
 scale all elements in one channel More...
 

Private Member Functions

void calc_pre_wnd (MHASignal::waveform_t &dest, const MHASignal::waveform_t &src)
 Applies analysis window weights to current input signal and writes windowed signal to correct place in FFT buffer. More...
 

Private Attributes

unsigned int nwnd
 window length More...
 
unsigned int nwndshift
 window shift or hop size More...
 
mha_fft_t ft
 FFT instance used for transformation. More...
 
unsigned int npad1
 length of zero padding before window More...
 
unsigned int npad2
 length of zero padding after window More...
 
MHAWindow::base_t window
 Analysis window. More...
 
MHASignal::waveform_t calc_in
 waveform buffer with FFT length samples per channel More...
 
MHASignal::waveform_t in_buf
 waveform buffer with window length samples per channel More...
 
MHASignal::spectrum_t spec_in
 spectrum buffer containing only the positive frequency bins More...
 
std::string ac_wndshape_name
 name of window shape AC variable More...
 

Additional Inherited Members

- Public Attributes inherited from mha_spec_t
mha_complex_tbuf
 signal buffer More...
 
unsigned int num_channels
 number of channels More...
 
unsigned int num_frames
 number of frames in each channel More...
 
mha_channel_info_tchannel_info
 detailed channel description More...
 
- Protected Attributes inherited from MHA_AC::spectrum_t
algo_comm_tac
 AC variable space. More...
 
const std::string name
 Name of this AC variable in the AC variable space. More...
 
const bool remove_during_destructor
 flag whether to remove from AC variable space in destructor. More...
 

Detailed Description

Runtime configuration class for plugin wave2spec.

Manages window shift, windowing, zero-padding, and FFT. Inserts current window shape and current STFT spectrum into AC space.

Constructor & Destructor Documentation

◆ wave2spec_t()

wave2spec_t::wave2spec_t ( unsigned int  nfft,
unsigned int  nwnd_,
unsigned int  nwndshift_,
unsigned int  nch,
mha_real_t  wndpos,
const MHAWindow::base_t window,
MHA_AC::algo_comm_t ac,
std::string  algo 
)

Constructor computes window and zeropadding, allocates storage and FFT plan.

Parameters
nfftFFT length
nwnd_window length in samples
nwndshift_window shift (hop size) in samples
nchnumber of audio channels
wndposfor cases nfft > nwnd_, where to place the window inside the FFT buffer: 0 = at start, 1 = at end, 0.5 = centered. Position is rounded to full samples and determines zero-padding
windowAnalysis window shape
acalgorithm communication storage accessor
algoconfigured name of this plugin, used to name the AC variables published by wave2spec

◆ ~wave2spec_t()

wave2spec_t::~wave2spec_t ( )

Destructor removes AC variables from AC space and deallocates memory.

Member Function Documentation

◆ publish_ac_variables()

void wave2spec_t::publish_ac_variables ( )

Insert two AC variables into AC space:

  • <configured_name>: Contains the current STFT spectrum.
  • <configured_name>_wnd: Contains the window shape as individual weights.

◆ process()

mha_spec_t * wave2spec_t::process ( mha_wave_t wave_in)

Perform signal shift, windowing, zero-padding and FFT.

Parameters
wave_inlatest block of audio signal (hop size samples per channel)
Returns
pointer to current STFT spectrum. Storage is managed by this object. Downstream plugins may modify the signal in place.

◆ get_zeropadding()

unsigned wave2spec_t::get_zeropadding ( bool  after) const
inline

Getter method to read zeropadding computed for the STFT configuration parameters.

Result is only valid after prepare() has been called.

Returns
Computed zeropadding before or after the analysis window in number of samples.
Parameters
afterWhen false, return length of zeropadding before the analysis window. When true, return length of zeropadding in samples after the analysis window.

◆ calc_pre_wnd()

void wave2spec_t::calc_pre_wnd ( MHASignal::waveform_t dest,
const MHASignal::waveform_t src 
)
private

Applies analysis window weights to current input signal and writes windowed signal to correct place in FFT buffer.

Ensures zero-padding regions contain only zeros. To be invoked before applying FFT.

Parameters
[out]destwaveform buffer with FFT length audio samples, completely overwritten by this method
[in]srcwaveform buffer with window length audio samples, these samples are written to dest after window shape has been applied to the individual samples.

Member Data Documentation

◆ nwnd

unsigned int wave2spec_t::nwnd
private

window length

◆ nwndshift

unsigned int wave2spec_t::nwndshift
private

window shift or hop size

◆ ft

mha_fft_t wave2spec_t::ft
private

FFT instance used for transformation.

◆ npad1

unsigned int wave2spec_t::npad1
private

length of zero padding before window

◆ npad2

unsigned int wave2spec_t::npad2
private

length of zero padding after window

◆ window

MHAWindow::base_t wave2spec_t::window
private

Analysis window.

◆ calc_in

MHASignal::waveform_t wave2spec_t::calc_in
private

waveform buffer with FFT length samples per channel

◆ in_buf

MHASignal::waveform_t wave2spec_t::in_buf
private

waveform buffer with window length samples per channel

◆ spec_in

MHASignal::spectrum_t wave2spec_t::spec_in
private

spectrum buffer containing only the positive frequency bins

◆ ac_wndshape_name

std::string wave2spec_t::ac_wndshape_name
private

name of window shape AC variable


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