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 00023 #ifndef _SpectralFilterGen_ 00024 #define _SpectralFilterGen_ 00025 00026 #include "Processing.hxx" 00027 #include "ProcessingData.hxx" 00028 #include "OutPort.hxx" 00029 #include "InControl.hxx" 00030 #include "DataTypes.hxx" 00031 #include "Audio.hxx" 00032 #include "Spectrum.hxx" 00033 #include "Enum.hxx" 00034 00035 namespace CLAM { 00036 00037 class EFDFilterGenControls : public Enum 00038 { 00039 public: 00040 00041 EFDFilterGenControls() : Enum(ValueTable(), gain) { } 00042 EFDFilterGenControls(tValue v) : Enum(ValueTable(), v) { } 00043 EFDFilterGenControls(std::string s) : Enum(ValueTable(), s) { } 00044 ~EFDFilterGenControls() { }; 00045 00046 Component * Species() const 00047 { 00048 return new EFDFilterGenControls; 00049 } 00050 00051 typedef enum 00052 { 00053 gain=0, 00054 highcutoff, 00055 lowcutoff, 00056 passbandslope, 00057 stopbandslope 00058 } tEnum; 00059 00060 static tEnumValue * ValueTable() 00061 { 00062 static tEnumValue sEnumValues[] = 00063 { 00064 { gain, "gain" }, 00065 { highcutoff, "highcutoff" }, 00066 { lowcutoff, "lowcutoff" }, 00067 { passbandslope, "passbandslope" }, 00068 { stopbandslope, "stopbandslope" }, 00069 { 0, NULL } 00070 }; 00071 return sEnumValues; 00072 } 00073 }; 00074 00076 class EFDFilterType : public Enum 00077 { 00078 public: 00079 00080 EFDFilterType() : Enum(ValueTable(), eLowPass) {} 00081 EFDFilterType(tValue v) : Enum(ValueTable(), v) {}; 00082 EFDFilterType(std::string s) : Enum(ValueTable(), s) {}; 00083 00084 typedef enum { 00085 eLowPass, 00086 eHighPass, 00087 eBandPass, 00088 eStopBand 00089 }; 00090 00091 virtual Component* Species() const 00092 { 00093 // TODO: This is a xapusa. I want a default constructor! 00094 return (Component*) new EFDFilterType(eLowPass); 00095 }; 00096 static tEnumValue * ValueTable() 00097 { 00098 static tEnumValue sEnumValues[] = { 00099 {eLowPass,"Low-pass"}, 00100 {eHighPass,"High-pass"}, 00101 {eBandPass,"Band-pass"}, 00102 {eStopBand,"Stop-Band"}, 00103 {0,NULL} 00104 }; 00105 return sEnumValues; 00106 } 00107 }; 00108 00109 00111 class FDFilterGenConfig: public ProcessingConfig 00112 { 00113 public: 00114 DYNAMIC_TYPE_USING_INTERFACE (FDFilterGenConfig, 7, ProcessingConfig); 00115 DYN_ATTRIBUTE (0, public, EFDFilterType, Type); 00116 DYN_ATTRIBUTE (1, public, TData, SpectralRange); 00117 DYN_ATTRIBUTE (2, public, TData, Gain); 00118 DYN_ATTRIBUTE (3, public, TData, HighCutOff); 00119 DYN_ATTRIBUTE (4, public, TData, LowCutOff); 00120 DYN_ATTRIBUTE (5, public, TData, PassBandSlope); 00121 DYN_ATTRIBUTE (6, public, TData, StopBandSlope); 00122 protected: 00123 void DefaultInit(void); 00124 }; 00125 00127 class FDFilterGen: public Processing 00128 { 00129 private: 00130 typedef InControlTmpl<FDFilterGen> FDFilterGenCtrl; 00131 00132 public: 00133 OutPort<Spectrum> Output; 00134 00135 FDFilterGenCtrl Gain; 00136 FDFilterGenCtrl HighCutOff; 00137 FDFilterGenCtrl LowCutOff; 00138 FDFilterGenCtrl PassBandSlope; 00139 FDFilterGenCtrl StopBandSlope; 00140 00141 private: 00142 TData SpectralRange; 00143 EFDFilterType Type; 00144 00145 FDFilterGenConfig mConfig; 00146 00147 bool mControlChanged; 00148 protected: 00149 00150 // Control change callback function 00151 int UpdateControlChangedFlag(TControlData); 00152 00153 00154 public: 00155 00156 FDFilterGen(); 00157 00161 FDFilterGen(const FDFilterGenConfig &c); 00162 00163 00164 virtual ~FDFilterGen() 00165 { 00166 } 00170 bool Do(void); 00171 00180 bool Do(Spectrum &out); 00181 00183 const ProcessingConfig &GetConfig() const { return mConfig; }; 00184 00185 private: 00186 00187 const char *GetClassName() const {return "FDFilterGen";} 00188 00190 bool ConcreteConfigure(const ProcessingConfig& c); 00191 00193 void SetFilterPoint( 00194 Spectrum& out, 00195 TIndex pos, 00196 TData freq, 00197 TData mag, 00198 TData phase=0 00199 ); 00200 00201 }; 00202 00203 } //namespace CLAM 00204 00205 00206 #endif // _FFT_ 00207