SMSMorph.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 "SMSMorph.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 
00028 namespace Hidden
00029 {
00030         static const char * metadata[] = {
00031                 "key", "SMSMorph",
00032                 "category", "SMS Transformations",
00033                 "description", "SMSMorph",
00034                 0
00035         };
00036         static FactoryRegistrator<ProcessingFactory, SMSMorph> reg = metadata;
00037 }
00038 
00039 bool SMSMorph::Do(const Frame& in1, const Frame& in2, Frame& out)
00040 {
00041         return Do( in1.GetSpectralPeakArray(),
00042                    in1.GetFundamental(),
00043                    in1.GetResidualSpec(),
00044 
00045                    in2.GetSpectralPeakArray(),
00046                    in2.GetFundamental(),
00047                    in2.GetResidualSpec(),
00048 
00049                    out.GetSpectralPeakArray(),
00050                    out.GetFundamental(), 
00051                    out.GetResidualSpec() 
00052                  );
00053 }
00054 
00055 bool SMSMorph::Do( const SpectralPeakArray& inPeaks1, 
00056                    const Fundamental& inFund1,
00057                    const Spectrum& inSpectrum1,
00058 
00059                    const SpectralPeakArray& inPeaks2,
00060                    const Fundamental& inFund2,
00061                    const Spectrum& inSpectrum2,
00062 
00063                    SpectralPeakArray& outPeaks,
00064                    Fundamental& outFund,
00065                    Spectrum& outSpectrum
00066                  )
00067 {
00068         bool Harmonic = false;
00069         if ( inFund1.GetFreq()!=0 && inFund2.GetFreq()!=0 && mConfig.GetIsHarmonic1() && mConfig.GetIsHarmonic2 () )
00070                 Harmonic = true;
00071 
00072         TData alpha = mInterpolationFactor.GetLastValue();
00073 
00074         TData newPitch = (1. - alpha)*inFund1.GetFreq() + alpha*inFund2.GetFreq();
00075         if( Harmonic ) newPitch=0;
00076         //Sets new fund freq
00077         if (outFund.GetnCandidates()==0)
00078                 outFund.AddElem(newPitch,0);
00079         else
00080                 outFund.SetFreq(0,newPitch);
00081         outFund.SetnCandidates(1);
00082 
00083         SendFloatToInControl(mPeaksInterpolator,"MagInterpolationFactor",alpha);
00084 //      mPeaksInterpolator.GetInControl("FreqInterpolationFactor").DoControl(alpha);
00085 //      mPeaksInterpolator.GetInControl("PitchInterpolationFactor").DoControl(alpha);
00086         mPeaksInterpolator.Do(inPeaks1, inPeaks2, outPeaks);
00087 
00088 
00089 //TODO separate alpha/interpolation value for peaks and residual????
00090 
00091         outSpectrum = inSpectrum1; //FIXME asserts without this...
00092         CLAM_DEBUG_ASSERT( inSpectrum1.GetSize()==inSpectrum2.GetSize(), "Expected two spectrums of the same size");
00093         SendFloatToInControl(mSpectrumInterpolator,"InterpolationFactor",alpha);
00094 
00095 //      TODO fix (and check SpectrumInterpolator bug... (add/fix const inputs) mSpectrumInterpolator.Do(inSpectrum1, inSpectrum2, outSpectrum);)
00096         mSpectrumInterpolator.Do(const_cast<Spectrum&>(inSpectrum1), const_cast<Spectrum&>(inSpectrum2), outSpectrum);
00097 
00098         return true;
00099 }
00100 
00101 bool SMSMorph::ConcreteConfigure(const ProcessingConfig& config)
00102 {
00103         CopyAsConcreteConfig( mConfig, config );
00104 
00105         mInterpolationFactor.SetBounds(0.,1.);
00106         mInterpolationFactor.SetDefaultValue(0.5);
00107 
00108         return true;
00109 }
00110 
00111 }
Generated by  doxygen 1.6.3