SegmentSMSHarmonizer.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifndef _SegmentSMSHarmonizer_
00024 #define _SegmentSMSHarmonizer_
00025 
00026 #include "SMSPitchShift.hxx"
00027 #include "SpectrumAdder2.hxx"
00028 #include "FrameTransformation.hxx"
00029 
00030 
00031 // TODO: this transformation needs to be ported to inherit from FrameTransformation instead of SegmentTransformation
00032 //               also, a solution has to be figured out to make the transformation controllable via ports
00033 
00034 namespace CLAM{
00035 
00036 
00037         class SegmentSMSHarmonizer: public FrameTransformation
00038         {
00039                 
00043                 const char *GetClassName() const {return "SegmentSMSHarmonizer";}
00044                 
00045                 FloatInControl mIndexCtl;//says what the amount sent as control is modifying
00046                 FloatInControl mTransCtl;
00050                 FloatInControl mIgnoreResidualCtl;
00051                 FloatInControl mUpdateBPFCtl;
00052         public:
00053                         
00054                 void UpdateBPF(TControlData value)
00055                 {
00056                         CLAM::BPF& bpf= mConfig.GetBPF();
00057                         //this should never happen, it should be initialized at configuration time
00058                         if(bpf.Size()==0)
00059                         {
00060                                 InitBPF();
00061                         }
00062                         
00063                         bpf.SetValue((int)mIndexCtl.GetLastValue(), mTransCtl.GetLastValue());
00064                 }
00065                 void IgnoreResidual(TControlData value)
00066                 {
00067                         mPitchShift.mIgnoreResidual.DoControl(value);
00068                 }
00069         public:
00071                 SegmentSMSHarmonizer()
00072                         : mIndexCtl("Index", this)
00073                         , mTransCtl("Transposition",this)
00074                         , mIgnoreResidualCtl("IgnoreResidual",this, &SegmentSMSHarmonizer::IgnoreResidual)
00075                         , mUpdateBPFCtl("UpdateBPF", this, &SegmentSMSHarmonizer::UpdateBPF)
00076                 {
00077                         Configure(FrameTransformationConfig());
00078                         mTmpFrame.AddAll();
00079                         mTmpFrame.UpdateData();
00080                         mTmpFund.AddElem();
00081                 }
00082                 
00083                 bool ConcreteConfigure(const ProcessingConfig& c)
00084                 {
00085                         CopyAsConcreteConfig( mConfig, c );
00086                         InitBPF();
00087                         mPitchShift.Configure(FrameTransformationConfig());
00088                         //By default we ignore residual!!
00089                         mIgnoreResidualCtl.DoControl(1.);
00090                         return true;
00091                 }
00092 
00094                 ~SegmentSMSHarmonizer()
00095                 {}
00096                 
00097                 bool Do()
00098                 {
00099                         CLAM_ASSERT(false, "Do with ports not implemented");
00100                         return false;
00101                 }
00102                 
00103                 bool Do(const Frame& in, Frame& out);
00104         private:
00105                 SMSPitchShift mPitchShift;
00106                 SpectrumAdder2 mSpectrumAdder;
00107                 void AddFrame(const Frame& in1, const Frame& in2, Frame& out);
00108                 void Gain(Frame& inputFrame, TData gain);
00109                 
00110                 Fundamental mTmpFund;
00111                 Frame mTmpFrame;
00112                 
00113                 void InitBPF()
00114                 {
00115                         if (!mConfig.HasBPF())
00116                         {
00117                                 mConfig.AddBPF();
00118                                 mConfig.UpdateData();
00119                         }
00120                         if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before
00121                         {
00122                                 BPF& bpf=mConfig.GetBPF();
00123                                 bpf.Resize(10);
00124                                 bpf.SetSize(10);
00125                                 int i;
00126                                 //we add ten voices with gain going from -30 to +30 but no transposition (note that X controls gain and Y transposition)
00127                                 for (i=0; i< 10; i++)
00128                                 {
00129                                         bpf.SetValue(i,1);
00130                                         bpf.SetXValue(i,(i-5)*6);
00131                                 }
00132                         }
00133                 }
00134                 
00135         
00136         };              
00137 };//namespace CLAM
00138 
00139 #endif // _SegmentSMSHarmonizer_
00140 
Generated by  doxygen 1.6.3