00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00139 bool Do(Audio& out);
00141 bool Do(TData& out);
00142 };
00143
00144 }
00145
00146 #endif
00147
00148