The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
alsa_t< T > Class Template Reference

Our representation of one alsa device. More...

Inheritance diagram for alsa_t< T >:
Inheritance graph

Public Member Functions

 alsa_t (const alsa_dev_par_parser_t &par, unsigned int rate, unsigned int fragsize, unsigned int channels)
 Constructor receives the parameters for this device. More...
 
 ~alsa_t ()
 Destructor closes the sound device. More...
 
void start () override
 start puts alsa device in usable state More...
 
void stop () override
 stop informs alsa device that we do not need any more samples / will not provide any more samples More...
 
bool read (mha_wave_t **) override
 read audio samples from the device into an internal mha_wave_t buffer, then update the pointer given as parameter to point to the internal structure. More...
 
bool write (mha_wave_t *) override
 write audio samples from the given waveform buffer to the sound device. More...
 
- Public Member Functions inherited from alsa_base_t
 alsa_base_t ()
 
virtual ~alsa_base_t ()=default
 

Private Attributes

unsigned int channels
 
unsigned int fragsize
 
T * buffer
 
std::vector< mha_real_tframe_data
 
MHASignal::waveform_t wave
 internal buffer to store sound samples coming from the sound card. More...
 
const mha_real_t gain
 
const mha_real_t invgain
 
snd_pcm_format_t pcm_format
 

Additional Inherited Members

- Public Attributes inherited from alsa_base_t
snd_pcm_t * pcm
 The underlying alsa handle to this sound card. More...
 

Detailed Description

template<typename T>
class alsa_t< T >

Our representation of one alsa device.

We can start and stop the device, and depending on the direction, read or write samples.

Constructor & Destructor Documentation

◆ alsa_t()

template<typename T >
alsa_t< T >::alsa_t ( const alsa_dev_par_parser_t par,
unsigned int  rate,
unsigned int  fragsize,
unsigned int  channels 
)

Constructor receives the parameters for this device.

It opens the sound device using the alsa library and selects the given parameters, but does not yet start the sound device to perform real I/O.

Parameters
parour parser variable aggregator (containing direction, device name, and number of periods to place in alsa buffer)
ratesampling rate in Hz
fragsizesamples per block per channel
channelsnumber of audio channels to open

◆ ~alsa_t()

template<typename T >
alsa_t< T >::~alsa_t

Destructor closes the sound device.

Member Function Documentation

◆ start()

template<typename T >
void alsa_t< T >::start
overridevirtual

start puts alsa device in usable state

Implements alsa_base_t.

◆ stop()

template<typename T >
void alsa_t< T >::stop
overridevirtual

stop informs alsa device that we do not need any more samples / will not provide any more samples

Implements alsa_base_t.

◆ read()

template<typename T >
bool alsa_t< T >::read ( mha_wave_t **  s)
overridevirtual

read audio samples from the device into an internal mha_wave_t buffer, then update the pointer given as parameter to point to the internal structure.

Converts sound samples from the integer data type provided by the sound card to floating-point values needed by the MHA in the range [-1.0,1.0]

Implements alsa_base_t.

◆ write()

template<typename T >
bool alsa_t< T >::write ( mha_wave_t s)
overridevirtual

write audio samples from the given waveform buffer to the sound device.

converts the floating point values coming from the MHA to the integer samples required by the sound card.

Implements alsa_base_t.

Member Data Documentation

◆ channels

template<typename T >
unsigned int alsa_t< T >::channels
private

◆ fragsize

template<typename T >
unsigned int alsa_t< T >::fragsize
private

◆ buffer

template<typename T >
T* alsa_t< T >::buffer
private

◆ frame_data

template<typename T >
std::vector<mha_real_t> alsa_t< T >::frame_data
private

◆ wave

template<typename T >
MHASignal::waveform_t alsa_t< T >::wave
private

internal buffer to store sound samples coming from the sound card.

◆ gain

template<typename T >
const mha_real_t alsa_t< T >::gain
private

◆ invgain

template<typename T >
const mha_real_t alsa_t< T >::invgain
private

◆ pcm_format

template<typename T >
snd_pcm_format_t alsa_t< T >::pcm_format
private

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