eDSP  0.0.1
A cross-platform DSP library written in C++.
amplifier.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: amplifier.hpp
19  * Date: 09/06/18
20  * Author: Mohammed Boujemaoui
21  */
22 
23 #ifndef EDSP_AMPLIFIER_HPP
24 #define EDSP_AMPLIFIER_HPP
25 
26 #include <edsp/meta/iterator.hpp>
27 #include <algorithm>
28 
29 namespace edsp { inline namespace algorithm {
30 
45  template <typename InputIt, typename OutputIt, typename Numeric>
46  constexpr void amplifier(InputIt first, InputIt last, OutputIt d_first, Numeric factor) {
47  std::transform(
48  first, last, d_first,
49  [=](const meta::value_type_t<InputIt> val) -> meta::value_type_t<OutputIt> { return factor * val; });
50  }
51 
71  template <typename InputIt, typename OutputIt, typename Numeric>
72  constexpr void amplifier(InputIt first, InputIt last, OutputIt d_first, Numeric factor, Numeric min, Numeric max) {
73  std::transform(first, last, d_first,
74  [=](const meta::value_type_t<InputIt> val) -> meta::value_type_t<OutputIt> {
75  const auto scaled = factor * val;
76  return (scaled < min) ? min : (scaled > max) ? max : scaled;
77  });
78  }
79 
80 }} // namespace edsp::algorithm
81 
82 #endif // EDSP_AMPLIFIER_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 amplifier(InputIt first, InputIt last, OutputIt d_first, Numeric factor)
Amplifies or attenuates the elements in the range [first, last) and stores the result in another rang...
Definition: amplifier.hpp:46
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