Jamoma API  0.6.0.a19
Filter.h
1 // Filter.h
2 /***************************************************/
3 /*! \class Filter
4  \brief Filter class
5 
6  A High Mid Low shelf filter. Shelf centre frequencies are immutable.
7 
8  Based on:
9  Biquad.h by Gary Scavone and Perry Cook, and
10  hml_shelf~.c by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006
11 
12  by Tristan Matthews and Nils Peters, 2007-2008.
13  */
14 /***************************************************/
15 
16 #ifndef _FILTER_H_
17 #define _FILTER_H_
18 
19 #include "Properties.h"
20 #include "TTDSP.h"
21 
22 class Filter {
23  private:
24  const static int ORDER_PLUS_ONE = 3;
25  double in_[ORDER_PLUS_ONE];
26  double out_;
27 
28  protected:
29  //! Pi divided by the sample rate.
30  double sr_;
31  //! Filter coefficient.
32  double b1_;
33  //! Filter coefficient.
34  double b2_;
35  //! Filter coefficient.
36  double a0_;
37  //! Filter coefficient.
38  double a1_;
39  //! Filter coefficient.
40  double a2_;
41  //! Convert percentage to linear gain.
42  double percentToGain(double gainPercentage);
43  //! Max gain value.
44  const static double MAX_;
45  //! Min gain value.
46  const static double MIN_;
47 
48  public:
49  //! Class constructor.
50  Filter();
51 
52  //! Given an input sample, returns a filtered output sample.
53  double tick(double input);
54 
55  //! Prints information about the given filter.
56  virtual void print() const = 0;
57 
58  //! Reinitialize filter's memory.
59  void clear();
60 
61  //! Virtual destructor.
62  virtual ~Filter() {};
63 };
64 
65 inline double Filter::tick(double input)
66 {
67 #ifndef __INTEL_COMPILER
68  if (IEM_NAN(input)) // NAN protect
69  input = 0.0;
70 #endif
71 
72  in_[0] = input + b1_ * in_[1] + b2_ * in_[2];
73  out_ = a0_ * in_[0] + a1_ * in_[1] + a2_ * in_[2];
74  in_[2] = in_[1];
75  in_[1] = in_[0];
76 
77  // NAN and denormal protect
78 #ifndef __INTEL_COMPILER
79  TTZeroDenormal(in_[2]);
80  TTZeroDenormal(in_[1]);
81  if (IEM_NAN(in_[2]))
82  in_[2] = 0.0;
83  if (IEM_NAN(in_[1]))
84  in_[1] = 0.0;
85 #endif
86 
87  /*if (IEM_DENORMAL(in_[0]) || IEM_NAN(in_[0]))
88  in_[0] = 0.0f;
89  if (IEM_DENORMAL(out_) || IEM_NAN(out_))
90  out_ = 0.0f; */
91 
92  return out_;
93 }
94 
95 #endif
96 // vim:sw=4:et:cindent:
static const double MAX_
Max gain value.
Definition: Filter.h:44
double a2_
Filter coefficient.
Definition: Filter.h:40
double sr_
Pi divided by the sample rate.
Definition: Filter.h:30
Filter class.
Definition: Filter.h:22
Jamoma DSP Library.
double tick(double input)
Given an input sample, returns a filtered output sample.
Definition: Filter.h:65
virtual void print() const =0
Prints information about the given filter.
Filter()
Class constructor.
Definition: Filter.cpp:26
double percentToGain(double gainPercentage)
Convert percentage to linear gain.
Definition: Filter.cpp:40
static const double MIN_
Min gain value.
Definition: Filter.h:46
virtual ~Filter()
Virtual destructor.
Definition: Filter.h:62
void clear()
Reinitialize filter's memory.
Definition: Filter.cpp:32
double b1_
Filter coefficient.
Definition: Filter.h:32
double b2_
Filter coefficient.
Definition: Filter.h:34
double a1_
Filter coefficient.
Definition: Filter.h:38
double a0_
Filter coefficient.
Definition: Filter.h:36