SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Public Attributes | Private Attributes | List of all members
leansdr::rate_estimator< T > Struct Template Reference

#include <generic.h>

+ Inheritance diagram for leansdr::rate_estimator< T >:
+ Collaboration diagram for leansdr::rate_estimator< T >:

Public Member Functions

 rate_estimator (scheduler *sch, pipebuf< int > &_num, pipebuf< int > &_den, pipebuf< float > &_rate)
 
void run ()
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Public Attributes

int sample_size
 
- Public Attributes inherited from leansdr::runnable_common
const char * name
 

Private Attributes

pipereader< int > num
 
pipereader< int > den
 
pipewriter< float > rate
 
acc_num
 
acc_den
 

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T>
struct leansdr::rate_estimator< T >

Definition at line 338 of file generic.h.

Constructor & Destructor Documentation

◆ rate_estimator()

template<typename T>
leansdr::rate_estimator< T >::rate_estimator ( scheduler sch,
pipebuf< int > &  _num,
pipebuf< int > &  _den,
pipebuf< float > &  _rate 
)
inline

Definition at line 342 of file generic.h.

345  : runnable(sch, "rate_estimator"),
346  sample_size(10000),
347  num(_num), den(_den), rate(_rate),
348  acc_num(0), acc_den(0)
349  {
350  }
pipereader< int > den
Definition: generic.h:373
pipewriter< float > rate
Definition: generic.h:374
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
pipereader< int > num
Definition: generic.h:373
scheduler * sch
Definition: framework.h:199

Member Function Documentation

◆ run()

template<typename T>
void leansdr::rate_estimator< T >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 352 of file generic.h.

353  {
354  if (rate.writable() < 1)
355  return;
356  int count = min(num.readable(), den.readable());
357  int *pnum = num.rd(), *pden = den.rd();
358  for (int n = count; n--; ++pnum, ++pden)
359  {
360  acc_num += *pnum;
361  acc_den += *pden;
362  }
363  num.read(count);
364  den.read(count);
365  if (acc_den >= sample_size)
366  {
367  rate.write((float)acc_num / acc_den);
368  acc_num = acc_den = 0;
369  }
370  }
pipereader< int > den
Definition: generic.h:373
pipewriter< float > rate
Definition: generic.h:374
pipereader< int > num
Definition: generic.h:373
void write(const T &e)
Definition: framework.h:319
void read(unsigned long n)
Definition: framework.h:367
T min(const T &x, const T &y)
Definition: framework.h:440

Member Data Documentation

◆ acc_den

template<typename T>
T leansdr::rate_estimator< T >::acc_den
private

Definition at line 375 of file generic.h.

◆ acc_num

template<typename T>
T leansdr::rate_estimator< T >::acc_num
private

Definition at line 375 of file generic.h.

◆ den

template<typename T>
pipereader<int> leansdr::rate_estimator< T >::den
private

Definition at line 373 of file generic.h.

◆ num

template<typename T>
pipereader<int> leansdr::rate_estimator< T >::num
private

Definition at line 373 of file generic.h.

◆ rate

template<typename T>
pipewriter<float> leansdr::rate_estimator< T >::rate
private

Definition at line 374 of file generic.h.

◆ sample_size

template<typename T>
int leansdr::rate_estimator< T >::sample_size

Definition at line 340 of file generic.h.


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