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

          Line data    Source code
       1             : /**
       2             :  * \file FIRFilter.h
       3             :  */
       4             : 
       5             : #ifndef ATK_EQ_FIRFILTER_H
       6             : #define ATK_EQ_FIRFILTER_H
       7             : 
       8             : #include <ATK/config.h>
       9             : #include <ATK/EQ/config.h>
      10             : 
      11             : #include <gsl/gsl>
      12             : 
      13             : #include <cassert>
      14             : #include <cstdint>
      15             : #include <vector>
      16             : 
      17             : namespace ATK
      18             : {
      19             :   /**
      20             :    * FIR filter template class
      21             :    */
      22             :   template<class Coefficients >
      23             :   class ATK_EQ_EXPORT FIRFilter final : public Coefficients
      24             :   {
      25             :   protected:
      26             :     using Parent = Coefficients;
      27             :     using typename Parent::DataType;
      28             :     using typename Parent::AlignedScalarVector;
      29             : 
      30             :     using Parent::converted_inputs;
      31             :     using Parent::outputs;
      32             :     using Parent::coefficients_in;
      33             :     using Parent::input_sampling_rate;
      34             :     using Parent::output_sampling_rate;
      35             :     using Parent::nb_input_ports;
      36             :     using Parent::nb_output_ports;
      37             : 
      38             :     using Parent::in_order;
      39             :     using Parent::input_delay;
      40             :     using Parent::setup;
      41             :     
      42             :   public:
      43             :     /*!
      44             :      * @brief Constructor
      45             :      * @param nb_channels is the number of input and output channels
      46             :      */
      47           4 :     explicit FIRFilter(gsl::index nb_channels = 1)
      48           4 :       :Parent(nb_channels)
      49             :     {
      50           4 :     }
      51             : 
      52             :     /// Move constructor
      53             :     FIRFilter(FIRFilter&& other)
      54             :     :Parent(std::move(other))
      55             :     {
      56             :     }
      57             : 
      58          13 :     void setup() override
      59             :     {
      60          13 :       Parent::setup();
      61          12 :       input_delay = in_order;
      62          12 :     }
      63             :     
      64        2049 :     void process_impl(gsl::index size) const final
      65             :     {
      66        2049 :       assert(input_sampling_rate == output_sampling_rate);
      67        2049 :       assert(nb_input_ports == nb_output_ports);
      68        2049 :       assert(coefficients_in.data());
      69             : 
      70        2049 :       const auto* ATK_RESTRICT coefficients_in_ptr = coefficients_in.data();
      71             : 
      72        4098 :       for (gsl::index channel = 0; channel < nb_input_ports; ++channel)
      73             :       {
      74        2049 :         const DataType* ATK_RESTRICT input = converted_inputs[channel] - static_cast<int64_t>(in_order);
      75        2049 :         DataType* ATK_RESTRICT output = outputs[channel];
      76             : 
      77     2229254 :         for (gsl::index i = 0; i < size; ++i)
      78             :         {
      79     2227202 :           output[i] = 0;
      80             :         }
      81             : 
      82    20470028 :         for (gsl::index j = 0; j < in_order + 1; ++j)
      83             :         {
      84 20981403960 :           for (gsl::index i = 0; i < size; ++i)
      85             :           {
      86 20960903940 :             output[i] += coefficients_in_ptr[j] * input[i + j];
      87             :           }
      88             :         }
      89             :       }
      90             : 
      91        2049 :     }
      92             :     
      93             :     /// Returns the vector of internal coefficients for the MA section 
      94             :     const AlignedScalarVector& get_coefficients_in() const
      95             :     {
      96             :       return coefficients_in;
      97             :     }
      98             :   };
      99             :   
     100             : }
     101             : 
     102             : #endif

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