Line data Source code
1 : /** 2 : * \file GainExpanderFilter.cpp 3 : */ 4 : 5 : #include "GainExpanderFilter.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 : GainExpanderFilter<DataType_>::GainExpanderFilter(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 8 : void GainExpanderFilter<DataType_>::set_softness(DataType_ softness) 22 : { 23 8 : if (softness < 0) 24 : { 25 1 : throw ATK::RuntimeError("Softness factor must be positive value"); 26 : } 27 7 : this->softness = softness; 28 7 : start_recomputeLUT(); 29 7 : } 30 : 31 : template<typename DataType_> 32 1 : DataType_ GainExpanderFilter<DataType_>::get_softness() const 33 : { 34 1 : return softness; 35 : } 36 : 37 : template<typename DataType_> 38 1311210 : DataType_ GainExpanderFilter<DataType_>::computeGain( DataType_ value ) const 39 : { 40 1311210 : if(value == 0) 41 : { 42 81 : return 0; 43 : } 44 1311130 : DataType diff = -10 * fmath::log10(value); 45 1311130 : return static_cast<DataType>(fmath::pow(10, -(std::sqrt(diff*diff + softness) + diff) / 40 * (ratio - 1))); 46 : } 47 : 48 : #if ATK_ENABLE_INSTANTIATION 49 : template class GainExpanderFilter<float>; 50 : template class GainFilter<GainExpanderFilter<float>>; 51 : #endif 52 : template class GainExpanderFilter<double>; 53 : template class GainFilter<GainExpanderFilter<double>>; 54 : }