CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef _WINDOW_GENERATOR_ 00023 #define _WINDOW_GENERATOR_ 00024 00025 #include <typeinfo> // std::bad_cast 00026 #include "DataTypes.hxx" 00027 #include "GlobalEnums.hxx" 00028 #include "Processing.hxx" 00029 #include "InControl.hxx" 00030 #include "Processing.hxx" 00031 #include "WindowGeneratorConfig.hxx" 00032 #include "Array.hxx" 00033 #include "AudioOutPort.hxx" 00034 00035 namespace CLAM { 00036 00037 class Audio; 00038 class Spectrum; 00039 class Storage; 00040 class ProcessingConfig; 00041 00080 class WindowGenerator: public Processing { 00081 public: 00082 typedef WindowGeneratorConfig Config; 00083 private: 00084 Config mConfig; 00085 00086 const char *GetClassName() const {return "WindowGenerator";} 00087 00091 bool ConcreteConfigure(const ProcessingConfig& c); 00092 00093 public: 00094 WindowGenerator(const WindowGeneratorConfig &c=Config()); 00095 00096 ~WindowGenerator(); 00097 00098 const ProcessingConfig &GetConfig() const { return mConfig;} 00099 00100 bool Do(void); 00101 00102 bool Do(DataArray& output); 00103 bool Do(Spectrum& output); 00104 bool Do(Audio& output); 00105 00106 bool MayDisableExecution() const {return true;} 00107 00108 void SetSize(TSize size) 00109 { 00110 CLAM_DEBUG_ASSERT(size%2==1,"Window size must be odd"); 00111 mSize.DoControl((TControlData)size); 00112 } 00113 00114 protected: 00115 AudioOutPort mOutput; 00116 00117 private: 00118 InControl mSize; 00119 DataArray mTable; 00120 00121 void CreateTable(DataArray& table,EWindowType windowType,long windowsize) const; 00122 void CreateWindowFromTable(DataArray &window) const; 00123 double BesselFunction(double x) const; 00124 void KaiserBessel(long size,DataArray& window, 00125 double alpha) const; 00126 void BlackmanHarrisX(long size,DataArray& window, 00127 double a0,double a1,double a2,double a3 = 0.) const; 00128 void BlackmanHarris62(long size,DataArray& window) const; 00129 void BlackmanHarris70(long size,DataArray& window) const; 00130 void BlackmanHarris74(long size,DataArray& window) const; 00131 void BlackmanHarris92(long size,DataArray& window) const; 00132 void BlackmanHarrisLike(long size,DataArray& window) const; 00133 void Hamming(long size,DataArray& window) const; 00134 void Triangular(long size,DataArray& window) const; 00135 void BlackmanHarris92TransMainLobe(long size,DataArray& window) const; 00136 void Gaussian(long size,DataArray& window) const; 00137 void Sine(long size,DataArray& window) const; 00138 void Square(long size,DataArray& window) const; 00139 00140 void InvertWindow(const DataArray& originalWindow, 00141 DataArray& invertedWindow) const; 00142 void InvertWindow(DataArray& window) const; 00143 void NormalizeWindow(DataArray& window) const; 00144 double Sinc(double x, short N) const; 00145 00146 }; 00147 00148 };//namespace CLAM 00149 00150 #endif //_WINDOW_GENERATOR_ 00151