Add short paths for the smoothers
When the input is basically constant in particular
This commit is contained in:
parent
41a719a720
commit
f874ad3db5
3 changed files with 20 additions and 2 deletions
|
|
@ -25,6 +25,8 @@ class OnePoleFilter {
|
||||||
public:
|
public:
|
||||||
OnePoleFilter() = default;
|
OnePoleFilter() = default;
|
||||||
|
|
||||||
|
Type current() const { return state; }
|
||||||
|
|
||||||
void setGain(Type gain)
|
void setGain(Type gain)
|
||||||
{
|
{
|
||||||
G = gain / (1 + gain);
|
G = gain / (1 + gain);
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,25 @@ void Smoother::reset(float value)
|
||||||
|
|
||||||
void Smoother::process(absl::Span<const float> input, absl::Span<float> output)
|
void Smoother::process(absl::Span<const float> input, absl::Span<float> output)
|
||||||
{
|
{
|
||||||
if (smoothing)
|
CHECK_SPAN_SIZES(input, output);
|
||||||
|
if (input.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto midValue = input[input.size() / 2];
|
||||||
|
const bool shortcut = (
|
||||||
|
input.front() == input.back()
|
||||||
|
&& input.front() == midValue
|
||||||
|
&& input.front() == current()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (smoothing && !shortcut) {
|
||||||
filter.processLowpass(input, output);
|
filter.processLowpass(input, output);
|
||||||
else
|
}
|
||||||
|
else if (input.data() != output.data()) {
|
||||||
copy<float>(input, output);
|
copy<float>(input, output);
|
||||||
|
} else {
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void process(absl::Span<const float> input, absl::Span<float> output);
|
void process(absl::Span<const float> input, absl::Span<float> output);
|
||||||
|
|
||||||
|
float current() const { return filter.current(); }
|
||||||
private:
|
private:
|
||||||
bool smoothing { false };
|
bool smoothing { false };
|
||||||
OnePoleFilter<float> filter {};
|
OnePoleFilter<float> filter {};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue