Beatmup
Beatmup::MovingAverage< log_length, datatype > Class Template Reference

Computes moving average over a given number of samples. More...

#include <profiler.h>

Public Member Functions

 MovingAverage ()
 
datatype update (datatype newSample)
 
datatype operator() () const
 

Private Attributes

datatype samples [1<< log_length]
 
datatype sum
 
size_t idx
 
size_t level
 

Static Private Attributes

static const size_t MASK = (1 << log_length) - 1
 

Detailed Description

template<const size_t log_length, typename datatype = float>
class Beatmup::MovingAverage< log_length, datatype >

Computes moving average over a given number of samples.

Definition at line 64 of file profiler.h.

Constructor & Destructor Documentation

◆ MovingAverage()

template<const size_t log_length, typename datatype = float>
Beatmup::MovingAverage< log_length, datatype >::MovingAverage ( )
inline

Definition at line 70 of file profiler.h.

70 : sum(0), idx(0), level(0) {}

Member Function Documentation

◆ update()

template<const size_t log_length, typename datatype = float>
datatype Beatmup::MovingAverage< log_length, datatype >::update ( datatype  newSample)
inline

Definition at line 72 of file profiler.h.

72  {
73  sum += newSample;
74  if (level <= MASK)
75  ++level;
76  else
77  sum -= samples[idx & MASK];
78  samples[idx & MASK] = newSample;
79  ++idx;
80  return sum / level;
81  }
static const size_t MASK
Definition: profiler.h:66
datatype samples[1<< log_length]
Definition: profiler.h:67

◆ operator()()

template<const size_t log_length, typename datatype = float>
datatype Beatmup::MovingAverage< log_length, datatype >::operator() ( ) const
inline

Definition at line 83 of file profiler.h.

83  {
84  return level > 0 ? sum / level : 0;
85  }

Member Data Documentation

◆ MASK

template<const size_t log_length, typename datatype = float>
const size_t Beatmup::MovingAverage< log_length, datatype >::MASK = (1 << log_length) - 1
staticprivate

Definition at line 66 of file profiler.h.

◆ samples

template<const size_t log_length, typename datatype = float>
datatype Beatmup::MovingAverage< log_length, datatype >::samples[1<< log_length]
private

Definition at line 67 of file profiler.h.

◆ sum

template<const size_t log_length, typename datatype = float>
datatype Beatmup::MovingAverage< log_length, datatype >::sum
private

Definition at line 67 of file profiler.h.

◆ idx

template<const size_t log_length, typename datatype = float>
size_t Beatmup::MovingAverage< log_length, datatype >::idx
private

Definition at line 68 of file profiler.h.

◆ level

template<const size_t log_length, typename datatype = float>
size_t Beatmup::MovingAverage< log_length, datatype >::level
private

Definition at line 68 of file profiler.h.


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