00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #if !defined(_SPANDSP_COMPLEX_H_)
00039 #define _SPANDSP_COMPLEX_H_
00040
00041
00042
00043
00044 typedef struct
00045 {
00046 float re;
00047 float im;
00048 } complexf_t;
00049
00050
00051
00052
00053 typedef struct
00054 {
00055 double re;
00056 double im;
00057 } complex_t;
00058
00059 #if defined(HAVE_LONG_DOUBLE)
00060
00061
00062
00063 typedef struct
00064 {
00065 long double re;
00066 long double im;
00067 } complexl_t;
00068 #endif
00069
00070
00071
00072
00073 typedef struct
00074 {
00075 int re;
00076 int im;
00077 } icomplex_t;
00078
00079
00080
00081
00082 typedef struct
00083 {
00084 int16_t re;
00085 int16_t im;
00086 } i16complex_t;
00087
00088
00089
00090
00091 typedef struct
00092 {
00093 int32_t re;
00094 int32_t im;
00095 } i32complex_t;
00096
00097 #ifdef __cplusplus
00098 extern "C"
00099 {
00100 #endif
00101
00102 static __inline__ complexf_t complex_setf(float re, float im)
00103 {
00104 complexf_t z;
00105
00106 z.re = re;
00107 z.im = im;
00108 return z;
00109 }
00110
00111
00112 static __inline__ complex_t complex_set(float re, float im)
00113 {
00114 complex_t z;
00115
00116 z.re = re;
00117 z.im = im;
00118 return z;
00119 }
00120
00121
00122 #if defined(HAVE_LONG_DOUBLE)
00123 static __inline__ complexl_t complex_setl(long double re, long double im)
00124 {
00125 complexl_t z;
00126
00127 z.re = re;
00128 z.im = im;
00129 return z;
00130 }
00131
00132 #endif
00133
00134 static __inline__ icomplex_t icomplex_set(int re, int im)
00135 {
00136 icomplex_t z;
00137
00138 z.re = re;
00139 z.im = im;
00140 return z;
00141 }
00142
00143
00144 static __inline__ complexf_t complex_addf(const complexf_t *x, const complexf_t *y)
00145 {
00146 complexf_t z;
00147
00148 z.re = x->re + y->re;
00149 z.im = x->im + y->im;
00150 return z;
00151 }
00152
00153
00154 static __inline__ complex_t complex_add(const complex_t *x, const complex_t *y)
00155 {
00156 complex_t z;
00157
00158 z.re = x->re + y->re;
00159 z.im = x->im + y->im;
00160 return z;
00161 }
00162
00163
00164 #if defined(HAVE_LONG_DOUBLE)
00165 static __inline__ complexl_t complex_addl(const complexl_t *x, const complexl_t *y)
00166 {
00167 complexl_t z;
00168
00169 z.re = x->re + y->re;
00170 z.im = x->im + y->im;
00171 return z;
00172 }
00173
00174 #endif
00175
00176 static __inline__ icomplex_t icomplex_add(const icomplex_t *x, const icomplex_t *y)
00177 {
00178 icomplex_t z;
00179
00180 z.re = x->re + y->re;
00181 z.im = x->im + y->im;
00182 return z;
00183 }
00184
00185
00186 static __inline__ complexf_t complex_subf(const complexf_t *x, const complexf_t *y)
00187 {
00188 complexf_t z;
00189
00190 z.re = x->re - y->re;
00191 z.im = x->im - y->im;
00192 return z;
00193 }
00194
00195
00196 static __inline__ complex_t complex_sub(const complex_t *x, const complex_t *y)
00197 {
00198 complex_t z;
00199
00200 z.re = x->re - y->re;
00201 z.im = x->im - y->im;
00202 return z;
00203 }
00204
00205
00206 #if defined(HAVE_LONG_DOUBLE)
00207 static __inline__ complexl_t complex_subl(const complexl_t *x, const complexl_t *y)
00208 {
00209 complexl_t z;
00210
00211 z.re = x->re - y->re;
00212 z.im = x->im - y->im;
00213 return z;
00214 }
00215
00216 #endif
00217
00218 static __inline__ icomplex_t icomplex_sub(const icomplex_t *x, const icomplex_t *y)
00219 {
00220 icomplex_t z;
00221
00222 z.re = x->re - y->re;
00223 z.im = x->im - y->im;
00224 return z;
00225 }
00226
00227
00228 static __inline__ complexf_t complex_mulf(const complexf_t *x, const complexf_t *y)
00229 {
00230 complexf_t z;
00231
00232 z.re = x->re*y->re - x->im*y->im;
00233 z.im = x->re*y->im + x->im*y->re;
00234 return z;
00235 }
00236
00237
00238 static __inline__ complex_t complex_mul(const complex_t *x, const complex_t *y)
00239 {
00240 complex_t z;
00241
00242 z.re = x->re*y->re - x->im*y->im;
00243 z.im = x->re*y->im + x->im*y->re;
00244 return z;
00245 }
00246
00247
00248 #if defined(HAVE_LONG_DOUBLE)
00249 static __inline__ complexl_t complex_mull(const complexl_t *x, const complexl_t *y)
00250 {
00251 complexl_t z;
00252
00253 z.re = x->re*y->re - x->im*y->im;
00254 z.im = x->re*y->im + x->im*y->re;
00255 return z;
00256 }
00257
00258 #endif
00259
00260 static __inline__ complexf_t complex_divf(const complexf_t *x, const complexf_t *y)
00261 {
00262 complexf_t z;
00263 float f;
00264
00265 f = y->re*y->re + y->im*y->im;
00266 z.re = ( x->re*y->re + x->im*y->im)/f;
00267 z.im = (-x->re*y->im + x->im*y->re)/f;
00268 return z;
00269 }
00270
00271
00272 static __inline__ complex_t complex_div(const complex_t *x, const complex_t *y)
00273 {
00274 complex_t z;
00275 double f;
00276
00277 f = y->re*y->re + y->im*y->im;
00278 z.re = ( x->re*y->re + x->im*y->im)/f;
00279 z.im = (-x->re*y->im + x->im*y->re)/f;
00280 return z;
00281 }
00282
00283
00284 #if defined(HAVE_LONG_DOUBLE)
00285 static __inline__ complexl_t complex_divl(const complexl_t *x, const complexl_t *y)
00286 {
00287 complexl_t z;
00288 long double f;
00289
00290 f = y->re*y->re + y->im*y->im;
00291 z.re = ( x->re*y->re + x->im*y->im)/f;
00292 z.im = (-x->re*y->im + x->im*y->re)/f;
00293 return z;
00294 }
00295
00296 #endif
00297
00298 static __inline__ complexf_t complex_conjf(const complexf_t *x)
00299 {
00300 complexf_t z;
00301
00302 z.re = x->re;
00303 z.im = -x->im;
00304 return z;
00305 }
00306
00307
00308 static __inline__ complex_t complex_conj(const complex_t *x)
00309 {
00310 complex_t z;
00311
00312 z.re = x->re;
00313 z.im = -x->im;
00314 return z;
00315 }
00316
00317
00318 #if defined(HAVE_LONG_DOUBLE)
00319 static __inline__ complexl_t complex_conjl(const complexl_t *x)
00320 {
00321 complexl_t z;
00322
00323 z.re = x->re;
00324 z.im = -x->im;
00325 return z;
00326 }
00327
00328 #endif
00329
00330 static __inline__ icomplex_t icomplex_conj(const icomplex_t *x)
00331 {
00332 icomplex_t z;
00333
00334 z.re = x->re;
00335 z.im = -x->im;
00336 return z;
00337 }
00338
00339
00340 static __inline__ float powerf(const complexf_t *x)
00341 {
00342 return x->re*x->re + x->im*x->im;
00343 }
00344
00345
00346 static __inline__ double power(const complex_t *x)
00347 {
00348 return x->re*x->re + x->im*x->im;
00349 }
00350
00351
00352 #if defined(HAVE_LONG_DOUBLE)
00353 static __inline__ long double powerl(const complexl_t *x)
00354 {
00355 return x->re*x->re + x->im*x->im;
00356 }
00357
00358 #endif
00359
00360 #ifdef __cplusplus
00361 }
00362 #endif
00363
00364 #endif
00365