52 lines
944 B
C++
52 lines
944 B
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef SAMPLERATEESTIMATOR_H
|
||
#define SAMPLERATEESTIMATOR_H
|
||
|
||
#include "../../data/Timestamp.h"
|
||
|
||
class SampleRateEstimator {
|
||
|
||
private:
|
||
|
||
const double a = 0.99;
|
||
double curHz = 0;
|
||
Timestamp tsLast;
|
||
|
||
public:
|
||
|
||
float update(const Timestamp ts) {
|
||
|
||
// first
|
||
if (tsLast.isZero()) {
|
||
tsLast = ts;
|
||
return 0;
|
||
}
|
||
|
||
const double diffSec = static_cast<double>((ts-tsLast).sec());
|
||
tsLast = ts;
|
||
|
||
if (diffSec != 0) {
|
||
curHz = a*curHz + (1-a) * (1.0/diffSec);
|
||
}
|
||
|
||
return static_cast<float>(curHz);
|
||
|
||
}
|
||
|
||
float getCurHz() const {
|
||
return static_cast<float>(curHz);
|
||
}
|
||
|
||
};
|
||
|
||
#endif // SAMPLERATEESTIMATOR_H
|