CLAM-Development  1.4.0
FrameInterpolator.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"
23 #include "SpecTypeFlags.hxx"
24 #include "FrameInterpolator.hxx"
25 #include "BPF.hxx"
26 #include "Point.hxx"
27 
28 namespace CLAM {
29 
31  {
32  AddAll();
33  UpdateData();
34  DefaultValues();
35  }
36 
38  {
39  SetMagInterpolationFactor( 0.0 );
40  SetFreqInterpolationFactor( 0.0 );
41  SetPitchInterpolationFactor( 0.0 );
42  SetResidualInterpolationFactor( 0.0 );
43  SetHarmonic( true );
44  SetUseSpectralShape(false);
45  }
46 
47 
49  : mFrameInterpolationFactorCtl("FrameInterpolationFactor",this,&FrameInterpolator::DoFrameFactorControl)
50  , mMagInterpolationFactorCtl("MagInterpolationFactor",this,&FrameInterpolator::DoMagFactorControl)
51  , mFreqInterpolationFactorCtl("FreqInterpolationFactor",this,&FrameInterpolator::DoFreqFactorControl)
52  , mPitchInterpolationFactorCtl("PitchInterpolationFactor",this,&FrameInterpolator::DoPitchFactorControl)
53  , mResidualInterpolationFactorCtl("ResidualInterpolationFactor",this,&FrameInterpolator::DoResidualFactorControl)
54  , mPitch1Ctl("Pitch1",this,&FrameInterpolator::DoPitch1Control)
55  , mPitch2Ctl("Pitch2",this,&FrameInterpolator::DoPitch2Control)
56  , mIsHarmonicCtl("IsHarmonic",this,&FrameInterpolator::DoHarmonicControl)
57  , mIn1("Input 1",this)
58  , mIn2("Input 2",this)
59  , mOut("Output",this)
60  , mpSpectralShape(0)
61  {
62  AttachChildren();
63  Configure(c);
64  }
65 
66 
67  bool FrameInterpolator::ConcreteConfigure(const ProcessingConfig&c)
68  {
69  CopyAsConcreteConfig(mConfig, c);
70 
71  //Configure children processing
72  PeaksInterpConfig pkInterpConfig;
73  pkInterpConfig.SetMagInterpolationFactor(mConfig.GetMagInterpolationFactor());
74  pkInterpConfig.SetFreqInterpolationFactor(mConfig.GetFreqInterpolationFactor());
75  pkInterpConfig.SetPitchInterpolationFactor(mConfig.GetPitchInterpolationFactor());
76  pkInterpConfig.SetHarmonic(mConfig.GetHarmonic());
77  pkInterpConfig.SetUseSpectralShape(mConfig.GetUseSpectralShape());
78  mPO_PeaksInterpolator.Configure(pkInterpConfig);
79 
80  //todo: using Interpolator with ports is still not available!!
81  if(mConfig.GetUseSpectralShape())
82  {
83  mPO_PeaksInterpolator.AttachSpectralShape(*mpSpectralShape);
84  }
85 
86  SpecInterpConfig spInterpConfig;
87  spInterpConfig.SetInterpolationFactor(mConfig.GetResidualInterpolationFactor());
88 
89  mPO_SpectrumInterpolator.Configure(spInterpConfig);
90 
91  //Initialize interpolation factor control from value in the configuration
92  mMagInterpolationFactorCtl.DoControl(mConfig.GetMagInterpolationFactor());
93  mFreqInterpolationFactorCtl.DoControl(mConfig.GetFreqInterpolationFactor());
94  mPitchInterpolationFactorCtl.DoControl(mConfig.GetPitchInterpolationFactor());
95  mResidualInterpolationFactorCtl.DoControl(mConfig.GetResidualInterpolationFactor());
96  mIsHarmonicCtl.DoControl(mConfig.GetHarmonic());
97 
98  return true;
99  }
100 
101  void FrameInterpolator::AttachChildren()
102  {
103  mPO_SpectrumInterpolator.SetParent(this);
104  mPO_PeaksInterpolator.SetParent(this);
105  }
106 
107 
108  // Unsupervised Do() function.
109  bool FrameInterpolator::Do(const Frame& in1, const Frame& in2, Frame& out)
110  {
112  "FrameInterpolator::Do(): Not in execution mode");
113 
114  if(in1.GetFundamentalFreq()!=0 && in2.GetFundamentalFreq()!=0 && mConfig.GetHarmonic())
116  else mIsHarmonicCtl.DoControl(0);
117 
120 
122  if(!mIsHarmonicCtl.GetLastValue()) newPitch=0;
123  //Sets new fund freq
124 
125  if(out.GetFundamental().GetnCandidates()==0)
126  out.GetFundamental().AddElem(newPitch,0);
127  else
128  out.GetFundamental().SetFreq(0,newPitch);
129  out.GetFundamental().SetnCandidates(1);
130 
131  if(mConfig.GetUseSpectralShape())
132  mPO_PeaksInterpolator.Do(
133  in1.GetSpectralPeakArray(),
134  in2.GetSpectralPeakArray(),
136  out.GetSpectralPeakArray() );
137  else
138  mPO_PeaksInterpolator.Do(in1.GetSpectralPeakArray(),in2.GetSpectralPeakArray(),out.GetSpectralPeakArray());
139  mPO_SpectrumInterpolator.Do(in1.GetResidualSpec(),in2.GetResidualSpec(),out.GetResidualSpec());
140 
141  return true;
142  }
143 
145  {
146  CLAM_ASSERT(false,"FrameInterpolator::Do(): Not implemented");
147 
148  return true;
149  }
150 
151 
152  void FrameInterpolator::DoFrameFactorControl(TControlData value)
153  {
158  }
159 
160  void FrameInterpolator::DoMagFactorControl(TControlData value)
161  {
162  mPO_PeaksInterpolator.mMagInterpolationFactorCtl.DoControl(value);
163  }
164 
165  void FrameInterpolator::DoFreqFactorControl(TControlData value)
166  {
167  mPO_PeaksInterpolator.mFreqInterpolationFactorCtl.DoControl(value);
168  }
169 
170  void FrameInterpolator::DoPitchFactorControl(TControlData value)
171  {
172  mPO_PeaksInterpolator.mPitchInterpolationFactorCtl.DoControl(value);
173  }
174 
175  void FrameInterpolator::DoResidualFactorControl(TControlData value)
176  {
177  mPO_SpectrumInterpolator.mInterpolationFactorCtl.DoControl(value);
178  }
179 
180  void FrameInterpolator::DoPitch1Control(TControlData value)
181  {
182  mPO_PeaksInterpolator.mPitch1Ctl.DoControl(value);
183  }
184 
185  void FrameInterpolator::DoPitch2Control(TControlData value)
186  {
187  mPO_PeaksInterpolator.mPitch2Ctl.DoControl(value);
188  }
189 
190  void FrameInterpolator::DoHarmonicControl(TControlData value)
191  {
192  mPO_PeaksInterpolator.mIsHarmonicCtl.DoControl(value);
193  }
194 
195 
196 
197 }
198