LCOV - code coverage report
Current view: top level - Dynamic - PowerFilter.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 19 19 100.0 %
Date: 2021-02-18 20:07:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /**
       2             :  * \file PowerFilter.cpp
       3             :  */
       4             : 
       5             : #include "PowerFilter.h"
       6             : #include <ATK/Core/Utilities.h>
       7             : 
       8             : #include <cassert>
       9             : #include <cstdint>
      10             : 
      11             : namespace ATK
      12             : {
      13             :   template<typename DataType_>
      14          12 :   PowerFilter<DataType_>::PowerFilter(gsl::index nb_channels)
      15          12 :   :Parent(nb_channels, nb_channels)
      16             :   {
      17          12 :     output_delay = 1;
      18          12 :   }
      19             : 
      20             :   template<typename DataType_>
      21          12 :   void PowerFilter<DataType_>::set_memory(DataType_ memory_factor)
      22             :   {
      23          12 :     if(memory_factor < 0 || memory_factor >= 1)
      24             :     {
      25           2 :       throw ATK::RuntimeError("Memory factor must be a positive value less than 1 (so that it doesn't diverge)");
      26             :     }
      27          10 :     this->memory_factor = memory_factor;
      28          10 :   }
      29             :   
      30             :   template<typename DataType_>
      31           1 :   DataType_ PowerFilter<DataType_>::get_memory() const
      32             :   {
      33           1 :     return memory_factor;
      34             :   }
      35             :   
      36             :   template<typename DataType_>
      37          18 :   void PowerFilter<DataType_>::process_impl(gsl::index size) const
      38             :   {
      39          18 :     assert(nb_input_ports == nb_output_ports);
      40             : 
      41          36 :     for(gsl::index channel = 0; channel < nb_input_ports; ++channel)
      42             :     {
      43          18 :       const DataType* ATK_RESTRICT input = converted_inputs[channel];
      44          18 :       DataType* ATK_RESTRICT output = outputs[channel];
      45     1179670 :       for(gsl::index i = 0; i < size; ++i)
      46             :       {
      47     1179650 :         output[i] = (1 - memory_factor) * input[i] * input[i] + memory_factor * output[i-1];
      48             :       }
      49             :     }
      50          18 :   }
      51             :   
      52             : #if ATK_ENABLE_INSTANTIATION
      53             :   template class PowerFilter<float>;
      54             : #endif
      55             :   template class PowerFilter<double>;
      56             : }

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