|
CLAM-Development
1.3
|
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 typedef SimpleOscillatorConfig Config; 00088 AudioOutPort mOutput; 00089 SimpleOscillatorConfig mConfig; 00090 TData mAmp; 00091 TData mPhase; 00092 TData mDeltaPhase; 00093 TData mSamplingRate; 00094 00095 bool mFreqUpdated; 00096 bool mAmpUpdated; 00097 FloatInControl mFreqCtl; 00098 FloatInControl mAmpCtl; 00099 //xamat: kludge to convert this into an LFO, eventually separate into a different class 00100 FloatInControl mSamplesBetweenCallsCtl; 00101 00102 protected: 00103 00104 inline void ApplyFreqAndAmpControls() 00105 { 00106 if ( mFreqUpdated ) 00107 { 00108 mDeltaPhase = TData(2. * PI * mFreqCtl.GetLastValue() / mSamplingRate); 00109 mFreqUpdated = false; 00110 } 00111 if ( mAmpUpdated ) 00112 { 00113 mAmp = mAmpCtl.GetLastValue(); 00114 mAmpUpdated = false; 00115 } 00116 } 00117 00118 void UpdateFreq( TControlData ); 00119 void UpdateAmp( TControlData ); 00120 00121 public: 00122 00123 SimpleOscillator(const SimpleOscillatorConfig& c = Config() ); 00124 00125 virtual ~SimpleOscillator(); 00126 00127 const char * GetClassName() const {return "SimpleOscillator";} 00128 00129 virtual const ProcessingConfig &GetConfig() const { return mConfig;} 00130 00131 virtual bool ConcreteConfigure(const ProcessingConfig& c); 00132 00133 virtual bool Do(void); 00134 00135 // "Generative Do" 00136 bool Do(Audio& out); 00138 bool Do(TData& out); 00139 }; 00140 00141 } 00142 00143 #endif 00144 00145
1.7.6.1