CLAM-Development  1.4.0
SMSSineFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _SMSSineFilter_
23 #define _SMSSineFilter_
24 
25 #include "BPF.hxx"
26 #include "InPort.hxx"
27 #include "OutPort.hxx"
28 #include "Frame.hxx"
29 #include "SpectralPeakArray.hxx"
30 #include "FrameTransformation.hxx"
32 #include "Processing.hxx"
34 
35 
36 namespace CLAM
37 {
38 #if 0
39  class SMSSineFilterConfig : public ProcessingConfig
40  {
41 
42  public:
43  DYNAMIC_TYPE_USING_INTERFACE (SMSSineFilterConfig, 1,ProcessingConfig);
45 // DYN_ATTRIBUTE (0, public, TData, Amount);
47  DYN_ATTRIBUTE (0, public, BPF, BPF);
48 
49 
50  private:
51 
52 
53  void DefaultInit()
54  {
55  AddAll();
56  UpdateData();
57  DefaultValues();
58  }
59 
60  void DefaultValues()
61  {
62  GetBPF().Insert( 0, 0 );
63  GetBPF().Insert( 22050, 0 );
64  }
65 
66  };
67 #endif
69  {
70 
74  const char *GetClassName() const {return "SMSSineFilter";}
75 
78 
79  FloatInControl mIndexCtl;//says what the amount sent as control is modifying
80  FloatInControl mUpdateBPFCtl;//"boolean" control used to say that we want to update BPF
81  FloatInControl mGainCtl;
82 
83  void UpdateBPF(TControlData value)
84  {
85  CLAM::BPF& bpf= mConfig.GetBPF();
86  //this should never happen, it should be initialized at configuration time
87  if(bpf.Size()==0)
88  {
89  InitBPF();
90  }
91 
92  bpf.SetValue((int)mIndexCtl.GetLastValue(), mGainCtl.GetLastValue());
93  }
94 
95  public:
98  : mInPeaks("In SpectralPeaks", this)
99  , mOutPeaks("Out SpectralPeaks", this)
100  , mIndexCtl("Index", this)
101  , mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF)
102  , mGainCtl("Gain",this)
103 
104  {
105 
106  //setting default configuration
107  mConfig.AddBPF();
109  Configure( mConfig );
110  }
115  : mInPeaks("In SpectralPeaks", this)
116  , mOutPeaks("Out SpectralPeaks", this)
117  , mIndexCtl("Index", this)
118  , mUpdateBPFCtl("UpdateBPF", this, &SMSSineFilter::UpdateBPF)
119  , mGainCtl("Gain",this)
120  {
121  Configure( cfg );
122  }
123 
124  virtual bool ConcreteConfigure(const ProcessingConfig& cfg)
125  {
127  InitBPF();
128  return true;
129  }
130 
131  const ProcessingConfig& GetConfig() const { return mConfig; }
132 
135  {}
136 
137  bool Do(const Frame& in, Frame& out)
138  {
139  return Do( in.GetSpectralPeakArray(), out.GetSpectralPeakArray() );
140  }
141 
142  bool Do(const SpectralPeakArray& in, SpectralPeakArray& out);
143 
144  // Note that overriding this method breaks the processing chain functionality.
145  bool Do()
146  {
147  bool result = Do( mInPeaks.GetData(), mOutPeaks.GetData() );
148  mInPeaks.Consume();
149  mOutPeaks.Produce();
150  return result;
151  }
152 
153  void InitBPF()
154  {
155  if (!mConfig.HasBPF())
156  {
157  mConfig.AddBPF();
159  }
160  if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before
161  {
162  BPF& bpf=mConfig.GetBPF();
163  bpf.Resize(500);
164  bpf.SetSize(500);
165  int i;
166  for (i=0; i< 500; i++)
167  {
168  bpf.SetValue(i,0);
169  }
170  }
171  }
172 
173  };
174 } //namespace CLAM
175 
176 #endif // _SMSSineFilter_
177