The Open Master Hearing Aid (openMHA)
openMHA
Open community platform for hearing aid algorithm research
|
A FIFO class for blocksize adaptation without Synchronization. More...
Public Member Functions | |
virtual void | write (const T *data, unsigned count) |
write data to fifo More... | |
virtual void | read (T *buf, unsigned count) |
Read data from fifo. More... | |
virtual unsigned | get_fill_count () const |
Return fill_count, adding mha_drifter_fifo_t<T>::startup_zeros to the number of samples actually in the fifo's buffer. More... | |
virtual unsigned | get_available_space () const |
Return available space, subtracting number of mha_drifter_fifo_t<T>::startup_zeros from the available_space actually present in the fifo's buffer. More... | |
virtual unsigned | get_des_fill_count () const |
The desired fill count of this fifo. More... | |
virtual unsigned | get_min_fill_count () const |
The minimum fill count of this fifo. More... | |
virtual void | stop () |
Called by mha_drifter_fifo_t<T>::read or mha_drifter_fifo_t<T>::write when their xrun in succession counter exceeds its limit. More... | |
virtual void | starting () |
Called by mha_drifter_fifo_t<T>::read or mha_drifter_fifo_t<T>::write when the respective flag (mha_drifter_fifo_t<T>::reader_started or mha_drifter_fifo_t<T>::writer_started) is about to be toggled from false to true. More... | |
mha_drifter_fifo_t (unsigned min_fill_count, unsigned desired_fill_count, unsigned max_fill_count) | |
Create drifter FIFO. More... | |
mha_drifter_fifo_t (unsigned min_fill_count, unsigned desired_fill_count, unsigned max_fill_count, const T &t) | |
Create drifter FIFO where all (initially unused) copies of T are initialized as copies of t. More... | |
Public Member Functions inherited from mha_fifo_t< T > | |
virtual unsigned | get_max_fill_count () const |
The capacity of this fifo. More... | |
mha_fifo_t (unsigned max_fill_count, const T &t=T()) | |
Create FIFO with fixed buffer size, where all (initially unused) instances of T are initialized as copies of t. More... | |
virtual | ~mha_fifo_t ()=default |
Make destructor virtual. More... | |
mha_fifo_t (const mha_fifo_t &)=delete | |
Copy constructor. More... | |
mha_fifo_t (mha_fifo_t &&)=delete | |
Move constructor. More... | |
mha_fifo_t< T > & | operator= (const mha_fifo_t< T > &)=delete |
Assignment operator. More... | |
mha_fifo_t< T > & | operator= (mha_fifo_t< T > &&)=delete |
Move assignment operator. More... | |
Private Attributes | |
const unsigned | minimum_fill_count |
The minimum fill count of this fifo. More... | |
const unsigned | desired_fill_count |
The desired fill count of the fifo. More... | |
bool | writer_started |
Flag set to true when write is called the first time. More... | |
bool | reader_started |
Flag set to true when read is called for the first time. More... | |
unsigned | writer_xruns_total |
The number of xruns seen by the writer since object instantiation. More... | |
unsigned | reader_xruns_total |
The number of xruns seen by the reader since object instantiation. More... | |
unsigned | writer_xruns_since_start |
The number of xruns seen by the writer since the last start of processing. More... | |
unsigned | reader_xruns_since_start |
The number of xruns seen by the reader since the last start of processing. More... | |
unsigned | writer_xruns_in_succession |
The number of xruns seen by the writer in succession. More... | |
unsigned | reader_xruns_in_succession |
The number of xruns seen by the reader in succession. More... | |
unsigned | maximum_writer_xruns_in_succession_before_stop |
A limit to the number of xruns seen in succession during write before the data transmission through the FIFO is stopped. More... | |
unsigned | maximum_reader_xruns_in_succession_before_stop |
A limit to the number of xruns seen in succession during read before the data transmission through the FIFO is stopped. More... | |
mha_fifo_t< T >::value_type | null_data |
The value used in place of missing data. More... | |
unsigned | startup_zeros |
When processing starts, that is when both mha_drifter_fifo_t<T>::reader_started and mha_drifter_fifo_t<T>::writer_started are true, then first mha_drifter_fifo_t<T>::desired_fill_count instances of mha_drifter_fifo_t<T>::null_data are delivered to the reader. More... | |
Additional Inherited Members | |
Public Types inherited from mha_fifo_t< T > | |
typedef std::vector< T >::value_type | value_type |
The data type exchanged by this fifo. More... | |
Protected Member Functions inherited from mha_fifo_t< T > | |
void | clear () |
Empty the fifo at once. More... | |
const T * | get_write_ptr () const |
read-only access to the write pointer for derived classes More... | |
const T * | get_read_ptr () const |
read-only access to read pointer for derived classes More... | |
unsigned | get_fill_count (const T *wp, const T *rp) const |
Compute fill count from given write pointer and read pointer. More... | |
A FIFO class for blocksize adaptation without Synchronization.
Features: delay concept (desired, minimum and maximum delay), drifting support by throwing away data or inserting zeroes.
mha_drifter_fifo_t< T >::mha_drifter_fifo_t | ( | unsigned | min_fill_count, |
unsigned | desired_fill_count, | ||
unsigned | max_fill_count | ||
) |
Create drifter FIFO.
mha_drifter_fifo_t< T >::mha_drifter_fifo_t | ( | unsigned | min_fill_count, |
unsigned | desired_fill_count, | ||
unsigned | max_fill_count, | ||
const T & | t | ||
) |
Create drifter FIFO where all (initially unused) copies of T are initialized as copies of t.
|
virtual |
write data to fifo
Sets writer_started to true.
When processing has started, i.e. both reader_started and writer_started are true, write specified ammount of data to the fifo. If there is not enough space available, then the exceeding data is lost and the writer xrun counters are increased.
Processing is stopped when writer_xruns_in_succession exceeds maximum_writer_xruns_in_succession_before_stop.
data | Pointer to source data. |
count | Number of instances to copy |
Reimplemented from mha_fifo_t< T >.
|
virtual |
Read data from fifo.
Sets reader_started to true.
When processing has started, i.e. both reader_started and writer_started are true, then read specified ammount of data from the fifo. As long as startup_zeros is > 0, null_data is delivered to the reader and startup_zeros is diminished. Only when startup_zeros has reached 0, data is actually read from the fifo's buffer.
If the read would cause the fifo's fill count to drop below minimum_fill_count, then only so much data are read that minimum_fill_count entries remain in the fifo, the missing data is replaced with null_data, and the reader xrun counters are increased.
Processing is stopped when reader_xruns_in_succession exceeds maximum_reader_xruns_in_succession_before_stop.
buf | Pointer to the target buffer |
count | Number of instances to copy |
Reimplemented from mha_fifo_t< T >.
|
virtual |
Return fill_count, adding mha_drifter_fifo_t<T>::startup_zeros to the number of samples actually in the fifo's buffer.
Reimplemented from mha_fifo_t< T >.
|
virtual |
Return available space, subtracting number of mha_drifter_fifo_t<T>::startup_zeros from the available_space actually present in the fifo's buffer.
TODO: uncertain if this is a good idea.
Reimplemented from mha_fifo_t< T >.
|
inlinevirtual |
The desired fill count of this fifo.
|
inlinevirtual |
The minimum fill count of this fifo.
|
virtual |
Called by mha_drifter_fifo_t<T>::read or mha_drifter_fifo_t<T>::write when their xrun in succession counter exceeds its limit.
Called by read or write when their xrun in succession counter exceeds its limit.
May also be called explicitly.
|
virtual |
Called by mha_drifter_fifo_t<T>::read or mha_drifter_fifo_t<T>::write when the respective flag (mha_drifter_fifo_t<T>::reader_started or mha_drifter_fifo_t<T>::writer_started) is about to be toggled from false to true.
The fifo's buffer is emptied, this method resets startup_zeros to desired_fill_count, and it also resets reader_xruns_since_start and writer_xruns_since_start to 0.
|
private |
The minimum fill count of this fifo.
|
private |
The desired fill count of the fifo.
The fifo is initialized with this ammount of data when data transmission starts.
|
private |
Flag set to true when write is called the first time.
|
private |
Flag set to true when read is called for the first time.
|
private |
The number of xruns seen by the writer since object instantiation.
|
private |
The number of xruns seen by the reader since object instantiation.
|
private |
The number of xruns seen by the writer since the last start of processing.
|
private |
The number of xruns seen by the reader since the last start of processing.
|
private |
The number of xruns seen by the writer in succession.
Reset to 0 every time a write succeeds without xrun.
|
private |
The number of xruns seen by the reader in succession.
Reset to 0 every time a read succeeds without xrun.
|
private |
A limit to the number of xruns seen in succession during write before the data transmission through the FIFO is stopped.
|
private |
A limit to the number of xruns seen in succession during read before the data transmission through the FIFO is stopped.
|
private |
The value used in place of missing data.
|
private |
When processing starts, that is when both mha_drifter_fifo_t<T>::reader_started and mha_drifter_fifo_t<T>::writer_started are true, then first mha_drifter_fifo_t<T>::desired_fill_count instances of mha_drifter_fifo_t<T>::null_data are delivered to the reader.
These null_data instances are not transmitted through the fifo because filling the fifo with enough null_data might not be realtime safe and this filling has to be initiated by starting or stop (this implementation: starting) which are be called with realtime constraints.