-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinearSmoother.h
65 lines (60 loc) · 1.63 KB
/
LinearSmoother.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
/**
* @brief Linear smoother
*
*/
class LinearSmoother {
public:
/**
* @brief Set the sample rate.
*
* @param sampleRate
*/
void setSampleRate(float sampleRate);
/**
* @brief Set the smoothing time in seconds.
*
* @param smoothValue
* @param sampleRate
*/
void setSmoothTime(float smoothTime);
/**
* @brief Reset the filter state to a given value
*
* @param value
*/
void clear(float value = 0.0f);
/**
* @brief Reset to the target value (the back of the last vector passed)
*/
void clearToTarget();
/**
* @brief Process a span of data. Input and output can refer to the same
* memory.
*
* @param input
* @param output
* @param count
* @param canShortcut whether we can have a fast path if the filter is within
* a reasonable range around the first value of the input
* span.
*/
void process(const float *input, float *output, unsigned count, bool canShortcut = false);
/**
* @brief Get the current value
*/
float current() const { return current_; }
private:
void updateParameters();
private:
float current_ = 0.0;
float target_ = 0.0;
float step_ = 0.0;
int smoothFrames_ = 0;
float smoothTime_ = 0;
float sampleRate_ = 0;
};