The Open Master Hearing Aid (openMHA)
openMHA
Open community platform for hearing aid algorithm research
|
acwriter_t decouples signal processing from writing to disk. More...
Public Types | |
typedef double | output_type |
The numeric data type used for outputting the data to disk. More... | |
Public Member Functions | |
acwriter_t (bool active, unsigned fifosize, unsigned minwrite, const std::string &prefix, bool use_date, const std::string &varname) | |
Constructor allocates fifo and disk output buffer. More... | |
~acwriter_t ()=default | |
Deallocates memory but does not terminate the write_thread. More... | |
void | process (MHA_AC::comm_var_t *) |
Place the data present in the algorithm communication variable into the fifo for output to disk. More... | |
void | exit_request () |
Terminate output thread. More... | |
const std::string & | get_varname () const |
getter for ac variable name More... | |
Private Member Functions | |
void | write_thread () |
Main method of the disk writer thread. More... | |
void | create_datafile (const std::string &prefix, bool use_date) |
Open data file for output. 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< output_type > > | 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< output_type[]> | diskbuffer |
Intermediate buffer to receive data from fifo and store on disk. More... | |
std::fstream | outfile |
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... | |
const std::string | varname |
The name of the ac variable to publish. More... | |
acwriter_t decouples signal processing from writing to disk.
Data arriving in numeric AC variables is converted to data type double, placed into a fifo pipeline to transport the data from the signal processing thread to the disk writing thread, and finally written to disk in chunks of at least minwrite numbers. All numbers are written to disk as binary doubles (8 bytes) in host byte order.
typedef double plugins::hoertech::acrec::acwriter_t::output_type |
The numeric data type used for outputting the data to disk.
acwriter_t::acwriter_t | ( | bool | active, |
unsigned | fifosize, | ||
unsigned | minwrite, | ||
const std::string & | prefix, | ||
bool | use_date, | ||
const std::string & | varname | ||
) |
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.
active | Only write data to disk when this is true. |
fifosize | Capacity of both the fifo pipeline and of the disk buffer. |
minwrite | Wait 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. |
prefix | Path and start of output file name. Will be extended with file name extension ".dat". |
use_date | When true, the current date and time will be appended to the output file name before the file name extension. |
varname | Name 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. |
|
default |
Deallocates memory but does not terminate the write_thread.
write_thread must be terminated before the destructor executes by calling exit_request.
void acwriter_t::process | ( | MHA_AC::comm_var_t * | s | ) |
Place the data present in the algorithm communication variable into the fifo for output to disk.
void acwriter_t::exit_request | ( | ) |
Terminate output thread.
|
inline |
getter for ac variable name
|
private |
Main method of the disk writer thread.
Periodically wakes up and checks if data needs to be written to disk.
|
private |
Open data file for output.
Combine prefix, date, and file name extension
prefix | Path and start of output file name. Will be extended with file name extension ".dat". |
use_date | When true, the current date and time will be appended to the output file name before the file name extension. |
|
private |
cross-thread-synchronization.
write_thread() terminates after this is set to true by exit_request().
|
private |
The writer thread and the output file will only be created when active is true.
|
private |
Fifo for decoupling signal processing thread from disk writer thread.
|
private |
Minimum number of samples that need to be waiting in the fifo before the disk writer thread writes them to disk.
|
private |
The thread that writes to disk.
|
private |
Intermediate buffer to receive data from fifo and store on disk.
|
private |
Ouput file.
|
private |
Number of channels of AC variable using stride.
If the number of channels changes during processing, an exception is thrown.
|
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.
|
private |
If the AC variable is of complex valued type or not.
If this changes during processing, then an exception is thrown.
|
private |
The name of the ac variable to publish.