Nsound  0.9.4
Filter.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Filter.h 911 2015-07-10 03:04:24Z 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) 2007 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 
34 #ifndef _NSOUND_FILTER_H_
35 #define _NSOUND_FILTER_H_
36 
37 #include <Nsound/Nsound.h>
38 
39 #include <string>
40 
41 namespace Nsound
42 {
43 
44 class AudioStream;
45 class Buffer;
46 
47 //-----------------------------------------------------------------------------
49 class Filter
50 {
51  public:
52 
53  Filter(const float64 & sample_rate);
54 
55  virtual ~Filter() {};
56 
57  void setRealtime(bool flag) {is_realtime_ = flag;}
58 
60  filter(const AudioStream & x);
61 
63  filter(const AudioStream & x, const float64 & frequency);
64 
66  filter(const AudioStream & x, const Buffer & frequencies);
67 
68  Buffer
69  filter(const Buffer & x);
70 
71  Buffer
72  filter(const Buffer & x, const float64 & frequency);
73 
74  Buffer
75  filter(const Buffer & x, const Buffer & frequencies);
76 
77  virtual
78  float64
79  filter(const float64 & x) = 0;
80 
81  virtual
82  float64
83  filter(const float64 & x, const float64 & frequency) = 0;
84 
85  Buffer
86  getFrequencyAxis(const uint32 n_fft = 8192);
87 
88  Buffer
89  getFrequencyResponse(const uint32 n_fft = 8192);
90 
91  Buffer
92  getImpulseResponse(const uint32 n_samples = 8192);
93 
94  virtual
95  uint32
96  getKernelSize() const {return kernel_size_;};
97 
98  Buffer
100 
101  float64
102  getSampleRate() const { return sample_rate_; };
103 
104  void
105  plot(boolean show_phase = false);
106 
107  virtual
108  void
109  reset() = 0;
110 
111  protected:
112 
115  float64 sample_time_; // 1.0 / sample_rate_
117 
119 
120 }; // class Filter
121 
122 } // namespace
123 
124 // :mode=c++: jEdit modeline
125 #endif
float64 getSampleRate() const
Definition: Filter.h:102
float64 sample_time_
Definition: Filter.h:115
unsigned int uint32
Definition: Nsound.h:153
void setRealtime(bool flag)
Definition: Filter.h:57
Buffer getPhaseResponse()
Definition: Filter.cc:245
double float64
Definition: Nsound.h:146
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: Filter.cc:225
virtual void reset()=0
Base class for IIR Filters, defines the interface.
Definition: Filter.h:49
Buffer getFrequencyAxis(const uint32 n_fft=8192)
Definition: Filter.cc:185
uint32 kernel_size_
Definition: Filter.h:116
void plot(boolean show_phase=false)
Definition: Filter.cc:262
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
bool is_realtime_
Definition: Filter.h:118
virtual ~Filter()
Definition: Filter.h:55
Filter(const float64 &sample_rate)
Definition: Filter.cc:41
virtual uint32 getKernelSize() const
Definition: Filter.h:96
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer getFrequencyResponse(const uint32 n_fft=8192)
Definition: Filter.cc:210
float64 two_pi_over_sample_rate_
Definition: Filter.h:114
float64 sample_rate_
Definition: Filter.h:113