#include <Nsound/FilterCombLowPassFeedback.h>

A class for filtering audio in the frequecy domain.
Definition at line 48 of file FilterCombLowPassFeedback.h.
| FilterCombLowPassFeedback::FilterCombLowPassFeedback | ( | const float64 & | sample_rate, | |
| const float64 & | delay_time_seconds, | |||
| const float64 & | feedback_gain, | |||
| const float64 & | low_pass_frequency_Hz | |||
| ) |
Definition at line 48 of file FilterCombLowPassFeedback.cc.
References damp1_, damp2_, delay_, feedback_gain_, reset(), and Nsound::Filter::sample_rate_.
00054 : 00055 Filter(sample_rate), 00056 delay_(NULL), 00057 feedback_gain_(feedback_gain), 00058 damp1_(0.0), 00059 damp2_(0.0), 00060 y_history_(0.0) 00061 { 00062 delay_ = new FilterDelay(sample_rate_, delay_time_seconds); 00063 00064 FilterCombLowPassFeedback::reset(); 00065 00066 if(feedback_gain_ < 0.0) 00067 { 00068 feedback_gain_ = 0.0; 00069 } 00070 00071 if(feedback_gain_ >= 1.0) 00072 { 00073 feedback_gain_ = 0.999999; 00074 } 00075 00076 damp1_ = low_pass_frequency_Hz / sample_rate_; 00077 00078 if(damp1_ > 0.5) 00079 { 00080 damp1_ = 0.5; 00081 } 00082 00083 damp2_ = 1.0 - damp1_; }
| FilterCombLowPassFeedback::FilterCombLowPassFeedback | ( | const FilterCombLowPassFeedback & | copy | ) |
Definition at line 87 of file FilterCombLowPassFeedback.cc.
00089 : 00090 Filter(copy.sample_rate_), 00091 delay_(new FilterDelay(*copy.delay_)), 00092 feedback_gain_(copy.feedback_gain_), 00093 damp1_(copy.damp1_), 00094 damp2_(copy.damp2_), 00095 y_history_(y_history_) 00096 { }
| FilterCombLowPassFeedback::~FilterCombLowPassFeedback | ( | ) | [virtual] |
Definition at line 101 of file FilterCombLowPassFeedback.cc.
References delay_.
00102 { 00103 delete delay_; 00104 }
| AudioStream FilterCombLowPassFeedback::filter | ( | const AudioStream & | x | ) |
Reimplemented from Nsound::Filter.
Definition at line 109 of file FilterCombLowPassFeedback.cc.
References reset().
Referenced by Nsound::ReverberationRoom::filter(), filter(), and FilterCombLowPassFeedback_UnitTest().
00110 { 00111 FilterCombLowPassFeedback::reset(); 00112 return Filter::filter(x); 00113 }
| AudioStream FilterCombLowPassFeedback::filter | ( | const AudioStream & | x, | |
| const Buffer & | frequencies | |||
| ) |
Reimplemented from Nsound::Filter.
Definition at line 118 of file FilterCombLowPassFeedback.cc.
References filter(), and reset().
00119 { 00120 FilterCombLowPassFeedback::reset(); 00121 return Filter::filter(x, frequencies); 00122 }
Reimplemented from Nsound::Filter.
Definition at line 127 of file FilterCombLowPassFeedback.cc.
References filter(), and reset().
00128 { 00129 FilterCombLowPassFeedback::reset(); 00130 return Filter::filter(x); 00131 }
Reimplemented from Nsound::Filter.
Definition at line 136 of file FilterCombLowPassFeedback.cc.
References filter(), and reset().
00137 { 00138 FilterCombLowPassFeedback::reset(); 00139 return Filter::filter(x, frequencies); 00140 }
Implements Nsound::Filter.
Definition at line 145 of file FilterCombLowPassFeedback.cc.
References damp1_, damp2_, delay_, feedback_gain_, Nsound::FilterDelay::filter(), and y_history_.
00146 { 00147 float64 d = delay_->filter(x + y_history_ * feedback_gain_); 00148 00149 y_history_ = d * damp2_ + y_history_ * damp1_; 00150 00151 return d; 00152 }
| float64 FilterCombLowPassFeedback::filter | ( | const float64 & | x, | |
| const float64 & | frequency | |||
| ) | [virtual] |
Implements Nsound::Filter.
Definition at line 157 of file FilterCombLowPassFeedback.cc.
References damp1_, damp2_, filter(), and Nsound::Filter::sample_rate_.
00158 { 00159 damp1_ = frequency_Hz / sample_rate_; 00160 00161 if(damp1_ > 0.5) 00162 { 00163 damp1_ = 0.5; 00164 } 00165 00166 damp2_ = 1.0 - damp1_; 00167 00168 return FilterCombLowPassFeedback::filter(x); 00169 }
| FilterCombLowPassFeedback & FilterCombLowPassFeedback::operator= | ( | const FilterCombLowPassFeedback & | rhs | ) |
Definition at line 174 of file FilterCombLowPassFeedback.cc.
References damp1_, damp2_, delay_, feedback_gain_, and y_history_.
00175 { 00176 *delay_ = *rhs.delay_; 00177 feedback_gain_ = rhs.feedback_gain_; 00178 damp1_ = rhs.damp1_; 00179 damp2_ = rhs.damp2_; 00180 y_history_ = rhs.y_history_; 00181 00182 return *this; 00183 }
Definition at line 188 of file FilterCombLowPassFeedback.cc.
References Nsound::Plotter::axvline(), damp1_, Nsound::Filter::sample_rate_, Nsound::Plotter::subplot(), and Nsound::Plotter::title().
00189 { 00190 char title[128]; 00191 sprintf(title, 00192 "Comb Low Pass Feedback Frequency Response\n" 00193 "order = %d, fc = %0.1f Hz, sr = %0.1f Hz", 00194 2, 00195 damp1_ * sample_rate_, 00196 sample_rate_); 00197 00198 Filter::plot(show_phase); 00199 00200 Plotter pylab; 00201 00202 int32 topplot = 111; 00203 00204 if(show_phase) 00205 { 00206 topplot = 211; 00207 } 00208 00209 if(show_fc) 00210 { 00211 pylab.subplot(topplot); 00212 00213 pylab.axvline(damp1_ * sample_rate_,"color='red'"); 00214 00215 pylab.title(title); 00216 } 00217 }
| void FilterCombLowPassFeedback::reset | ( | ) | [virtual] |
Implements Nsound::Filter.
Definition at line 222 of file FilterCombLowPassFeedback.cc.
References delay_, Nsound::FilterDelay::reset(), and y_history_.
Referenced by filter(), FilterCombLowPassFeedback(), and Nsound::ReverberationRoom::reset().
00223 { 00224 delay_->reset(); 00225 y_history_ = 0.0; 00226 }
| 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 }
FilterDelay* Nsound::FilterCombLowPassFeedback::delay_ [protected] |
Definition at line 106 of file FilterCombLowPassFeedback.h.
Referenced by filter(), FilterCombLowPassFeedback(), operator=(), reset(), and ~FilterCombLowPassFeedback().
Definition at line 108 of file FilterCombLowPassFeedback.h.
Referenced by filter(), FilterCombLowPassFeedback(), and operator=().
float64 Nsound::FilterCombLowPassFeedback::damp1_ [protected] |
Definition at line 110 of file FilterCombLowPassFeedback.h.
Referenced by filter(), FilterCombLowPassFeedback(), operator=(), and plot().
float64 Nsound::FilterCombLowPassFeedback::damp2_ [protected] |
Definition at line 111 of file FilterCombLowPassFeedback.h.
Referenced by filter(), FilterCombLowPassFeedback(), and operator=().
float64 Nsound::FilterCombLowPassFeedback::y_history_ [protected] |
Definition at line 113 of file FilterCombLowPassFeedback.h.
Referenced by filter(), operator=(), and reset().
float64 Nsound::Filter::sample_rate_ [protected, inherited] |
Definition at line 131 of file Filter.h.
Referenced by Nsound::FilterPhaser::filter(), Nsound::FilterDelay::filter(), filter(), Nsound::FilterAllPass::FilterAllPass(), 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(), 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