CLAM-Development  1.4.0
SpectralEnvelopeApply.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 "Complex.hxx"
24 
25 #define CLASS "SpectralEnvelopeApply"
26 
27 namespace CLAM {
28 
29  /* Processing object Method implementations */
30 
32  {
34  }
35 
37  {
38  Configure(c);
39  }
40 
42  {}
43 
44 
45  /* Configure the Processing Object according to the Config object */
46 
47  bool SpectralEnvelopeApply::ConcreteConfigure(const ProcessingConfig& c)
48  {
49 
50  CopyAsConcreteConfig(mConfig, c);
51  return true;
52  }
53 
54  /* Setting Prototypes for faster processing */
55 
57  {
58  return true;
59  }
60 
62  {
63  return true;
64  }
65 
67  {
68  return true;
69  }
70 
71  /* The supervised Do() function */
72 
74  {
75  CLAM_ASSERT(false,CLASS"::Do(): Supervised mode not implemented");
76  return false;
77  }
78 
79  /* The unsupervised Do() function */
80  bool SpectralEnvelopeApply::Do(const SpectralPeakArray& input, const Spectrum& spectralEnvelope, SpectralPeakArray& output)
81  {
82  output.SetScale(input.GetScale());
83  CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
84 
85  TSize nPeaks=input.GetnPeaks();
86  //Unused variable: DataArray& imagBuffer=input.GetMagBuffer();
87  DataArray& iphaseBuffer=input.GetPhaseBuffer();
88  DataArray& ifreqBuffer=input.GetFreqBuffer();
89 
90  if(output.GetnMaxPeaks()!=input.GetnMaxPeaks())
91  output.SetnMaxPeaks(input.GetnMaxPeaks());
92  if(output.GetnPeaks()!=input.GetnPeaks())
93  output.SetnPeaks(input.GetnPeaks());
94 
95  DataArray& omagBuffer=output.GetMagBuffer();
96  DataArray& ophaseBuffer=output.GetPhaseBuffer();
97  DataArray& ofreqBuffer=output.GetFreqBuffer();
98 
99  int i;
100 
101  BPF& env = spectralEnvelope.GetMagBPF();
102  for(i=0;i<nPeaks;i++)
103  {
104  ophaseBuffer[i]=iphaseBuffer[i];
105  omagBuffer[i]=env.GetValue(ifreqBuffer[i]);
106  ofreqBuffer[i]=ifreqBuffer[i];
107  }
108 
109  return true;
110  }
111 
112  /* The unsupervised Do() function */
113  bool SpectralEnvelopeApply::Do(const Spectrum& input, const Spectrum& spectralEnvelope, Spectrum& output)
114  {
115  output.SetScale(input.GetScale());
116  CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
117 
118  output=input;
119 
120  int spectrumSize=input.GetSize();
121 
122  int i;
123  TData delta = input.GetSpectralRange()/(spectrumSize-1);
124  DataArray& outMag = output.GetMagBuffer();
125  BPF& env = spectralEnvelope.GetMagBPF();
126 
127  TData currentFreq = 0.;
128  for(i=0;i<spectrumSize;i++, currentFreq+=delta)
129  //for(i=0;currentFreq<10000;i++, currentFreq+=delta)
130  {
131  //std::cout<<outMag[i] << " will be " << env.GetValue(currentFreq) <<std::endl;
132  outMag[i] = env.GetValue(currentFreq);
133 
134  //output.SetMag(i,spectralEnvelope.GetMag((TData)i*delta));
135  }
136 
137 
138  return true;
139  }
140 
141 
142 };//namespace CLAM
143