#include <Nsound/Filter.h>

Public Member Functions | |
| Filter (const float64 &sample_rate) | |
| virtual | ~Filter () |
| AudioStream | filter (const AudioStream &x) |
| AudioStream | filter (const AudioStream &x, const float64 &frequency) |
| AudioStream | filter (const AudioStream &x, const Buffer &frequencies) |
| Buffer | filter (const Buffer &x) |
| Buffer | filter (const Buffer &x, const float64 &frequency) |
| Buffer | filter (const Buffer &x, const Buffer &frequencies) |
| virtual float64 | filter (const float64 &x)=0 |
| virtual float64 | filter (const float64 &x, const float64 &frequency)=0 |
| 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) |
| virtual void | reset ()=0 |
Protected Attributes | |
| float64 | sample_rate_ |
| float64 | two_pi_over_sample_rate_ |
| uint32 | kernel_size_ |
Base class for IIR Filters, defines the interface.
Definition at line 49 of file Filter.h.
| Filter::Filter | ( | const float64 & | sample_rate | ) |
Definition at line 42 of file Filter.cc.
00044 : 00045 sample_rate_(sample_rate), 00046 two_pi_over_sample_rate_(2.0 * M_PI / sample_rate), 00047 kernel_size_(0) 00048 { }
| virtual Nsound::Filter::~Filter | ( | ) | [inline, virtual] |
| AudioStream Filter::filter | ( | const AudioStream & | x | ) |
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassFIR, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectFIR, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterPhaser, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Definition at line 53 of file Filter.cc.
References Nsound::AudioStream::getNChannels(), Nsound::AudioStream::getSampleRate(), and reset().
Referenced by filter(), and getImpulseResponse().
00054 { 00055 reset(); 00056 00057 uint32 n_channels = x.getNChannels(); 00058 00059 AudioStream y(x.getSampleRate(), n_channels); 00060 00061 for(uint32 channel = 0; channel < n_channels; ++channel) 00062 { 00063 y[channel] = filter(x[channel]); 00064 } 00065 00066 return y; 00067 }
| AudioStream Filter::filter | ( | const AudioStream & | x, | |
| const float64 & | frequency | |||
| ) |
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 filter(), Nsound::AudioStream::getNChannels(), Nsound::AudioStream::getSampleRate(), and 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 }
| AudioStream Filter::filter | ( | const AudioStream & | x, | |
| const Buffer & | frequencies | |||
| ) |
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Definition at line 91 of file Filter.cc.
References filter(), Nsound::AudioStream::getNChannels(), Nsound::AudioStream::getSampleRate(), and reset().
00092 { 00093 reset(); 00094 00095 uint32 n_channels = x.getNChannels(); 00096 00097 AudioStream y(x.getSampleRate(), n_channels); 00098 00099 for(uint32 channel = 0; channel < n_channels; ++channel) 00100 { 00101 y[channel] = filter(x[channel], frequency); 00102 } 00103 00104 return y; 00105 }
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassFIR, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectFIR, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterPhaser, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Definition at line 110 of file Filter.cc.
References filter(), Nsound::Buffer::getLength(), and reset().
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(), filter(), Nsound::Buffer::getLength(), and 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 }
Reimplemented in Nsound::FilterAllPass, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Definition at line 151 of file Filter.cc.
References Nsound::Buffer::begin(), Nsound::Buffer::cbegin(), Nsound::Buffer::end(), filter(), Nsound::Buffer::getLength(), and reset().
00152 { 00153 reset(); 00154 00155 Buffer::circular_iterator freq = frequencies.cbegin(); 00156 00157 Buffer::const_iterator itor = x.begin(); 00158 Buffer::const_iterator end = x.end(); 00159 00160 Buffer y(x.getLength()); 00161 00162 while(itor != end) 00163 { 00164 y << filter(*itor, *freq); 00165 00166 ++itor; 00167 ++freq; 00168 } 00169 00170 return y; 00171 }
Implemented in Nsound::FilterAllPass, Nsound::FilterBandPassFIR, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectFIR, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterPhaser, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
| virtual float64 Nsound::Filter::filter | ( | const float64 & | x, | |
| const float64 & | frequency | |||
| ) | [pure virtual] |
Implemented in Nsound::FilterAllPass, Nsound::FilterBandPassFIR, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectFIR, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterPhaser, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Definition at line 176 of file Filter.cc.
References Nsound::FFTransform::roundUp2(), and sample_rate_.
Referenced by main(), 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(), getImpulseResponse(), and sample_rate_.
Referenced by Nsound::FilterBandPassIIR::FilterBandPassIIR(), FilterLeastSquaresFIR_UnitTest(), Nsound::FilterIIR::getRMS(), main(), 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 filter(), and reset().
Referenced by getFrequencyResponse(), and getPhaseResponse().
| virtual uint32 Nsound::Filter::getKernelSize | ( | ) | const [inline, virtual] |
Reimplemented in Nsound::FilterIIR, and Nsound::FilterTone.
Definition at line 109 of file Filter.h.
References kernel_size_.
Referenced by Nsound::FilterBandPassIIR::FilterBandPassIIR(), Nsound::FilterBandRejectIIR::plot(), Nsound::FilterBandPassIIR::plot(), and Nsound::FilterBandPassFIR::plot().
00109 {return kernel_size_;};
| Buffer Filter::getPhaseResponse | ( | ) |
Definition at line 239 of file Filter.cc.
References Nsound::FFTransform::fft(), getImpulseResponse(), Nsound::Buffer::getLength(), sample_rate_, and Nsound::Buffer::subbuffer().
Referenced by 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] |
| void Filter::plot | ( | boolean | show_phase = false |
) |
Definition at line 257 of file Filter.cc.
References Nsound::Plotter::figure(), Nsound::Buffer::getdB(), getFrequencyAxis(), getFrequencyResponse(), Nsound::Buffer::getMax(), 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 }
| virtual void Nsound::Filter::reset | ( | ) | [pure virtual] |
Implemented in Nsound::FilterAllPass, Nsound::FilterBandPassFIR, Nsound::FilterBandPassIIR, Nsound::FilterBandPassVocoder, Nsound::FilterBandRejectFIR, Nsound::FilterBandRejectIIR, Nsound::FilterCombLowPassFeedback, Nsound::FilterDelay, Nsound::FilterFlanger, Nsound::FilterHighPassFIR, Nsound::FilterHighPassIIR, Nsound::FilterIIR, Nsound::FilterLeastSquaresFIR, Nsound::FilterLowPassFIR, Nsound::FilterLowPassIIR, Nsound::FilterMovingAverage, Nsound::FilterParametricEqualizer, Nsound::FilterPhaser, Nsound::FilterSlinky, Nsound::FilterStageIIR, and Nsound::FilterTone.
Referenced by filter(), and getImpulseResponse().
float64 Nsound::Filter::sample_rate_ [protected] |
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(), getFrequencyAxis(), getFrequencyResponse(), getPhaseResponse(), 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] |
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] |
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(), 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