mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
use simple Delay for the window
This commit is contained in:
parent
b934d9fe4e
commit
1ae40ccf3b
1 changed files with 43 additions and 4 deletions
47
movext.hh
47
movext.hh
|
|
@ -6,6 +6,7 @@ Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "delay.hh"
|
||||
#include "deque.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
|
@ -44,22 +45,60 @@ public:
|
|||
template <typename TYPE, int NUM>
|
||||
class MovMin
|
||||
{
|
||||
MovExt<TYPE, std::equal_to<TYPE>, std::less<TYPE>, NUM> movmin;
|
||||
Delay<TYPE, NUM> window;
|
||||
Deque<TYPE, NUM> dispenser, refill;
|
||||
public:
|
||||
MovMin() : window(std::numeric_limits<TYPE>::max())
|
||||
{
|
||||
dispenser.push_front(std::numeric_limits<TYPE>::max());
|
||||
}
|
||||
TYPE operator () (TYPE input)
|
||||
{
|
||||
return movmin(input);
|
||||
if (window(input) == dispenser.front())
|
||||
dispenser.pop_front();
|
||||
|
||||
while (!refill.empty() && input < refill.front())
|
||||
refill.pop_front();
|
||||
refill.push_front(input);
|
||||
|
||||
if (dispenser.empty()) {
|
||||
while (!refill.empty()) {
|
||||
dispenser.push_front(refill.front());
|
||||
refill.pop_front();
|
||||
}
|
||||
return dispenser.front();
|
||||
}
|
||||
return dispenser.front() < refill.back() ? dispenser.front() : refill.back();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TYPE, int NUM>
|
||||
class MovMax
|
||||
{
|
||||
MovExt<TYPE, std::equal_to<TYPE>, std::greater<TYPE>, NUM> movmax;
|
||||
Delay<TYPE, NUM> window;
|
||||
Deque<TYPE, NUM> dispenser, refill;
|
||||
public:
|
||||
MovMax() : window(std::numeric_limits<TYPE>::min())
|
||||
{
|
||||
dispenser.push_front(std::numeric_limits<TYPE>::min());
|
||||
}
|
||||
TYPE operator () (TYPE input)
|
||||
{
|
||||
return movmax(input);
|
||||
if (window(input) == dispenser.front())
|
||||
dispenser.pop_front();
|
||||
|
||||
while (!refill.empty() && input > refill.front())
|
||||
refill.pop_front();
|
||||
refill.push_front(input);
|
||||
|
||||
if (dispenser.empty()) {
|
||||
while (!refill.empty()) {
|
||||
dispenser.push_front(refill.front());
|
||||
refill.pop_front();
|
||||
}
|
||||
return dispenser.front();
|
||||
}
|
||||
return dispenser.front() > refill.back() ? dispenser.front() : refill.back();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue