eDSP  0.0.1
A cross-platform DSP library written in C++.
clipper.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17  *
18  * File: clipper.hpp
19  * Date: 09/06/18
20  * Author: Mohammed Boujemaoui
21  */
22 
23 #ifndef EDSP_CLIPPER_HPP
24 #define EDSP_CLIPPER_HPP
25 
26 #include <algorithm>
27 #include <edsp/meta/iterator.hpp>
28 
29 namespace edsp { inline namespace algorithm {
30 
41  template <typename InputItr, typename OutputIt, typename Numeric>
42  constexpr void clipper(InputItr first, InputItr last, OutputIt d_first, Numeric min, Numeric max) {
43  std::transform(first, last, d_first,
44  [=](const meta::value_type_t<InputItr> val) -> meta::value_type_t<OutputIt> {
45  return (val < min) ? min : (val > max) ? max : val;
46  });
47  }
48 
49 }} // namespace edsp::algorithm
50 
51 #endif // EDSP_CLIPPER_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 void clipper(InputItr first, InputItr last, OutputIt d_first, Numeric min, Numeric max)
Limits the values of the elements in the range [first, last) once it exceeds a threshold [min...
Definition: clipper.hpp:42
constexpr meta::value_type_t< ForwardIt > min(ForwardIt first, ForwardIt last)
Computes the minimum value of the range [first, last)
Definition: min.hpp:38
Definition: amplifier.hpp:29