Line data Source code
1 : /** 2 : * \file TanhShaperFilter.cpp 3 : */ 4 : 5 : #include "TanhShaperFilter.h" 6 : #include <ATK/Utility/fmath.h> 7 : 8 : #include <cassert> 9 : #include <cmath> 10 : 11 : namespace ATK 12 : { 13 : template<typename DataType_> 14 4 : TanhShaperFilter<DataType_>::TanhShaperFilter(gsl::index nb_channels) 15 4 : :Parent(nb_channels, nb_channels) 16 : { 17 4 : } 18 : 19 : template<typename DataType_> 20 3 : void TanhShaperFilter<DataType_>::set_coefficient(DataType coeff) 21 : { 22 3 : if(coeff <= 0) 23 : { 24 1 : throw std::out_of_range("Coefficient must be strictly positive."); 25 : } 26 2 : this->coeff = coeff; 27 2 : } 28 : 29 : template<typename DataType_> 30 1 : DataType_ TanhShaperFilter<DataType_>::get_coefficient() const 31 : { 32 1 : return coeff; 33 : } 34 : 35 : template<typename DataType_> 36 2 : void TanhShaperFilter<DataType_>::process_impl(gsl::index size) const 37 : { 38 4 : for(gsl::index channel = 0; channel < nb_input_ports; ++channel) 39 : { 40 2 : const DataType* ATK_RESTRICT input = converted_inputs[channel]; 41 2 : DataType* ATK_RESTRICT output = outputs[channel]; 42 2002 : for(gsl::index i = 0; i < size; ++i) 43 : { 44 2000 : auto exp = fmath::exp(2 * coeff * input[i]); 45 2000 : output[i] = (exp - 1) / (coeff * (exp + 1)); 46 : } 47 : } 48 2 : } 49 : 50 : #if ATK_ENABLE_INSTANTIATION 51 : template class TanhShaperFilter<float>; 52 : #endif 53 : template class TanhShaperFilter<double>; 54 : }