qm-dsp
1.8
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 QM DSP library 00005 Centre for Digital Music, Queen Mary, University of London. 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. See the file 00011 COPYING included with this distribution for more information. 00012 */ 00013 00014 #ifndef KAISER_WINDOW_H 00015 #define KAISER_WINDOW_H 00016 00017 #include <vector> 00018 #include <cmath> 00019 00025 class KaiserWindow 00026 { 00027 public: 00028 struct Parameters { 00029 int length; 00030 double beta; 00031 }; 00032 00037 KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); } 00038 00043 static KaiserWindow byTransitionWidth(double attenuation, 00044 double transition) { 00045 return KaiserWindow 00046 (parametersForTransitionWidth(attenuation, transition)); 00047 } 00048 00053 static KaiserWindow byBandwidth(double attenuation, 00054 double bandwidth, 00055 double samplerate) { 00056 return KaiserWindow 00057 (parametersForBandwidth(attenuation, bandwidth, samplerate)); 00058 } 00059 00064 static Parameters parametersForTransitionWidth(double attenuation, 00065 double transition); 00066 00072 static Parameters parametersForBandwidth(double attenuation, 00073 double bandwidth, 00074 double samplerate) { 00075 return parametersForTransitionWidth 00076 (attenuation, (bandwidth * 2 * M_PI) / samplerate); 00077 } 00078 00079 int getLength() const { 00080 return m_length; 00081 } 00082 00083 const double *getWindow() const { 00084 return m_window.data(); 00085 } 00086 00087 void cut(double *src) const { 00088 cut(src, src); 00089 } 00090 00091 void cut(const double *src, double *dst) const { 00092 for (int i = 0; i < m_length; ++i) { 00093 dst[i] = src[i] * m_window[i]; 00094 } 00095 } 00096 00097 private: 00098 int m_length; 00099 double m_beta; 00100 std::vector<double> m_window; 00101 00102 void init(); 00103 }; 00104 00105 #endif