Line data Source code
1 : /** 2 : * \file GainColoredCompressorFilter.cpp 3 : */ 4 : 5 : #include "GainColoredCompressorFilter.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 11 : GainColoredCompressorFilter<DataType_>::GainColoredCompressorFilter(gsl::index nb_channels, size_t LUTsize, size_t LUTprecision) 16 11 : :Parent(nb_channels, LUTsize, LUTprecision) 17 : { 18 11 : } 19 : 20 : template<typename DataType_> 21 4 : void GainColoredCompressorFilter<DataType_>::set_softness(DataType_ softness) 22 : { 23 4 : if (softness < 0) 24 : { 25 1 : throw ATK::RuntimeError("Softness factor must be positive value"); 26 : } 27 3 : this->softness = softness; 28 3 : start_recomputeLUT(); 29 3 : } 30 : 31 : template<typename DataType_> 32 1 : DataType_ GainColoredCompressorFilter<DataType_>::get_softness() const 33 : { 34 1 : return softness; 35 : } 36 : 37 : template<typename DataType_> 38 3 : void GainColoredCompressorFilter<DataType_>::set_color(DataType_ color) 39 : { 40 3 : this->color = color; 41 3 : start_recomputeLUT(); 42 3 : } 43 : 44 : template<typename DataType_> 45 1 : DataType_ GainColoredCompressorFilter<DataType_>::get_color() const 46 : { 47 1 : return color; 48 : } 49 : 50 : template<typename DataType_> 51 4 : void GainColoredCompressorFilter<DataType_>::set_quality(DataType_ quality) 52 : { 53 4 : if (quality <= 0) 54 : { 55 1 : throw ATK::RuntimeError("Quality factor must be a strictly positive value"); 56 : } 57 3 : this->quality = quality; 58 3 : start_recomputeLUT(); 59 3 : } 60 : 61 : template<typename DataType_> 62 1 : DataType_ GainColoredCompressorFilter<DataType_>::get_quality() const 63 : { 64 1 : return quality; 65 : } 66 : 67 : template<typename DataType_> 68 1442240 : DataType_ GainColoredCompressorFilter<DataType_>::computeGain( DataType_ value ) const 69 : { 70 1442240 : if(value == 0) 71 : { 72 81 : return 1; 73 : } 74 1442150 : DataType diff = 10 * fmath::log10(value); 75 : 76 1442160 : DataType additional_color = color * fmath::exp(- diff * diff * quality); 77 1442160 : return static_cast<DataType>(fmath::pow(10, -(std::sqrt(diff*diff + softness) + diff) / 40 * (ratio - 1) / ratio)) + additional_color; 78 : } 79 : 80 : #if ATK_ENABLE_INSTANTIATION 81 : template class GainColoredCompressorFilter<float>; 82 : template class GainFilter<GainColoredCompressorFilter<float>>; 83 : #endif 84 : template class GainColoredCompressorFilter<double>; 85 : template class GainFilter<GainColoredCompressorFilter<double>>; 86 : }