27 #ifndef EDSP_DURATION_HPP 28 #define EDSP_DURATION_HPP 34 namespace edsp {
namespace feature {
inline namespace temporal {
43 template <
typename ForwardIt,
typename Numeric>
44 constexpr
auto duration(ForwardIt first, ForwardIt last, Numeric samplerate) {
45 using value_type =
typename std::iterator_traits<ForwardIt>::value_type;
46 return static_cast<value_type
>(
std::distance(first, last)) / samplerate;
62 template <
typename ForwardIt,
typename Numeric>
63 constexpr
auto effective_duration(ForwardIt first, ForwardIt last, Numeric samplerate, Numeric threshold) {
64 using value_type =
typename std::iterator_traits<ForwardIt>::value_type;
65 const auto pair = std::minmax_element(first, last);
66 const value_type limit = threshold *
std::max(std::abs(pair.first), std::abs(pair.second));
67 const auto get_threshold = std::find_if(first, last,
68 std::bind(std::greater_equal<value_type>(), std::placeholders::_1, limit));
69 const auto let_threshold = std::find_if(get_threshold, last,
70 std::bind(std::greater_equal<value_type>(), std::placeholders::_1, limit));
71 const auto samples = std::count_if(get_threshold, let_threshold);
72 return static_cast<value_type
>(samples) / static_cast<value_type>(samplerate);
76 #endif //EDSP_DURATION_HPP constexpr meta::value_type_t< ForwardIt > max(ForwardIt first, ForwardIt last)
Computes the maximum value of the range [first, last)
Definition: max.hpp:38
constexpr auto effective_duration(ForwardIt first, ForwardIt last, Numeric samplerate, Numeric threshold)
Computes the effective duration of the elements in the range [first, last)
Definition: duration.hpp:63
constexpr auto duration(ForwardIt first, ForwardIt last, Numeric samplerate)
Computes the duration of the elements in the range [first, last)
Definition: duration.hpp:44
constexpr T distance(T x, T y) noexcept
Computes the distance between x and y.
Definition: numeric.hpp:328
Definition: amplifier.hpp:29