Line data Source code
1 : /** 2 : * \file ComplexConvertFilter.cpp 3 : */ 4 : 5 : #include "ComplexConvertFilter.h" 6 : 7 : #include <cassert> 8 : #include <cmath> 9 : #include <complex> 10 : #include <cstdint> 11 : 12 : namespace ATK 13 : { 14 : template<typename DataType_> 15 1 : RealToComplexFilter<DataType_>::RealToComplexFilter(gsl::index nb_channels) 16 1 : :Parent(2 * nb_channels, nb_channels) 17 : { 18 1 : } 19 : 20 : template<typename DataType_> 21 1 : void RealToComplexFilter<DataType_>::process_impl(gsl::index size) const 22 : { 23 1 : assert(nb_input_ports == 2*nb_output_ports); 24 : 25 2 : for(gsl::index channel = 0; channel < nb_output_ports; ++channel) 26 : { 27 1 : const auto* ATK_RESTRICT input1 = converted_inputs[2 * channel]; 28 1 : const auto* ATK_RESTRICT input2 = converted_inputs[2 * channel + 1]; 29 1 : auto* ATK_RESTRICT output = outputs[channel]; 30 1048580 : for(gsl::index i = 0; i < size; ++i) 31 : { 32 1048580 : output[i] = std::complex<DataType_>(input1[i], input2[i]); 33 : } 34 : } 35 1 : } 36 : 37 : template<typename DataType_> 38 1 : ComplexToRealFilter<DataType_>::ComplexToRealFilter(gsl::index nb_channels) 39 1 : :Parent(nb_channels, 2 * nb_channels) 40 : { 41 1 : } 42 : 43 : template<typename DataType_> 44 1 : void ComplexToRealFilter<DataType_>::process_impl(gsl::index size) const 45 : { 46 1 : assert(2* nb_input_ports == nb_output_ports); 47 : 48 2 : for (gsl::index channel = 0; channel < nb_input_ports; ++channel) 49 : { 50 1 : const auto* ATK_RESTRICT input = converted_inputs[channel]; 51 1 : auto* ATK_RESTRICT output1 = outputs[2 * channel]; 52 1 : auto* ATK_RESTRICT output2 = outputs[2 * channel + 1]; 53 1048580 : for (gsl::index i = 0; i < size; ++i) 54 : { 55 1048580 : output1[i] = std::real(input[i]); 56 1048580 : output2[i] = std::imag(input[i]); 57 : } 58 : } 59 1 : } 60 : 61 : template class RealToComplexFilter<float>; 62 : template class ComplexToRealFilter<float>; 63 : #if ATK_ENABLE_INSTANTIATION 64 : template class RealToComplexFilter<double>; 65 : template class ComplexToRealFilter<double>; 66 : #endif 67 : }