CLAM-Development  1.4.0
SegmentSMSHarmonizer.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 _SegmentSMSHarmonizer_
24 #define _SegmentSMSHarmonizer_
25 
26 #include "SMSPitchShift.hxx"
27 #include "SpectrumAdder2.hxx"
28 #include "FrameTransformation.hxx"
29 
30 
31 // TODO: this transformation needs to be ported to inherit from FrameTransformation instead of SegmentTransformation
32 // also, a solution has to be figured out to make the transformation controllable via ports
33 
34 namespace CLAM{
35 
36 
38  {
39 
43  const char *GetClassName() const {return "SegmentSMSHarmonizer";}
44 
45  FloatInControl mIndexCtl;//says what the amount sent as control is modifying
46  FloatInControl mTransCtl;
50  FloatInControl mIgnoreResidualCtl;
51  FloatInControl mUpdateBPFCtl;
52  public:
53 
54  void UpdateBPF(TControlData value)
55  {
56  CLAM::BPF& bpf= mConfig.GetBPF();
57  //this should never happen, it should be initialized at configuration time
58  if(bpf.Size()==0)
59  {
60  InitBPF();
61  }
62 
63  bpf.SetValue((int)mIndexCtl.GetLastValue(), mTransCtl.GetLastValue());
64  }
66  {
67  mPitchShift.mIgnoreResidual.DoControl(value);
68  }
69  public:
72  : mIndexCtl("Index", this)
73  , mTransCtl("Transposition",this)
74  , mIgnoreResidualCtl("IgnoreResidual",this, &SegmentSMSHarmonizer::IgnoreResidual)
75  , mUpdateBPFCtl("UpdateBPF", this, &SegmentSMSHarmonizer::UpdateBPF)
76  {
78  mTmpFrame.AddAll();
79  mTmpFrame.UpdateData();
80  mTmpFund.AddElem();
81  }
82 
84  {
86  InitBPF();
87  mPitchShift.Configure(FrameTransformationConfig());
88  //By default we ignore residual!!
89  mIgnoreResidualCtl.DoControl(1.);
90  return true;
91  }
92 
95  {}
96 
97  bool Do()
98  {
99  CLAM_ASSERT(false, "Do with ports not implemented");
100  return false;
101  }
102 
103  bool Do(const Frame& in, Frame& out);
104  private:
105  SMSPitchShift mPitchShift;
106  SpectrumAdder2 mSpectrumAdder;
107  void AddFrame(const Frame& in1, const Frame& in2, Frame& out);
108  void Gain(Frame& inputFrame, TData gain);
109 
110  Fundamental mTmpFund;
111  Frame mTmpFrame;
112 
113  void InitBPF()
114  {
115  if (!mConfig.HasBPF())
116  {
117  mConfig.AddBPF();
119  }
120  if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before
121  {
122  BPF& bpf=mConfig.GetBPF();
123  bpf.Resize(10);
124  bpf.SetSize(10);
125  int i;
126  //we add ten voices with gain going from -30 to +30 but no transposition (note that X controls gain and Y transposition)
127  for (i=0; i< 10; i++)
128  {
129  bpf.SetValue(i,1);
130  bpf.SetXValue(i,(i-5)*6);
131  }
132  }
133  }
134 
135 
136  };
137 };//namespace CLAM
138 
139 #endif // _SegmentSMSHarmonizer_
140