CLAM-Development  1.4.0
3BandFilter.cxx
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 #include "3BandFilter.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 namespace Hidden
28 {
29  static const char * metadata[] = {
30  "key", "ThreeBandFilter",
31  "category", "Spectral Transformations",
32  "description", "ThreeBandFilter",
33  0
34  };
35  static FactoryRegistrator<ProcessingFactory, ThreeBandFilter> reg = metadata;
36 }
37 
38 
39 bool ThreeBandFilter::Do(const Spectrum& in, Spectrum& out)
40 {
41  if ( !mConfig.GetPreserveOuts() )
42  {
43  out = in; //TODO big cludge for streaming
44  }
45 
46  DataArray& oMag = out.GetMagBuffer();
47 
48  int spectrumSize = in.GetSize();
49 
50  TData spectralResolution = spectrumSize/in.GetSpectralRange();
51 
52  int lowCutoff = Round(mLowCutoffFreqCtl.GetLastValue()* spectralResolution);
53  int highCutoff = Round(mHighCutoffFreqCtl.GetLastValue()* spectralResolution);
54 
55  //note: control is supposed to be sent as dB's
56  TData lowGain = log2lin(mLowGainCtl.GetLastValue());
57  TData midGain = log2lin(mMidGainCtl.GetLastValue());
58  TData highGain = log2lin(mHighGainCtl.GetLastValue());
59 
60  TData currentGain = lowGain;
61  for(int i = 0; i<spectrumSize; i++)
62  {
63  if(i>highCutoff)
64  currentGain = highGain;
65  else if(i==highCutoff)
66  currentGain = (highGain+midGain)*0.5; //implementing small rolloff to avoid Gibbs effect
67  else if(i>lowCutoff)
68  currentGain = midGain;
69  else if(i==lowCutoff)
70  currentGain = (lowGain+midGain)*0.5; //implementing small rolloff to avoid Gibbs effect
71  oMag[i] *= currentGain;
72  }
73  return true;
74 }
75 
76 
77 }
78