CLAM-Development  1.4.0
ComplexToPolarCnv.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 /* Template class used to convert array of polars into arrays of complexs */
23 
24 #ifndef _ComplexToPolarCnv_
25 #define _ComplexToPolarCnv_
26 
27 #include "Complex.hxx"
28 #include "Polar.hxx"
29 #include "Array.hxx"
30 #include "Err.hxx"
31 #include "DataTypes.hxx"
32 
33 namespace CLAM {
34 
35 template <class T> class ComplexToPolarCnv
36 {
37 public:
38 
39 /* Constructors and destructors */
42 
43 /* Converting routines */
44 
45  /* Complex To Polar */
46  void ToPolar(const Array<ComplexTmpl<T> > &inputArray,
47  Array<PolarTmpl<T> > &outputArray) const
48  {
49  CLAM_ASSERT(outputArray.Size() == inputArray.Size(),
50  "ComplexToPolarCnv::Convert: unable to convert buffers with different sizes");
51 
52  for (int i=0; i<inputArray.Size(); i++) {
53  outputArray[i].SetMag(inputArray[i].Mag());
54  outputArray[i].SetAng(inputArray[i].Ang());
55  }
56  }
57 
58  /* Polar To Complex */
59  void ToComplex(const Array<PolarTmpl<T> > &inputArray,
60  Array<ComplexTmpl<T> > &outputArray) const
61  {
62  CLAM_ASSERT(outputArray.Size() == inputArray.Size(),
63  "ComplexToPolarCnv::Convert: unable to convert buffers with different sizes");
64 
65  for (int i=0; i<inputArray.Size(); i++) {
66  outputArray[i].SetReal(inputArray[i].Real());
67  outputArray[i].SetImag(inputArray[i].Imag());
68  }
69  }
70 };
71 
73 
74 }
75 
76 #endif
77