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(const FrameInterpConfig &c)
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(c);
00064         }
00065 
00066 
00067         bool FrameInterpolator::ConcreteConfigure(const ProcessingConfig&c)
00068         {
00069                 CopyAsConcreteConfig(mConfig, c);
00070 
00071                 //Configure children processing
00072                 PeaksInterpConfig pkInterpConfig;
00073                 pkInterpConfig.SetMagInterpolationFactor(mConfig.GetMagInterpolationFactor());
00074                 pkInterpConfig.SetFreqInterpolationFactor(mConfig.GetFreqInterpolationFactor());
00075                 pkInterpConfig.SetPitchInterpolationFactor(mConfig.GetPitchInterpolationFactor());
00076                 pkInterpConfig.SetHarmonic(mConfig.GetHarmonic());
00077                 pkInterpConfig.SetUseSpectralShape(mConfig.GetUseSpectralShape());
00078                 mPO_PeaksInterpolator.Configure(pkInterpConfig);
00079 
00080                 //todo: using Interpolator with ports is still not available!!
00081                 if(mConfig.GetUseSpectralShape())
00082                 {
00083                         mPO_PeaksInterpolator.AttachSpectralShape(*mpSpectralShape);
00084                 }
00085 
00086                 SpecInterpConfig spInterpConfig;
00087                 spInterpConfig.SetInterpolationFactor(mConfig.GetResidualInterpolationFactor());
00088 
00089                 mPO_SpectrumInterpolator.Configure(spInterpConfig);
00090 
00091                 //Initialize interpolation factor control from value in the configuration
00092                 mMagInterpolationFactorCtl.DoControl(mConfig.GetMagInterpolationFactor());
00093                 mFreqInterpolationFactorCtl.DoControl(mConfig.GetFreqInterpolationFactor());
00094                 mPitchInterpolationFactorCtl.DoControl(mConfig.GetPitchInterpolationFactor());
00095                 mResidualInterpolationFactorCtl.DoControl(mConfig.GetResidualInterpolationFactor());
00096                 mIsHarmonicCtl.DoControl(mConfig.GetHarmonic());
00097 
00098                 return true;
00099         }
00100 
00101         void FrameInterpolator::AttachChildren()
00102         {
00103                 mPO_SpectrumInterpolator.SetParent(this);
00104                 mPO_PeaksInterpolator.SetParent(this);
00105         }
00106 
00107 
00108         // Unsupervised Do() function.
00109         bool FrameInterpolator::Do(const Frame& in1, const Frame& in2, Frame& out)
00110         {
00111                 CLAM_DEBUG_ASSERT(IsRunning(),
00112                         "FrameInterpolator::Do(): Not in execution mode");
00113 
00114                 if(in1.GetFundamentalFreq()!=0 && in2.GetFundamentalFreq()!=0 && mConfig.GetHarmonic())
00115                         mIsHarmonicCtl.DoControl(1);
00116                 else mIsHarmonicCtl.DoControl(0);
00117 
00118                 mPitch1Ctl.DoControl(in1.GetFundamentalFreq());
00119                 mPitch2Ctl.DoControl(in2.GetFundamentalFreq());
00120 
00121                 TData newPitch=mPitch1Ctl.GetLastValue()*(1-mPitchInterpolationFactorCtl.GetLastValue())+mPitch2Ctl.GetLastValue()*mPitchInterpolationFactorCtl.GetLastValue();
00122                 if(!mIsHarmonicCtl.GetLastValue()) newPitch=0;
00123                 //Sets new fund freq
00124                 
00125                 if(out.GetFundamental().GetnCandidates()==0)
00126                         out.GetFundamental().AddElem(newPitch,0);
00127                 else
00128                         out.GetFundamental().SetFreq(0,newPitch);
00129                 out.GetFundamental().SetnCandidates(1);
00130 
00131                 if(mConfig.GetUseSpectralShape())
00132                         mPO_PeaksInterpolator.Do(
00133                                         in1.GetSpectralPeakArray(),
00134                                         in2.GetSpectralPeakArray(),
00135                                         *mpSpectralShape,
00136                                         out.GetSpectralPeakArray() );
00137                 else
00138                         mPO_PeaksInterpolator.Do(in1.GetSpectralPeakArray(),in2.GetSpectralPeakArray(),out.GetSpectralPeakArray());
00139                 mPO_SpectrumInterpolator.Do(in1.GetResidualSpec(),in2.GetResidualSpec(),out.GetResidualSpec());
00140 
00141                 return true;
00142         }
00143 
00144         bool FrameInterpolator::Do(void)
00145         {
00146                 CLAM_ASSERT(false,"FrameInterpolator::Do(): Not implemented");
00147 
00148                 return true;
00149         }
00150 
00151         
00152         void FrameInterpolator::DoFrameFactorControl(TControlData value)
00153         {
00154                 mMagInterpolationFactorCtl.DoControl(value);
00155                 mFreqInterpolationFactorCtl.DoControl(value);
00156                 mPitchInterpolationFactorCtl.DoControl(value);
00157                 mResidualInterpolationFactorCtl.DoControl(value);
00158         }
00159 
00160         void FrameInterpolator::DoMagFactorControl(TControlData value)
00161         {
00162                 mPO_PeaksInterpolator.mMagInterpolationFactorCtl.DoControl(value);
00163         }
00164 
00165         void FrameInterpolator::DoFreqFactorControl(TControlData value)
00166         {
00167                 mPO_PeaksInterpolator.mFreqInterpolationFactorCtl.DoControl(value);
00168         }
00169 
00170         void FrameInterpolator::DoPitchFactorControl(TControlData value)
00171         {
00172                 mPO_PeaksInterpolator.mPitchInterpolationFactorCtl.DoControl(value);
00173         }
00174 
00175         void FrameInterpolator::DoResidualFactorControl(TControlData value)
00176         {
00177                 mPO_SpectrumInterpolator.mInterpolationFactorCtl.DoControl(value);
00178         }
00179 
00180         void FrameInterpolator::DoPitch1Control(TControlData value)
00181         {
00182                 mPO_PeaksInterpolator.mPitch1Ctl.DoControl(value);
00183         }
00184 
00185         void FrameInterpolator::DoPitch2Control(TControlData value)
00186         {
00187                 mPO_PeaksInterpolator.mPitch2Ctl.DoControl(value);
00188         }
00189 
00190         void FrameInterpolator::DoHarmonicControl(TControlData value)
00191         {
00192                 mPO_PeaksInterpolator.mIsHarmonicCtl.DoControl(value);
00193         }
00194 
00195 
00196 
00197 }
00198 
Generated by  doxygen 1.6.3