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

          Line data    Source code
       1             : /**
       2             :  * \file PedalToneStackFilter.hxx
       3             :  */
       4             : 
       5             : #include "PedalToneStackFilter.h"
       6             : 
       7             : #include <boost/math/tools/polynomial.hpp>
       8             : 
       9             : namespace ATK
      10             : {
      11             :   template<typename DataType>
      12          12 :   SD1ToneCoefficients<DataType>::SD1ToneCoefficients(gsl::index nb_channels)
      13          12 :   :TypedBaseFilter<DataType>(nb_channels, nb_channels)
      14             :   {
      15          12 :   }
      16             : 
      17             :   template<typename DataType>
      18          28 :   void SD1ToneCoefficients<DataType>::setup()
      19             :   {
      20          28 :     Parent::setup();
      21             :     
      22          28 :     coefficients_in.assign(in_order+1, 0);
      23          28 :     coefficients_out.assign(out_order, 0);
      24             : 
      25          28 :     CoeffDataType tempm[2] = {static_cast<CoeffDataType>(-2) * input_sampling_rate, static_cast<CoeffDataType>(2) * input_sampling_rate};
      26          28 :     CoeffDataType tempp[2] = {static_cast<CoeffDataType>(1), static_cast<CoeffDataType>(1)};
      27          56 :     boost::math::tools::polynomial<CoeffDataType> poly1(tempm, 1);
      28          56 :     boost::math::tools::polynomial<CoeffDataType> poly2(tempp, 1);
      29             : 
      30          56 :     boost::math::tools::polynomial<CoeffDataType> b;
      31          56 :     boost::math::tools::polynomial<CoeffDataType> a;
      32             :     
      33          28 :     b += poly2 * poly2;
      34          28 :     b += poly2 * poly1 * (C2*R3+R4*C3+alpha*(1-alpha)*R2*C2+alpha*C2*R4);
      35          28 :     b += poly1 * poly1 * (C3*R4*(R3*C2+alpha*(1-alpha)*R2*C2));
      36             : 
      37          28 :     a += poly2 * poly2;
      38          28 :     a += poly2 * poly1 * (C2*R3+R1*C1+alpha*(1-alpha)*R2*C2+(1-alpha)*C2*R1);
      39          28 :     a += poly1 * poly1 * (C1*R1*(R3*C2+alpha*(1-alpha)*R2*C2));
      40             : 
      41         112 :     for(gsl::index i = 0; i < in_order + 1; ++i)
      42             :     {
      43          84 :       coefficients_in[i] = b[i] / a[out_order];
      44             :     }
      45          84 :     for(gsl::index i = 0; i < out_order; ++i)
      46             :     {
      47          56 :       coefficients_out[i] = -a[i] / a[out_order];
      48             :     }
      49          28 :   }
      50             : 
      51             :   template<typename DataType_>
      52          12 :   void SD1ToneCoefficients<DataType_>::set_tone(CoeffDataType alpha)
      53             :   {
      54          12 :     if(alpha < 0 || alpha > 1)
      55             :     {
      56           2 :       throw std::out_of_range("Tone is outside the interval [0,1]");
      57             :     }
      58          10 :     this->alpha = alpha;
      59             : 
      60          10 :     setup();
      61          10 :   }
      62             :   
      63             :   template<typename DataType_>
      64           1 :   typename SD1ToneCoefficients<DataType_>::CoeffDataType SD1ToneCoefficients<DataType_>::get_tone() const
      65             :   {
      66           1 :     return alpha;
      67             :   }
      68             : 
      69             :   template<typename DataType>
      70          12 :   TS9ToneCoefficients<DataType>::TS9ToneCoefficients(gsl::index nb_channels)
      71          12 :   :TypedBaseFilter<DataType>(nb_channels, nb_channels)
      72             :   {
      73          12 :   }
      74             :   
      75             :   template<typename DataType>
      76          28 :   void TS9ToneCoefficients<DataType>::setup()
      77             :   {
      78          28 :     Parent::setup();
      79             :     
      80          28 :     coefficients_in.assign(in_order+1, 0);
      81          28 :     coefficients_out.assign(out_order, 0);
      82             :     
      83          28 :     CoeffDataType tempm[2] = {static_cast<CoeffDataType>(-2) * input_sampling_rate, static_cast<CoeffDataType>(2) * input_sampling_rate};
      84          28 :     CoeffDataType tempp[2] = {static_cast<CoeffDataType>(1), static_cast<CoeffDataType>(1)};
      85          56 :     boost::math::tools::polynomial<CoeffDataType> poly1(tempm, 1);
      86          56 :     boost::math::tools::polynomial<CoeffDataType> poly2(tempp, 1);
      87             :     
      88          56 :     boost::math::tools::polynomial<CoeffDataType> b;
      89          56 :     boost::math::tools::polynomial<CoeffDataType> a;
      90             :     
      91          28 :     b += poly2 * poly2 * R2;
      92          28 :     b += poly2 * poly1 * (alpha * C2 * R2 * R3 + alpha * (1-alpha) * C2 * P * R2 + R2 * R4 * C2);
      93             :     
      94          28 :     a += poly2 * poly2 * (R2 + R1);
      95          28 :     a += poly2 * poly1 * ((1-alpha) * C2 * (alpha * P * R2 + R1 * alpha * P + R1 * R2) + R4 * C2 * (R2 + R1) + R1 * C1 * R2);
      96          28 :     a += poly1 * poly1 * (C2 * R4 * C1 * R2 * R1 + (1-alpha) * C2 * R1 * P * C1 * R2);
      97             :     
      98         112 :     for(gsl::index i = 0; i < in_order + 1; ++i)
      99             :     {
     100          84 :       coefficients_in[i] = b[i] / a[out_order];
     101             :     }
     102          84 :     for(gsl::index i = 0; i < out_order; ++i)
     103             :     {
     104          56 :       coefficients_out[i] = -a[i] / a[out_order];
     105             :     }
     106          28 :   }
     107             :   
     108             :   template<typename DataType_>
     109          12 :   void TS9ToneCoefficients<DataType_>::set_tone(CoeffDataType alpha)
     110             :   {
     111          12 :     if(alpha < 0 || alpha > 1)
     112             :     {
     113           2 :       throw std::out_of_range("Tone is outside the interval [0,1]");
     114             :     }
     115          10 :     this->alpha = alpha;
     116             :     
     117          10 :     setup();
     118          10 :   }
     119             :   
     120             :   template<typename DataType_>
     121           1 :   typename TS9ToneCoefficients<DataType_>::CoeffDataType TS9ToneCoefficients<DataType_>::get_tone() const
     122             :   {
     123           1 :     return alpha;
     124             :   }
     125             : }

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