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