22 #ifndef EDSP_FEATURE_TEMPORAL_EnvelopeFollower_HPP 23 #define EDSP_FEATURE_TEMPORAL_EnvelopeFollower_HPP 63 constexpr
value_type samplerate() const noexcept;
112 constexpr
void reset() noexcept;
122 template <typename InIterator, typename OutputIt>
123 constexpr
void apply(InIterator first, InIterator last, OutputIt d_first);
132 bool rectification_{
false};
135 template <
typename T>
145 template <
typename T>
150 template <
typename T>
156 template <
typename T>
161 template <
typename T>
167 template <
typename T>
169 return release_time_;
172 template <
typename T>
178 template <
typename T>
180 return rectification_;
183 template <
typename T>
185 rectification_ = enabled;
188 template <
typename T>
190 attack_gain_ = (attack_gain_ > 0) ? static_cast<value_type>(std::exp(-1 / (attack_time_ * samplerate_))) : 0;
191 release_gain_ = (release_gain_ > 0) ? static_cast<value_type>(std::exp(-1 / (release_time_ * samplerate_))) : 0;
195 template <
typename T>
196 template <
typename InIterator,
typename OutputIt>
198 for (; first != last; ++first, ++d_first) {
199 const auto rectified = rectification_ ? std::abs(*first) : *first;
200 const auto current = (last_ < rectified) ? (1 - attack_gain_) * rectified + attack_gain_ * last_
201 : (1 - release_gain_) * rectified + release_gain_ * last_;
209 #endif // EDSP_FEATURE_TEMPORAL_EnvelopeFollower_HPP This class implements a basic envelope-follower.
Definition: envelope_follower.hpp:44
constexpr bool rectification() const noexcept
Checks if the rectification is enabled.
Definition: envelope_follower.hpp:179
constexpr value_type attack_time() const noexcept
Returns the attack time of the first order lowpass in the attack phase.
Definition: envelope_follower.hpp:157
std::size_t size_type
Definition: envelope_follower.hpp:47
constexpr bool is_denormal(T x)
Determines if the number is denormal floating-point.
Definition: numeric.hpp:80
constexpr void apply(InIterator first, InIterator last, OutputIt d_first)
Computes the envelope of the element's value in the range [first, last), and stores the result in ano...
Definition: envelope_follower.hpp:197
constexpr void set_attack_time(value_type attackTime) noexcept
Set the the attack time of the first order lowpass in the attack phase.
Definition: envelope_follower.hpp:162
constexpr void reset() noexcept
Resets the temporal an internal data.
Definition: envelope_follower.hpp:189
constexpr void rectify(InputIt first, InputIt last, OutputIt d_first)
For each element in the range [first, last) computes the absolute value not and stores the result in ...
Definition: rectify.hpp:41
constexpr value_type samplerate() const noexcept
Returns the sample rate in Hz.
Definition: envelope_follower.hpp:146
constexpr void set_release_time(value_type releaseTime) noexcept
Set the the release time of the first order lowpass in the attack phase.
Definition: envelope_follower.hpp:173
constexpr void set_rectification(bool enabled) noexcept
Enables the rectification of the output signal.
Definition: envelope_follower.hpp:184
constexpr value_type release_time() const noexcept
Returns the release time of the first order lowpass in the release phase.
Definition: envelope_follower.hpp:168
constexpr envelope_follower(value_type samplerate, value_type attackTime, value_type releaseTime, bool rectify=false) noexcept
Creates an EnvelopeFollower object class.
Definition: envelope_follower.hpp:136
Definition: amplifier.hpp:29
T value_type
Definition: envelope_follower.hpp:46
constexpr void set_samplerate(value_type samplerate) noexcept
Sets the sample rate in Hz and resets the internal parameters.
Definition: envelope_follower.hpp:151