mirror of https://github.com/Genymobile/scrcpy
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
483 B
C
27 lines
483 B
C
#include "average.h"
|
|
|
|
#include <assert.h>
|
|
|
|
void
|
|
sc_average_init(struct sc_average *avg, unsigned range) {
|
|
avg->range = range;
|
|
avg->avg = 0;
|
|
avg->count = 0;
|
|
}
|
|
|
|
void
|
|
sc_average_push(struct sc_average *avg, float value) {
|
|
if (avg->count < avg->range) {
|
|
++avg->count;
|
|
}
|
|
|
|
assert(avg->count);
|
|
avg->avg = ((avg->count - 1) * avg->avg + value) / avg->count;
|
|
}
|
|
|
|
float
|
|
sc_average_get(struct sc_average *avg) {
|
|
assert(avg->count);
|
|
return avg->avg;
|
|
}
|