CLAM-Development  1.4.0
SpectralDelay.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 "SpectralDelay.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "SpectralDelay",
32  "category", "Spectral Transformations",
33  "description", "SpectralDelay",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, SpectralDelay> reg = metadata;
37 }
38 
39 
40 
41 bool SpectralDelay::Do(const Spectrum& in, Spectrum& out)
42 {
43  if ( !mConfig.GetPreserveOuts() )
44  {
45  out = in; //TODO big cludge for streaming
46  }
47 
48  //first convert from ms to token size
49  //mFrameSize should be set somehow in the configuration! It is the difference between one frame center and the next
50  mFrameSize = 1024;
51 
52 
53  TData lfDelay = mLowDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
54  TData mfDelay = mMidDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
55  TData hfDelay = mHighDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
56 
57  //these controls could just be connected at the beginning
58  SendFloatToInControl(mLFDelay,"Delay Control",lfDelay);
59  SendFloatToInControl(mMFDelay,"Delay Control",mfDelay);
60  SendFloatToInControl(mHFDelay,"Delay Control",hfDelay);
61 
62  //now we are ready to get the appropriate spectrums
63  mLFDelay.Do(in, mLFSpectrum);
64  mMFDelay.Do(in, mMFSpectrum);
65  mHFDelay.Do(in, mHFSpectrum);
66 
67  DataArray& hfMag = mHFSpectrum.GetMagBuffer();
68  DataArray& hfPhase = mHFSpectrum.GetPhaseBuffer();
69  DataArray& mfMag = mMFSpectrum.GetMagBuffer();
70  DataArray& mfPhase = mMFSpectrum.GetPhaseBuffer();
71  DataArray& lfMag = mLFSpectrum.GetMagBuffer();
72  DataArray& lfPhase = mLFSpectrum.GetPhaseBuffer();
73 
74  DataArray& oMag = out.GetMagBuffer();
75  DataArray& oPhase = out.GetPhaseBuffer();
76 
77  int spectrumSize = in.GetSize();
78 
79  TData spectralResolution = spectrumSize/in.GetSpectralRange();
80 
81  int lowCutoff = Round(mLowCutoffFreqCtl.GetLastValue()* spectralResolution);
82  int highCutoff = Round(mHighCutoffFreqCtl.GetLastValue()* spectralResolution);
83 
84  for(int i = 0; i<spectrumSize; i++)
85  {
86  if(i>highCutoff)
87  {
88  oMag[i] = hfMag[i];
89  oPhase[i] = hfPhase[i];
90  }
91  else if(i>lowCutoff)
92  {
93  oMag[i] = mfMag[i];
94  oPhase[i] = mfPhase[i];
95  }
96  else
97  {
98  oMag[i] = lfMag[i];
99  oPhase[i] = lfPhase[i];
100  }
101  }
102  return true;
103 }
104 
105 
106 }
107