mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-04 00:59:32 +02:00
improved time sync
This commit is contained in:
parent
48ac9d2209
commit
c92588344e
5 changed files with 44 additions and 17 deletions
|
@ -37,13 +37,27 @@ public:
|
|||
buffer.pop_front();
|
||||
}
|
||||
|
||||
T median() const
|
||||
T median(unsigned int mean = 1) const
|
||||
{
|
||||
if (buffer.empty())
|
||||
return 0;
|
||||
std::deque<T> tmpBuffer(buffer.begin(), buffer.end());
|
||||
std::sort(tmpBuffer.begin(), tmpBuffer.end());
|
||||
return tmpBuffer[tmpBuffer.size() / 2];
|
||||
if ((mean <= 1) || (tmpBuffer.size() < mean))
|
||||
return tmpBuffer[tmpBuffer.size() / 2];
|
||||
else
|
||||
{
|
||||
unsigned int low = tmpBuffer.size() / 2;
|
||||
unsigned int high = low;
|
||||
low -= mean/2;
|
||||
high += mean/2;
|
||||
T result((T)0);
|
||||
for (unsigned int i=low; i<=high; ++i)
|
||||
{
|
||||
result += tmpBuffer[i];
|
||||
}
|
||||
return result / mean;
|
||||
}
|
||||
}
|
||||
|
||||
double mean() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue