2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 ////////////////////////////////////////////////////////////////////////////////
35 Complex(float r
, float i
) : real(r
), imag(i
) {}
36 void Set(float r
, float i
) { real
= r
; imag
= i
; }
38 Complex
& operator=(Complex b
) { real
= b
.real
; imag
= b
.imag
; return *this; }
39 Complex
& operator=(float b
) { real
= b
; imag
= 0.; return *this; }
44 void ToPolarInPlace();
45 void ToPolarApxInPlace();
53 Polar(float m
, float p
) : mag(m
), phase(p
) {}
54 void Set(float m
, float p
) { mag
= m
; phase
= p
; }
57 Complex
ToComplexApx();
59 void ToComplexInPlace();
60 void ToComplexApxInPlace();
77 void ToComplex(Polar in
, Complex
& out
);
79 inline Complex
operator+(Complex a
, Complex b
) { return Complex(a
.real
+ b
.real
, a
.imag
+ b
.imag
); }
80 inline Complex
operator+(Complex a
, float b
) { return Complex(a
.real
+ b
, a
.imag
); }
81 inline Complex
operator+(float a
, Complex b
) { return Complex(a
+ b
.real
, b
.imag
); }
83 inline Complex
& operator+=(Complex
& a
, const Complex
& b
) { a
.real
+= b
.real
, a
.imag
+= b
.imag
; return a
; }
84 inline Complex
& operator+=(Complex
& a
, float b
) { a
.real
+= b
; return a
; }
86 inline Complex
operator-(Complex a
, Complex b
) { return Complex(a
.real
- b
.real
, a
.imag
- b
.imag
); }
87 inline Complex
operator-(Complex a
, float b
) { return Complex(a
.real
- b
, a
.imag
); }
88 inline Complex
operator-(float a
, Complex b
) { return Complex(a
- b
.real
, b
.imag
); }
90 inline Complex
operator-=(Complex a
, Complex b
) { a
.real
-= b
.real
, a
.imag
-= b
.imag
; return a
; }
91 inline Complex
operator-=(Complex a
, float b
) { a
.real
-= b
; return a
; }
93 inline Complex
operator*(Complex a
, Complex b
)
95 return Complex(a
.real
* b
.real
- a
.imag
* b
.imag
, a
.real
* b
.imag
+ a
.imag
* b
.real
);
98 inline Complex
operator*(Complex a
, float b
)
100 return Complex(a
.real
* b
, a
.imag
* b
);
103 inline Complex
operator*(float a
, Complex b
)
105 return Complex(b
.real
* a
, b
.imag
* a
);
108 inline Complex
operator*=(Complex a
, Complex b
)
111 a
.real
* b
.real
- a
.imag
* b
.imag
,
112 a
.real
* b
.imag
+ a
.imag
* b
.real
117 inline Complex
operator*=(Complex a
, float b
)
125 inline Polar
operator*(Polar a
, float b
)
127 return Polar(a
.mag
* b
, a
.phase
);
130 inline Polar
operator*(float a
, Polar b
)
132 return Polar(a
* b
.mag
, b
.phase
);
135 inline Polar
operator*=(Polar a
, float b
)