eDSP  0.0.1
A cross-platform DSP library written in C++.
lat.hpp
Go to the documentation of this file.
1 
27 #ifndef EDSP_LAT_HPP
28 #define EDSP_LAT_HPP
29 
30 #include <algorithm>
31 #include <functional>
32 #include <cmath>
33 
34 namespace edsp { namespace feature { inline namespace temporal {
35 
57  template <typename ForwardIt, typename Numeric>
58  constexpr auto lat(ForwardIt first, ForwardIt last, Numeric samplerate,
59  Numeric start_threshold, Numeric stop_threshold) {
60  using value_type = typename std::iterator_traits<ForwardIt>::value_type;
61  const auto max_value = *std::max_element(first, last);
62  const auto cutoff_start_attack = max_value * start_threshold;
63  const auto cutoff_stop_attack = max_value * stop_threshold;
64  const auto start_iter = std::find_if(first, last,
65  std::bind(std::greater_equal<value_type>(), std::placeholders::_1, cutoff_start_attack));
66  const auto stop_iter = std::find_if(first, last,
67  std::bind(std::greater_equal<value_type >(), std::placeholders::_1, cutoff_stop_attack));
68  const auto start_attack = std::distance(first, start_iter);
69  const auto stop_attack = std::distance(first, stop_iter);
70  const auto attack_time = static_cast<value_type>(stop_attack - start_attack)
71  / static_cast<value_type>(samplerate);
72  constexpr auto threshold = static_cast<value_type >(10e-5);
73  return (attack_time > threshold) ? static_cast<T>(std::log10(attack_time)) : -5;
74  }
75 }}}
76 
77 #endif //EDSP_LAT_HPP
constexpr auto lat(ForwardIt first, ForwardIt last, Numeric samplerate, Numeric start_threshold, Numeric stop_threshold)
The laq class estimates the logarithmic attack time of an envelope signal.
Definition: lat.hpp:58
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29