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 _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 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 */ 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 InControl mIndexCtl;//says what the amount sent as control is modifying 00080 InControlTmpl<SMSSineFilter> mUpdateBPFCtl;//"boolean" control used to say that we want to update BPF 00081 InControl mGainCtl; 00082 00083 int 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 return 0; 00094 } 00095 00096 public: 00098 SMSSineFilter() 00099 : 00100 mInPeaks("In SpectralPeaks", this), 00101 mOutPeaks("Out SpectralPeaks", this), 00102 mIndexCtl("Index", this), 00103 mGainCtl("Gain",this), 00104 mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF, true) 00105 00106 { 00107 00108 //setting default configuration 00109 mConfig.AddBPF(); 00110 mConfig.UpdateData(); 00111 Configure( mConfig ); 00112 } 00116 SMSSineFilter(const FrameTransformationConfig& cfg ) 00117 : 00118 mInPeaks("In SpectralPeaks", this), 00119 mOutPeaks("Out SpectralPeaks", this), 00120 mIndexCtl("Index", this), 00121 mGainCtl("Gain",this), 00122 mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF, true) 00123 { 00124 Configure( cfg ); 00125 } 00126 00127 virtual bool ConcreteConfigure(const ProcessingConfig& cfg) 00128 { 00129 CopyAsConcreteConfig( mConfig, cfg ); 00130 InitBPF(); 00131 return true; 00132 } 00133 00134 const ProcessingConfig& GetConfig() const { return mConfig; } 00135 00137 ~SMSSineFilter() 00138 {} 00139 00140 bool Do(const Frame& in, Frame& out) 00141 { 00142 return Do( in.GetSpectralPeakArray(), out.GetSpectralPeakArray() ); 00143 } 00144 00145 bool Do(const SpectralPeakArray& in, SpectralPeakArray& out); 00146 00147 // Note that overriding this method breaks the processing chain functionality. 00148 bool Do() 00149 { 00150 bool result = Do( mInPeaks.GetData(), mOutPeaks.GetData() ); 00151 mInPeaks.Consume(); 00152 mOutPeaks.Produce(); 00153 return result; 00154 } 00155 00156 void InitBPF() 00157 { 00158 if (!mConfig.HasBPF()) 00159 { 00160 mConfig.AddBPF(); 00161 mConfig.UpdateData(); 00162 } 00163 if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before 00164 { 00165 BPF& bpf=mConfig.GetBPF(); 00166 bpf.Resize(500); 00167 bpf.SetSize(500); 00168 int i; 00169 for (i=0; i< 500; i++) 00170 { 00171 bpf.SetValue(i,0); 00172 } 00173 } 00174 } 00175 00176 }; 00177 } //namespace CLAM 00178 00179 #endif // _SMSSineFilter_ 00180