CLAM-Development  1.4.0
Spectrum.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_
23 #define _Spectrum_
24 
25 #include <typeinfo>
26 #include "Array.hxx"
27 #include "Complex.hxx"
28 #include "Polar.hxx"
29 #include "BPF.hxx"
30 #include "ProcessingData.hxx"
31 
32 namespace CLAM {
33 
34 class SpectrumConfig;
35 
36 struct SpecTypeFlags;
37 
45 class Spectrum : public ProcessingData
46 {
47 public:
52  DYN_ATTRIBUTE (0, public, EScale, Scale);
53  DYN_ATTRIBUTE (1, public, TData, SpectralRange);
54 
55 private:
56  DYN_ATTRIBUTE (2, private, int, prSize);
57  DYN_ATTRIBUTE (3, private, int, prBPFSize);
58 public:
59  DYN_ATTRIBUTE (4, public, DataArray, MagBuffer);
60  DYN_ATTRIBUTE (5, public, DataArray, PhaseBuffer);
61  DYN_ATTRIBUTE (6, public, Array<Complex>, ComplexArray);
62  DYN_ATTRIBUTE (7, public, Array<Polar>, PolarArray);
63  DYN_ATTRIBUTE (8, public, BPF, MagBPF);
64  DYN_ATTRIBUTE (9, public, BPF, PhaseBPF);
65 
66 public:
67  Spectrum(const SpectrumConfig &newConfig);
68 
69  void Configure(const SpectrumConfig &newConfig);
70 
78  void GetConfig(SpectrumConfig& c) const;
79 protected:
80  void DefaultInit();
81 
82 public:
86  TData GetMag(TIndex pos) const;
90  TData GetMag(TData freq) const;
94  TData GetPhase(TIndex pos) const;
98  TData GetPhase(TData freq) const;
102  void SetMag(TIndex pos,TData newMag);
106  void SetMag(TData freq,TData newMag);
110  void SetPhase(TIndex pos,TData newPhase);
114  void SetPhase(TData freq,TData newPhase);
116  void SynchronizeTo(const SpecTypeFlags& tmpFlags);
118  void SynchronizeTo(const Spectrum& in);
120  void SynchronizeTo(const SpecTypeFlags& tmpFlags,const Spectrum& in);
121 
122 
123 
124 // Config shortcut interface.
125 
127  int GetSize() const;
129  void SetSize(int s);
130 
137  int GetBPFSize() const;
144  void SetBPFSize(int s);
145 
149  void GetType(SpecTypeFlags& f) const;
150 
155  void SetType(const SpecTypeFlags& newFlags);
156 
160  void SetTypeSynchronize(const SpecTypeFlags& newFlags);
161 
165  void ToDB();
166 
170  void ToLinear();
171 
172 private:
173 
177  void PRSetType(const SpecTypeFlags& tmpFlags,int size,int bpfsize);
178 
179 public:
181  inline TIndex IndexFromFreq(TData freq) const;
182 
183 
184 public:
185 // Internal converting routines
187  inline void Complex2Polar() ;
189  inline void Polar2Complex() ;
191  inline void Complex2MagPhase() ;
193  inline void Polar2MagPhase() ;
195  inline void MagPhase2Polar() ;
197  inline void MagPhase2Complex() ;
199  inline void MagPhase2BPF() ;
201  inline void BPF2MagPhase();
202 
203 // Converting routines from a second input spectrum
205  inline void Complex2Polar(const Spectrum& in) ;
207  inline void Polar2Complex(const Spectrum& in) ;
209  inline void Complex2MagPhase(const Spectrum& in) ;
211  inline void Polar2MagPhase(const Spectrum& in) ;
213  inline void MagPhase2Polar(const Spectrum& in) ;
215  inline void MagPhase2Complex(const Spectrum& in) ;
217  inline void MagPhase2BPF(const Spectrum& in) ;
219  inline void BPF2MagPhase(const Spectrum& in);
220 private:
221 //Low level converting routines
222  inline void Polar2MagPhase(const Array<Polar>& polarArray,DataArray& magBuffer, DataArray& phaseBuffer);
223  inline void Complex2MagPhase(const Array<Complex>& complexArray, DataArray& magBuffer, DataArray& phaseBuffer);
224  inline void MagPhase2Polar(const DataArray& magBuffer,const DataArray& phaseBuffer,Array<Polar>& polarArray);
225  inline void MagPhase2Complex(const DataArray& magBuffer,const DataArray& phaseBuffer,Array<Complex>& complexArray);
226  inline void MagPhase2BPF(const DataArray& magBuffer, const DataArray& phaseBuffer, BPF& magBPF, BPF& phaseBPF);
227  inline void BPF2MagPhase( const BPF& magBPF, const BPF& phaseBPF, DataArray& magBuffer, DataArray& phaseBuffer);
228 
229 };
230 
231 }; // namespace CLAM
232 
233 #endif
234