SMSMorph.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00085
00086 mPeaksInterpolator.Do(inPeaks1, inPeaks2, outPeaks);
00087
00088
00089
00090
00091 outSpectrum = inSpectrum1;
00092 CLAM_DEBUG_ASSERT( inSpectrum1.GetSize()==inSpectrum2.GetSize(), "Expected two spectrums of the same size");
00093 SendFloatToInControl(mSpectrumInterpolator,"InterpolationFactor",alpha);
00094
00095
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 }