CLAM-Development  1.4.0
SpectrumAdder.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 _SPECTRUM_ADDER_
23 #define _SPECTRUM_ADDER_
24 
25 #include "Processing.hxx"
26 #include "DynamicType.hxx"
27 #include "InPort.hxx"
28 #include "OutPort.hxx"
29 
30 #include "Spectrum.hxx"
31 
32 namespace CLAM {
33 
34 
36  {
37  public:
39  DYN_ATTRIBUTE (0, public, int, NInputs);
40  protected:
41  void DefaultInit();
42 
43  };
44 
76  class SpectrumAdder: public Processing {
77  SpecAdderConfig mConfig;
78 
80  int mSize;
81 
83  int mNInputs;
84 
88  InPort<Spectrum> **mInputs;
89 
92  Complex **complex_bufs;
93  Polar **polar_bufs;
94  TData **mag_bufs;
95  TData **phase_bufs;
96  bool *remove;
97 
98  OutPort<Spectrum> mOut;
99 
101  typedef enum {
102  // Type states in with the same attribute is used for all
103  // of the inputs and the outputs (it may or may not be
104  // present; in the second case it will be added at Do(...)
105  // time.
106  SMagPhase, SComplex, SPolar,
107 
108  // State when any of the inputs has only a BPF instantiated.
109  ShasBPF,
110 
111  // State in which nothing is known about prototypes.
112  SOther
113  } PrototypeState;
114 
116  typedef enum { Slin, Slog} ScaleState;
117 
119  PrototypeState mProtoState;
121  ScaleState mScaleState;
122 
124  std::string NewUniqueName();
125 
126  const char *GetClassName() const {return "SpectrumAdder";}
127 
131  bool ConcreteConfigure(const ProcessingConfig&);
132 
133  public:
134  SpectrumAdder();
135 
136  SpectrumAdder(const SpecAdderConfig &c);
137 
138  ~SpectrumAdder();
139 
140  const ProcessingConfig &GetConfig() const { return mConfig;}
141 
142  bool Do(void);
143 
144  bool Do(Spectrum **inputs, Spectrum& out);
145 
146 
147 
154  bool SetPrototypes(Spectrum **inputs,const Spectrum& out);
155 
156  bool SetPrototypes();
157 
158  bool UnsetPrototypes();
159 
160  bool MayDisableExecution() const {return true;}
161 
162  private:
163 
167  inline void Add(Spectrum **inputs, Spectrum& out);
168 
169  // Adder methods for optimized configurations of the inputs/output
170 
171  // Direct sums
172  inline void AddMagPhase(Spectrum **inputs, Spectrum& out);
173  inline void AddMagPhaseLin(Spectrum **inputs, Spectrum& out);
174  inline void AddMagPhaseLog(Spectrum **inputs, Spectrum& out);
175  inline void AddComplex(Spectrum **inputs, Spectrum& out);
176  inline void AddComplexLin(Spectrum **inputs, Spectrum& out);
177  inline void AddComplexLog(Spectrum **inputs, Spectrum& out);
178  inline void AddPolar(Spectrum **inputs, Spectrum& out);
179  inline void AddPolarLin(Spectrum **inputs, Spectrum& out);
180  inline void AddPolarLog(Spectrum **inputs, Spectrum& out);
181  };
182 
183 }
184 
185 #endif // _SPECTRUM_ADDER_
186