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

A FIFO class for blocksize adaptation without Synchronization. More...

Inheritance diagram for mha_drifter_fifo_t< T >:
Inheritance graph

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...
 

Detailed Description

template<class T>
class mha_drifter_fifo_t< T >

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.

Constructor & Destructor Documentation

◆ mha_drifter_fifo_t() [1/2]

template<class T >
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() [2/2]

template<class T >
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.

Member Function Documentation

◆ write()

template<class T >
void mha_drifter_fifo_t< T >::write ( const T *  data,
unsigned  count 
)
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.

Parameters
dataPointer to source data.
countNumber of instances to copy

Reimplemented from mha_fifo_t< T >.

◆ read()

template<class T >
void mha_drifter_fifo_t< T >::read ( T *  buf,
unsigned  count 
)
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.

Parameters
bufPointer to the target buffer
countNumber of instances to copy

Reimplemented from mha_fifo_t< T >.

◆ get_fill_count()

template<class T >
unsigned mha_drifter_fifo_t< T >::get_fill_count
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 >.

◆ get_available_space()

template<class T >
unsigned mha_drifter_fifo_t< T >::get_available_space
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 >.

◆ get_des_fill_count()

template<class T >
virtual unsigned mha_drifter_fifo_t< T >::get_des_fill_count ( ) const
inlinevirtual

The desired fill count of this fifo.

◆ get_min_fill_count()

template<class T >
virtual unsigned mha_drifter_fifo_t< T >::get_min_fill_count ( ) const
inlinevirtual

The minimum fill count of this fifo.

◆ stop()

template<class T >
void mha_drifter_fifo_t< T >::stop
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.

◆ starting()

template<class T >
void mha_drifter_fifo_t< T >::starting
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.

Member Data Documentation

◆ minimum_fill_count

template<class T >
const unsigned mha_drifter_fifo_t< T >::minimum_fill_count
private

The minimum fill count of this fifo.

◆ desired_fill_count

template<class T >
const unsigned mha_drifter_fifo_t< T >::desired_fill_count
private

The desired fill count of the fifo.

The fifo is initialized with this ammount of data when data transmission starts.

◆ writer_started

template<class T >
bool mha_drifter_fifo_t< T >::writer_started
private

Flag set to true when write is called the first time.

◆ reader_started

template<class T >
bool mha_drifter_fifo_t< T >::reader_started
private

Flag set to true when read is called for the first time.

◆ writer_xruns_total

template<class T >
unsigned mha_drifter_fifo_t< T >::writer_xruns_total
private

The number of xruns seen by the writer since object instantiation.

◆ reader_xruns_total

template<class T >
unsigned mha_drifter_fifo_t< T >::reader_xruns_total
private

The number of xruns seen by the reader since object instantiation.

◆ writer_xruns_since_start

template<class T >
unsigned mha_drifter_fifo_t< T >::writer_xruns_since_start
private

The number of xruns seen by the writer since the last start of processing.

◆ reader_xruns_since_start

template<class T >
unsigned mha_drifter_fifo_t< T >::reader_xruns_since_start
private

The number of xruns seen by the reader since the last start of processing.

◆ writer_xruns_in_succession

template<class T >
unsigned mha_drifter_fifo_t< T >::writer_xruns_in_succession
private

The number of xruns seen by the writer in succession.

Reset to 0 every time a write succeeds without xrun.

◆ reader_xruns_in_succession

template<class T >
unsigned mha_drifter_fifo_t< T >::reader_xruns_in_succession
private

The number of xruns seen by the reader in succession.

Reset to 0 every time a read succeeds without xrun.

◆ maximum_writer_xruns_in_succession_before_stop

template<class T >
unsigned mha_drifter_fifo_t< T >::maximum_writer_xruns_in_succession_before_stop
private

A limit to the number of xruns seen in succession during write before the data transmission through the FIFO is stopped.

◆ maximum_reader_xruns_in_succession_before_stop

template<class T >
unsigned mha_drifter_fifo_t< T >::maximum_reader_xruns_in_succession_before_stop
private

A limit to the number of xruns seen in succession during read before the data transmission through the FIFO is stopped.

◆ null_data

template<class T >
mha_fifo_t<T>::value_type mha_drifter_fifo_t< T >::null_data
private

The value used in place of missing data.

◆ startup_zeros

template<class T >
unsigned mha_drifter_fifo_t< T >::startup_zeros
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.


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