Ignore:
Timestamp:
04/08/16 15:40:57 (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairFilter/src/unexported/ButterworthLowPass_impl.h

    r10 r15  
    1717#include <Butterworth.h>
    1818
    19 namespace flair
    20 {
    21     namespace core
    22     {
    23         class cvmatrix;
    24     }
    25     namespace gui
    26     {
    27         class LayoutPosition;
    28         class SpinBox;
    29         class DoubleSpinBox;
    30     }
    31     namespace filter
    32     {
    33         class ButterworthLowPass;
    34     }
     19namespace flair {
     20namespace core {
     21class cvmatrix;
     22}
     23namespace gui {
     24class LayoutPosition;
     25class SpinBox;
     26class DoubleSpinBox;
     27}
     28namespace filter {
     29class ButterworthLowPass;
     30}
    3531}
    3632
    3733// Storage for Layout
    38 //de-templatized for pimpl idom
    39 //comes from iir from Bernd Porr
    40 class LayoutStorage
    41 {
    42     public:
    43         LayoutStorage(int MaxPoles)
    44         {
    45             this->MaxPoles=MaxPoles;
    46             m_pairs=(Iir::PoleZeroPair*)malloc((MaxPoles+1)/2*sizeof(Iir::PoleZeroPair));
    47         }
    48         ~LayoutStorage()
    49         {
    50             free(m_pairs);
    51         }
    52         operator Iir::LayoutBase ()
    53         {
    54             return Iir::LayoutBase (MaxPoles, m_pairs);
    55         }
     34// de-templatized for pimpl idom
     35// comes from iir from Bernd Porr
     36class LayoutStorage {
     37public:
     38  LayoutStorage(int MaxPoles) {
     39    this->MaxPoles = MaxPoles;
     40    m_pairs = (Iir::PoleZeroPair *)malloc((MaxPoles + 1) / 2 *
     41                                          sizeof(Iir::PoleZeroPair));
     42  }
     43  ~LayoutStorage() { free(m_pairs); }
     44  operator Iir::LayoutBase() { return Iir::LayoutBase(MaxPoles, m_pairs); }
    5645
    57     private:
    58         Iir::PoleZeroPair *m_pairs;
    59         int MaxPoles;
     46private:
     47  Iir::PoleZeroPair *m_pairs;
     48  int MaxPoles;
    6049};
    6150
    6251// Storage for Cascade
    63 //de-templatized for pimpl idom
    64 //comes from iir from Bernd Porr
    65 class CascadeStages
    66 {
    67     public:
    68         CascadeStages(int MaxStages)
    69         {
    70             this->MaxStages=MaxStages;
    71             m_stages=(Iir::Cascade::Stage*)malloc(MaxStages*sizeof(Iir::Cascade::Stage));
    72             m_states=(Iir::DirectFormII*)malloc(MaxStages*sizeof(Iir::DirectFormII));
    73         }
    74         ~CascadeStages()
    75         {
    76             free(m_stages);
    77             free(m_states);
    78         }
    79         void reset ()
    80         {
    81             Iir::DirectFormII* state = m_states;
    82             for (int i = MaxStages; --i >= 0; ++state)
    83             state->reset();
    84         }
     52// de-templatized for pimpl idom
     53// comes from iir from Bernd Porr
     54class CascadeStages {
     55public:
     56  CascadeStages(int MaxStages) {
     57    this->MaxStages = MaxStages;
     58    m_stages =
     59        (Iir::Cascade::Stage *)malloc(MaxStages * sizeof(Iir::Cascade::Stage));
     60    m_states =
     61        (Iir::DirectFormII *)malloc(MaxStages * sizeof(Iir::DirectFormII));
     62  }
     63  ~CascadeStages() {
     64    free(m_stages);
     65    free(m_states);
     66  }
     67  void reset() {
     68    Iir::DirectFormII *state = m_states;
     69    for (int i = MaxStages; --i >= 0; ++state)
     70      state->reset();
     71  }
    8572
    86         template <typename Sample>
    87         inline Sample filter(const Sample in)
    88         {
    89             double out = in;
    90             Iir::DirectFormII* state = m_states;
    91             Iir::Biquad const* stage = m_stages;
    92             for (int i = MaxStages; --i >= 0; ++state, ++stage)
    93             out = state->process1 (out, *stage);
    94             return static_cast<Sample> (out);
    95         }
     73  template <typename Sample> inline Sample filter(const Sample in) {
     74    double out = in;
     75    Iir::DirectFormII *state = m_states;
     76    Iir::Biquad const *stage = m_stages;
     77    for (int i = MaxStages; --i >= 0; ++state, ++stage)
     78      out = state->process1(out, *stage);
     79    return static_cast<Sample>(out);
     80  }
    9681
    97         Iir::Cascade::Storage getCascadeStorage()
    98         {
    99             return Iir::Cascade::Storage (MaxStages, m_stages);
    100         }
     82  Iir::Cascade::Storage getCascadeStorage() {
     83    return Iir::Cascade::Storage(MaxStages, m_stages);
     84  }
    10185
    102     private:
    103         int MaxStages;
    104         Iir::Cascade::Stage *m_stages;
    105         Iir::DirectFormII *m_states;
     86private:
     87  int MaxStages;
     88  Iir::Cascade::Stage *m_stages;
     89  Iir::DirectFormII *m_states;
    10690};
    10791
    108 //de-templatized for pimpl idom
    109 //comes from iir from Bernd Porr
    110 class PoleFilter : Iir::Butterworth::LowPassBase,public CascadeStages
    111 {
    112     public:
    113         PoleFilter (int MaxPoles):CascadeStages((MaxPoles + 1) / 2)
    114         {
    115             this->MaxPoles=MaxPoles;
    116             m_analogStorage=new LayoutStorage(MaxPoles);
    117             m_digitalStorage=new LayoutStorage(MaxPoles);
    118             // This glues together the factored base classes
    119             // with the templatized storage classes.
    120             Iir::Butterworth::LowPassBase::setCascadeStorage (this->getCascadeStorage());
    121             Iir::Butterworth::LowPassBase::setPrototypeStorage (*m_analogStorage,*m_digitalStorage);
    122         }
    123         ~PoleFilter()
    124         {
    125             delete m_analogStorage;
    126             delete m_digitalStorage;
    127         }
    128         void setup (double sampleRate,double cutoffFrequency)
    129         {
    130             Iir::Butterworth::LowPassBase::setup (MaxPoles, sampleRate,cutoffFrequency);
    131         }
     92// de-templatized for pimpl idom
     93// comes from iir from Bernd Porr
     94class PoleFilter : Iir::Butterworth::LowPassBase, public CascadeStages {
     95public:
     96  PoleFilter(int MaxPoles) : CascadeStages((MaxPoles + 1) / 2) {
     97    this->MaxPoles = MaxPoles;
     98    m_analogStorage = new LayoutStorage(MaxPoles);
     99    m_digitalStorage = new LayoutStorage(MaxPoles);
     100    // This glues together the factored base classes
     101    // with the templatized storage classes.
     102    Iir::Butterworth::LowPassBase::setCascadeStorage(this->getCascadeStorage());
     103    Iir::Butterworth::LowPassBase::setPrototypeStorage(*m_analogStorage,
     104                                                       *m_digitalStorage);
     105  }
     106  ~PoleFilter() {
     107    delete m_analogStorage;
     108    delete m_digitalStorage;
     109  }
     110  void setup(double sampleRate, double cutoffFrequency) {
     111    Iir::Butterworth::LowPassBase::setup(MaxPoles, sampleRate, cutoffFrequency);
     112  }
    132113
    133     private:
    134         int MaxPoles;
    135         LayoutStorage* m_analogStorage;
    136         LayoutStorage* m_digitalStorage;
     114private:
     115  int MaxPoles;
     116  LayoutStorage *m_analogStorage;
     117  LayoutStorage *m_digitalStorage;
    137118};
    138119
     120class ButterworthLowPass_impl {
     121public:
     122  ButterworthLowPass_impl(flair::filter::ButterworthLowPass *self,
     123                          const flair::gui::LayoutPosition *position,
     124                          std::string name, int order);
     125  ~ButterworthLowPass_impl();
     126  void UpdateFrom(const flair::core::io_data *data);
     127  flair::core::cvmatrix *output;
    139128
    140 class ButterworthLowPass_impl
    141 {
    142     public:
    143         ButterworthLowPass_impl(flair::filter::ButterworthLowPass* self,const flair::gui::LayoutPosition* position,std::string name,int order);
    144         ~ButterworthLowPass_impl();
    145         void UpdateFrom(const flair::core::io_data *data);
    146         flair::core::cvmatrix *output;
    147 
    148     private:
    149         flair::gui::DoubleSpinBox *cutoff,*T;
    150         PoleFilter* f;
    151         bool first_update;
    152         flair::core::Time previous_time;
     129private:
     130  flair::gui::DoubleSpinBox *cutoff, *T;
     131  PoleFilter *f;
     132  bool first_update;
     133  flair::core::Time previous_time;
    153134};
    154135
Note: See TracChangeset for help on using the changeset viewer.