CLAM-Development  1.4.0
SpectralFocus.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 "SpectralFocus.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "SpectralFocus",
32  // "category", "Spectral Transformations",
33  // "description", "SpectralFocus",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, SpectralFocus> reg = metadata;
37 }
38 
40  inSpec,Spectrum& outSpec)
41 {
42 
43  if (!mConfig.GetPreserveOuts())
44  {
45  outSpec = inSpec; //TODO big cludge for streaming
46  }
47 
48  int spectrumSize = inSpec.GetSize();
49  TData spectralResolution = spectrumSize/inSpec.GetSpectralRange();
50 
51  int centerPoint = Round (mCenterFreqCtl.GetLastValue()*spectralResolution);
52  int amount= Round(mAmount.GetLastValue()*spectralResolution);
53 
54  mBPFSpectrum.SetSize(spectrumSize);
55 
56 
57  //Shift spectral shape
58  Array<Point>& magBPF=mBPFSpectrum.GetMagBPF().GetPointArray();
59  //magBPF.SetIntpType(EInterpolation::eLinear);
60  Array<Point>& phaseBPF=mBPFSpectrum.GetPhaseBPF().GetPointArray();
61  //phaseBPF.SetIntpType(EInterpolation::eLinear);
62 
63  magBPF.SetSize(0);
64  phaseBPF.SetSize(0);
65 
66  DataArray& inMag = inSpec.GetMagBuffer();
67  DataArray& inPhase = inSpec.GetPhaseBuffer();
68 
69  TData binWidth = 1./spectralResolution;
70  int i;
71  TData freq = amount*binWidth;
72  TData mag;
73  TData phase;
74  int nPoints = 0;
75  for (i=amount; i<centerPoint; i++)
76  {
77  mag = inMag[i-amount];
78  phase = inPhase[i-amount];
79  magBPF.AddElem(Point(freq,mag));
80  phaseBPF.AddElem(Point(freq, phase));
81  freq += binWidth;
82  nPoints++;
83  }
84 
85  freq = centerPoint * binWidth;
86  magBPF.AddElem(Point(freq, inMag[centerPoint]));
87  phaseBPF.AddElem(Point(freq, inPhase[centerPoint]));
88  nPoints++;
89 
90  freq = (centerPoint+1)*binWidth;
91 
92  for (i=centerPoint+1 ; i<spectrumSize-amount; i++)
93  {
94  mag = inMag[i+amount];
95  phase = inPhase[i+amount];
96  magBPF.AddElem(Point(freq,mag));
97  phaseBPF.AddElem(Point(freq, phase));
98  freq += binWidth;
99  nPoints++;
100  }
101 
102  mBPFSpectrum.SetBPFSize(nPoints);
103  mBPFSpectrum.SynchronizeTo(mFlag);
104  outSpec.SetMagBuffer(mBPFSpectrum.GetMagBuffer());
105  outSpec.SetPhaseBuffer(mBPFSpectrum.GetPhaseBuffer());
106 
107  return true;
108 }
109 
110 
111 }
112