UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
MovingAverage Class Reference

#include <decklink_drift_fix.hpp>

Collaboration diagram for MovingAverage:
Collaboration graph

Public Member Functions

 MovingAverage (unsigned int period)
 
 ~MovingAverage ()
 
void add (double val)
 
double avg () const
 
ptrdiff_t filled ()
 
double getTotal () const
 
ptrdiff_t size () const
 

Private Member Functions

void inc (double *&p)
 

Private Attributes

double * head
 
unsigned int period
 
double * tail
 
double total
 
double * window
 

Detailed Description

Definition at line 58 of file decklink_drift_fix.hpp.

Constructor & Destructor Documentation

◆ MovingAverage()

MovingAverage::MovingAverage ( unsigned int period)
inline

Definition at line 60 of file decklink_drift_fix.hpp.

60 :
61 period(period),
62 window(new double[period]),
63 head(NULL),
64 tail(NULL),
65 total(0) {
66
67 assert(period >= 1);
68 }

References period.

◆ ~MovingAverage()

MovingAverage::~MovingAverage ( )
inline

Definition at line 70 of file decklink_drift_fix.hpp.

70 {
71 delete[] window;
72 }

References window.

Member Function Documentation

◆ add()

void MovingAverage::add ( double val)
inline

Definition at line 74 of file decklink_drift_fix.hpp.

74 {
75 // Init
76 if (head == NULL) {
77 head = window;
78 *head = val;
79 tail = head;
80 inc(tail);
81 total = val;
82 return;
83 }
84 // full?
85 if (head == tail) {
86 total -= *head;
87 inc(head);
88 }
89
90 *tail = val;
91 inc(tail);
92 total += val;
93 }
int void * val
void inc(double *&p)

References head, inc(), tail, total, val, and window.

Referenced by DecklinkAudioSummary::calculate_missing(), and AudioDriftFixer::update().

Here is the call graph for this function:

◆ avg()

double MovingAverage::avg ( ) const
inline

Definition at line 97 of file decklink_drift_fix.hpp.

97 {
98 ptrdiff_t size = this->size();
99 if (size == 0) {
100 return 0; // No entries => 0 average
101 }
102 return total / (double)size;
103 }
ptrdiff_t size() const

References size(), and total.

Referenced by DecklinkAudioSummary::calculate_missing(), AudioDriftFixer::get_buffer_avg(), DecklinkAudioSummary::report(), and AudioDriftFixer::update().

Here is the call graph for this function:

◆ filled()

ptrdiff_t MovingAverage::filled ( )
inline

Definition at line 113 of file decklink_drift_fix.hpp.

113 {
114 bool filled = false;
115 if (this->size() >= (ptrdiff_t) this->period ){
116 filled = true;
117 }
118 return filled;
119 }

References filled(), period, and size().

Referenced by DecklinkAudioSummary::calculate_missing(), filled(), and AudioDriftFixer::update().

Here is the call graph for this function:

◆ getTotal()

double MovingAverage::getTotal ( ) const
inline

Definition at line 121 of file decklink_drift_fix.hpp.

121 {
122 return total;
123 }

References total.

◆ inc()

void MovingAverage::inc ( double *& p)
inlineprivate

Definition at line 132 of file decklink_drift_fix.hpp.

132 {
133 if (++p >= window + period) {
134 p = window;
135 }
136 }

References period, and window.

Referenced by add().

◆ size()

ptrdiff_t MovingAverage::size ( ) const
inline

Definition at line 105 of file decklink_drift_fix.hpp.

105 {
106 if (head == NULL)
107 return 0;
108 if (head == tail)
109 return period;
110 return (period + tail - head) % period;
111 }

References head, period, and tail.

Referenced by avg(), and filled().

Member Data Documentation

◆ head

double* MovingAverage::head
private

Definition at line 128 of file decklink_drift_fix.hpp.

Referenced by add(), and size().

◆ period

unsigned int MovingAverage::period
private

Definition at line 126 of file decklink_drift_fix.hpp.

Referenced by MovingAverage(), filled(), inc(), and size().

◆ tail

double* MovingAverage::tail
private

Definition at line 129 of file decklink_drift_fix.hpp.

Referenced by add(), and size().

◆ total

double MovingAverage::total
private

Definition at line 130 of file decklink_drift_fix.hpp.

Referenced by add(), avg(), and getTotal().

◆ window

double* MovingAverage::window
private

Definition at line 127 of file decklink_drift_fix.hpp.

Referenced by ~MovingAverage(), add(), and inc().


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