22 #ifndef EDSP_MU_LAW_COMPRESSOR_HPP 23 #define EDSP_MU_LAW_COMPRESSOR_HPP 25 #include <edsp/meta/expects.hpp> 27 #include <edsp/meta/iterator.hpp> 31 namespace edsp {
namespace quantizer {
47 template <
typename InputIt,
typename OutputIt>
49 meta::value_type_t<InputIt> absolute_max_value,
50 meta::diff_type_t<InputIt> compression_factor) {
51 meta::expects(absolute_max_value > 0,
"Expected a maximum absolute value higher than zero");
52 meta::expects(compression_factor > 0,
"The compression factor should be a positive number");
53 using value_type = meta::value_type_t<InputIt>;
54 const auto lambda = [absolute_max_value](
const value_type input) -> value_type {
55 const auto ratio = std::fabs(input) / absolute_max_value;
56 return math::sign(input) * absolute_max_value *
57 std::log(static_cast<value_type>(1 + compression_factor * ratio)) /
58 std::log(static_cast<value_type>(1 + compression_factor));
60 std::transform(first, last, d_first, std::cref(lambda));
79 template <
typename InputIt,
typename OutputIt>
81 meta::value_type_t<InputIt> absolute_max_value,
82 meta::diff_type_t<InputIt> compression_factor) {
83 meta::expects(absolute_max_value > 0,
"Expected a maximum absolute value higher than zero");
84 meta::expects(compression_factor > 0,
"The compression factor should be a positive number");
85 using value_type = meta::value_type_t<InputIt>;
86 const auto lambda = [absolute_max_value](
const value_type input) -> value_type {
87 const auto ratio = std::fabs(input) / absolute_max_value;
88 return math::sign(input) * absolute_max_value *
89 (std::pow(static_cast<value_type>(1 + compression_factor), ratio) - 1) /
90 std::log(static_cast<value_type>(1 + compression_factor));
92 std::transform(first, last, d_first, std::cref(lambda));
97 #endif // EDSP_MU_LAW_COMPRESSOR_HPP constexpr void inverse_mu_law_compression(InputIt first, InputIt last, OutputIt d_first, meta::value_type_t< InputIt > absolute_max_value, meta::diff_type_t< InputIt > compression_factor)
The law converts data in 8-bit µ-law format to 16-bit linear formats.
Definition: mu_law_compressor.hpp:80
constexpr T sign(T x) noexcept
Determines the sign of the input number.
Definition: numeric.hpp:155
Definition: amplifier.hpp:29
constexpr void mu_law_compression(InputIt first, InputIt last, OutputIt d_first, meta::value_type_t< InputIt > absolute_max_value, meta::diff_type_t< InputIt > compression_factor)
The law converts data in 16-bit linear formats to a 8-bit µ-law format.
Definition: mu_law_compressor.hpp:48