Nsound  0.9.4
Public Member Functions | Protected Attributes | List of all members
Nsound::FilterAllPass Class Reference

#include <Nsound/FilterAllPass.h>

Inheritance diagram for Nsound::FilterAllPass:
Inheritance graph
[legend]

Public Member Functions

 FilterAllPass (const float64 &sample_rate, const float64 &max_delay_time_seconds, const float64 &gain)
 
 FilterAllPass (const FilterAllPass &copy)
 
virtual ~FilterAllPass ()
 
AudioStream filter (const AudioStream &x)
 
AudioStream filter (const AudioStream &x, const float64 &delay_in_seconds)
 
AudioStream filter (const AudioStream &x, const Buffer &delay_in_seconds)
 
Buffer filter (const Buffer &x)
 
Buffer filter (const Buffer &x, const float64 &delay_in_seconds)
 
Buffer filter (const Buffer &x, const Buffer &delay_in_seconds)
 
float64 filter (const float64 &x)
 
float64 filter (const float64 &x, const float64 &delay_in_seconds)
 
FilterAllPassoperator= (const FilterAllPass &rhs)
 
void plot (boolean show_fc=true, boolean show_phase=false)
 
void reset ()
 
void setRealtime (bool flag)
 
Buffer getFrequencyAxis (const uint32 n_fft=8192)
 
Buffer getFrequencyResponse (const uint32 n_fft=8192)
 
Buffer getImpulseResponse (const uint32 n_samples=8192)
 
virtual uint32 getKernelSize () const
 
Buffer getPhaseResponse ()
 
float64 getSampleRate () const
 
void plot (boolean show_phase=false)
 

Protected Attributes

FilterDelayx_delay_
 
FilterDelayy_delay_
 
float64 gain_
 
float64 y_history_
 
float64 sample_rate_
 
float64 two_pi_over_sample_rate_
 
float64 sample_time_
 
uint32 kernel_size_
 
bool is_realtime_
 

Detailed Description

Definition at line 47 of file FilterAllPass.h.

Constructor & Destructor Documentation

FilterAllPass::FilterAllPass ( const float64 sample_rate,
const float64 max_delay_time_seconds,
const float64 gain 
)

Definition at line 48 of file FilterAllPass.cc.

References reset(), Nsound::Filter::sample_rate_, x_delay_, and y_delay_.

52  :
53  Filter(sample_rate),
54  x_delay_(NULL),
55  y_delay_(NULL),
56  gain_(gain),
57  y_history_(0.0)
58 {
59  x_delay_ = new FilterDelay(sample_rate_, max_delay_time_seconds);
60  y_delay_ = new FilterDelay(sample_rate_, max_delay_time_seconds);
61 
63 }
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
Filter(const float64 &sample_rate)
Definition: Filter.cc:41
A class for filtering audio in the frequecy domain.
Definition: FilterDelay.h:47
float64 sample_rate_
Definition: Filter.h:113
FilterAllPass::FilterAllPass ( const FilterAllPass copy)

Definition at line 67 of file FilterAllPass.cc.

References x_delay_, and y_delay_.

68  :
69  Filter(copy.sample_rate_),
70  x_delay_(NULL),
71  y_delay_(NULL),
72  gain_(copy.gain_),
73  y_history_(0.0)
74 {
75  x_delay_ = new FilterDelay(*copy.x_delay_);
76  y_delay_ = new FilterDelay(*copy.y_delay_);
77 
78  *this = copy;
79 }
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
Filter(const float64 &sample_rate)
Definition: Filter.cc:41
A class for filtering audio in the frequecy domain.
Definition: FilterDelay.h:47
float64 sample_rate_
Definition: Filter.h:113
FilterAllPass::~FilterAllPass ( )
virtual

Definition at line 83 of file FilterAllPass.cc.

References x_delay_, and y_delay_.

84 {
85  delete x_delay_;
86  delete y_delay_;
87 }
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96

Member Function Documentation

AudioStream FilterAllPass::filter ( const AudioStream x)

Definition at line 91 of file FilterAllPass.cc.

References Nsound::Filter::filter().

Referenced by Nsound::FilterPhaser::filter(), and Nsound::ReverberationRoom::filter().

92 {
93  return Filter::filter(x);
94 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
AudioStream FilterAllPass::filter ( const AudioStream x,
const float64 delay_in_seconds 
)

Definition at line 98 of file FilterAllPass.cc.

References Nsound::Filter::filter().

99 {
100  return Filter::filter(x, delay_in_seconds);
101 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
AudioStream FilterAllPass::filter ( const AudioStream x,
const Buffer delay_in_seconds 
)

Definition at line 105 of file FilterAllPass.cc.

References Nsound::Filter::filter().

106 {
107  return Filter::filter(x, delay_in_seconds);
108 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
Buffer FilterAllPass::filter ( const Buffer x)

Definition at line 112 of file FilterAllPass.cc.

References Nsound::Filter::filter().

113 {
114  return Filter::filter(x);
115 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
Buffer FilterAllPass::filter ( const Buffer x,
const float64 delay_in_seconds 
)

Definition at line 119 of file FilterAllPass.cc.

References Nsound::Filter::filter().

120 {
121  return Filter::filter(x, delay_in_seconds);
122 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
Buffer FilterAllPass::filter ( const Buffer x,
const Buffer delay_in_seconds 
)

Definition at line 126 of file FilterAllPass.cc.

References Nsound::Filter::filter().

127 {
128  return Filter::filter(x, delay_in_seconds);
129 }
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
float64 FilterAllPass::filter ( const float64 x)
virtual

Implements Nsound::Filter.

Definition at line 133 of file FilterAllPass.cc.

References Nsound::FilterDelay::filter(), gain_, x_delay_, y_delay_, and y_history_.

134 {
135  float64 y = gain_ * x + x_delay_->filter(x)
137 
138  y_history_ = y;
139 
140  return y;
141 }
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
Definition: FilterDelay.cc:98
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
float64 FilterAllPass::filter ( const float64 x,
const float64 delay_in_seconds 
)
virtual

Implements Nsound::Filter.

Definition at line 145 of file FilterAllPass.cc.

References Nsound::FilterDelay::filter(), gain_, x_delay_, y_delay_, and y_history_.

146 {
147  float64 y = gain_ * x + x_delay_->filter(x, delay)
148  - gain_ * y_delay_->filter(y_history_, delay);
149 
150  y_history_ = y;
151 
152  return y;
153 }
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
Definition: FilterDelay.cc:98
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
FilterAllPass & FilterAllPass::operator= ( const FilterAllPass rhs)

Definition at line 158 of file FilterAllPass.cc.

References gain_, x_delay_, y_delay_, and y_history_.

159 {
160  if(this == &rhs)
161  {
162  return *this;
163  }
164 
165  *x_delay_ = *rhs.x_delay_;
166  *y_delay_ = *rhs.y_delay_;
167 
168  gain_ = rhs.gain_;
169  y_history_ = rhs.y_history_;
170 
171  return *this;
172 }
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
void FilterAllPass::plot ( boolean  show_fc = true,
boolean  show_phase = false 
)

Definition at line 176 of file FilterAllPass.cc.

References Nsound::Filter::plot(), Nsound::Filter::sample_rate_, Nsound::Plotter::subplot(), and Nsound::Plotter::title().

177 {
178  char title[128];
179  sprintf(title,
180  "All Pass Frequency Response\n"
181  "sr = %0.1f Hz",
182  sample_rate_);
183 
184  Filter::plot(show_phase);
185 
186  Plotter pylab;
187 
188  uint32 n_rows = 1;
189  uint32 n_cols = 1;
190 
191  if(show_phase)
192  {
193  n_rows = 2;
194  }
195 
196  if(show_fc)
197  {
198  pylab.subplot(n_rows, n_cols, 1);
199 
200  pylab.title(title);
201  }
202 }
unsigned int uint32
Definition: Nsound.h:153
void title(const std::string &title, const std::string &kwargs="")
Add a title to the plot at the top and centered.
Definition: Plotter.cc:1127
Axes subplot(const uint32 n_rows, const uint32 n_cols, const uint32 n, const std::string &kwargs="", Axes *sharex=NULL, Axes *sharey=NULL)
Creates a figure in a subplot, subplot(A, B, C, **kwargs)
Definition: Plotter.cc:1031
void plot(boolean show_phase=false)
Definition: Filter.cc:262
float64 sample_rate_
Definition: Filter.h:113
void FilterAllPass::reset ( )
virtual

Implements Nsound::Filter.

Definition at line 206 of file FilterAllPass.cc.

References Nsound::FilterDelay::reset(), x_delay_, y_delay_, and y_history_.

Referenced by FilterAllPass(), Nsound::FilterPhaser::reset(), and Nsound::ReverberationRoom::reset().

207 {
208  x_delay_->reset();
209  y_delay_->reset();
210  y_history_ = 0.0;
211 }
FilterDelay * y_delay_
Definition: FilterAllPass.h:97
FilterDelay * x_delay_
Definition: FilterAllPass.h:96
void Nsound::Filter::setRealtime ( bool  flag)
inlineinherited

Definition at line 57 of file Filter.h.

References Nsound::Filter::is_realtime_.

57 {is_realtime_ = flag;}
bool is_realtime_
Definition: Filter.h:118
Buffer Filter::getFrequencyAxis ( const uint32  n_fft = 8192)
inherited

Definition at line 185 of file Filter.cc.

References Nsound::FFTransform::roundUp2(), and Nsound::Filter::sample_rate_.

Referenced by main(), Nsound::Filter::plot(), and Nsound::FilterIIR::savePlot().

186 {
187  uint32 fft_chunk_size = FFTransform::roundUp2(
188  static_cast<int32>(n_fft));
189 
190  uint32 n_samples = fft_chunk_size / 2 + 1;
191 
192  float64 f_step = (1.0 / (static_cast<float64>(fft_chunk_size) / 2.0))
193  * (sample_rate_ / 2.0);
194 
195  Buffer f_axis;
196 
197  float64 f = 0.0;
198 
199  for(uint32 i = 0; i < n_samples; ++i)
200  {
201  f_axis << f;
202  f += f_step;
203  }
204 
205  return f_axis;
206 };
unsigned int uint32
Definition: Nsound.h:153
double float64
Definition: Nsound.h:146
static int32 roundUp2(int32 raw)
Returns nearest power of 2 >= raw.
Definition: FFTransform.cc:274
A Buffer for storing audio samples.
Definition: Buffer.h:60
float64 sample_rate_
Definition: Filter.h:113
Buffer Filter::getFrequencyResponse ( const uint32  n_fft = 8192)
inherited

Definition at line 210 of file Filter.cc.

References Nsound::FFTransform::fft(), Nsound::Filter::getImpulseResponse(), and Nsound::Filter::sample_rate_.

Referenced by Nsound::FilterBandPassIIR::FilterBandPassIIR(), FilterLeastSquaresFIR_UnitTest(), Nsound::FilterIIR::getRMS(), main(), Nsound::Filter::plot(), and Nsound::FilterIIR::savePlot().

211 {
213 
214 //~ fft.setWindow(HANNING);
215 
216  FFTChunkVector vec;
217 
218  vec = fft.fft(getImpulseResponse(), n_fft);
219 
220  return vec[0].getMagnitude();
221 }
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: Filter.cc:225
A Class that performes the Fast Fouier Transfrom on a Buffer.
Definition: FFTransform.h:57
std::vector< FFTChunk > FFTChunkVector
Definition: FFTChunk.h:119
float64 sample_rate_
Definition: Filter.h:113
Buffer Filter::getImpulseResponse ( const uint32  n_samples = 8192)
inherited

Definition at line 225 of file Filter.cc.

References Nsound::Filter::filter(), Nsound::Filter::is_realtime_, and Nsound::Filter::reset().

Referenced by Nsound::Filter::getFrequencyResponse(), Nsound::FilterHighPassFIR::getImpulseResponse(), Nsound::FilterLowPassFIR::getImpulseResponse(), Nsound::FilterLeastSquaresFIR::getImpulseResponse(), Nsound::FilterIIR::getImpulseResponse(), and Nsound::Filter::getPhaseResponse().

226 {
227  if(!is_realtime_) reset();
228 
229  Buffer response(n_samples);
230 
231  response << filter(1.0);
232 
233  for(uint32 i = 1; i < n_samples; ++i)
234  {
235  response << filter(0.0);
236  }
237 
238  if(!is_realtime_) reset();
239 
240  return response;
241 }
unsigned int uint32
Definition: Nsound.h:153
virtual void reset()=0
AudioStream filter(const AudioStream &x)
Definition: Filter.cc:53
bool is_realtime_
Definition: Filter.h:118
A Buffer for storing audio samples.
Definition: Buffer.h:60
virtual uint32 Nsound::Filter::getKernelSize ( ) const
inlinevirtualinherited
Buffer Filter::getPhaseResponse ( )
inherited

Definition at line 245 of file Filter.cc.

References Nsound::FFTransform::fft(), Nsound::Filter::getImpulseResponse(), Nsound::Buffer::getLength(), Nsound::Filter::sample_rate_, and Nsound::Buffer::subbuffer().

Referenced by Nsound::Filter::plot().

246 {
247  uint32 n_samples = static_cast<uint32>(sample_rate_ * 2);
248 
249  FFTransform fft(n_samples);
250 
251  FFTChunkVector vec;
252 
253  vec = fft.fft(getImpulseResponse(), n_samples);
254 
255  Buffer phase = vec[0].getPhase();
256 
257  return phase.subbuffer(0, phase.getLength() / 2 + 1);
258 }
Buffer subbuffer(uint32 start_index, uint32 n_samples=0) const
Slice the Buffer.
Definition: Buffer.cc:2073
unsigned int uint32
Definition: Nsound.h:153
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
Buffer getImpulseResponse(const uint32 n_samples=8192)
Definition: Filter.cc:225
A Class that performes the Fast Fouier Transfrom on a Buffer.
Definition: FFTransform.h:57
A Buffer for storing audio samples.
Definition: Buffer.h:60
std::vector< FFTChunk > FFTChunkVector
Definition: FFTChunk.h:119
float64 sample_rate_
Definition: Filter.h:113
float64 Nsound::Filter::getSampleRate ( ) const
inlineinherited

Definition at line 102 of file Filter.h.

References Nsound::Filter::sample_rate_.

102 { return sample_rate_; };
float64 sample_rate_
Definition: Filter.h:113
void Filter::plot ( boolean  show_phase = false)
inherited

Definition at line 262 of file Filter.cc.

References Nsound::Plotter::figure(), Nsound::Buffer::getdB(), Nsound::Filter::getFrequencyAxis(), Nsound::Filter::getFrequencyResponse(), Nsound::Buffer::getMax(), Nsound::Filter::getPhaseResponse(), Nsound::Plotter::plot(), Nsound::Plotter::subplot(), Nsound::Plotter::xlabel(), Nsound::Plotter::ylabel(), and Nsound::Plotter::ylim().

Referenced by main(), Nsound::FilterLowPassMoogVcf::plot(), Nsound::FilterPhaser::plot(), Nsound::FilterTone::plot(), Nsound::FilterHighPassIIR::plot(), Nsound::FilterCombLowPassFeedback::plot(), Nsound::FilterLowPassIIR::plot(), Nsound::FilterLowPassFIR::plot(), Nsound::FilterHighPassFIR::plot(), plot(), Nsound::FilterBandPassVocoder::plot(), Nsound::FilterBandPassFIR::plot(), Nsound::FilterLeastSquaresFIR::plot(), Nsound::FilterFlanger::plot(), Nsound::FilterBandRejectFIR::plot(), Nsound::FilterBandRejectIIR::plot(), Nsound::FilterBandPassIIR::plot(), and Nsound::FilterParametricEqualizer::plot().

263 {
264  Buffer x = getFrequencyAxis();
266 
267  Plotter pylab;
268 
269  pylab.figure();
270 
271  uint32 n_rows = 1;
272  uint32 n_cols = 1;
273 
274  if(show_phase)
275  {
276  n_rows = 2;
277  }
278 
279  pylab.subplot(n_rows, n_cols, 1);
280 
281  // Frequency response
282  pylab.plot(x,fr, "blue");
283 
284  pylab.xlabel("Frequency (Hz)");
285  pylab.ylabel("Frequency Response (dB)");
286 
287  // Phase response
288  if(show_phase)
289  {
290  pylab.subplot(n_rows, n_cols, 2);
291 
292  Buffer pr = getPhaseResponse().getdB();
293 
294  pylab.plot(x,pr);
295 
296  pylab.xlabel("Frequency (Hz)");
297  pylab.ylabel("Phase Response (dB)");
298  }
299 
300  float64 ymax = fr.getMax();
301  float64 height = ymax - -60.0;
302 
303  pylab.ylim(-60.0, ymax + 0.05 * height);
304 }
unsigned int uint32
Definition: Nsound.h:153
void xlabel(const std::string &label, const std::string &kwargs="")
Add a label x axis.
Definition: Plotter.cc:1154
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
Definition: Plotter.cc:765
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
Definition: Plotter.cc:455
Buffer getPhaseResponse()
Definition: Filter.cc:245
double float64
Definition: Nsound.h:146
Axes subplot(const uint32 n_rows, const uint32 n_cols, const uint32 n, const std::string &kwargs="", Axes *sharex=NULL, Axes *sharey=NULL)
Creates a figure in a subplot, subplot(A, B, C, **kwargs)
Definition: Plotter.cc:1031
void ylim(const float64 &ymin, const float64 &ymax)
Definition: Plotter.cc:422
Buffer getFrequencyAxis(const uint32 n_fft=8192)
Definition: Filter.cc:185
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
Definition: Plotter.cc:1180
A Buffer for storing audio samples.
Definition: Buffer.h:60
Buffer getFrequencyResponse(const uint32 n_fft=8192)
Definition: Filter.cc:210
float64 getMax() const
Returns the maximum sample value in the Buffer.
Definition: Buffer.cc:951
Buffer getdB() const
Returns the Buffer in dB.
Definition: Buffer.h:487

Member Data Documentation

FilterDelay* Nsound::FilterAllPass::x_delay_
protected

Definition at line 96 of file FilterAllPass.h.

Referenced by filter(), FilterAllPass(), operator=(), reset(), and ~FilterAllPass().

FilterDelay* Nsound::FilterAllPass::y_delay_
protected

Definition at line 97 of file FilterAllPass.h.

Referenced by filter(), FilterAllPass(), operator=(), reset(), and ~FilterAllPass().

float64 Nsound::FilterAllPass::gain_
protected

Definition at line 99 of file FilterAllPass.h.

Referenced by filter(), and operator=().

float64 Nsound::FilterAllPass::y_history_
protected

Definition at line 101 of file FilterAllPass.h.

Referenced by filter(), operator=(), and reset().

float64 Nsound::Filter::sample_rate_
protectedinherited

Definition at line 113 of file Filter.h.

Referenced by Nsound::FilterPhaser::filter(), Nsound::FilterCombLowPassFeedback::filter(), Nsound::FilterDelay::filter(), FilterAllPass(), Nsound::FilterCombLowPassFeedback::FilterCombLowPassFeedback(), Nsound::FilterDelay::FilterDelay(), Nsound::FilterFlanger::FilterFlanger(), Nsound::FilterPhaser::FilterPhaser(), Nsound::FilterSlinky::FilterSlinky(), Nsound::Filter::getFrequencyAxis(), Nsound::Filter::getFrequencyResponse(), Nsound::Filter::getPhaseResponse(), Nsound::Filter::getSampleRate(), Nsound::FilterStageIIR::makeIIRKernelHelper(), Nsound::FilterHighPassFIR::makeKernel(), Nsound::FilterStageIIR::makeKernel(), Nsound::FilterBandPassVocoder::makeKernel(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::FilterParametricEqualizer::makeKernel(), Nsound::FilterPhaser::operator=(), Nsound::FilterLeastSquaresFIR::operator=(), Nsound::FilterFlanger::operator=(), Nsound::FilterIIR::operator=(), Nsound::FilterLowPassMoogVcf::plot(), Nsound::FilterPhaser::plot(), Nsound::FilterTone::plot(), Nsound::FilterHighPassIIR::plot(), Nsound::FilterCombLowPassFeedback::plot(), Nsound::FilterLowPassIIR::plot(), Nsound::FilterLowPassFIR::plot(), plot(), Nsound::FilterHighPassFIR::plot(), Nsound::FilterBandPassFIR::plot(), Nsound::FilterLeastSquaresFIR::plot(), Nsound::FilterFlanger::plot(), Nsound::FilterBandRejectFIR::plot(), Nsound::FilterBandPassIIR::plot(), Nsound::FilterBandRejectIIR::plot(), Nsound::FilterParametricEqualizer::plot(), Nsound::FilterLowPassIIR::setCutoff(), and Nsound::FilterLeastSquaresFIR::setWindow().

float64 Nsound::Filter::two_pi_over_sample_rate_
protectedinherited
float64 Nsound::Filter::sample_time_
protectedinherited

Definition at line 115 of file Filter.h.

Referenced by Nsound::FilterLowPassMoogVcf::_make_filter().

uint32 Nsound::Filter::kernel_size_
protectedinherited
bool Nsound::Filter::is_realtime_
protectedinherited

The documentation for this class was generated from the following files: