The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
ac2xdf::acwriter_t< T > Class Template Reference
Inheritance diagram for ac2xdf::acwriter_t< T >:
Inheritance graph

Public Member Functions

 acwriter_t (bool active, unsigned fifosize, unsigned minwrite, const std::string &varname, double sampling_rate, output_file_t *outfile, uint32_t stream_id)
 Constructor allocates fifo and disk output buffer. More...
 
 acwriter_t (const acwriter_t &)=delete
 
 acwriter_t (acwriter_t &&)=delete
 
virtual ~acwriter_t ()=default
 Deallocates memory but does not terminate the write_thread. More...
 
void process (comm_var_t &s) override
 
void exit_request () override
 Terminate output thread. More...
 
const char * get_varname () const override
 
- Public Member Functions inherited from ac2xdf::acwriter_base_t
virtual ~acwriter_base_t ()=default
 

Private Member Functions

void write_thread ()
 Main method of the disk writer thread. More...
 

Private Attributes

std::atomic< bool > close_session
 cross-thread-synchronization. More...
 
const bool active
 The writer thread and the output file will only be created when active is true. More...
 
std::unique_ptr< mha_fifo_lf_t< T > > fifo
 Fifo for decoupling signal processing thread from disk writer thread. More...
 
const unsigned int disk_write_threshold_min_num_samples
 Minimum number of samples that need to be waiting in the fifo before the disk writer thread writes them to disk. More...
 
std::thread writethread
 The thread that writes to disk. More...
 
std::unique_ptr< T[]> diskbuffer
 Intermediate buffer to receive data from fifo and store on disk. More...
 
output_file_toutfile
 Ouput file. More...
 
unsigned num_channels = 0U
 Number of channels of AC variable using stride. More...
 
bool is_num_channels_known = false
 The number of channels is determined during the first process callback. More...
 
bool is_complex = false
 If the AC variable is of complex valued type or not. More...
 
unsigned int data_type = MHA_AC_UNKNOWN
 Data type of the ac variable. Used to protect against data type change during processing. More...
 
const std::string varname
 The name of the ac variable to publish. More...
 
const uint32_t stream_id
 
bool is_stream_initialized =false
 
double sampling_rate
 

Constructor & Destructor Documentation

◆ acwriter_t() [1/3]

template<typename T >
ac2xdf::acwriter_t< T >::acwriter_t ( bool  active,
unsigned  fifosize,
unsigned  minwrite,
const std::string &  varname,
double  sampling_rate,
output_file_t outfile,
uint32_t  stream_id 
)

Constructor allocates fifo and disk output buffer.

It spawns a new thread for writing data to disk when active==true. In order to terminate the thread, method exit_request must be called before this object is destroyed.

Parameters
activeOnly write data to disk when this is true.
fifosizeCapacity of both the fifo pipeline and of the disk buffer.
minwriteWait for a fifo fill count of at least minwrite doubles before flushing the contents of the fifo to disk. Fifo is also flushed before this object is destroyed.
varnameName of AC variable to save into file. Can be accessed through getter method get_varname(). Stored here to avoid races between processing thread and configuration thread.
outfileHandle to the output file
stream_idNumerical id of the stream.

◆ acwriter_t() [2/3]

template<typename T >
ac2xdf::acwriter_t< T >::acwriter_t ( const acwriter_t< T > &  )
delete

◆ acwriter_t() [3/3]

template<typename T >
ac2xdf::acwriter_t< T >::acwriter_t ( acwriter_t< T > &&  )
delete

◆ ~acwriter_t()

template<typename T >
virtual ac2xdf::acwriter_t< T >::~acwriter_t ( )
virtualdefault

Deallocates memory but does not terminate the write_thread.

write_thread must be terminated before the destructor executes by calling exit_request.

Member Function Documentation

◆ process()

template<typename T >
void ac2xdf::acwriter_t< T >::process ( comm_var_t s)
overridevirtual

◆ exit_request()

template<typename T >
void ac2xdf::acwriter_t< T >::exit_request
overridevirtual

Terminate output thread.

Implements ac2xdf::acwriter_base_t.

◆ get_varname()

template<typename T >
const char* ac2xdf::acwriter_t< T >::get_varname ( ) const
inlineoverridevirtual

◆ write_thread()

template<typename T >
void ac2xdf::acwriter_t< T >::write_thread
private

Main method of the disk writer thread.

Periodically wakes up and checks if data needs to be written to disk.

Member Data Documentation

◆ close_session

template<typename T >
std::atomic<bool> ac2xdf::acwriter_t< T >::close_session
private

cross-thread-synchronization.

write_thread() terminates after this is set to true by exit_request().

◆ active

template<typename T >
const bool ac2xdf::acwriter_t< T >::active
private

The writer thread and the output file will only be created when active is true.

◆ fifo

template<typename T >
std::unique_ptr<mha_fifo_lf_t<T> > ac2xdf::acwriter_t< T >::fifo
private

Fifo for decoupling signal processing thread from disk writer thread.

◆ disk_write_threshold_min_num_samples

template<typename T >
const unsigned int ac2xdf::acwriter_t< T >::disk_write_threshold_min_num_samples
private

Minimum number of samples that need to be waiting in the fifo before the disk writer thread writes them to disk.

◆ writethread

template<typename T >
std::thread ac2xdf::acwriter_t< T >::writethread
private

The thread that writes to disk.

◆ diskbuffer

template<typename T >
std::unique_ptr<T[]> ac2xdf::acwriter_t< T >::diskbuffer
private

Intermediate buffer to receive data from fifo and store on disk.

◆ outfile

template<typename T >
output_file_t* ac2xdf::acwriter_t< T >::outfile
private

Ouput file.

◆ num_channels

template<typename T >
unsigned ac2xdf::acwriter_t< T >::num_channels = 0U
private

Number of channels of AC variable using stride.

If the number of channels changes during processing, an exception is thrown.

◆ is_num_channels_known

template<typename T >
bool ac2xdf::acwriter_t< T >::is_num_channels_known = false
private

The number of channels is determined during the first process callback.

is_num_channels_known is set to true after the first process callback.

◆ is_complex

template<typename T >
bool ac2xdf::acwriter_t< T >::is_complex = false
private

If the AC variable is of complex valued type or not.

If this changes during processing, then an exception is thrown.

◆ data_type

template<typename T >
unsigned int ac2xdf::acwriter_t< T >::data_type = MHA_AC_UNKNOWN
private

Data type of the ac variable. Used to protect against data type change during processing.

◆ varname

template<typename T >
const std::string ac2xdf::acwriter_t< T >::varname
private

The name of the ac variable to publish.

◆ stream_id

template<typename T >
const uint32_t ac2xdf::acwriter_t< T >::stream_id
private

◆ is_stream_initialized

template<typename T >
bool ac2xdf::acwriter_t< T >::is_stream_initialized =false
private

◆ sampling_rate

template<typename T >
double ac2xdf::acwriter_t< T >::sampling_rate
private

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