LCOV - code coverage report
Current view: top level - Tools - OversamplingFilter.hxx (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 133 133 100.0 %
Date: 2021-02-18 20:07:22 Functions: 20 20 100.0 %

          Line data    Source code
       1             : /**
       2             :  * \file OversamplingFilter.hxx
       3             :  */
       4             : 
       5             : #include "OversamplingFilter.h"
       6             : 
       7             : #include <cassert>
       8             : 
       9             : namespace ATK
      10             : {
      11             :   template<class DataType_>
      12           1 :   Oversampling6points5order_2<DataType_>::Oversampling6points5order_2()
      13             :   {
      14           1 :     coeffs[0][0] = 0.40513396007145713;
      15           1 :     coeffs[0][1] = 0.09251794438424393;
      16           1 :     coeffs[0][2] = 0.00234806603570670;
      17           1 :     coeffs[1][0] = 0.28342806338906690;
      18           1 :     coeffs[1][1] = 0.21703277024054901;
      19           1 :     coeffs[1][2] = 0.01309294748731515;
      20           1 :     coeffs[2][0] = -0.191337682540351941;
      21           1 :     coeffs[2][1] = 0.16187844487943592;
      22           1 :     coeffs[2][2] = 0.02946017143111912;
      23           1 :     coeffs[3][0] = -0.16471626390554542;
      24           1 :     coeffs[3][1] = -0.00154547203542499;
      25           1 :     coeffs[3][2] = 0.03399271444851909;
      26           1 :     coeffs[4][0] = 0.03845798729588149;
      27           1 :     coeffs[4][1] = -0.05712936104242644;
      28           1 :     coeffs[4][2] = 0.01866750929921070;
      29           1 :     coeffs[5][0] = 0.04317950185225609;
      30           1 :     coeffs[5][1] = -0.01802814255926417;
      31           1 :     coeffs[5][2] = 0.00152170021558204;
      32           1 :   }
      33             : 
      34             :   template<class DataType_>
      35          12 :   Oversampling6points5order_4<DataType_>::Oversampling6points5order_4()
      36             :   {
      37          12 :     coeffs[0][0] = 0.41496902959240894;
      38          12 :     coeffs[0][1] = 0.08343081932889224;
      39          12 :     coeffs[0][2] = 0.00160015038681571;
      40          12 :     coeffs[1][0] = 0.31625515004859783;
      41          12 :     coeffs[1][1] = 0.21197848565176958;
      42          12 :     coeffs[1][2] = 0.02337283412161328;
      43          12 :     coeffs[2][0] = -0.203271896548875371;
      44          12 :     coeffs[2][1] = 0.17989908432249280;
      45          12 :     coeffs[2][2] = 0.02337283412161328;
      46          12 :     coeffs[3][0] = -0.20209241069835732;
      47          12 :     coeffs[3][1] = 0.01760734419526000;
      48          12 :     coeffs[3][2] = 0.02985927012435252;
      49          12 :     coeffs[4][0] = 0.04100948858761910;
      50          12 :     coeffs[4][1] = -0.06147760875085254;
      51          12 :     coeffs[4][2] = 0.02046802954581191;
      52          12 :     coeffs[5][0] = 0.06607747864416924;
      53          12 :     coeffs[5][1] = -0.03255079211953620;
      54          12 :     coeffs[5][2] = 0.00628989632244913;
      55          12 :   }
      56             : 
      57             :   template<class DataType_>
      58           1 :   Oversampling6points5order_8<DataType_>::Oversampling6points5order_8()
      59             :   {
      60           1 :     coeffs[0][0] = 0.41660797292569773;
      61           1 :     coeffs[0][1] = 0.08188468587188069;
      62           1 :     coeffs[0][2] = 0.00150734119050266;
      63           1 :     coeffs[1][0] = 0.32232780822726981;
      64           1 :     coeffs[1][1] = 0.21076321997422021;
      65           1 :     coeffs[1][2] = 0.00907649978070957;
      66           1 :     coeffs[2][0] = -0.205219993961471501;
      67           1 :     coeffs[2][1] = 0.18282942057327367;
      68           1 :     coeffs[2][2] = 0.02239057377093268;
      69           1 :     coeffs[3][0] = -0.21022298520246224;
      70           1 :     coeffs[3][1] = 0.02176417471349534;
      71           1 :     coeffs[3][2] = 0.02898626924395209;
      72           1 :     coeffs[4][0] = 0.04149963966704384;
      73           1 :     coeffs[4][1] = -0.06224707096203808;
      74           1 :     coeffs[4][2] = 0.02074742969707599;
      75           1 :     coeffs[5][0] = 0.07517133281176167;
      76           1 :     coeffs[5][1] = -0.03751837438141215;
      77           1 :     coeffs[5][2] = 0.00747588873055296;
      78           1 :   }
      79             : 
      80             :   template<class DataType_>
      81           1 :   Oversampling6points5order_16<DataType_>::Oversampling6points5order_16()
      82             :   {
      83           1 :     coeffs[0][0] = 0.41809989254549901;
      84           1 :     coeffs[0][1] = 0.08049339946273310;
      85           1 :     coeffs[0][2] = 0.00140670799165932;
      86           1 :     coeffs[1][0] = 0.32767596257424964;
      87           1 :     coeffs[1][1] = 0.20978189376640677;
      88           1 :     coeffs[1][2] = 0.00859567104974701;
      89           1 :     coeffs[2][0] = -0.2069944618112960001;
      90           1 :     coeffs[2][1] = 0.18541689550861262;
      91           1 :     coeffs[2][2] = 0.02152772260740132;
      92           1 :     coeffs[3][0] = -0.21686095413034051;
      93           1 :     coeffs[3][1] = 0.02509557922091643;
      94           1 :     coeffs[3][2] = 0.02831484751363800;
      95           1 :     coeffs[4][0] = 0.04163046817137675;
      96           1 :     coeffs[4][1] = -0.06244556931623735;
      97           1 :     coeffs[4][2] = 0.02081510113314315;
      98           1 :     coeffs[5][0] = 0.07990500783668089;
      99           1 :     coeffs[5][1] = -0.03994519162531633;
     100           1 :     coeffs[5][2] = 0.00798609327859495;
     101           1 :   }
     102             : 
     103             :   template<class DataType_>
     104           2 :   Oversampling6points5order_32<DataType_>::Oversampling6points5order_32()
     105             :   {
     106           2 :     coeffs[0][0] = 0.42685983409379380;
     107           2 :     coeffs[0][1] = 0.07238123511170030;
     108           2 :     coeffs[0][2] = 0.00075893079450573;
     109           2 :     coeffs[1][0] = 0.35831772348893259;
     110           2 :     coeffs[1][1] = 0.20451644554758297;
     111           2 :     coeffs[1][2] = 0.00562658797241955;
     112           2 :     coeffs[2][0] = -0.217009177221292431;
     113           2 :     coeffs[2][1] = 0.20051376594086157;
     114           2 :     coeffs[2][2] = 0.01649541128040211;
     115           2 :     coeffs[3][0] = -0.25112715343740988;
     116           2 :     coeffs[3][1] = 0.04223025992200458;
     117           2 :     coeffs[3][2] = 0.02488727472995134;
     118           2 :     coeffs[4][0] = 0.04166746673533273;
     119           2 :     coeffs[4][1] = -0.06250420114356986;
     120           2 :     coeffs[4][2] = 0.02083473440841799;
     121           2 :     coeffs[5][0] = 0.08349799235675044;
     122           2 :     coeffs[5][1] = -0.04174912841630993;
     123           2 :     coeffs[5][2] = 0.00834987866042734;
     124           2 :   }
     125             : 
     126             :   template<class DataType, class Coefficients>
     127          17 :   OversamplingFilter<DataType, Coefficients>::OversamplingFilter(gsl::index nb_channels)
     128          17 :     :TypedBaseFilter<DataType>(nb_channels, nb_channels)
     129             :   {
     130          17 :     input_delay = Coefficients::points;
     131          17 :   }
     132             : 
     133             :   template<class DataType, class Coefficients>
     134          17 :   void OversamplingFilter<DataType, Coefficients>::process_impl(gsl::index size) const
     135             :   {
     136          17 :     assert(input_sampling_rate * Coefficients::oversampling_factor == output_sampling_rate);
     137          17 :     assert(nb_input_ports == nb_output_ports);
     138             : 
     139          34 :     for(gsl::index channel = 0; channel < nb_input_ports; ++channel)
     140             :     {
     141          17 :       const DataType* ATK_RESTRICT input = converted_inputs[channel];
     142          17 :       DataType* ATK_RESTRICT output = outputs[channel];
     143             :       
     144          17 :       process_one_channel(size, input, output);
     145             :     }
     146          17 :   }
     147             :   
     148             :   template<class DataType, class Coefficients>
     149          17 :   void OversamplingFilter<DataType, Coefficients>::process_one_channel(gsl::index size, const DataType* ATK_RESTRICT input, DataType* ATK_RESTRICT output) const
     150             :   {
     151       14609 :     for(gsl::index i = 0; i < size / Coefficients::oversampling_factor; ++i)
     152             :     {
     153             :       DataType even[Coefficients::points / 2];
     154       58368 :       for(gsl::index j = 0; j < Coefficients::points / 2; ++j)
     155             :       {
     156       43776 :         even[j] = input[i - Coefficients::points + Coefficients::points / 2 + j] + input[i - Coefficients::points + Coefficients::points / 2 - 1 - j];
     157             :       }
     158             :       DataType odd[Coefficients::points / 2];
     159       58368 :       for(gsl::index j = 0; j < Coefficients::points / 2; ++j)
     160             :       {
     161       43776 :         odd[j] = input[i - Coefficients::points + Coefficients::points / 2 + j] - input[i - Coefficients::points + Coefficients::points / 2 - 1 - j];
     162             :       }
     163             :       DataType c[Coefficients::order + 1];
     164             : 
     165       58368 :       for(gsl::index j = 0; j < Coefficients::order + 1; j += 2)
     166             :       {
     167       43776 :       c[j] = TypeTraits<DataType>::Zero();
     168      175104 :         for(gsl::index k = 0; k < Coefficients::points / 2; ++k)
     169             :         {
     170      131328 :           c[j] = c[j] + even[k] * coeffs.coeffs[j][k];
     171             :         }
     172             :       }
     173       58368 :       for(gsl::index j = 1; j < Coefficients::order + 1; j += 2)
     174             :       {
     175       43776 :         c[j] = TypeTraits<DataType>::Zero();
     176      175104 :         for(gsl::index k = 0; k < Coefficients::points / 2; ++k)
     177             :         {
     178      131328 :           c[j] = c[j] + odd[k] * coeffs.coeffs[j][k];
     179             :         }
     180             :       }
     181             : 
     182      107712 :       for (gsl::index j = 0; j < Coefficients::oversampling_factor; ++j)
     183             :       {
     184       93120 :         auto z = static_cast<typename TypeTraits<DataType>::Scalar>(j) / Coefficients::oversampling_factor - static_cast<typename TypeTraits<DataType>::Scalar>(1 / 2.);
     185             : 
     186       93120 :         DataType temp = TypeTraits<DataType>::Zero();
     187      651840 :         for(gsl::index k = 0; k <= Coefficients::order; ++k)
     188             :         {
     189      558720 :           temp = temp * z + c[Coefficients::order - k];
     190             :         }
     191       93120 :         *(output++) = temp;
     192             :       }
     193             :     }
     194          17 :   }
     195             : }

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