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

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