MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_SmoothedValue.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10
11#ifndef MARVIN_LINEARSMOOTHEDVALUE_H
12#define MARVIN_LINEARSMOOTHEDVALUE_H
14namespace marvin::utils {
22
27 template <FloatType SampleType, SmoothingType Type>
29 public:
44 void reset(int stepsSamples, bool skipRemaining = true);
51 void reset(double sampleRate, double timeMs, bool skipRemaining = true);
56 void setCurrentAndTargetValue(SampleType newValue);
57
62 void setTargetValue(SampleType newValue);
71 [[nodiscard]] SampleType operator()() noexcept;
76 [[nodiscard]] bool isSmoothing() const noexcept;
77
81 [[nodiscard]] int getRemainingSamples() const noexcept;
82
86 [[nodiscard]] SampleType getTargetValue() const noexcept;
87
88 private:
89 int m_duration{ 1 };
90 int m_samplesRemaining{ 0 };
91 SampleType m_currentValue{ static_cast<SampleType>(0.0) };
92 SampleType m_targetValue{ static_cast<SampleType>(0.0) };
93 SampleType m_slew{ static_cast<SampleType>(0.0) };
94 SampleType m_approxTarget{};
95 };
96} // namespace marvin::utils
97#endif
A utility class to smooth discrete values over a given period.
Definition marvin_SmoothedValue.h:28
bool isSmoothing() const noexcept
SampleType operator()() noexcept
void reset(int stepsSamples, bool skipRemaining=true)
int getRemainingSamples() const noexcept
void reset(double sampleRate, double timeMs, bool skipRemaining=true)
SampleType getTargetValue() const noexcept
void setCurrentAndTargetValue(SampleType newValue)
void setTargetValue(SampleType newValue)
Utility helper functions and classes.
Definition marvin_Utils.h:21
SmoothingType
Enum to configure SmoothedValue to either use linear smoothing, or exponential (lowpass) smoothing.
Definition marvin_SmoothedValue.h:18
@ Linear
Definition marvin_SmoothedValue.h:19
@ Exponential
Definition marvin_SmoothedValue.h:20