CLAM-Development  1.4.0
SMSMorph.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 "SMSMorph.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "SMSMorph",
32  "category", "SMS Transformations",
33  "description", "SMSMorph",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, SMSMorph> reg = metadata;
37 }
38 
39 bool SMSMorph::Do(const Frame& in1, const Frame& in2, Frame& out)
40 {
41  return Do( in1.GetSpectralPeakArray(),
42  in1.GetFundamental(),
43  in1.GetResidualSpec(),
44 
45  in2.GetSpectralPeakArray(),
46  in2.GetFundamental(),
47  in2.GetResidualSpec(),
48 
49  out.GetSpectralPeakArray(),
50  out.GetFundamental(),
51  out.GetResidualSpec()
52  );
53 }
54 
55 bool SMSMorph::Do( const SpectralPeakArray& inPeaks1,
56  const Fundamental& inFund1,
57  const Spectrum& inSpectrum1,
58 
59  const SpectralPeakArray& inPeaks2,
60  const Fundamental& inFund2,
61  const Spectrum& inSpectrum2,
62 
63  SpectralPeakArray& outPeaks,
64  Fundamental& outFund,
65  Spectrum& outSpectrum
66  )
67 {
68  bool Harmonic = false;
69  if ( inFund1.GetFreq()!=0 && inFund2.GetFreq()!=0 && mConfig.GetIsHarmonic1() && mConfig.GetIsHarmonic2 () )
70  Harmonic = true;
71 
72  TData alpha = mInterpolationFactor.GetLastValue();
73 
74  TData newPitch = (1. - alpha)*inFund1.GetFreq() + alpha*inFund2.GetFreq();
75  if( Harmonic ) newPitch=0;
76  //Sets new fund freq
77  if (outFund.GetnCandidates()==0)
78  outFund.AddElem(newPitch,0);
79  else
80  outFund.SetFreq(0,newPitch);
81  outFund.SetnCandidates(1);
82 
83  SendFloatToInControl(mPeaksInterpolator,"MagInterpolationFactor",alpha);
84 // mPeaksInterpolator.GetInControl("FreqInterpolationFactor").DoControl(alpha);
85 // mPeaksInterpolator.GetInControl("PitchInterpolationFactor").DoControl(alpha);
86  mPeaksInterpolator.Do(inPeaks1, inPeaks2, outPeaks);
87 
88 
89 //TODO separate alpha/interpolation value for peaks and residual????
90 
91  outSpectrum = inSpectrum1; //FIXME asserts without this...
92  CLAM_DEBUG_ASSERT( inSpectrum1.GetSize()==inSpectrum2.GetSize(), "Expected two spectrums of the same size");
93  SendFloatToInControl(mSpectrumInterpolator,"InterpolationFactor",alpha);
94 
95 // TODO fix (and check SpectrumInterpolator bug... (add/fix const inputs) mSpectrumInterpolator.Do(inSpectrum1, inSpectrum2, outSpectrum);)
96  mSpectrumInterpolator.Do(const_cast<Spectrum&>(inSpectrum1), const_cast<Spectrum&>(inSpectrum2), outSpectrum);
97 
98  return true;
99 }
100 
102 {
103  CopyAsConcreteConfig( mConfig, config );
104 
105  mInterpolationFactor.SetBounds(0.,1.);
106  mInterpolationFactor.SetDefaultValue(0.5);
107 
108  return true;
109 }
110 
111 }