CLAM-Development  1.4.0
SMSHarmonizer.hxx
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 
23 #ifndef _SMSHarmonizer_
24 #define _SMSHarmonizer_
25 
26 #include "SMSHarmonizerConfig.hxx"
27 #include "Frame.hxx"
28 #include "InPort.hxx"
29 #include "OutPort.hxx"
30 #include "InControl.hxx"
31 #include "InControlArray.hxx"
32 #include "FrameTransformation.hxx"
33 #include "SpectralPeakArray.hxx"
34 #include "SMSPitchShift.hxx"
35 #include "SpectrumAdder2.hxx"
36 #include "SMSSinusoidalGain.hxx"
37 #include "TokenDelay.hxx"
38 #include "SpectralPeakArray.hxx"
39 
40 namespace CLAM{
41 
47  {
48 
52  const char *GetClassName() const { return "SMSHarmonizer"; }
53 
56  InPort<Fundamental> mInFund;
57  OutPort<Fundamental> mOutFund;
58  InPort<Spectrum> mInSpectrum;
59  OutPort<Spectrum> mOutSpectrum;
60 
61  FloatInControl mInputVoiceGain;
62 
63  //(fixed) max amount of voices: adding many voices is translated into many performance issues
64  #define MAX_AMOUNT_OF_VOICES 6
65 
66  InControlArray mVoicesPitch;
67  InControlArray mVoicesGain;
68  InControlArray mVoicesDetuningAmount;
69  InControlArray mVoicesDelay;
70 
71  // FIXME move ore remove this?
72  #define frand() ( float( rand() ) / float(RAND_MAX) )
73 
78  bool mIgnoreResidual;
79  public:
81  :
82  mInPeaks("In SpectralPeaks", this),
83  mOutPeaks("Out SpectralPeaks", this),
84  mInFund("In Fundamental", this),
85  mOutFund("Out Fundamental", this),
86  mInSpectrum("In Spectrum", this),
87  mOutSpectrum("Out Spectrum", this),
88 
89  mInputVoiceGain("Input Voice Gain", this),
90  mVoicesPitch(0, "Pitch", this),
91  mVoicesGain(0, "Gain", this),
92  mVoicesDetuningAmount(0, "Voice Detuning", this),
93  mVoicesDelay(0, "Voice Delay", this)
94  {
95  Configure( mConfig );
96  }
97 
99 
100  bool Do()
101  {
102  bool result = Do(mInPeaks.GetData(),
103  mInFund.GetData(),
104  mInSpectrum.GetData(),
105  mOutPeaks.GetData(),
106  mOutFund.GetData(),
107  mOutSpectrum.GetData()
108  );
109 
110  mInPeaks.Consume();
111  mInFund.Consume();
112  mInSpectrum.Consume();
113  mOutPeaks.Produce();
114  mOutFund.Produce();
115  mOutSpectrum.Produce();
116 
117  return result;
118  }
119 
120  bool Do(const Frame& in, Frame& out);
121 
122  bool Do(const SpectralPeakArray& inPeaks,
123  const Fundamental& inFund,
124  const Spectrum& inSpectrum,
125  SpectralPeakArray& outPeaks,
126  Fundamental& outFund,
127  Spectrum& outSpectrum
128  );
129 
131  {
132  mPitchShift.mIgnoreResidual.DoControl(value);
133  return 0;
134  }
135 
137 
138  const ProcessingConfig & GetConfig() const
139  {
140  return mConfig;
141  }
142 
143  protected:
144  bool ConcreteConfigure(const ProcessingConfig& config);
145 
146  private:
147  Config mConfig;
148 
149 
151  SMSPitchShift mPitchShift;
152  SpectrumAdder2 mSpectrumAdder;
153  SMSSinusoidalGain mSinusoidalGain;
154 
155  TokenDelay<SpectralPeakArray> mPeaksDelay;
156 
157  };
158 
159 };//namespace CLAM
160 
161 #endif // _SMSHarmonizer_
162