|
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 __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 ); // Available instrument 00095 else 00096 mState.SendControl( 1 ); // Busy intrument 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 // Unsupervised mode 00116 bool Do(void); // { return true; } 00117 00118 bool Do( Audio& out); 00119 00120 }; 00121 } 00122 00123 #endif 00124
1.7.6.1