ADSR.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __ADSR__
00023 #define __ADSR__
00024
00025 #include "Processing.hxx"
00026 #include "ProcessingData.hxx"
00027 #include "Audio.hxx"
00028 #include "OSDefines.hxx"
00029 #include "InControl.hxx"
00030 #include "AudioOutPort.hxx"
00031 #include "OutControl.hxx"
00032
00033 namespace CLAM
00034 {
00035 class ADSRConfig: public ProcessingConfig
00036 {
00037 public:
00038 DYNAMIC_TYPE_USING_INTERFACE (ADSRConfig, 5, ProcessingConfig);
00039 DYN_ATTRIBUTE (0, public, TData, AttackTime);
00040 DYN_ATTRIBUTE (1, public, TData, DecayTime);
00041 DYN_ATTRIBUTE (2, public, TData, SustainLevel);
00042 DYN_ATTRIBUTE (3, public, TData , ReleaseTime);
00043 DYN_ATTRIBUTE (4, public, TData , SampleRate);
00044 protected:
00045 void DefaultInit(void);
00046 };
00047
00048 class ADSR: public Processing
00049 {
00050 public:
00051 typedef ADSRConfig Config;
00052 AudioOutPort mOutput;
00053 enum Status {
00054 Attack = 0,
00055 Decay = 1,
00056 Sustain = 2,
00057 Release = 3,
00058 Done = 4,
00059 };
00060
00061 private:
00062 FloatInControl mAmplitude;
00063 ADSRConfig mConfig;
00064 TControlData mAmpValue;
00065 TData mAttackTime;
00066 TData mDecayTime;
00067 TData mSustainLevel;
00068 TData mReleaseTime;
00069 TData mSamplingRate;
00070 TData mLevel;
00071 TData mDLevel;
00072 Status mStatus;
00073 FloatOutControl mState;
00074
00075 protected:
00076 void HandleAttack();
00077
00078 void HandleDecay();
00079
00080 void HandleRelease();
00081
00082 void HandleAmplitude()
00083 {
00084 if ( mAmpValue > 0 )
00085 HandleAttack();
00086
00087 if ( mAmpValue == 0 )
00088 HandleRelease();
00089 }
00090
00091 void UpdateState()
00092 {
00093 if( mStatus == Done )
00094 mState.SendControl( 0 );
00095 else
00096 mState.SendControl( 1 );
00097 }
00098
00099 void UpdateAmp( TControlData value )
00100 {
00101 mAmpValue = value ;
00102 HandleAmplitude();
00103 }
00104
00105 public:
00106 ADSR( const ADSRConfig& c = Config() );
00107 ~ADSR(){}
00108
00109 const char * GetClassName() const {return "ADSR";}
00110
00111 const ProcessingConfig &GetConfig() const { return mConfig; }
00112
00113 bool ConcreteConfigure( const ProcessingConfig& c );
00114
00115
00116 bool Do(void);
00117
00118 bool Do( Audio& out);
00119
00120 };
00121 }
00122
00123 #endif
00124