CLAM-Development  1.4.0
FreqShift.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 "FreqShift.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "FreqShift",
32  // "category", "Spectral Transformations",
33  // "description", "FreqShift",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, FreqShift> reg = metadata;
37 }
38 
39 
40 bool FreqShift::Do(const Spectrum& in, Spectrum& out)
41 {
42 
43  if ( !mConfig.GetPreserveOuts() )
44  {
45  out = in; //TODO big cludge for streaming
46  }
47 
48  //xamat: todo, we just hope the spectrum is in mag/phase format
49  DataArray& iMagArray = in.GetMagBuffer();
50  DataArray& iPhaseArray = in.GetPhaseBuffer();
51  TSize spectrumSize = in.GetSize();
52  //I need to keep a copy of the magnitude array to guarantee inplace processing is possible
53  mOMagArray.Resize(spectrumSize);
54  mOMagArray.SetSize(spectrumSize);
55  mOPhaseArray.Resize(spectrumSize);
56  mOPhaseArray.SetSize(spectrumSize);
57 
58  //actually this is one over the spectral resolution, but it will be better for what I need afterwords
59  TData spectralResolution = spectrumSize/in.GetSpectralRange();
60  int amount = Round(mShiftAmount.GetLastValue() * spectralResolution);
61 
62  for(int i = 0; i<spectrumSize; i++)
63  {
64  if(i<amount)
65  {
66  mOMagArray[i] = 0;
67  mOPhaseArray[i] = 0;
68  }
69  else if(i>spectrumSize+amount)
70  {
71  mOMagArray[i] = 0;
72  mOPhaseArray[i] = 0;
73  }
74  else
75  {
76  mOMagArray[i] = iMagArray[i-amount];
77  mOPhaseArray[i] = iPhaseArray[i-amount];
78  }
79  }
80  out.SetMagBuffer(mOMagArray);
81  out.SetPhaseBuffer(mOPhaseArray);
82  return true;
83 }
84 
85 
86 }
87