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 _EnvelopeExtractor_ 00023 #define _EnvelopeExtractor_ 00024 00025 #include "ControlConfig.hxx" 00026 #include "Processing.hxx" 00027 #include "InPort.hxx" 00028 #include "OutPort.hxx" 00029 #include "InControl.hxx" 00030 #include "Envelope.hxx" 00031 #include "Audio.hxx" 00032 00033 namespace CLAM 00034 { 00035 00044 class IntervalAmplitudeAverages 00045 { 00054 Array<TData> mArray; 00055 00059 int mCurrentPos; 00060 00062 int mPointsPerFrame; 00063 00066 int mNMemoryPoints; 00067 00068 inline TData AcumulationShape(int pos); 00069 00070 inline TData& Current(int index); 00071 00072 public: 00073 00074 inline void Reconfigure(int PointsPerFrame,int MemoryPoints); 00075 00076 inline bool Configured(); 00077 00078 inline void Clear(void); 00079 00080 inline void AdvanceFrame(void); 00081 00082 inline TData Acumulated(int index); 00083 00084 inline void Compute(int interval, 00085 Array<TData> &audio, 00086 int interval_start, 00087 int interval_end); 00088 }; 00089 00090 00091 class EnvExtractorConfig: public ProcessingConfig 00092 { 00093 public: 00094 DYNAMIC_TYPE_USING_INTERFACE (EnvExtractorConfig, 9, ProcessingConfig); 00095 DYN_ATTRIBUTE (0, public, TData, SampleRate); 00096 00098 DYN_ATTRIBUTE (1, public, int, FrameSize); 00099 00112 DYN_ATTRIBUTE (2, public, ControlConfig, InterpolationPeriod); 00113 00126 DYN_ATTRIBUTE (3, public, ControlConfig, IntegrationLength); 00127 00133 DYN_ATTRIBUTE (4, public, int, NInterpPointsPerFrame); 00134 00148 DYN_ATTRIBUTE (5, public, int, NMemoryPoints); 00149 00150 DYN_ATTRIBUTE (6, public, ControlConfig, NormalLevel); 00151 00152 DYN_ATTRIBUTE (7, public, ControlConfig, SilenceLevel); 00153 00154 DYN_ATTRIBUTE (8, public, EInterpolation, InterpolationType); 00155 protected: 00156 00157 void DefaultInit(void); 00158 }; 00159 00160 00161 class EnvelopeExtractor: public Processing 00162 { 00163 TTime mInterpolationPeriodControl; 00164 TTime mIntegrationLengthControl; 00165 TData mNormalLevelControl; 00166 TData mSilenceLevelControl; 00167 00168 public: 00169 00170 InControlTmpl<EnvelopeExtractor> cInterpolationPeriod; 00171 InControlTmpl<EnvelopeExtractor> cIntegrationLength; 00172 InControlTmpl<EnvelopeExtractor> cNormalLevel; 00173 InControlTmpl<EnvelopeExtractor> cSilenceLevel; 00174 00175 InPort<Audio> Input; 00176 OutPort<Envelope> Output; 00177 00178 EnvelopeExtractor(const EnvExtractorConfig& c = EnvExtractorConfig()); 00179 00180 const char * GetClassName() const {return "EnvelopeExtractor";} 00181 00182 const ProcessingConfig &GetConfig() const { return mConfig;} 00183 00184 void Attach(Audio& inp, Envelope& env); 00185 00186 bool Do(void); 00187 00188 bool Do(const Audio& inp, Envelope& env); 00189 00190 // Debugging accessors 00191 00192 int NPoints() const { return mPointsPerFrame; } 00193 00194 TData NormalLevel() const {return mNormalLevel;} 00195 00196 TData SilenceLevel() const {return mSilenceLevel;} 00197 00198 TTime InterpolationPeriod() const {return mInterpolationPeriod;} 00199 00200 TTime IntegrationLength() const {return mIntegrationLength;} 00201 00202 TData NormalLevelControl() const {return mNormalLevelControl;} 00203 00204 TData SilenceLevelControl() const {return mSilenceLevelControl;} 00205 00206 TTime InterpolationPeriodControl() const {return mInterpolationPeriodControl;} 00207 00208 TTime IntegrationLengthControl() const {return mIntegrationLengthControl;} 00209 00210 private: 00211 00212 EnvExtractorConfig mConfig; 00214 int mPointsPerFrame; 00216 int mNMemoryPoints; 00218 TData mNormalLevel; 00220 TData mSilenceLevel; 00222 TTime mDeltaX; 00224 TTime mFrameTime; 00226 int mFrameSize; 00228 TTime mSampleDelta; 00230 TTime mInterpolationPeriod; 00232 TTime mIntegrationLength; 00233 00235 IntervalAmplitudeAverages mAmplitudeAverages; 00236 00248 Array<TData> mInterpolationPoints; 00249 00253 bool mIsSpline; 00254 00255 TData mIpMin, mIpFactor, 00256 mIlMin, mIlFactor, 00257 mNlMin, mNlFactor, 00258 mSlMin, mSlFactor; 00259 00260 bool SetPointsPerFrame(int npoints); 00261 bool SetInterpolationPeriod(TTime period); 00262 void SetNMemoryPoints(int mpoints); 00263 bool SetIntegrationLength(TTime length); 00264 void SetNormalLevel(TData nlevel); 00265 void SetSilenceLevel(TData slevel); 00266 00267 bool ConcreteConfigure(const ProcessingConfig& c); 00268 00269 bool ConcreteStart(); 00270 00271 void ConfigureEnvelope(BPFTmpl<TTime,TData> &bpf); 00272 00273 void WriteEnvelope (BPFTmpl<TTime,TData> &bpf); 00274 00275 void StoreInterpolationPoints(); 00276 00277 void CleanSilence(); 00278 00279 void InitializeControls(); 00280 00281 int InterpolationPeriodChange(TControlData val); 00282 00283 int IntegrationLengthChange(TControlData val); 00284 00285 int NormalLevelChange(TControlData val); 00286 00287 int SilenceLevelChange(TControlData val); 00288 00289 }; 00290 00291 } 00292 00293 #endif 00294 00295