Nsound  0.9.4
FilterIIR.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FilterIIR.h 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2009 to Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_FILTER_IIR_H_
34 #define _NSOUND_FILTER_IIR_H_
35 
36 #include <Nsound/Filter.h>
37 
38 #include <set>
39 
40 namespace Nsound
41 {
42 
43 // Forward class declarations
44 class AudioStream;
45 class Buffer;
46 class Kernel;
47 class RngTausworthe;
48 
49 //-----------------------------------------------------------------------------
52 class FilterIIR : public Filter
53 {
54  public:
55 
56  FilterIIR(
57  const float64 & sample_rate,
58  uint32 n_poles);
59 
60  FilterIIR(const FilterIIR & copy);
61 
62  virtual ~FilterIIR();
63 
65  //
70  Buffer
72  const Buffer & frequency_response,
73  const float64 & max_error = 0.01,
74  const int32 max_iterations = 1000);
75 
77  //
82  Buffer
84  const Buffer & impulse_response,
85  const float64 & max_error = 0.01,
86  const int32 max_iterations = 1000);
87 
89  filter(const AudioStream & x)
90  { return Filter::filter(x);};
91 
93  filter(const AudioStream & x, const Buffer & frequencies)
94  { return Filter::filter(x);};
95 
96  Buffer
97  filter(const Buffer & x)
98  {return Filter::filter(x);};
99 
100  Buffer
101  filter(const Buffer & x, const Buffer & frequencies)
102  {return filter(x);};
103 
104  float64
105  filter(const float64 & x);
106 
107  float64
108  filter(const float64 & x, const float64 & frequency);
109 
110  uint32
111  getKernelSize() const {return n_poles_;};
112 
113  Buffer
114  getImpulseResponse(const uint32 n_samples = 8192)
115  { reset(); return Filter::getImpulseResponse(n_samples); };
116 
117  FilterIIR &
118  operator=(const FilterIIR & rhs);
119 
120  #ifndef SWIG
121  friend
123  std::ostream &
124  operator<<(std::ostream & out,const FilterIIR & rhs);
125  #endif
126 
127  void
128  reset();
129 
130  protected:
131 
133  {
136  };
137 
139  //
144  Buffer
145  designKernel(
146  const Buffer & response,
147  const float64 & max_rms_error,
148  const int32 max_iterations,
149  const SignalType type);
150 
151  float64
152  getRMS(
153  const Kernel & kernel,
154  const Buffer & response,
155  const SignalType type);
156 
157  void
158  savePlot(
159  const Kernel & k,
160  const Buffer & response,
161  uint32 n,
162  const float64 & error);
163 
165 
167 
171 
175 
177 
178 };
179 
180 std::ostream &
181 operator<<(std::ostream & out,const FilterIIR & rhs);
182 
183 };
184 
185 // :mode=c++: jEdit modeline
186 
187 #endif
unsigned int uint32
Definition: Nsound.h:153
std::ostream & operator<<(std::ostream &out, const Buffer &rhs_buffer)
Definition: Buffer.cc:1338
Buffer filter(const Buffer &x)
Definition: FilterIIR.h:97
virtual ~FilterIIR()
Definition: FilterIIR.cc:116
friend std::ostream & operator<<(std::ostream &out, const FilterIIR &rhs)
Prints the coeffents.
float64 * x_ptr_
Definition: FilterIIR.h:169
Buffer filter(const Buffer &x, const Buffer &frequencies)
Definition: FilterIIR.h:101
float64 * x_history_
Definition: FilterIIR.h:168
FilterIIR & operator=(const FilterIIR &rhs)
Definition: FilterIIR.cc:683
AudioStream filter(const AudioStream &x)
Definition: FilterIIR.h:89
double float64
Definition: Nsound.h:146
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: Filter.cc:225
Buffer designFrequencyResponse(const Buffer &frequency_response, const float64 &max_error=0.01, const int32 max_iterations=1000)
Designs a filter kernel using a genetic algorithm that trys to match the provided frequency response...
Definition: FilterIIR.cc:127
float64 getRMS(const Kernel &kernel, const Buffer &response, const SignalType type)
Definition: FilterIIR.cc:211
float64 * y_history_
Definition: FilterIIR.h:172
Base class for IIR Filters, defines the interface.
Definition: Filter.h:49
Kernel * kernel_
Definition: FilterIIR.h:166
RngTausworthe * rng_
Definition: FilterIIR.h:176
float64 * x_end_ptr_
Definition: FilterIIR.h:170
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: FilterIIR.h:114
AudioStream filter(const AudioStream &x, const Buffer &frequencies)
Definition: FilterIIR.h:93
void savePlot(const Kernel &k, const Buffer &response, uint32 n, const float64 &error)
Definition: FilterIIR.cc:735
A Buffer for storing audio samples.
Definition: Buffer.h:60
float64 * y_end_ptr_
Definition: FilterIIR.h:174
Buffer designImpulseResponse(const Buffer &impulse_response, const float64 &max_error=0.01, const int32 max_iterations=1000)
Designs a filter kernel using a genetic algorithm that trys to match the provided impulse response...
Definition: FilterIIR.cc:141
signed int int32
Definition: Nsound.h:142
FilterIIR(const float64 &sample_rate, uint32 n_poles)
Definition: FilterIIR.cc:59
uint32 getKernelSize() const
Definition: FilterIIR.h:111
Buffer designKernel(const Buffer &response, const float64 &max_rms_error, const int32 max_iterations, const SignalType type)
Designs a filter kernel that trys to match the provide frequency response.
Definition: FilterIIR.cc:249
float64 * y_ptr_
Definition: FilterIIR.h:173