CLAM-Development  1.4.0
EnvelopeExtractor.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _EnvelopeExtractor_
23 #define _EnvelopeExtractor_
24 
25 #include "ControlConfig.hxx"
26 #include "Processing.hxx"
27 #include "InPort.hxx"
28 #include "OutPort.hxx"
29 #include "InControl.hxx"
30 #include "Envelope.hxx"
31 #include "Audio.hxx"
32 
33 namespace CLAM
34 {
35 
45  {
54  Array<TData> mArray;
55 
59  int mCurrentPos;
60 
62  int mPointsPerFrame;
63 
66  int mNMemoryPoints;
67 
68  inline TData AcumulationShape(int pos);
69 
70  inline TData& Current(int index);
71 
72  public:
73 
74  inline void Reconfigure(int PointsPerFrame,int MemoryPoints);
75 
76  inline bool Configured();
77 
78  inline void Clear(void);
79 
80  inline void AdvanceFrame(void);
81 
82  inline TData Acumulated(int index);
83 
84  inline void Compute(int interval,
85  Array<TData> &audio,
86  int interval_start,
87  int interval_end);
88  };
89 
90 
92  {
93  public:
95  DYN_ATTRIBUTE (0, public, TData, SampleRate);
96 
98  DYN_ATTRIBUTE (1, public, int, FrameSize);
99 
112  DYN_ATTRIBUTE (2, public, ControlConfig, InterpolationPeriod);
113 
126  DYN_ATTRIBUTE (3, public, ControlConfig, IntegrationLength);
127 
133  DYN_ATTRIBUTE (4, public, int, NInterpPointsPerFrame);
134 
148  DYN_ATTRIBUTE (5, public, int, NMemoryPoints);
149 
150  DYN_ATTRIBUTE (6, public, ControlConfig, NormalLevel);
151 
152  DYN_ATTRIBUTE (7, public, ControlConfig, SilenceLevel);
153 
154  DYN_ATTRIBUTE (8, public, EInterpolation, InterpolationType);
155  protected:
156 
157  void DefaultInit(void);
158  };
159 
160 
162  {
163  TTime mInterpolationPeriodControl;
164  TTime mIntegrationLengthControl;
165  TData mNormalLevelControl;
166  TData mSilenceLevelControl;
167 
168  public:
169 
174 
177 
179 
180  const char * GetClassName() const {return "EnvelopeExtractor";}
181 
182  const ProcessingConfig &GetConfig() const { return mConfig;}
183 
184  void Attach(Audio& inp, Envelope& env);
185 
186  bool Do();
187 
188  bool Do(const Audio& inp, Envelope& env);
189 
190  // Debugging accessors
191 
192  int NPoints() const { return mPointsPerFrame; }
193 
194  TData NormalLevel() const {return mNormalLevel;}
195 
196  TData SilenceLevel() const {return mSilenceLevel;}
197 
198  TTime InterpolationPeriod() const {return mInterpolationPeriod;}
199 
200  TTime IntegrationLength() const {return mIntegrationLength;}
201 
202  TData NormalLevelControl() const {return mNormalLevelControl;}
203 
204  TData SilenceLevelControl() const {return mSilenceLevelControl;}
205 
206  TTime InterpolationPeriodControl() const {return mInterpolationPeriodControl;}
207 
208  TTime IntegrationLengthControl() const {return mIntegrationLengthControl;}
209 
210  private:
211 
212  EnvExtractorConfig mConfig;
214  int mPointsPerFrame;
216  int mNMemoryPoints;
218  TData mNormalLevel;
220  TData mSilenceLevel;
222  TTime mDeltaX;
224  TTime mFrameTime;
226  int mFrameSize;
228  TTime mSampleDelta;
230  TTime mInterpolationPeriod;
232  TTime mIntegrationLength;
233 
235  IntervalAmplitudeAverages mAmplitudeAverages;
236 
248  Array<TData> mInterpolationPoints;
249 
253  bool mIsSpline;
254 
255  TData mIpMin, mIpFactor,
256  mIlMin, mIlFactor,
257  mNlMin, mNlFactor,
258  mSlMin, mSlFactor;
259 
260  bool SetPointsPerFrame(int npoints);
261  bool SetInterpolationPeriod(TTime period);
262  void SetNMemoryPoints(int mpoints);
263  bool SetIntegrationLength(TTime length);
264  void SetNormalLevel(TData nlevel);
265  void SetSilenceLevel(TData slevel);
266 
267  bool ConcreteConfigure(const ProcessingConfig& c);
268 
269  bool ConcreteStart();
270 
271  void ConfigureEnvelope(BPFTmpl<TTime,TData> &bpf);
272 
273  void WriteEnvelope (BPFTmpl<TTime,TData> &bpf);
274 
275  void StoreInterpolationPoints();
276 
277  void CleanSilence();
278 
279  void InitializeControls();
280 
281  void InterpolationPeriodChange(TControlData val);
282 
283  void IntegrationLengthChange(TControlData val);
284 
285  void NormalLevelChange(TControlData val);
286 
287  void SilenceLevelChange(TControlData val);
288 
289  };
290 
291 }
292 
293 #endif
294 
295