|
CLAM-Development
1.3
|
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 _SMSSineFilter_ 00023 #define _SMSSineFilter_ 00024 00025 #include "BPF.hxx" 00026 #include "InPort.hxx" 00027 #include "OutPort.hxx" 00028 #include "Frame.hxx" 00029 #include "SpectralPeakArray.hxx" 00030 #include "FrameTransformation.hxx" 00031 #include "FrameTransformationConfig.hxx" 00032 #include "Processing.hxx" 00033 #include "SegmentTransformationConfig.hxx" 00034 00035 00036 namespace CLAM 00037 { 00038 #if 0 00039 class SMSSineFilterConfig : public ProcessingConfig 00040 { 00041 00042 public: 00043 DYNAMIC_TYPE_USING_INTERFACE (SMSSineFilterConfig, 1,ProcessingConfig); 00045 // DYN_ATTRIBUTE (0, public, TData, Amount); 00047 DYN_ATTRIBUTE (0, public, BPF, BPF); 00048 00049 00050 private: 00051 00052 00053 void DefaultInit() 00054 { 00055 AddAll(); 00056 UpdateData(); 00057 DefaultValues(); 00058 } 00059 00060 void DefaultValues() 00061 { 00062 GetBPF().Insert( 0, 0 ); 00063 GetBPF().Insert( 22050, 0 ); 00064 } 00065 00066 }; 00067 #endif 00068 class SMSSineFilter: public FrameTransformation 00069 { 00070 00074 const char *GetClassName() const {return "SMSSineFilter";} 00075 00076 InPort<SpectralPeakArray> mInPeaks; 00077 OutPort<SpectralPeakArray> mOutPeaks; 00078 00079 FloatInControl mIndexCtl;//says what the amount sent as control is modifying 00080 FloatInControl mUpdateBPFCtl;//"boolean" control used to say that we want to update BPF 00081 FloatInControl mGainCtl; 00082 00083 void UpdateBPF(TControlData value) 00084 { 00085 CLAM::BPF& bpf= mConfig.GetBPF(); 00086 //this should never happen, it should be initialized at configuration time 00087 if(bpf.Size()==0) 00088 { 00089 InitBPF(); 00090 } 00091 00092 bpf.SetValue((int)mIndexCtl.GetLastValue(), mGainCtl.GetLastValue()); 00093 } 00094 00095 public: 00097 SMSSineFilter() 00098 : mInPeaks("In SpectralPeaks", this) 00099 , mOutPeaks("Out SpectralPeaks", this) 00100 , mIndexCtl("Index", this) 00101 , mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF) 00102 , mGainCtl("Gain",this) 00103 00104 { 00105 00106 //setting default configuration 00107 mConfig.AddBPF(); 00108 mConfig.UpdateData(); 00109 Configure( mConfig ); 00110 } 00114 SMSSineFilter(const FrameTransformationConfig& cfg ) 00115 : mInPeaks("In SpectralPeaks", this) 00116 , mOutPeaks("Out SpectralPeaks", this) 00117 , mIndexCtl("Index", this) 00118 , mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF) 00119 , mGainCtl("Gain",this) 00120 { 00121 Configure( cfg ); 00122 } 00123 00124 virtual bool ConcreteConfigure(const ProcessingConfig& cfg) 00125 { 00126 CopyAsConcreteConfig( mConfig, cfg ); 00127 InitBPF(); 00128 return true; 00129 } 00130 00131 const ProcessingConfig& GetConfig() const { return mConfig; } 00132 00134 ~SMSSineFilter() 00135 {} 00136 00137 bool Do(const Frame& in, Frame& out) 00138 { 00139 return Do( in.GetSpectralPeakArray(), out.GetSpectralPeakArray() ); 00140 } 00141 00142 bool Do(const SpectralPeakArray& in, SpectralPeakArray& out); 00143 00144 // Note that overriding this method breaks the processing chain functionality. 00145 bool Do() 00146 { 00147 bool result = Do( mInPeaks.GetData(), mOutPeaks.GetData() ); 00148 mInPeaks.Consume(); 00149 mOutPeaks.Produce(); 00150 return result; 00151 } 00152 00153 void InitBPF() 00154 { 00155 if (!mConfig.HasBPF()) 00156 { 00157 mConfig.AddBPF(); 00158 mConfig.UpdateData(); 00159 } 00160 if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before 00161 { 00162 BPF& bpf=mConfig.GetBPF(); 00163 bpf.Resize(500); 00164 bpf.SetSize(500); 00165 int i; 00166 for (i=0; i< 500; i++) 00167 { 00168 bpf.SetValue(i,0); 00169 } 00170 } 00171 } 00172 00173 }; 00174 } //namespace CLAM 00175 00176 #endif // _SMSSineFilter_ 00177
1.7.6.1