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 #ifndef __SimpleOscillator_hxx__ 00023 #define __SimpleOscillator_hxx__ 00024 00025 #include "Processing.hxx" 00026 #include "ProcessingData.hxx" 00027 #include "OSDefines.hxx" 00028 #include "Audio.hxx" 00029 #include "AudioOutPort.hxx" 00030 #include "InControl.hxx" 00031 #include "Enum.hxx" 00032 #include <string> 00033 00034 namespace CLAM 00035 { 00036 00037 class EOscillatorControls : public Enum 00038 { 00039 public: 00040 00041 EOscillatorControls() : Enum(ValueTable(), pitch) { } 00042 EOscillatorControls(tValue v) : Enum(ValueTable(), v) { } 00043 EOscillatorControls(std::string s) : Enum(ValueTable(), s) { } 00044 ~EOscillatorControls() { }; 00045 00046 Component * Species() const 00047 { 00048 return new EOscillatorControls; 00049 } 00050 typedef enum 00051 { 00052 pitch=0, 00053 amplitude, 00054 modidx, 00055 phase 00056 } tEnum; 00057 static tEnumValue * ValueTable() 00058 { 00059 static tEnumValue sEnumValues[] = 00060 { 00061 { pitch, "pitch" }, 00062 { amplitude, "amplitude" }, 00063 { modidx, "modidx" }, 00064 { phase, "phase" }, 00065 { 0, NULL } 00066 }; 00067 return sEnumValues; 00068 } 00069 }; 00070 00071 class SimpleOscillatorConfig: public ProcessingConfig 00072 { 00073 public: 00074 DYNAMIC_TYPE_USING_INTERFACE (SimpleOscillatorConfig, 4, ProcessingConfig); 00075 DYN_ATTRIBUTE (0, public, TData, Frequency); 00076 DYN_ATTRIBUTE (1, public, TData, Amplitude); 00077 DYN_ATTRIBUTE (2, public, TData, Phase); 00078 DYN_ATTRIBUTE (3, public, TData, SamplingRate); 00079 00080 protected: 00081 void DefaultInit(void); 00082 }; 00083 00084 class SimpleOscillator : public Processing 00085 { 00086 protected: 00087 AudioOutPort mOutput; 00088 SimpleOscillatorConfig mConfig; 00089 TData mAmp; 00090 TData mPhase; 00091 TData mDeltaPhase; 00092 TData mSamplingRate; 00093 00094 typedef InControlTmpl<SimpleOscillator> SimpleOscillatorCtrl; 00095 00096 bool mFreqUpdated; 00097 bool mAmpUpdated; 00098 SimpleOscillatorCtrl* mFreqCtl; 00099 SimpleOscillatorCtrl* mAmpCtl; 00100 00101 //xamat: kludge to convert this into an LFO, eventually separate into a different class 00102 InControl mSamplesBetweenCallsCtl; 00103 protected: 00104 00105 inline void ApplyFreqAndAmpControls() 00106 { 00107 if ( mFreqUpdated ) 00108 { 00109 mDeltaPhase = TData(2. * PI * mFreqCtl->GetLastValue() / mSamplingRate); 00110 mFreqUpdated = false; 00111 } 00112 if ( mAmpUpdated ) 00113 { 00114 mAmp = mAmpCtl->GetLastValue(); 00115 mAmpUpdated = false; 00116 } 00117 } 00118 00119 int UpdateFreq( TControlData ); 00120 int UpdateAmp( TControlData ); 00121 00122 public: 00123 00124 SimpleOscillator(); 00125 00126 SimpleOscillator(const SimpleOscillatorConfig& c ); 00127 00128 virtual ~SimpleOscillator(); 00129 00130 const char * GetClassName() const {return "SimpleOscillator";} 00131 00132 virtual const ProcessingConfig &GetConfig() const { return mConfig;} 00133 00134 virtual bool ConcreteConfigure(const ProcessingConfig& c); 00135 00136 virtual bool Do(void); 00137 00138 // "Generative Do" 00139 bool Do(Audio& out); 00141 bool Do(TData& out); 00142 }; 00143 00144 } 00145 00146 #endif 00147 00148