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

output_file_t represents one XDF output file. More...

Public Member Functions

 output_file_t (const std::string &prefix, bool use_date)
 Constructor. More...
 
void initialize_stream (uint32_t stream_id, const std::string &varname, const std::string &channel_format, unsigned num_channels, double sampling_rate=0)
 Initialize stream. More...
 
template<typename T = double>
void write (uint32_t stream_id, const T *buf, std::size_t frames, std::size_t channels)
 Write data chunk to the stream with id stream_id. More...
 
void close_stream (uint32_t stream_id)
 Close stream with id stream_id by writing stream footer. More...
 

Private Attributes

std::mutex write_lock
 Mutex to protect write access to the output file. More...
 
std::unique_ptr< XDFWriter > outfile
 XDFWriter. Handles the translation into the xdf format and disk writes. More...
 

Detailed Description

output_file_t represents one XDF output file.

It wraps around the XDFWriter class, which handles the conversion of a stream into the bits and bytes on disk. Access to the output file protected by a lock. There's usually one output file per plugin instance shared by all acwriters.

Constructor & Destructor Documentation

◆ output_file_t()

ac2xdf::output_file_t::output_file_t ( const std::string &  prefix,
bool  use_date 
)

Constructor.

Parameters
prefixPath and start of output file name. Will be extended with file name extension ".xdf".
use_dateWhen true, the current date and time will be appended to the output file name before the file name extension.

Member Function Documentation

◆ initialize_stream()

void ac2xdf::output_file_t::initialize_stream ( uint32_t  stream_id,
const std::string &  varname,
const std::string &  channel_format,
unsigned  num_channels,
double  sampling_rate = 0 
)

Initialize stream.

Writes a minimal stream header and a boundary chunk

Parameters
stream_idNumerical stream id.
varnameHuman-readable stream id. Gets saved as stream name in metadata
channel_formatData type of the stream, gets written into the channel_format metadata. must be one of {"int8", "int16", "int32", "int64","float32" ,"double64" , "string"}
num_channelsNumber of channels in stream to be written in metadata
sampling_rateNominal sampling rate in Hz. To be written in metadata. Zero means irregular rate

◆ write()

template<typename T >
template void ac2xdf::output_file_t::write< mha_real_t > ( uint32_t  stream_id,
const T *  buf,
std::size_t  frames,
std::size_t  channels 
)

Write data chunk to the stream with id stream_id.

Parameters
stream_idThe stream id.
bufPointer to buffer containing frames entries. The caller retains ownership of buf.
Pointerto buffer containing frames * channels values. Interleaved storage: The first channels values in memory contain the values of the first frame, etc. The caller retains ownership of buf.
framesNumber of entries per channel in buf.
channelsNumber of channels in buf.

◆ close_stream()

void ac2xdf::output_file_t::close_stream ( uint32_t  stream_id)

Close stream with id stream_id by writing stream footer.

Parameters
stream_idNumeric ID of the stream to be closed

Member Data Documentation

◆ write_lock

std::mutex ac2xdf::output_file_t::write_lock
private

Mutex to protect write access to the output file.

◆ outfile

std::unique_ptr<XDFWriter> ac2xdf::output_file_t::outfile
private

XDFWriter. Handles the translation into the xdf format and disk writes.


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