OpenWareLaboratory
SmoothingFilter.h
Go to the documentation of this file.
1 #ifndef __SmoothingFilter_h__
2 #define __SmoothingFilter_h__
3 
4 #include "FloatArray.h"
5 #include "SignalProcessor.h"
6 
11 private:
12  const float lambda;
13  float y;
14 public:
15  SmoothingFilter(float lambda = 0.995): lambda(lambda), y(0) {}
16 
17  /* process a single sample and return the result */
18  float process(float x){
19  y = y*lambda + x*(1.0f - lambda);
20  return y;
21  }
22 
23  void process(float* input, float* output, size_t size){
24  float x;
25  while(size--){
26  x = *input++;
27  y = y*lambda + x*(1.0f - lambda);
28  *output++ = y;
29  }
30  }
31 
32  /* perform in-place processing */
33  void process(float* buf, int size){
34  process(buf, buf, size);
35  }
36 
37  void process(FloatArray in){
38  process(in, in, in.getSize());
39  }
40 
41  void process(FloatArray in, FloatArray out){
42  ASSERT(out.getSize() >= in.getSize(), "output array must be at least as long as input");
43  process(in, out, in.getSize());
44  }
45 
46  static SmoothingFilter* create(float lambda){
47  return new SmoothingFilter(lambda);
48  }
49 
50  static void destroy(SmoothingFilter* obj){
51  delete obj;
52  }
53 };
54 
56 private:
57  SmoothingFilter left, right;
58 public:
59  StereoSmoothingFilter(float lambda = 0.995): left(lambda), right(lambda) {}
60  void process(AudioBuffer& input, AudioBuffer& output){
63  }
64 
65  static StereoSmoothingFilter* create(float lambda){
66  return new StereoSmoothingFilter(lambda);
67  }
68 
69  static void destroy(StereoSmoothingFilter* obj){
70  delete obj;
71  }
72 };
73 
74 #endif // __SmoothingFilter_h__
@ RIGHT_CHANNEL
Definition: Patch.h:18
@ LEFT_CHANNEL
Definition: Patch.h:17
virtual FloatArray getSamples(int channel)=0
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
Base class for signal processors such as Filters.
size_t getSize() const
Definition: SimpleArray.h:31
AC Blocking IIR filter, the Leaky Integrator.
void process(FloatArray in)
float process(float x)
void process(float *input, float *output, size_t size)
SmoothingFilter(float lambda=0.995)
static void destroy(SmoothingFilter *obj)
void process(float *buf, int size)
static SmoothingFilter * create(float lambda)
void process(FloatArray in, FloatArray out)
static void destroy(StereoSmoothingFilter *obj)
static StereoSmoothingFilter * create(float lambda)
void process(AudioBuffer &input, AudioBuffer &output)
StereoSmoothingFilter(float lambda=0.995)
#define ASSERT(cond, msg)
Definition: message.h:16