LCOV - code coverage report
Current view: top level - Dynamic - GainMaxExpanderFilter.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 28 28 100.0 %
Date: 2021-02-18 20:07:22 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /**
       2             :  * \file GainMaxExpanderFilter.cpp
       3             :  */
       4             : 
       5             : #include "GainMaxExpanderFilter.h"
       6             : #include <ATK/Core/Utilities.h>
       7             : #include <ATK/Utility/fmath.h>
       8             : 
       9             : #include <cmath>
      10             : #include <cstdint>
      11             : #include <iostream>
      12             : 
      13             : namespace ATK
      14             : {
      15             :   template<typename DataType_>
      16          10 :   GainMaxExpanderFilter<DataType_>::GainMaxExpanderFilter(gsl::index nb_channels, size_t LUTsize, size_t LUTprecision)
      17          10 :   :Parent(nb_channels, LUTsize, LUTprecision)
      18             :   {
      19          10 :   }
      20             : 
      21             :   template<typename DataType_>
      22           5 :   void GainMaxExpanderFilter<DataType_>::set_softness(DataType_ softness)
      23             :   {
      24           5 :     if (softness < 0)
      25             :     {
      26           1 :       throw ATK::RuntimeError("Softness factor must be positive value");
      27             :     }
      28           4 :     this->softness = softness;
      29           4 :     start_recomputeLUT();
      30           4 :   }
      31             :   
      32             :   template<typename DataType_>
      33           1 :   DataType_ GainMaxExpanderFilter<DataType_>::get_softness() const
      34             :   {
      35           1 :     return softness;
      36             :   }
      37             : 
      38             :   template<typename DataType_>
      39           4 :   void GainMaxExpanderFilter<DataType_>::set_max_reduction(DataType_ max_reduction)
      40             :   {
      41           4 :     if (max_reduction <= 0)
      42             :     {
      43           1 :       throw ATK::RuntimeError("Maximum reduction factor must be strictly positive value");
      44             :     }
      45           3 :     this->max_reduction = max_reduction;
      46           3 :     start_recomputeLUT();
      47           3 :   }
      48             : 
      49             :   template<typename DataType_>
      50           1 :   void GainMaxExpanderFilter<DataType_>::set_max_reduction_db(DataType_ max_reduction_db)
      51             :   {
      52           1 :     this->max_reduction = static_cast<DataType_>(std::pow(10, max_reduction_db / 10));
      53           1 :     start_recomputeLUT();
      54           1 :   }
      55             : 
      56             :   template<typename DataType_>
      57           2 :   DataType_ GainMaxExpanderFilter<DataType_>::get_max_reduction() const
      58             :   {
      59           2 :     return max_reduction;
      60             :   }
      61             : 
      62             :   template<typename DataType_>
      63     1311090 :   DataType_ GainMaxExpanderFilter<DataType_>::computeGain( DataType_ value ) const
      64             :   {
      65     1311090 :     if(value == 0)
      66             :     {
      67          77 :       return static_cast<DataType_>(fmath::pow(max_reduction, 1 / (ratio - 1)));
      68             :     }
      69             : 
      70     1311010 :     DataType diff = static_cast<DataType_>(-5 * fmath::log10(value * value + fmath::pow(max_reduction, 2 / (ratio - 1))));
      71             : 
      72     1311010 :     return static_cast<DataType>(fmath::pow(10, -(std::sqrt(diff*diff + softness) + diff) / 40 * (ratio - 1)));
      73             :   }
      74             : 
      75             : #if ATK_ENABLE_INSTANTIATION
      76             :   template class GainMaxExpanderFilter<float>;
      77             :   template class GainFilter<GainMaxExpanderFilter<float>>;
      78             : #endif
      79             :   template class GainMaxExpanderFilter<double>;
      80             :   template class GainFilter<GainMaxExpanderFilter<double>>;
      81             : }

Generated by: LCOV version TK-3.3.0-4-gdba42eea