FrameInterpolator.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #include "Complex.hxx"
00023 #include "SpecTypeFlags.hxx"
00024 #include "FrameInterpolator.hxx"
00025 #include "BPF.hxx"
00026 #include "Point.hxx"
00027 
00028 namespace CLAM {
00029 
00030         void FrameInterpConfig::DefaultInit()
00031         {
00032                 AddAll();
00033                 UpdateData();
00034                 DefaultValues();
00035         }
00036 
00037         void FrameInterpConfig::DefaultValues()
00038         {
00039                 SetMagInterpolationFactor( 0.0 );
00040                 SetFreqInterpolationFactor( 0.0 );
00041                 SetPitchInterpolationFactor( 0.0 );
00042                 SetResidualInterpolationFactor( 0.0 );
00043                 SetHarmonic( true );
00044                 SetUseSpectralShape(false);
00045         }
00046 
00047 
00048         FrameInterpolator::FrameInterpolator()
00049                 : mFrameInterpolationFactorCtl("FrameInterpolationFactor",this,&FrameInterpolator::DoFrameFactorControl),
00050                   mMagInterpolationFactorCtl("MagInterpolationFactor",this,&FrameInterpolator::DoMagFactorControl),
00051                   mFreqInterpolationFactorCtl("FreqInterpolationFactor",this,&FrameInterpolator::DoFreqFactorControl),
00052                   mPitchInterpolationFactorCtl("PitchInterpolationFactor",this,&FrameInterpolator::DoPitchFactorControl),
00053                   mResidualInterpolationFactorCtl("ResidualInterpolationFactor",this,&FrameInterpolator::DoResidualFactorControl),
00054                   mPitch1Ctl("Pitch1",this,&FrameInterpolator::DoPitch1Control),
00055                   mPitch2Ctl("Pitch2",this,&FrameInterpolator::DoPitch2Control),
00056                   mIsHarmonicCtl("IsHarmonic",this,&FrameInterpolator::DoHarmonicControl),
00057                   mIn1("Input 1",this),
00058                   mIn2("Input 2",this),
00059                   mOut("Output",this),
00060                   mpSpectralShape(0)
00061         {
00062                 AttachChildren();
00063                 Configure(FrameInterpConfig());
00064         }
00065 
00066         FrameInterpolator::FrameInterpolator(const FrameInterpConfig &c)
00067                 : mFrameInterpolationFactorCtl("FrameInterpolationFactor",this,&FrameInterpolator::DoFrameFactorControl),
00068                   mMagInterpolationFactorCtl("MagInterpolationFactor",this,&FrameInterpolator::DoMagFactorControl),
00069                   mFreqInterpolationFactorCtl("FreqInterpolationFactor",this,&FrameInterpolator::DoFreqFactorControl),
00070                   mPitchInterpolationFactorCtl("PitchInterpolationFactor",this,&FrameInterpolator::DoPitchFactorControl),
00071                   mResidualInterpolationFactorCtl("ResidualInterpolationFactor",this,&FrameInterpolator::DoResidualFactorControl),
00072                   mPitch1Ctl("Pitch1",this,&FrameInterpolator::DoPitch1Control),
00073                   mPitch2Ctl("Pitch2",this,&FrameInterpolator::DoPitch2Control),
00074                   mIsHarmonicCtl("IsHarmonic",this,&FrameInterpolator::DoHarmonicControl),
00075                   mIn1("Input 1",this),
00076                   mIn2("Input 2",this),
00077                   mOut("Output",this),
00078                   mpSpectralShape(0)
00079         {
00080                 AttachChildren();
00081                 Configure(c);
00082         }
00083 
00084 
00085         bool FrameInterpolator::ConcreteConfigure(const ProcessingConfig&c)
00086         {
00087                 CopyAsConcreteConfig(mConfig, c);
00088 
00089                 //Configure children processing
00090                 PeaksInterpConfig pkInterpConfig;
00091                 pkInterpConfig.SetMagInterpolationFactor(mConfig.GetMagInterpolationFactor());
00092                 pkInterpConfig.SetFreqInterpolationFactor(mConfig.GetFreqInterpolationFactor());
00093                 pkInterpConfig.SetPitchInterpolationFactor(mConfig.GetPitchInterpolationFactor());
00094                 pkInterpConfig.SetHarmonic(mConfig.GetHarmonic());
00095                 pkInterpConfig.SetUseSpectralShape(mConfig.GetUseSpectralShape());
00096                 mPO_PeaksInterpolator.Configure(pkInterpConfig);
00097 
00098                 //todo: using Interpolator with ports is still not available!!
00099                 if(mConfig.GetUseSpectralShape())
00100                 {
00101                         mPO_PeaksInterpolator.AttachSpectralShape(*mpSpectralShape);
00102                 }
00103 
00104                 SpecInterpConfig spInterpConfig;
00105                 spInterpConfig.SetInterpolationFactor(mConfig.GetResidualInterpolationFactor());
00106 
00107                 mPO_SpectrumInterpolator.Configure(spInterpConfig);
00108 
00109                 //Initialize interpolation factor control from value in the configuration
00110                 mMagInterpolationFactorCtl.DoControl(mConfig.GetMagInterpolationFactor());
00111                 mFreqInterpolationFactorCtl.DoControl(mConfig.GetFreqInterpolationFactor());
00112                 mPitchInterpolationFactorCtl.DoControl(mConfig.GetPitchInterpolationFactor());
00113                 mResidualInterpolationFactorCtl.DoControl(mConfig.GetResidualInterpolationFactor());
00114                 mIsHarmonicCtl.DoControl(mConfig.GetHarmonic());
00115 
00116                 return true;
00117         }
00118 
00119         void FrameInterpolator::AttachChildren()
00120         {
00121                 mPO_SpectrumInterpolator.SetParent(this);
00122                 mPO_PeaksInterpolator.SetParent(this);
00123         }
00124 
00125 
00126         // Unsupervised Do() function.
00127         bool FrameInterpolator::Do(const Frame& in1, const Frame& in2, Frame& out)
00128         {
00129                 CLAM_DEBUG_ASSERT(IsRunning(),
00130                         "FrameInterpolator::Do(): Not in execution mode");
00131 
00132                 if(in1.GetFundamentalFreq()!=0 && in2.GetFundamentalFreq()!=0 && mConfig.GetHarmonic())
00133                         mIsHarmonicCtl.DoControl(1);
00134                 else mIsHarmonicCtl.DoControl(0);
00135 
00136                 mPitch1Ctl.DoControl(in1.GetFundamentalFreq());
00137                 mPitch2Ctl.DoControl(in2.GetFundamentalFreq());
00138 
00139                 TData newPitch=mPitch1Ctl.GetLastValue()*(1-mPitchInterpolationFactorCtl.GetLastValue())+mPitch2Ctl.GetLastValue()*mPitchInterpolationFactorCtl.GetLastValue();
00140                 if(!mIsHarmonicCtl.GetLastValue()) newPitch=0;
00141                 //Sets new fund freq
00142                 
00143                 if(out.GetFundamental().GetnCandidates()==0)
00144                         out.GetFundamental().AddElem(newPitch,0);
00145                 else
00146                         out.GetFundamental().SetFreq(0,newPitch);
00147                 out.GetFundamental().SetnCandidates(1);
00148 
00149                 if(mConfig.GetUseSpectralShape())
00150                         mPO_PeaksInterpolator.Do(
00151                                         in1.GetSpectralPeakArray(),
00152                                         in2.GetSpectralPeakArray(),
00153                                         *mpSpectralShape,
00154                                         out.GetSpectralPeakArray() );
00155                 else
00156                         mPO_PeaksInterpolator.Do(in1.GetSpectralPeakArray(),in2.GetSpectralPeakArray(),out.GetSpectralPeakArray());
00157                 mPO_SpectrumInterpolator.Do(in1.GetResidualSpec(),in2.GetResidualSpec(),out.GetResidualSpec());
00158 
00159                 return true;
00160         }
00161 
00162         bool FrameInterpolator::Do(void)
00163         {
00164                 CLAM_ASSERT(false,"FrameInterpolator::Do(): Not implemented");
00165 
00166                 return true;
00167         }
00168 
00169         
00170         int FrameInterpolator::DoFrameFactorControl(TControlData value)
00171         {
00172                 mMagInterpolationFactorCtl.DoControl(value);
00173                 mFreqInterpolationFactorCtl.DoControl(value);
00174                 mPitchInterpolationFactorCtl.DoControl(value);
00175                 mResidualInterpolationFactorCtl.DoControl(value);
00176                 return 0;
00177         }
00178 
00179         int FrameInterpolator::DoMagFactorControl(TControlData value)
00180         {
00181                 mPO_PeaksInterpolator.mMagInterpolationFactorCtl.DoControl(value);
00182                 return 0;
00183         }
00184 
00185         int FrameInterpolator::DoFreqFactorControl(TControlData value)
00186         {
00187                 mPO_PeaksInterpolator.mFreqInterpolationFactorCtl.DoControl(value);
00188                 return 0;
00189         }
00190 
00191         int FrameInterpolator::DoPitchFactorControl(TControlData value)
00192         {
00193                 mPO_PeaksInterpolator.mPitchInterpolationFactorCtl.DoControl(value);
00194                 return 0;
00195         }
00196 
00197         int FrameInterpolator::DoResidualFactorControl(TControlData value)
00198         {
00199                 mPO_SpectrumInterpolator.mInterpolationFactorCtl.DoControl(value);
00200                 return 0;
00201         }
00202 
00203         int FrameInterpolator::DoPitch1Control(TControlData value)
00204         {
00205                 mPO_PeaksInterpolator.mPitch1Ctl.DoControl(value);
00206                 return 0;
00207         }
00208 
00209         int FrameInterpolator::DoPitch2Control(TControlData value)
00210         {
00211                 mPO_PeaksInterpolator.mPitch2Ctl.DoControl(value);
00212                 return 0;
00213         }
00214 
00215         int FrameInterpolator::DoHarmonicControl(TControlData value)
00216         {
00217                 mPO_PeaksInterpolator.mIsHarmonicCtl.DoControl(value);
00218                 return 0;
00219         }
00220 
00221 
00222 
00223 }
00224 

Generated on Tue Aug 12 22:33:42 2008 for CLAM by  doxygen 1.5.5