CLAM-Development  1.4.0
SMSPitchDiscretization.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 
23 #include "ProcessingFactory.hxx"
24 
25 
26 
27 namespace CLAM
28 {
29 
30 
31 namespace Hidden
32 {
33  static const char * metadata[] = {
34  "key", "SMSPitchDiscretization",
35  "category", "SMS Transformations",
36  "description", "SMSPitchDiscretization",
37  0
38  };
39  static FactoryRegistrator<ProcessingFactory, SMSPitchDiscretization> reg = metadata;
40 }
41 
42 bool SMSPitchDiscretization::Do(const Frame& in, Frame& out)
43 {
44  return Do(in.GetSpectralPeakArray(),
45  in.GetFundamental(),
46  in.GetSpectrum(),
47 
48  out.GetSpectralPeakArray(),
49  out.GetFundamental(),
50  out.GetSpectrum()
51  );
52 }
53 
55  const Fundamental& inFund,
56  const Spectrum& inSpectrum,
57  SpectralPeakArray& outPeaks,
58  Fundamental& outFund,
59  Spectrum& outSpectrum
60  )
61 {
62  outPeaks = inPeaks;
63  outFund = inFund;
64  outSpectrum = inSpectrum;
65 
66  TData pitch = inFund.GetFreq();
67 
68  if (pitch>0)
69  {
70  TData log2=0.69314718f;
71 
72  int nst = Round(12*log(pitch/55)/log2);
73  TData pow2_1_12=1.0594630f;
74  TData discPitch=55*(CLAM_pow(pow2_1_12,nst));
75 
76  TData amount=discPitch/pitch;
77 
78  SendFloatToInControl(mPitchShift,"PitchSteps",amount);
79  mPitchShift.Do( inPeaks,
80  inFund,
81  inSpectrum,
82  outPeaks,
83  outFund,
84  outSpectrum);
85 
86  Fundamental tmpFund;
87  tmpFund.AddElem(discPitch);
88  outFund = tmpFund;
89  }
90  return true;
91 }
92 
93 
94 }