CLAM-Development
1.1
|
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 InControl mIndexCtl;//says what the amount sent as control is modifying 00046 InControlTmpl<SegmentSMSHarmonizer> mUpdateBPFCtl;//"boolean" control used to say that we want to update BPF 00047 InControl mTransCtl; 00051 InControlTmpl<SegmentSMSHarmonizer> mIgnoreResidualCtl; 00052 public: 00053 00054 int 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 return 0; 00065 } 00066 int IgnoreResidual(TControlData value) 00067 { 00068 return mPitchShift.mIgnoreResidual.DoControl(value); 00069 } 00070 public: 00072 SegmentSMSHarmonizer(): 00073 mIndexCtl("Index", this), 00074 mTransCtl("Transposition",this), 00075 mIgnoreResidualCtl("IgnoreResidual",this, &SegmentSMSHarmonizer::IgnoreResidual, true), 00076 mUpdateBPFCtl("UpdateBPF", this, &SegmentSMSHarmonizer::UpdateBPF, true) 00077 { 00078 Configure(FrameTransformationConfig()); 00079 mTmpFrame.AddAll(); 00080 mTmpFrame.UpdateData(); 00081 mTmpFund.AddElem(); 00082 } 00083 00084 bool ConcreteConfigure(const ProcessingConfig& c) 00085 { 00086 CopyAsConcreteConfig( mConfig, c ); 00087 InitBPF(); 00088 mPitchShift.Configure(FrameTransformationConfig()); 00089 //By default we ignore residual!! 00090 mIgnoreResidualCtl.DoControl(1.); 00091 return true; 00092 } 00093 00095 ~SegmentSMSHarmonizer() 00096 {} 00097 00098 bool Do() 00099 { 00100 CLAM_ASSERT(false, "Do with ports not implemented"); 00101 return false; 00102 } 00103 00104 bool Do(const Frame& in, Frame& out); 00105 private: 00106 SMSPitchShift mPitchShift; 00107 SpectrumAdder2 mSpectrumAdder; 00108 void AddFrame(const Frame& in1, const Frame& in2, Frame& out); 00109 void Gain(Frame& inputFrame, TData gain); 00110 00111 Fundamental mTmpFund; 00112 Frame mTmpFrame; 00113 00114 void InitBPF() 00115 { 00116 if (!mConfig.HasBPF()) 00117 { 00118 mConfig.AddBPF(); 00119 mConfig.UpdateData(); 00120 } 00121 if(mConfig.GetBPF().Size()==0)//else we asume that the user has initialized it before 00122 { 00123 BPF& bpf=mConfig.GetBPF(); 00124 bpf.Resize(10); 00125 bpf.SetSize(10); 00126 int i; 00127 //we add ten voices with gain going from -30 to +30 but no transposition (note that X controls gain and Y transposition) 00128 for (i=0; i< 10; i++) 00129 { 00130 bpf.SetValue(i,1); 00131 bpf.SetXValue(i,(i-5)*6); 00132 } 00133 } 00134 } 00135 00136 00137 }; 00138 };//namespace CLAM 00139 00140 #endif // _SegmentSMSHarmonizer_ 00141