SMSHarmonizer.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 _SMSHarmonizer_
00024 #define _SMSHarmonizer_
00025 
00026 #include "SMSHarmonizerConfig.hxx"
00027 #include "Frame.hxx"
00028 #include "InPort.hxx"
00029 #include "OutPort.hxx"
00030 #include "InControl.hxx"
00031 #include "InControlArray.hxx"
00032 #include "FrameTransformation.hxx"
00033 #include "SpectralPeakArray.hxx"
00034 #include "SMSPitchShift.hxx"
00035 #include "SpectrumAdder2.hxx"
00036 #include "SMSSinusoidalGain.hxx"
00037 #include "TokenDelay.hxx"
00038 #include "SpectralPeakArray.hxx"
00039 
00040 namespace CLAM{
00041 
00046         class SMSHarmonizer: public FrameTransformation
00047         {       
00048 
00052                 const char *GetClassName() const { return "SMSHarmonizer"; }
00053                 
00054                 InPort<SpectralPeakArray> mInPeaks;
00055                 OutPort<SpectralPeakArray> mOutPeaks;
00056                 InPort<Fundamental> mInFund;
00057                 OutPort<Fundamental> mOutFund;
00058                 InPort<Spectrum> mInSpectrum;
00059                 OutPort<Spectrum> mOutSpectrum;
00060 
00061                 FloatInControl mInputVoiceGain; 
00062 
00063                 //(fixed) max amount of voices: adding many voices is translated into many performance issues
00064                 #define MAX_AMOUNT_OF_VOICES 6
00065 
00066                 InControlArray mVoicesPitch; 
00067                 InControlArray mVoicesGain; 
00068                 InControlArray mVoicesDetuningAmount; 
00069                 InControlArray mVoicesDelay; 
00070 
00071                 // FIXME move ore remove this?
00072                 #define frand() ( float( rand() ) / float(RAND_MAX) )
00073 
00078                 bool mIgnoreResidual;
00079         public:
00080                 SMSHarmonizer()
00081                         :
00082                         mInPeaks("In SpectralPeaks", this),
00083                         mOutPeaks("Out SpectralPeaks", this),
00084                         mInFund("In Fundamental", this),
00085                         mOutFund("Out Fundamental", this),
00086                         mInSpectrum("In Spectrum", this),
00087                         mOutSpectrum("Out Spectrum", this),
00088 
00089                         mInputVoiceGain("Input Voice Gain", this),
00090                         mVoicesPitch(0, "Pitch", this),
00091                         mVoicesGain(0, "Gain", this),
00092                         mVoicesDetuningAmount(0, "Voice Detuning", this),
00093                         mVoicesDelay(0, "Voice Delay", this)
00094                 {
00095                         Configure( mConfig );
00096                 }
00097 
00098                 ~SMSHarmonizer() {}
00099 
00100                 bool Do()
00101                 {
00102                         bool result = Do(mInPeaks.GetData(), 
00103                                          mInFund.GetData(), 
00104                                          mInSpectrum.GetData(), 
00105                                          mOutPeaks.GetData(), 
00106                                          mOutFund.GetData(),
00107                                          mOutSpectrum.GetData() 
00108                                          );
00109 
00110                         mInPeaks.Consume(); 
00111                         mInFund.Consume(); 
00112                         mInSpectrum.Consume(); 
00113                         mOutPeaks.Produce(); 
00114                         mOutFund.Produce();
00115                         mOutSpectrum.Produce();
00116 
00117                         return result;
00118                 }
00119                 
00120                 bool Do(const Frame& in, Frame& out);
00121 
00122                 bool Do(const SpectralPeakArray& inPeaks,
00123                         const Fundamental& inFund,
00124                         const Spectrum& inSpectrum,
00125                         SpectralPeakArray& outPeaks,
00126                         Fundamental& outFund,
00127                         Spectrum& outSpectrum
00128                         );
00129 
00130                 int IgnoreResidual(TControlData value)
00131                 {
00132                         mPitchShift.mIgnoreResidual.DoControl(value);
00133                         return 0;
00134                 }
00135 
00136                 typedef SMSHarmonizerConfig Config;
00137 
00138                 const ProcessingConfig & GetConfig() const
00139                 {
00140                         return mConfig;
00141                 }
00142 
00143         protected:
00144                 bool ConcreteConfigure(const ProcessingConfig& config);
00145 
00146         private:
00147                 Config mConfig;
00148 
00149 
00151                 SMSPitchShift mPitchShift;
00152                 SpectrumAdder2 mSpectrumAdder;
00153                 SMSSinusoidalGain mSinusoidalGain;
00154 
00155                 TokenDelay<SpectralPeakArray> mPeaksDelay;
00156 
00157         };      
00158         
00159 };//namespace CLAM
00160 
00161 #endif // _SMSHarmonizer_
00162 
Generated by  doxygen 1.6.3