AutoPanner.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 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 #include "AutoPanner.hxx"
00023 #include "OSDefines.hxx"
00024 #include "CLAM_Math.hxx"
00025 #include "ProcessingFactory.hxx"
00026 
00027 
00028 
00029 namespace CLAM
00030 {
00031 
00032 namespace Hidden
00033 {
00034         static const char * metadata[] = {
00035                 "key", "AutoPanner",
00036                 "category", "Controls",
00037                 "description", "AutoPanner",
00038                 0
00039         };
00040         static FactoryRegistrator<ProcessingFactory, AutoPanner> reg = metadata;
00041 }
00042 
00043 void AutoPannerConfig::DefaultInit(void)
00044 {
00045         AddAll();       
00046         UpdateData();   
00047         SetFrequency(440.0);
00048         SetPhase(0.0);
00049         SetSamplingRate( 44100 );
00050         SetFrameSize( 512 );
00051 }
00052 
00053 AutoPanner::AutoPanner()
00054         : mLeft("Left Control", this ),
00055           mRight("Right Control", this )
00056 {
00057         AutoPannerConfig cfg;
00058 
00059         Configure(cfg);
00060 }
00061 
00062 AutoPanner::AutoPanner( const AutoPannerConfig & cfg)
00063         : mLeft("Left Control", this ),
00064           mRight("Right Control", this )
00065 {
00066 
00067         Configure(cfg);
00068 }
00069 
00070 
00071 bool AutoPanner::Do()
00072 {       
00073         if( !AbleToExecute() ) return true;
00074 
00075         CLAM::TData newValue = sin(mPhase);
00076         mPhase += mDeltaPhase;
00077         if (mPhase > (2*M_PI))
00078         {
00079                 mPhase = fmod(mPhase,TData(2*M_PI));
00080         }
00081 
00082         CLAM::TData firstValue = fabs(newValue);
00083         CLAM::TData secondValue = 1 - fabs(newValue);
00084 
00085         mLeft.SendControl(firstValue);
00086         mRight.SendControl(secondValue);
00087         return true;
00088 }
00089 
00090 bool AutoPanner::ConcreteConfigure(const ProcessingConfig& c)
00091 {
00092         CopyAsConcreteConfig(mConfig, c);
00093 
00094         mFreq = mConfig.GetFrequency();
00095         mSamplingRate = mConfig.GetSamplingRate();
00096         mPhase = mConfig.GetPhase();
00097         mFrameSize = mConfig.GetFrameSize();
00098         mDeltaPhase = ((2* TData(M_PI) *mFreq)/mSamplingRate)* mFrameSize;
00099 
00100         return true;
00101 }
00102 
00103 } // namespace CLAM
00104 
Generated by  doxygen 1.6.3