#include <Nsound/FilterMovingAverage.h>

Definition at line 47 of file FilterMovingAverage.h.
| FilterMovingAverage::FilterMovingAverage | ( | uint32 | n_samples_to_average | ) |
Definition at line 38 of file FilterMovingAverage.cc.
References delay_, n_samples_to_average_, and reset().
00040 : 00041 Filter(1.0), 00042 n_samples_to_average_(n_samples_to_average), 00043 running_sum_(0.0), 00044 delay_(NULL) 00045 { 00046 delay_ = new FilterDelay(1.0, n_samples_to_average_); 00047 00048 reset(); }
| FilterMovingAverage::FilterMovingAverage | ( | const FilterMovingAverage & | copy | ) |
Definition at line 52 of file FilterMovingAverage.cc.
00054 : 00055 Filter(1.0), 00056 n_samples_to_average_(copy.n_samples_to_average_), 00057 running_sum_(copy.running_sum_), 00058 delay_(new FilterDelay(*copy.delay_)) 00059 { }
| FilterMovingAverage::~FilterMovingAverage | ( | ) |
Definition at line 63 of file FilterMovingAverage.cc.
References delay_.
00064 { 00065 delete delay_; 00066 }
| AudioStream FilterMovingAverage::filter | ( | const AudioStream & | x | ) |
Reimplemented from Nsound::Filter.
Definition at line 71 of file FilterMovingAverage.cc.
References reset().
Referenced by filter(), main(), and Nsound::Buffer::smooth().
00072 { 00073 FilterMovingAverage::reset(); 00074 return Filter::filter(x); 00075 }
| AudioStream Nsound::FilterMovingAverage::filter | ( | const AudioStream & | x, | |
| const Buffer & | frequencies | |||
| ) | [inline] |
Reimplemented from Nsound::Filter.
Definition at line 67 of file FilterMovingAverage.h.
References filter().
Referenced by filter().
00068 { return filter(x); };
Reimplemented from Nsound::Filter.
Definition at line 80 of file FilterMovingAverage.cc.
References filter(), and reset().
00081 { 00082 FilterMovingAverage::reset(); 00083 return Filter::filter(x); 00084 }
| Buffer Nsound::FilterMovingAverage::filter | ( | const Buffer & | x, | |
| const Buffer & | frequencies | |||
| ) | [inline] |
Reimplemented from Nsound::Filter.
Definition at line 76 of file FilterMovingAverage.h.
References filter().
Referenced by filter().
00077 { return filter(x); };
Implements Nsound::Filter.
Definition at line 89 of file FilterMovingAverage.cc.
References delay_, Nsound::FilterDelay::filter(), n_samples_to_average_, and running_sum_.
00090 { 00091 float64 last_nth_x = delay_->filter(x); 00092 00093 running_sum_ += x - last_nth_x; 00094 00095 return running_sum_ / n_samples_to_average_; 00096 }
| float64 Nsound::FilterMovingAverage::filter | ( | const float64 & | x, | |
| const float64 & | frequency | |||
| ) | [inline, virtual] |
Implements Nsound::Filter.
Definition at line 85 of file FilterMovingAverage.h.
References filter().
Referenced by filter().
00086 { return filter(x); };
| FilterMovingAverage & FilterMovingAverage::operator= | ( | const FilterMovingAverage & | rhs | ) |
Definition at line 101 of file FilterMovingAverage.cc.
References delay_, n_samples_to_average_, and running_sum_.
00102 { 00103 if(this == & rhs) 00104 { 00105 return *this; 00106 } 00107 00108 n_samples_to_average_ = rhs.n_samples_to_average_; 00109 running_sum_ = rhs.running_sum_; 00110 00111 *delay_ = *rhs.delay_; 00112 00113 return *this; 00114 }
| void FilterMovingAverage::reset | ( | ) | [virtual] |
Implements Nsound::Filter.
Definition at line 119 of file FilterMovingAverage.cc.
References delay_, Nsound::FilterDelay::reset(), and running_sum_.
Referenced by filter(), and FilterMovingAverage().
00120 { 00121 running_sum_ = 0.0; 00122 delay_->reset(); 00123 }
| AudioStream Filter::filter | ( | const AudioStream & | x, | |
| const float64 & | frequency | |||
| ) | [inherited] |
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassIIR, Nsound::FilterBandRejectIIR, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, and Nsound::FilterStageIIR.
Definition at line 72 of file Filter.cc.
References Nsound::Filter::filter(), Nsound::AudioStream::getNChannels(), Nsound::AudioStream::getSampleRate(), and Nsound::Filter::reset().
00073 { 00074 reset(); 00075 00076 uint32 n_channels = x.getNChannels(); 00077 00078 AudioStream y(x.getSampleRate(), n_channels); 00079 00080 for(uint32 channel = 0; channel < n_channels; ++channel) 00081 { 00082 y[channel] = filter(x[channel], frequency); 00083 } 00084 00085 return y; 00086 }
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassIIR, Nsound::FilterBandRejectIIR, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, and Nsound::FilterStageIIR.
Definition at line 129 of file Filter.cc.
References Nsound::Buffer::begin(), Nsound::Buffer::end(), Nsound::Filter::filter(), Nsound::Buffer::getLength(), and Nsound::Filter::reset().
00130 { 00131 reset(); 00132 00133 Buffer::const_iterator itor = x.begin(); 00134 Buffer::const_iterator end = x.end(); 00135 00136 Buffer y(x.getLength()); 00137 00138 while(itor != end) 00139 { 00140 y << filter(*itor, frequency); 00141 00142 ++itor; 00143 } 00144 00145 return y; 00146 }
Definition at line 176 of file Filter.cc.
References Nsound::FFTransform::roundUp2(), and Nsound::Filter::sample_rate_.
Referenced by main(), Nsound::Filter::plot(), and Nsound::FilterIIR::savePlot().
00177 { 00178 uint32 fft_chunk_size = FFTransform::roundUp2( 00179 static_cast<int32>(n_fft)); 00180 00181 uint32 n_samples = fft_chunk_size / 2 + 1; 00182 00183 float64 f_step = (1.0 / (static_cast<float64>(fft_chunk_size) / 2.0)) 00184 * (sample_rate_ / 2.0); 00185 00186 Buffer f_axis; 00187 00188 float64 f = 0.0; 00189 00190 for(uint32 i = 0; i < n_samples; ++i) 00191 { 00192 f_axis << f; 00193 f += f_step; 00194 } 00195 00196 return f_axis; 00197 };
Definition at line 202 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().
00203 { 00204 FFTransform fft(sample_rate_); 00205 00206 //~ fft.setWindow(HANNING); 00207 00208 FFTChunkVector vec; 00209 00210 vec = fft.fft(getImpulseResponse(), n_fft); 00211 00212 return vec[0].getMagnitude(); 00213 }
Reimplemented in Nsound::FilterIIR.
Definition at line 218 of file Filter.cc.
References Nsound::Filter::filter(), and Nsound::Filter::reset().
Referenced by Nsound::Filter::getFrequencyResponse(), and Nsound::Filter::getPhaseResponse().
| virtual uint32 Nsound::Filter::getKernelSize | ( | ) | const [inline, virtual, inherited] |
Reimplemented in Nsound::FilterIIR, and Nsound::FilterTone.
Definition at line 109 of file Filter.h.
References Nsound::Filter::kernel_size_.
Referenced by Nsound::FilterBandPassIIR::FilterBandPassIIR(), Nsound::FilterBandRejectIIR::plot(), Nsound::FilterBandPassIIR::plot(), and Nsound::FilterBandPassFIR::plot().
00109 {return kernel_size_;};
| Buffer Filter::getPhaseResponse | ( | ) | [inherited] |
Definition at line 239 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().
00240 { 00241 uint32 n_samples = static_cast<uint32>(sample_rate_ * 2); 00242 00243 FFTransform fft(n_samples); 00244 00245 FFTChunkVector vec; 00246 00247 vec = fft.fft(getImpulseResponse(), n_samples); 00248 00249 Buffer phase = vec[0].getPhase(); 00250 00251 return phase.subbuffer(0, phase.getLength() / 2 + 1); 00252 }
| float64 Nsound::Filter::getSampleRate | ( | ) | const [inline, inherited] |
Definition at line 117 of file Filter.h.
References Nsound::Filter::sample_rate_.
00117 { return sample_rate_; };
| void Filter::plot | ( | boolean | show_phase = false |
) | [inherited] |
Definition at line 257 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().
00258 { 00259 Buffer x = getFrequencyAxis(); 00260 Buffer fr = getFrequencyResponse().getdB(); 00261 00262 Plotter pylab; 00263 00264 pylab.figure(); 00265 00266 int subplot_int = 111; 00267 00268 if(show_phase) 00269 { 00270 subplot_int = 211; 00271 } 00272 00273 pylab.subplot(subplot_int); 00274 00275 // Frequency response 00276 pylab.plot(x,fr, "blue"); 00277 00278 pylab.xlabel("Frequency (Hz)"); 00279 pylab.ylabel("Frequency Response (dB)"); 00280 00281 // Phase response 00282 if(show_phase) 00283 { 00284 pylab.subplot(subplot_int + 1); 00285 00286 Buffer pr = getPhaseResponse().getdB(); 00287 00288 pylab.plot(x,pr); 00289 00290 pylab.xlabel("Frequency (Hz)"); 00291 pylab.ylabel("Phase Response (dB)"); 00292 } 00293 00294 float64 ymax = fr.getMax(); 00295 float64 height = ymax - -60.0; 00296 00297 pylab.ylim(-60.0, ymax + 0.05 * height); 00298 00299 }
Definition at line 99 of file FilterMovingAverage.h.
Referenced by filter(), FilterMovingAverage(), and operator=().
float64 Nsound::FilterMovingAverage::running_sum_ [protected] |
Definition at line 100 of file FilterMovingAverage.h.
Referenced by filter(), operator=(), and reset().
FilterDelay* Nsound::FilterMovingAverage::delay_ [protected] |
Definition at line 102 of file FilterMovingAverage.h.
Referenced by filter(), FilterMovingAverage(), operator=(), reset(), and ~FilterMovingAverage().
float64 Nsound::Filter::sample_rate_ [protected, inherited] |
Definition at line 131 of file Filter.h.
Referenced by Nsound::FilterPhaser::filter(), Nsound::FilterDelay::filter(), Nsound::FilterCombLowPassFeedback::filter(), Nsound::FilterAllPass::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::FilterStageIIR::makeKernel(), Nsound::FilterParametricEqualizer::makeKernel(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::FilterHighPassFIR::makeKernel(), Nsound::FilterBandPassVocoder::makeKernel(), Nsound::FilterPhaser::operator=(), Nsound::FilterLeastSquaresFIR::operator=(), Nsound::FilterIIR::operator=(), Nsound::FilterFlanger::operator=(), Nsound::FilterTone::plot(), Nsound::FilterPhaser::plot(), Nsound::FilterParametricEqualizer::plot(), Nsound::FilterLowPassIIR::plot(), Nsound::FilterLowPassFIR::plot(), Nsound::FilterLeastSquaresFIR::plot(), Nsound::FilterHighPassIIR::plot(), Nsound::FilterHighPassFIR::plot(), Nsound::FilterFlanger::plot(), Nsound::FilterCombLowPassFeedback::plot(), Nsound::FilterBandRejectIIR::plot(), Nsound::FilterBandRejectFIR::plot(), Nsound::FilterBandPassIIR::plot(), Nsound::FilterBandPassFIR::plot(), Nsound::FilterAllPass::plot(), Nsound::FilterLowPassIIR::setCutoff(), and Nsound::FilterLeastSquaresFIR::setWindow().
float64 Nsound::Filter::two_pi_over_sample_rate_ [protected, inherited] |
Definition at line 132 of file Filter.h.
Referenced by Nsound::FilterTone::makeKernel(), Nsound::FilterParametricEqualizer::makeKernel(), and Nsound::FilterLowPassFIR::makeKernel().
uint32 Nsound::Filter::kernel_size_ [protected, inherited] |
Definition at line 133 of file Filter.h.
Referenced by Nsound::FilterLowPassFIR::filter(), Nsound::FilterLeastSquaresFIR::filter(), Nsound::FilterBandPassFIR::FilterBandPassFIR(), Nsound::FilterBandPassIIR::FilterBandPassIIR(), Nsound::FilterBandRejectIIR::FilterBandRejectIIR(), Nsound::FilterHighPassIIR::FilterHighPassIIR(), Nsound::FilterLeastSquaresFIR::FilterLeastSquaresFIR(), Nsound::FilterLowPassFIR::FilterLowPassFIR(), Nsound::FilterLowPassIIR::FilterLowPassIIR(), Nsound::FilterLeastSquaresFIR::getKernel(), Nsound::Filter::getKernelSize(), Nsound::FilterLowPassFIR::makeKernel(), Nsound::FilterLeastSquaresFIR::makeKernel(), Nsound::FilterHighPassFIR::makeKernel(), Nsound::FilterBandRejectFIR::makeKernel(), Nsound::FilterLeastSquaresFIR::operator=(), Nsound::FilterLowPassFIR::plot(), Nsound::FilterLeastSquaresFIR::plot(), Nsound::FilterHighPassFIR::plot(), Nsound::FilterBandRejectFIR::plot(), Nsound::FilterLowPassFIR::reset(), Nsound::FilterLeastSquaresFIR::reset(), Nsound::FilterHighPassFIR::reset(), Nsound::FilterLeastSquaresFIR::setKernel(), Nsound::FilterLeastSquaresFIR::setWindow(), and Nsound::FilterHighPassFIR::spectraReversal_().
1.6.3