1 /*
2
3 DSP operations
4 Copyright (C) 1998-2005 Jussi Laako
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
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <limits.h>
26 #ifdef USE_INTEL_MATH
27 #include <mathimf.h>
28 #else
29 #include <math.h>
30 #endif
31 #include <float.h>
32 #ifdef DSP_IPP
33 #include <ipp.h>
34 #endif
35 #ifdef __INTEL_COMPILER
36 #include <xmmintrin.h>
37 #include <pmmintrin.h>
38 #endif
39
40 #include "Compilers.hh"
41 #include "dsp/DSPOp.hh"
42 #ifdef DSP_X86
43 #include "dsp/X86.h"
44 #endif
45 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
46 #include "dsp/X86-64.h"
47 #endif
48
49
50 #ifdef DSP_X86
51 bool bHave3DNow = false;
52 bool bHaveSSE = false;
53 #endif
54
55
56 extern "C"
57 {
58
FloatCompare(const void * vpValue1,const void * vpValue2)59 INLINE int FloatCompare (const void *vpValue1, const void *vpValue2)
60 {
61 if (*(float *)vpValue1 == *(float *)vpValue2)
62 {
63 return 0;
64 }
65 if (*(float *)vpValue1 < *(float *)vpValue2)
66 {
67 return -1;
68 }
69 else
70 {
71 return 1;
72 }
73 }
74
75
DoubleCompare(const void * vpValue1,const void * vpValue2)76 INLINE int DoubleCompare (const void *vpValue1, const void *vpValue2)
77 {
78 if (*(double *)vpValue1 == *(double *)vpValue2)
79 {
80 return 0;
81 }
82 if (*(double *)vpValue1 < *(double *)vpValue2)
83 {
84 return -1;
85 }
86 else
87 {
88 return 1;
89 }
90 }
91
92
LongCompare(const void * vpValue1,const void * vpValue2)93 INLINE int LongCompare (const void *vpValue1, const void *vpValue2)
94 {
95 if (*(long *)vpValue1 == *(long *)vpValue2)
96 {
97 return 0;
98 }
99 if (*(long *)vpValue1 < *(long *)vpValue2)
100 {
101 return -1;
102 }
103 else
104 {
105 return 1;
106 }
107 }
108
109 }
110
111
Round(float fValue)112 signed long clDSPOp::Round (float fValue)
113 {
114 signed long slTemp;
115
116 // nearbyintf() seems to be buggy in some glibc versions
117 #if defined(USE_INTEL_MATH)
118 slTemp = lrintf(fValue);
119 #elif defined(_ISOC9X_SOURCE)
120 slTemp = (signed long) nearbyintf(fValue);
121 #else
122 slTemp = (fValue >= 0.0F) ?
123 ((signed long) (fValue + 0.5F)) : ((signed long) (fValue - 0.5F));
124 #endif
125 return slTemp;
126 }
127
128
Round(double dValue)129 signed long clDSPOp::Round (double dValue)
130 {
131 signed long slTemp;
132
133 // nearbyint() seems to be buggy in some glibc versions
134 #if defined(USE_INTEL_MATH)
135 slTemp = lrint(dValue);
136 #elif defined(_ISOC9X_SOURCE)
137 slTemp = (signed long) nearbyint(dValue);
138 #else
139 slTemp = (dValue >= 0.0) ?
140 ((signed long) (dValue + 0.5)) : ((signed long) (dValue - 0.5));
141 #endif
142 return slTemp;
143 }
144
145
Cart2Polar(float * fpMagn,float * fpPhase,float fReal,float fImag)146 INLINE void clDSPOp::Cart2Polar (float *fpMagn, float *fpPhase,
147 float fReal, float fImag)
148 {
149 #ifndef _ISOC9X_SOURCE
150 *fpMagn = sqrtf(fReal * fReal + fImag * fImag);
151 #else
152 *fpMagn = hypotf(fReal, fImag);
153 #endif
154 *fpPhase = atan2f(fImag, fReal);
155 }
156
157
Cart2Polar(double * dpMagn,double * dpPhase,double dReal,double dImag)158 INLINE void clDSPOp::Cart2Polar (double *dpMagn, double *dpPhase,
159 double dReal, double dImag)
160 {
161 #ifndef _ISOC9X_SOURCE
162 *dpMagn = sqrt(dReal * dReal + dImag * dImag);
163 #else
164 *dpMagn = hypot(dReal, dImag);
165 #endif
166 *dpPhase = atan2(dImag, dReal);
167 }
168
169
Cart2Polar(float * fpMagn,float * fpPhase,const stpSCplx spCplx)170 INLINE void clDSPOp::Cart2Polar (float *fpMagn, float *fpPhase,
171 const stpSCplx spCplx)
172 {
173 #ifndef _ISOC9X_SOURCE
174 *fpMagn = sqrtf(spCplx->R * spCplx->R + spCplx->I * spCplx->I);
175 #else
176 *fpMagn = hypotf(spCplx->R, spCplx->I);
177 #endif
178 *fpPhase = atan2f(spCplx->I, spCplx->R);
179 }
180
181
Cart2Polar(double * dpMagn,double * dpPhase,const stpDCplx spCplx)182 INLINE void clDSPOp::Cart2Polar (double *dpMagn, double *dpPhase,
183 const stpDCplx spCplx)
184 {
185 #ifndef _ISOC9X_SOURCE
186 *dpMagn = sqrt(spCplx->R * spCplx->R + spCplx->I * spCplx->I);
187 #else
188 *dpMagn = hypot(spCplx->R, spCplx->I);
189 #endif
190 *dpPhase = atan2(spCplx->I, spCplx->R);
191 }
192
193
Cart2Polar(stpSPolar spPolar,const stpSCplx spCplx)194 INLINE void clDSPOp::Cart2Polar (stpSPolar spPolar, const stpSCplx spCplx)
195 {
196 #ifndef _ISOC9X_SOURCE
197 spPolar->M = sqrtf(spCplx->R * spCplx->R + spCplx->I * spCplx->I);
198 #else
199 spPolar->M = hypotf(spCplx->R, spCplx->I);
200 #endif
201 spPolar->P = atan2f(spCplx->I, spCplx->R);
202 }
203
204
Cart2Polar(stpDPolar spPolar,const stpDCplx spCplx)205 INLINE void clDSPOp::Cart2Polar (stpDPolar spPolar, const stpDCplx spCplx)
206 {
207 #ifndef _ISOC9X_SOURCE
208 spPolar->M = sqrt(spCplx->R * spCplx->R + spCplx->I * spCplx->I);
209 #else
210 spPolar->M = hypot(spCplx->R, spCplx->I);
211 #endif
212 spPolar->P = atan2(spCplx->I, spCplx->R);
213 }
214
215
Cart2Polar(utpSCoord upCoord)216 INLINE void clDSPOp::Cart2Polar (utpSCoord upCoord)
217 {
218 #ifndef _ISOC9X_SOURCE
219 upCoord->P.M = sqrtf(upCoord->C.R * upCoord->C.R +
220 upCoord->C.I * upCoord->C.I);
221 #else
222 upCoord->P.M = hypotf(upCoord->C.R, upCoord->C.I);
223 #endif
224 upCoord->P.P = atan2f(upCoord->C.I, upCoord->C.R);
225 }
226
227
Cart2Polar(utpDCoord upCoord)228 INLINE void clDSPOp::Cart2Polar (utpDCoord upCoord)
229 {
230 #ifndef _ISOC9X_SOURCE
231 upCoord->P.M = sqrt(upCoord->C.R * upCoord->C.R +
232 upCoord->C.I * upCoord->C.I);
233 #else
234 upCoord->P.M = hypot(upCoord->C.R, upCoord->C.I);
235 #endif
236 upCoord->P.P = atan2(upCoord->C.I, upCoord->C.R);
237 }
238
239
Polar2Cart(float * fpReal,float * fpImag,float fMagn,float fPhase)240 INLINE void clDSPOp::Polar2Cart (float *fpReal, float *fpImag,
241 float fMagn, float fPhase)
242 {
243 #ifndef _GNU_SOURCE
244 *fpReal = fMagn * cosf(fPhase);
245 *fpImag = fMagn * sinf(fPhase);
246 #else
247 sincosf(fPhase, fpImag, fpReal);
248 *fpReal *= fMagn;
249 *fpImag *= fMagn;
250 #endif
251 }
252
253
Polar2Cart(double * dpReal,double * dpImag,double dMagn,double dPhase)254 INLINE void clDSPOp::Polar2Cart (double *dpReal, double *dpImag,
255 double dMagn, double dPhase)
256 {
257 #ifndef _GNU_SOURCE
258 *dpReal = dMagn * cos(dPhase);
259 *dpImag = dMagn * sin(dPhase);
260 #else
261 sincos(dPhase, dpImag, dpReal);
262 *dpReal *= dMagn;
263 *dpImag *= dMagn;
264 #endif
265 }
266
267
Polar2Cart(stpSCplx spCplx,float fMagn,float fPhase)268 INLINE void clDSPOp::Polar2Cart (stpSCplx spCplx, float fMagn, float fPhase)
269 {
270 #ifndef _GNU_SOURCE
271 spCplx->R = fMagn * cosf(fPhase);
272 spCplx->I = fMagn * sinf(fPhase);
273 #else
274 sincosf(fPhase, &spCplx->I, &spCplx->R);
275 spCplx->R *= fMagn;
276 spCplx->I *= fMagn;
277 #endif
278 }
279
280
Polar2Cart(stpDCplx spCplx,double dMagn,double dPhase)281 INLINE void clDSPOp::Polar2Cart (stpDCplx spCplx, double dMagn, double dPhase)
282 {
283 #ifndef _GNU_SOURCE
284 spCplx->R = dMagn * cos(dPhase);
285 spCplx->I = dMagn * sin(dPhase);
286 #else
287 sincos(dPhase, &spCplx->I, &spCplx->R);
288 spCplx->R *= dMagn;
289 spCplx->I *= dMagn;
290 #endif
291 }
292
293
Polar2Cart(stpSCplx spCplx,const stpSPolar spPolar)294 INLINE void clDSPOp::Polar2Cart (stpSCplx spCplx, const stpSPolar spPolar)
295 {
296 #ifndef _GNU_SOURCE
297 spCplx->R = spPolar->M * cosf(spPolar->P);
298 spCplx->I = spPolar->M * sinf(spPolar->P);
299 #else
300 sincosf(spPolar->P, &spCplx->I, &spCplx->R);
301 spCplx->R *= spPolar->M;
302 spCplx->I *= spPolar->M;
303 #endif
304 }
305
306
Polar2Cart(stpDCplx spCplx,const stpDPolar spPolar)307 INLINE void clDSPOp::Polar2Cart (stpDCplx spCplx, const stpDPolar spPolar)
308 {
309 #ifndef _GNU_SOURCE
310 spCplx->R = spPolar->M * cos(spPolar->P);
311 spCplx->I = spPolar->M * sin(spPolar->P);
312 #else
313 sincos(spPolar->P, &spCplx->I, &spCplx->R);
314 spCplx->R *= spPolar->M;
315 spCplx->I *= spPolar->M;
316 #endif
317 }
318
319
Polar2Cart(utpSCoord upCoord)320 INLINE void clDSPOp::Polar2Cart (utpSCoord upCoord)
321 {
322 #ifndef _GNU_SOURCE
323 upCoord->C.R = upCoord->P.M * cosf(upCoord->P.P);
324 upCoord->C.I = upCoord->P.M * sinf(upCoord->P.P);
325 #else
326 float fReal;
327 float fImag;
328
329 sincosf(upCoord->P.P, &fImag, &fReal);
330 upCoord->C.R = upCoord->P.M * fReal;
331 upCoord->C.I = upCoord->P.M * fImag;
332 #endif
333 }
334
335
Polar2Cart(utpDCoord upCoord)336 INLINE void clDSPOp::Polar2Cart (utpDCoord upCoord)
337 {
338 #ifndef _GNU_SOURCE
339 upCoord->C.R = upCoord->P.M * cos(upCoord->P.P);
340 upCoord->C.I = upCoord->P.M * sin(upCoord->P.P);
341 #else
342 double dReal;
343 double dImag;
344
345 sincos(upCoord->P.P, &dImag, &dReal);
346 upCoord->C.R = upCoord->P.M * dReal;
347 upCoord->C.I = upCoord->P.M * dImag;
348 #endif
349 }
350
351
CplxAdd(stpSCplx spCplxDest,const stpSCplx spCplxSrc)352 INLINE void clDSPOp::CplxAdd (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
353 {
354 spCplxDest->R += spCplxSrc->R;
355 spCplxDest->I += spCplxSrc->I;
356 }
357
358
CplxAdd(stpDCplx spCplxDest,const stpDCplx spCplxSrc)359 INLINE void clDSPOp::CplxAdd (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
360 {
361 spCplxDest->R += spCplxSrc->R;
362 spCplxDest->I += spCplxSrc->I;
363 }
364
365
CplxAdd(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2)366 INLINE void clDSPOp::CplxAdd (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
367 const stpSCplx spCplxSrc2)
368 {
369 spCplxDest->R = spCplxSrc1->R + spCplxSrc2->R;
370 spCplxDest->I = spCplxSrc1->I + spCplxSrc2->I;
371 }
372
373
CplxAdd(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2)374 INLINE void clDSPOp::CplxAdd (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
375 const stpDCplx spCplxSrc2)
376 {
377 spCplxDest->R = spCplxSrc1->R + spCplxSrc2->R;
378 spCplxDest->I = spCplxSrc1->I + spCplxSrc2->I;
379 }
380
381
CplxSub(stpSCplx spCplxDest,const stpSCplx spCplxSrc)382 INLINE void clDSPOp::CplxSub (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
383 {
384 spCplxDest->R -= spCplxSrc->R;
385 spCplxDest->I -= spCplxSrc->I;
386 }
387
388
CplxSub(stpDCplx spCplxDest,const stpDCplx spCplxSrc)389 INLINE void clDSPOp::CplxSub (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
390 {
391 spCplxDest->R -= spCplxSrc->R;
392 spCplxDest->I -= spCplxSrc->I;
393 }
394
395
CplxSub(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2)396 INLINE void clDSPOp::CplxSub (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
397 const stpSCplx spCplxSrc2)
398 {
399 spCplxDest->R = spCplxSrc1->R - spCplxSrc2->R;
400 spCplxDest->I = spCplxSrc1->I - spCplxSrc2->I;
401 }
402
403
CplxSub(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2)404 INLINE void clDSPOp::CplxSub (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
405 const stpDCplx spCplxSrc2)
406 {
407 spCplxDest->R = spCplxSrc1->R - spCplxSrc2->R;
408 spCplxDest->I = spCplxSrc1->I - spCplxSrc2->I;
409 }
410
411
CplxMul(stpSCplx spCplxDest,float fSrc)412 INLINE void clDSPOp::CplxMul (stpSCplx spCplxDest, float fSrc)
413 {
414 spCplxDest->R *= fSrc;
415 spCplxDest->I *= fSrc;
416 }
417
418
CplxMul(stpDCplx spCplxDest,double dSrc)419 INLINE void clDSPOp::CplxMul (stpDCplx spCplxDest, double dSrc)
420 {
421 spCplxDest->R *= dSrc;
422 spCplxDest->I *= dSrc;
423 }
424
425
CplxMul(stpSCplx spCplxDest,const stpSCplx spCplxSrc)426 INLINE void clDSPOp::CplxMul (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
427 {
428 float fReal;
429 float fImag;
430
431 fReal = spCplxDest->R * spCplxSrc->R - spCplxDest->I * spCplxSrc->I;
432 fImag = spCplxDest->R * spCplxSrc->I + spCplxDest->I * spCplxSrc->R;
433 spCplxDest->R = fReal;
434 spCplxDest->I = fImag;
435 }
436
437
CplxMul(stpDCplx spCplxDest,const stpDCplx spCplxSrc)438 INLINE void clDSPOp::CplxMul (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
439 {
440 double dReal;
441 double dImag;
442
443 dReal = spCplxDest->R * spCplxSrc->R - spCplxDest->I * spCplxSrc->I;
444 dImag = spCplxDest->R * spCplxSrc->I + spCplxDest->I * spCplxSrc->R;
445 spCplxDest->R = dReal;
446 spCplxDest->I = dImag;
447 }
448
449
CplxMul(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2)450 INLINE void clDSPOp::CplxMul (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
451 const stpSCplx spCplxSrc2)
452 {
453 spCplxDest->R =
454 spCplxSrc1->R * spCplxSrc2->R - spCplxSrc1->I * spCplxSrc2->I;
455 spCplxDest->I =
456 spCplxSrc1->R * spCplxSrc2->I + spCplxSrc1->I * spCplxSrc2->R;
457 }
458
459
CplxMul(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2)460 INLINE void clDSPOp::CplxMul (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
461 const stpDCplx spCplxSrc2)
462 {
463 spCplxDest->R =
464 spCplxSrc1->R * spCplxSrc2->R - spCplxSrc1->I * spCplxSrc2->I;
465 spCplxDest->I =
466 spCplxSrc1->R * spCplxSrc2->I + spCplxSrc1->I * spCplxSrc2->R;
467 }
468
469
CplxMulC(stpSCplx spCplxDest,const stpSCplx spCplxSrc)470 INLINE void clDSPOp::CplxMulC (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
471 {
472 float fReal;
473 float fImag;
474
475 fReal = spCplxDest->R * spCplxSrc->R - spCplxDest->I * (-spCplxSrc->I);
476 fImag = spCplxDest->R * (-spCplxSrc->I) + spCplxDest->I * spCplxSrc->R;
477 spCplxDest->R = fReal;
478 spCplxDest->I = fImag;
479 }
480
481
CplxMulC(stpDCplx spCplxDest,const stpDCplx spCplxSrc)482 INLINE void clDSPOp::CplxMulC (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
483 {
484 double dReal;
485 double dImag;
486
487 dReal = spCplxDest->R * spCplxSrc->R - spCplxDest->I * (-spCplxSrc->I);
488 dImag = spCplxDest->R * (-spCplxSrc->I) + spCplxDest->I * spCplxSrc->R;
489 spCplxDest->R = dReal;
490 spCplxDest->I = dImag;
491 }
492
493
CplxMulC(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2)494 INLINE void clDSPOp::CplxMulC (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
495 const stpSCplx spCplxSrc2)
496 {
497 spCplxDest->R =
498 spCplxSrc1->R * spCplxSrc2->R - spCplxSrc1->I * (-spCplxSrc2->I);
499 spCplxDest->I =
500 spCplxSrc1->R * (-spCplxSrc2->I) + spCplxSrc1->I * spCplxSrc2->R;
501 }
502
503
CplxMulC(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2)504 INLINE void clDSPOp::CplxMulC (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
505 const stpDCplx spCplxSrc2)
506 {
507 spCplxDest->R =
508 spCplxSrc1->R * spCplxSrc2->R - spCplxSrc1->I * (-spCplxSrc2->I);
509 spCplxDest->I =
510 spCplxSrc1->R * (-spCplxSrc2->I) + spCplxSrc1->I * spCplxSrc2->R;
511 }
512
513
CplxDiv(stpSCplx spCplxDest,const stpSCplx spCplxSrc)514 INLINE void clDSPOp::CplxDiv (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
515 {
516 float fReal;
517 float fImag;
518
519 fReal = (spCplxDest->R * spCplxSrc->R + spCplxDest->I * spCplxSrc->I) /
520 (spCplxSrc->R * spCplxSrc->R + spCplxSrc->I * spCplxSrc->I);
521 fImag = (spCplxDest->I * spCplxSrc->R - spCplxDest->R * spCplxSrc->I) /
522 (spCplxSrc->R * spCplxSrc->R + spCplxSrc->I * spCplxSrc->I);
523 spCplxDest->R = fReal;
524 spCplxDest->I = fImag;
525 }
526
527
CplxDiv(stpDCplx spCplxDest,const stpDCplx spCplxSrc)528 INLINE void clDSPOp::CplxDiv (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
529 {
530 double dReal;
531 double dImag;
532
533 dReal = (spCplxDest->R * spCplxSrc->R + spCplxDest->I * spCplxSrc->I) /
534 (spCplxSrc->R * spCplxSrc->R + spCplxSrc->I * spCplxSrc->I);
535 dImag = (spCplxDest->I * spCplxSrc->R - spCplxDest->R * spCplxSrc->I) /
536 (spCplxSrc->R * spCplxSrc->R + spCplxSrc->I * spCplxSrc->I);
537 spCplxDest->R = dReal;
538 spCplxDest->I = dImag;
539 }
540
541
CplxDiv(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2)542 INLINE void clDSPOp::CplxDiv (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
543 const stpSCplx spCplxSrc2)
544 {
545 spCplxDest->R =
546 (spCplxSrc1->R * spCplxSrc2->R + spCplxSrc1->I * spCplxSrc2->I) /
547 (spCplxSrc2->R * spCplxSrc2->R + spCplxSrc2->I * spCplxSrc2->I);
548 spCplxDest->I =
549 (spCplxSrc1->I * spCplxSrc2->R - spCplxSrc1->R * spCplxSrc2->I) /
550 (spCplxSrc2->R * spCplxSrc2->R + spCplxSrc2->I * spCplxSrc2->I);
551 }
552
553
CplxDiv(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2)554 INLINE void clDSPOp::CplxDiv (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
555 const stpDCplx spCplxSrc2)
556 {
557 spCplxDest->R =
558 (spCplxSrc1->R * spCplxSrc2->R + spCplxSrc1->I * spCplxSrc2->I) /
559 (spCplxSrc2->R * spCplxSrc2->R + spCplxSrc2->I * spCplxSrc2->I);
560 spCplxDest->I =
561 (spCplxSrc1->I * spCplxSrc2->R - spCplxSrc1->R * spCplxSrc2->I) /
562 (spCplxSrc2->R * spCplxSrc2->R + spCplxSrc2->I * spCplxSrc2->I);
563 }
564
565
CplxExp(stpSCplx spCplxDest,const stpSCplx spCplxSrc)566 INLINE void clDSPOp::CplxExp (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
567 {
568 float fRealExp;
569
570 fRealExp = expf(spCplxSrc->R);
571 #ifndef _GNU_SOURCE
572 spCplxDest->R = fRealExp * cosf(spCplxSrc->I);
573 spCplxDest->I = fRealExp * sinf(spCplxSrc->I);
574 #else
575 sincosf(spCplxSrc->I, &spCplxDest->I, &spCplxDest->R);
576 spCplxDest->R *= fRealExp;
577 spCplxDest->I *= fRealExp;
578 #endif
579 }
580
581
CplxExp(stpDCplx spCplxDest,const stpDCplx spCplxSrc)582 INLINE void clDSPOp::CplxExp (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
583 {
584 double dRealExp;
585
586 dRealExp = exp(spCplxSrc->R);
587 #ifndef _GNU_SOURCE
588 spCplxDest->R = dRealExp * cos(spCplxSrc->I);
589 spCplxDest->I = dRealExp * sin(spCplxSrc->I);
590 #else
591 sincos(spCplxSrc->I, &spCplxDest->I, &spCplxDest->R);
592 spCplxDest->R *= dRealExp;
593 spCplxDest->I *= dRealExp;
594 #endif
595 }
596
597
CplxLog(stpSCplx spCplxDest,const stpSCplx spCplxSrc)598 INLINE void clDSPOp::CplxLog (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
599 {
600 Cart2Polar(&spCplxDest->R, &spCplxDest->I, spCplxSrc->R, spCplxSrc->I);
601 spCplxDest->R = logf(spCplxDest->R);
602 }
603
604
CplxLog(stpDCplx spCplxDest,const stpDCplx spCplxSrc)605 INLINE void clDSPOp::CplxLog (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
606 {
607 Cart2Polar(&spCplxDest->R, &spCplxDest->I, spCplxSrc->R, spCplxSrc->I);
608 spCplxDest->R = log(spCplxDest->R);
609 }
610
611
CplxLog10(stpSCplx spCplxDest,const stpSCplx spCplxSrc)612 INLINE void clDSPOp::CplxLog10 (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
613 {
614 Cart2Polar(&spCplxDest->R, &spCplxDest->I, spCplxSrc->R, spCplxSrc->I);
615 spCplxDest->R = log10f(spCplxDest->R);
616 }
617
618
CplxLog10(stpDCplx spCplxDest,const stpDCplx spCplxSrc)619 INLINE void clDSPOp::CplxLog10 (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
620 {
621 Cart2Polar(&spCplxDest->R, &spCplxDest->I, spCplxSrc->R, spCplxSrc->I);
622 spCplxDest->R = log10(spCplxDest->R);
623 }
624
625
CplxPow(stpSCplx spCplxDest,const stpSCplx spCplxSrc,const stpSCplx spCplxExp)626 INLINE void clDSPOp::CplxPow (stpSCplx spCplxDest, const stpSCplx spCplxSrc,
627 const stpSCplx spCplxExp)
628 {
629 stSCplx sCplxTemp;
630
631 CplxLog(&sCplxTemp, spCplxSrc);
632 CplxMul(&sCplxTemp, spCplxExp);
633 CplxExp(spCplxDest, &sCplxTemp);
634 }
635
636
CplxPow(stpDCplx spCplxDest,const stpDCplx spCplxSrc,const stpDCplx spCplxExp)637 INLINE void clDSPOp::CplxPow (stpDCplx spCplxDest, const stpDCplx spCplxSrc,
638 const stpDCplx spCplxExp)
639 {
640 stDCplx sCplxTemp;
641
642 CplxLog(&sCplxTemp, spCplxSrc);
643 CplxMul(&sCplxTemp, spCplxExp);
644 CplxExp(spCplxDest, &sCplxTemp);
645 }
646
647
CplxRoot(stpSCplx spCplxDest,const stpSCplx spCplxSrc,const stpSCplx spCplxRoot)648 INLINE void clDSPOp::CplxRoot (stpSCplx spCplxDest, const stpSCplx spCplxSrc,
649 const stpSCplx spCplxRoot)
650 {
651 stSCplx sCplxExp;
652
653 sCplxExp.R = 1.0F;
654 sCplxExp.I = 0.0F;
655 CplxDiv(&sCplxExp, spCplxRoot);
656 CplxPow(spCplxDest, spCplxSrc, &sCplxExp);
657 }
658
659
CplxRoot(stpDCplx spCplxDest,const stpDCplx spCplxSrc,const stpDCplx spCplxRoot)660 INLINE void clDSPOp::CplxRoot (stpDCplx spCplxDest, const stpDCplx spCplxSrc,
661 const stpDCplx spCplxRoot)
662 {
663 stDCplx sCplxExp;
664
665 sCplxExp.R = 1.0;
666 sCplxExp.I = 0.0;
667 CplxDiv(&sCplxExp, spCplxRoot);
668 CplxPow(spCplxDest, spCplxSrc, &sCplxExp);
669 }
670
671
672 /*INLINE void clDSPOp::CplxConj (stpSCplx spCplx)
673 {
674 spCplx->I = -(spCplx->I);
675 }
676
677
678 INLINE void clDSPOp::CplxConj (stpDCplx spCplx)
679 {
680 spCplx->I = -(spCplx->I);
681 }*/
682
683
CplxConj(stpSCplx spCplxDest,const stpSCplx spCplxSrc)684 INLINE void clDSPOp::CplxConj (stpSCplx spCplxDest, const stpSCplx spCplxSrc)
685 {
686 spCplxDest->R = spCplxSrc->R;
687 spCplxDest->I = -(spCplxSrc->I);
688 }
689
690
CplxConj(stpDCplx spCplxDest,const stpDCplx spCplxSrc)691 INLINE void clDSPOp::CplxConj (stpDCplx spCplxDest, const stpDCplx spCplxSrc)
692 {
693 spCplxDest->R = spCplxSrc->R;
694 spCplxDest->I = -(spCplxSrc->I);
695 }
696
697
Multiple(long lValue)698 INLINE double clDSPOp::Multiple (long lValue)
699 {
700 long lLoopCntr;
701 double dMult = 1.0;
702
703 for (lLoopCntr = 1L; lLoopCntr <= lValue; lLoopCntr++)
704 {
705 dMult *= (double) lLoopCntr;
706 }
707 return dMult;
708 }
709
710
ModZeroBessel(float fValue)711 INLINE float clDSPOp::ModZeroBessel (float fValue)
712 {
713 long lLoopCntr;
714 float fMZBessel = 0.0F;
715 float fHalfValue;
716
717 fHalfValue = fValue / 2.0F;
718 for (lLoopCntr = 0L; lLoopCntr <= DSP_MAXBESSEL; lLoopCntr++)
719 {
720 fMZBessel += (float) pow(
721 pow(fHalfValue, lLoopCntr) / Multiple(lLoopCntr), 2.0);
722 }
723 return fMZBessel;
724 }
725
726
ModZeroBessel(double dValue)727 INLINE double clDSPOp::ModZeroBessel (double dValue)
728 {
729 long lLoopCntr;
730 double dMZBessel = 0.0;
731 double dHalfValue;
732
733 dHalfValue = dValue / 2.0;
734 for (lLoopCntr = 0L; lLoopCntr <= DSP_MAXBESSEL; lLoopCntr++)
735 {
736 dMZBessel += pow(
737 pow(dHalfValue, lLoopCntr) / Multiple(lLoopCntr), 2.0);
738 }
739 return dMZBessel;
740 }
741
742
ChebyshevPolynom(float fOrder,float fValue)743 float clDSPOp::ChebyshevPolynom (float fOrder, float fValue)
744 {
745 if (fabsf(fValue) <= 1.0F)
746 {
747 return cosf(fOrder * acosf(fValue));
748 }
749 else
750 {
751 return coshf(fOrder * acoshf(fValue));
752 }
753 }
754
755
ChebyshevPolynom(double dOrder,double dValue)756 double clDSPOp::ChebyshevPolynom (double dOrder, double dValue)
757 {
758 if (fabs(dValue) <= 1.0)
759 {
760 return cos(dOrder * acos(dValue));
761 }
762 else
763 {
764 return cosh(dOrder * acosh(dValue));
765 }
766 }
767
768
clDSPOp()769 clDSPOp::clDSPOp()
770 {
771 #ifdef DSP_X86
772 bHave3DNow = (dsp_x86_have_e3dnow()) ? true : false;
773 bHaveSSE = (dsp_x86_have_sse2()) ? true : false;
774 #ifdef __INTEL_COMPILER
775 if (bHaveSSE)
776 {
777 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
778 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
779 }
780 #endif
781 #endif
782 lPrevSrcCount = 0;
783 lPrevDestCount = 0;
784 // This is to get maximum precision for PI
785 #ifdef _ISOC9X_SOURCE
786 fPI = (float) acosl(-1.0);
787 dPI = (double) acosl(-1.0);
788 #else
789 fPI = (float) acos(-1.0);
790 dPI = acos(-1.0);
791 #endif
792 bFFTInitialized = false;
793 lpSBitRevWork = NULL;
794 lpDBitRevWork = NULL;
795 fpCosSinTable = NULL;
796 dpCosSinTable = NULL;
797 }
798
799
~clDSPOp()800 clDSPOp::~clDSPOp()
801 {
802 if (bFFTInitialized)
803 {
804 FFTUninitialize();
805 }
806 }
807
808
Add(float * fpDest,float fSrc,long lCount)809 void clDSPOp::Add (float *fpDest, float fSrc, long lCount)
810 {
811 #ifdef DSP_IPP
812 ippsAddC_32f_I(fSrc, fpDest, lCount);
813 #else
814 long lLoopCntr;
815
816 #ifdef DSP_X86
817 if (bHave3DNow)
818 {
819 dsp_x86_3dnow_addf(fpDest, fSrc, lCount);
820 }
821 else if (bHaveSSE)
822 {
823 dsp_x86_sse_addf(fpDest, fSrc, lCount);
824 }
825 else
826 #endif
827 {
828 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
829 {
830 fpDest[lLoopCntr] += fSrc;
831 }
832 }
833 #endif
834 }
835
836
Add(double * dpDest,double dSrc,long lCount)837 void clDSPOp::Add (double *dpDest, double dSrc, long lCount)
838 {
839 #ifdef DSP_IPP
840 ippsAddC_64f_I(dSrc, dpDest, lCount);
841 #else
842 long lLoopCntr;
843
844 #ifdef DSP_X86
845 if (bHaveSSE)
846 {
847 dsp_x86_sse_add(dpDest, dSrc, lCount);
848 }
849 else
850 #endif
851 {
852 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
853 {
854 dpDest[lLoopCntr] += dSrc;
855 }
856 }
857 #endif
858 }
859
860
Add(stpSCplx spCplxDest,stSCplx sCplxSrc,long lCount)861 void clDSPOp::Add (stpSCplx spCplxDest, stSCplx sCplxSrc, long lCount)
862 {
863 #ifdef DSP_IPP
864 ippsAddC_32fc_I(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest, lCount);
865 #else
866 long lLoopCntr;
867
868 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
869 {
870 CplxAdd(&spCplxDest[lLoopCntr], &sCplxSrc);
871 }
872 #endif
873 }
874
875
Add(stpDCplx spCplxDest,stDCplx sCplxSrc,long lCount)876 void clDSPOp::Add (stpDCplx spCplxDest, stDCplx sCplxSrc, long lCount)
877 {
878 #ifdef DSP_IPP
879 ippsAddC_64fc_I(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest, lCount);
880 #else
881 long lLoopCntr;
882
883 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
884 {
885 CplxAdd(&spCplxDest[lLoopCntr], &sCplxSrc);
886 }
887 #endif
888 }
889
890
Add(float * fpDest,const float * fpSrc,long lCount)891 void clDSPOp::Add (float *fpDest, const float *fpSrc, long lCount)
892 {
893 #ifdef DSP_IPP
894 ippsAdd_32f_I(fpSrc, fpDest, lCount);
895 #else
896 long lLoopCntr;
897
898 #ifdef DSP_X86
899 if (bHave3DNow)
900 {
901 dsp_x86_3dnow_add2f(fpDest, fpSrc, lCount);
902 }
903 else if (bHaveSSE)
904 {
905 dsp_x86_sse_add2f(fpDest, fpSrc, lCount);
906 }
907 else
908 #endif
909 {
910 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
911 {
912 fpDest[lLoopCntr] += fpSrc[lLoopCntr];
913 }
914 }
915 #endif
916 }
917
918
Add(double * dpDest,const double * dpSrc,long lCount)919 void clDSPOp::Add (double *dpDest, const double *dpSrc, long lCount)
920 {
921 #ifdef DSP_IPP
922 ippsAdd_64f_I(dpSrc, dpDest, lCount);
923 #else
924 long lLoopCntr;
925
926 #ifdef DSP_X86
927 if (bHaveSSE)
928 {
929 dsp_x86_sse_add2(dpDest, dpSrc, lCount);
930 }
931 else
932 #endif
933 {
934 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
935 {
936 dpDest[lLoopCntr] += dpSrc[lLoopCntr];
937 }
938 }
939 #endif
940 }
941
942
Add(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)943 void clDSPOp::Add (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
944 {
945 #ifdef DSP_IPP
946 ippsAdd_32fc_I((Ipp32fc *) spCplxSrc, (Ipp32fc *) spCplxDest, lCount);
947 #else
948 long lLoopCntr;
949
950 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
951 {
952 CplxAdd(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
953 }
954 #endif
955 }
956
957
Add(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)958 void clDSPOp::Add (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
959 {
960 #ifdef DSP_IPP
961 ippsAdd_64fc_I((Ipp64fc *) spCplxSrc, (Ipp64fc *) spCplxDest, lCount);
962 #else
963 long lLoopCntr;
964
965 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
966 {
967 CplxAdd(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
968 }
969 #endif
970 }
971
972
Add(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)973 void clDSPOp::Add (float *fpDest, const float *fpSrc1, const float *fpSrc2,
974 long lCount)
975 {
976 #ifdef DSP_IPP
977 ippsAdd_32f(fpSrc1, fpSrc2, fpDest, lCount);
978 #else
979 long lLoopCntr;
980
981 #ifdef DSP_X86
982 if (bHave3DNow)
983 {
984 dsp_x86_3dnow_add3f(fpDest, fpSrc1, fpSrc2, lCount);
985 }
986 else if (bHaveSSE)
987 {
988 dsp_x86_sse_add3f(fpDest, fpSrc1, fpSrc2, lCount);
989 }
990 else
991 #endif
992 {
993 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
994 {
995 fpDest[lLoopCntr] = fpSrc1[lLoopCntr] + fpSrc2[lLoopCntr];
996 }
997 }
998 #endif
999 }
1000
1001
Add(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)1002 void clDSPOp::Add (double *dpDest, const double *dpSrc1, const double *dpSrc2,
1003 long lCount)
1004 {
1005 #ifdef DSP_IPP
1006 ippsAdd_64f(dpSrc1, dpSrc2, dpDest, lCount);
1007 #else
1008 long lLoopCntr;
1009
1010 #ifdef DSP_X86
1011 if (bHaveSSE)
1012 {
1013 dsp_x86_sse_add3(dpDest, dpSrc1, dpSrc2, lCount);
1014 }
1015 else
1016 #endif
1017 {
1018 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1019 {
1020 dpDest[lLoopCntr] = dpSrc1[lLoopCntr] + dpSrc2[lLoopCntr];
1021 }
1022 }
1023 #endif
1024 }
1025
1026
Add(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2,long lCount)1027 void clDSPOp::Add (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
1028 const stpSCplx spCplxSrc2, long lCount)
1029 {
1030 #ifdef DSP_IPP
1031 ippsAdd_32fc((Ipp32fc *) spCplxSrc1, (Ipp32fc *) spCplxSrc2,
1032 (Ipp32fc *) spCplxDest, lCount);
1033 #else
1034 long lLoopCntr;
1035
1036 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1037 {
1038 CplxAdd(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1039 &spCplxSrc2[lLoopCntr]);
1040 }
1041 #endif
1042 }
1043
1044
Add(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2,long lCount)1045 void clDSPOp::Add (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
1046 const stpDCplx spCplxSrc2, long lCount)
1047 {
1048 #ifdef DSP_IPP
1049 ippsAdd_64fc((Ipp64fc *) spCplxSrc1, (Ipp64fc *) spCplxSrc2,
1050 (Ipp64fc *) spCplxDest, lCount);
1051 #else
1052 long lLoopCntr;
1053
1054 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1055 {
1056 CplxAdd(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1057 &spCplxSrc2[lLoopCntr]);
1058 }
1059 #endif
1060 }
1061
1062
Sub(float * fpDest,float fSrc,long lCount)1063 void clDSPOp::Sub (float *fpDest, float fSrc, long lCount)
1064 {
1065 #ifdef DSP_IPP
1066 ippsSubC_32f_I(fSrc, fpDest, lCount);
1067 #else
1068 long lLoopCntr;
1069
1070 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1071 {
1072 fpDest[lLoopCntr] -= fSrc;
1073 }
1074 #endif
1075 }
1076
1077
Sub(double * dpDest,double dSrc,long lCount)1078 void clDSPOp::Sub (double *dpDest, double dSrc, long lCount)
1079 {
1080 #ifdef DSP_IPP
1081 ippsSubC_64f_I(dSrc, dpDest, lCount);
1082 #else
1083 long lLoopCntr;
1084
1085 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1086 {
1087 dpDest[lLoopCntr] -= dSrc;
1088 }
1089 #endif
1090 }
1091
1092
Sub(stpSCplx spCplxDest,stSCplx sCplxSrc,long lCount)1093 void clDSPOp::Sub (stpSCplx spCplxDest, stSCplx sCplxSrc, long lCount)
1094 {
1095 #ifdef DSP_IPP
1096 ippsSubC_32fc_I(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest, lCount);
1097 #else
1098 long lLoopCntr;
1099
1100 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1101 {
1102 CplxSub(&spCplxDest[lLoopCntr], &sCplxSrc);
1103 }
1104 #endif
1105 }
1106
1107
Sub(stpDCplx spCplxDest,stDCplx sCplxSrc,long lCount)1108 void clDSPOp::Sub (stpDCplx spCplxDest, stDCplx sCplxSrc, long lCount)
1109 {
1110 #ifdef DSP_IPP
1111 ippsSubC_64fc_I(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest, lCount);
1112 #else
1113 long lLoopCntr;
1114
1115 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1116 {
1117 CplxSub(&spCplxDest[lLoopCntr], &sCplxSrc);
1118 }
1119 #endif
1120 }
1121
1122
Sub(float * fpDest,const float * fpSrc,long lCount)1123 void clDSPOp::Sub (float *fpDest, const float *fpSrc, long lCount)
1124 {
1125 #ifdef DSP_IPP
1126 ippsSub_32f_I(fpSrc, fpDest, lCount);
1127 #else
1128 long lLoopCntr;
1129
1130 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1131 {
1132 fpDest[lLoopCntr] -= fpSrc[lLoopCntr];
1133 }
1134 #endif
1135 }
1136
1137
Sub(double * dpDest,const double * dpSrc,long lCount)1138 void clDSPOp::Sub (double *dpDest, const double *dpSrc, long lCount)
1139 {
1140 #ifdef DSP_IPP
1141 ippsSub_64f_I(dpSrc, dpDest, lCount);
1142 #else
1143 long lLoopCntr;
1144
1145 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1146 {
1147 dpDest[lLoopCntr] -= dpSrc[lLoopCntr];
1148 }
1149 #endif
1150 }
1151
1152
Sub(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)1153 void clDSPOp::Sub (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
1154 {
1155 #ifdef DSP_IPP
1156 ippsSub_32fc_I((Ipp32fc *) spCplxSrc, (Ipp32fc *) spCplxDest, lCount);
1157 #else
1158 long lLoopCntr;
1159
1160 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1161 {
1162 CplxSub(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1163 }
1164 #endif
1165 }
1166
1167
Sub(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)1168 void clDSPOp::Sub (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
1169 {
1170 #ifdef DSP_IPP
1171 ippsSub_64fc_I((Ipp64fc *) spCplxSrc, (Ipp64fc *) spCplxDest, lCount);
1172 #else
1173 long lLoopCntr;
1174
1175 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1176 {
1177 CplxSub(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1178 }
1179 #endif
1180 }
1181
1182
Sub(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)1183 void clDSPOp::Sub (float *fpDest, const float *fpSrc1, const float *fpSrc2,
1184 long lCount)
1185 {
1186 #ifdef DSP_IPP
1187 ippsSub_32f(fpSrc1, fpSrc2, fpDest, lCount);
1188 #else
1189 long lLoopCntr;
1190
1191 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1192 {
1193 fpDest[lLoopCntr] = fpSrc1[lLoopCntr] - fpSrc2[lLoopCntr];
1194 }
1195 #endif
1196 }
1197
1198
Sub(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)1199 void clDSPOp::Sub (double *dpDest, const double *dpSrc1, const double *dpSrc2,
1200 long lCount)
1201 {
1202 #ifdef DSP_IPP
1203 ippsSub_64f(dpSrc1, dpSrc2, dpDest, lCount);
1204 #else
1205 long lLoopCntr;
1206
1207 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1208 {
1209 dpDest[lLoopCntr] = dpSrc1[lLoopCntr] - dpSrc2[lLoopCntr];
1210 }
1211 #endif
1212 }
1213
1214
Sub(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2,long lCount)1215 void clDSPOp::Sub (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
1216 const stpSCplx spCplxSrc2, long lCount)
1217 {
1218 #ifdef DSP_IPP
1219 ippsSub_32fc((Ipp32fc *) spCplxSrc1, (Ipp32fc *) spCplxSrc2,
1220 (Ipp32fc *) spCplxDest, lCount);
1221 #else
1222 long lLoopCntr;
1223
1224 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1225 {
1226 CplxSub(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1227 &spCplxSrc2[lLoopCntr]);
1228 }
1229 #endif
1230 }
1231
1232
Sub(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2,long lCount)1233 void clDSPOp::Sub (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
1234 const stpDCplx spCplxSrc2, long lCount)
1235 {
1236 #ifdef DSP_IPP
1237 ippsSub_64fc((Ipp64fc *) spCplxSrc1, (Ipp64fc *) spCplxSrc2,
1238 (Ipp64fc *) spCplxDest, lCount);
1239 #else
1240 long lLoopCntr;
1241
1242 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1243 {
1244 CplxSub(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1245 &spCplxSrc2[lLoopCntr]);
1246 }
1247 #endif
1248 }
1249
1250
1251
Mul(float * fpVect,float fSrc,long lCount)1252 void clDSPOp::Mul (float *fpVect, float fSrc, long lCount)
1253 {
1254 #ifdef DSP_IPP
1255 ippsMulC_32f_I(fSrc, fpVect, lCount);
1256 #else
1257 long lLoopCntr;
1258
1259 #ifdef DSP_X86
1260 if (bHave3DNow)
1261 {
1262 dsp_x86_3dnow_mulf(fpVect, fSrc, lCount);
1263 }
1264 else if (bHaveSSE)
1265 {
1266 dsp_x86_sse_mulf(fpVect, fSrc, lCount);
1267 }
1268 else
1269 #endif
1270 {
1271 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1272 {
1273 fpVect[lLoopCntr] *= fSrc;
1274 }
1275 }
1276 #endif
1277 }
1278
1279
Mul(double * dpVect,double dSrc,long lCount)1280 void clDSPOp::Mul (double *dpVect, double dSrc, long lCount)
1281 {
1282 #ifdef DSP_IPP
1283 ippsMulC_64f_I(dSrc, dpVect, lCount);
1284 #else
1285 long lLoopCntr;
1286
1287 #ifdef DSP_X86
1288 if (bHaveSSE)
1289 {
1290 dsp_x86_sse_mul(dpVect, dSrc, lCount);
1291 }
1292 else
1293 #endif
1294 {
1295 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1296 {
1297 dpVect[lLoopCntr] *= dSrc;
1298 }
1299 }
1300 #endif
1301 }
1302
1303
Mul(stpSCplx spCplxDest,float fSrc,long lCount)1304 void clDSPOp::Mul (stpSCplx spCplxDest, float fSrc, long lCount)
1305 {
1306 long lLoopCntr;
1307
1308 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1309 {
1310 CplxMul(&spCplxDest[lLoopCntr], fSrc);
1311 }
1312 }
1313
1314
Mul(stpDCplx spCplxDest,double dSrc,long lCount)1315 void clDSPOp::Mul (stpDCplx spCplxDest, double dSrc, long lCount)
1316 {
1317 long lLoopCntr;
1318
1319 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1320 {
1321 CplxMul(&spCplxDest[lLoopCntr], dSrc);
1322 }
1323 }
1324
1325
Mul(stpSCplx spCplxDest,stSCplx sCplxSrc,long lCount)1326 void clDSPOp::Mul (stpSCplx spCplxDest, stSCplx sCplxSrc, long lCount)
1327 {
1328 #ifdef DSP_IPP
1329 ippsMulC_32fc_I(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest, lCount);
1330 #else
1331 long lLoopCntr;
1332
1333 #ifdef DSP_X86
1334 if (bHave3DNow)
1335 {
1336 dsp_x86_3dnow_cmulf((float *) spCplxDest,
1337 (const float *) &sCplxSrc, lCount);
1338 }
1339 else if (bHaveSSE)
1340 {
1341 dsp_x86_sse_cmulf((float *) spCplxDest,
1342 (const float *) &sCplxSrc, lCount);
1343 }
1344 else
1345 #endif
1346 {
1347 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1348 {
1349 CplxMul(&spCplxDest[lLoopCntr], &sCplxSrc);
1350 }
1351 }
1352 #endif
1353 }
1354
1355
Mul(stpDCplx spCplxDest,stDCplx sCplxSrc,long lCount)1356 void clDSPOp::Mul (stpDCplx spCplxDest, stDCplx sCplxSrc, long lCount)
1357 {
1358 #ifdef DSP_IPP
1359 ippsMulC_64fc_I(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest, lCount);
1360 #else
1361 long lLoopCntr;
1362
1363 #ifdef DSP_X86
1364 if (bHaveSSE)
1365 {
1366 dsp_x86_sse_cmul((double *) spCplxDest,
1367 (const double *) &sCplxSrc, lCount);
1368 }
1369 else
1370 #endif
1371 {
1372 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1373 {
1374 CplxMul(&spCplxDest[lLoopCntr], &sCplxSrc);
1375 }
1376 }
1377 #endif
1378 }
1379
1380
Mul(float * fpDest,const float * fpSrc1,float fSrc2,long lCount)1381 void clDSPOp::Mul (float *fpDest, const float *fpSrc1, float fSrc2,
1382 long lCount)
1383 {
1384 #ifdef DSP_IPP
1385 ippsMulC_32f(fpSrc1, fSrc2, fpDest, lCount);
1386 #else
1387 long lLoopCntr;
1388
1389 #ifdef DSP_X86
1390 if (bHave3DNow)
1391 {
1392 dsp_x86_3dnow_mulf_nip(fpDest, fpSrc1, fSrc2, lCount);
1393 }
1394 else if (bHaveSSE)
1395 {
1396 dsp_x86_sse_mulf_nip(fpDest, fpSrc1, fSrc2, lCount);
1397 }
1398 else
1399 #endif
1400 {
1401 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1402 {
1403 fpDest[lLoopCntr] = fpSrc1[lLoopCntr] * fSrc2;
1404 }
1405 }
1406 #endif
1407 }
1408
1409
Mul(double * dpDest,const double * dpSrc1,double dSrc2,long lCount)1410 void clDSPOp::Mul (double *dpDest, const double *dpSrc1, double dSrc2,
1411 long lCount)
1412 {
1413 #ifdef DSP_IPP
1414 ippsMulC_64f(dpSrc1, dSrc2, dpDest, lCount);
1415 #else
1416 long lLoopCntr;
1417
1418 #ifdef DSP_X86
1419 if (bHaveSSE)
1420 {
1421 dsp_x86_sse_mul_nip(dpDest, dpSrc1, dSrc2, lCount);
1422 }
1423 else
1424 #endif
1425 {
1426 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1427 {
1428 dpDest[lLoopCntr] = dpSrc1[lLoopCntr] * dSrc2;
1429 }
1430 }
1431 #endif
1432 }
1433
1434
Mul(float * fpDest,const float * fpSrc,long lCount)1435 void clDSPOp::Mul (float *fpDest, const float *fpSrc, long lCount)
1436 {
1437 #ifdef DSP_IPP
1438 ippsMul_32f_I(fpSrc, fpDest, lCount);
1439 #else
1440 long lLoopCntr;
1441
1442 #ifdef DSP_X86
1443 if (bHave3DNow)
1444 {
1445 dsp_x86_3dnow_mul2f(fpDest, fpSrc, lCount);
1446 }
1447 else if (bHaveSSE)
1448 {
1449 dsp_x86_sse_mul2f(fpDest, fpSrc, lCount);
1450 }
1451 else
1452 #endif
1453 {
1454 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1455 {
1456 fpDest[lLoopCntr] *= fpSrc[lLoopCntr];
1457 }
1458 }
1459 #endif
1460 }
1461
1462
Mul(double * dpDest,const double * dpSrc,long lCount)1463 void clDSPOp::Mul (double *dpDest, const double *dpSrc, long lCount)
1464 {
1465 #ifdef DSP_IPP
1466 ippsMul_64f_I(dpSrc, dpDest, lCount);
1467 #else
1468 long lLoopCntr;
1469
1470 #ifdef DSP_X86
1471 if (bHaveSSE)
1472 {
1473 dsp_x86_sse_mul2(dpDest, dpSrc, lCount);
1474 }
1475 else
1476 #endif
1477 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1478 {
1479 dpDest[lLoopCntr] *= dpSrc[lLoopCntr];
1480 }
1481 #endif
1482 }
1483
1484
Mul(stpSCplx spCplxDest,const float * fpSrc,long lCount)1485 void clDSPOp::Mul (stpSCplx spCplxDest, const float *fpSrc, long lCount)
1486 {
1487 long lLoopCntr;
1488
1489 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1490 {
1491 CplxMul(&spCplxDest[lLoopCntr], fpSrc[lLoopCntr]);
1492 }
1493 }
1494
1495
Mul(stpDCplx spCplxDest,const double * dpSrc,long lCount)1496 void clDSPOp::Mul (stpDCplx spCplxDest, const double *dpSrc, long lCount)
1497 {
1498 long lLoopCntr;
1499
1500 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1501 {
1502 CplxMul(&spCplxDest[lLoopCntr], dpSrc[lLoopCntr]);
1503 }
1504 }
1505
1506
Mul(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)1507 void clDSPOp::Mul (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
1508 {
1509 #ifdef DSP_IPP
1510 ippsMul_32fc_I((Ipp32fc *) spCplxSrc, (Ipp32fc *) spCplxDest, lCount);
1511 #else
1512 long lLoopCntr;
1513
1514 #ifdef DSP_X86
1515 if (bHave3DNow)
1516 {
1517 dsp_x86_3dnow_cmul2f((float *) spCplxDest, (const float *) spCplxSrc,
1518 lCount);
1519 }
1520 else if (bHaveSSE)
1521 {
1522 dsp_x86_sse_cmul2f((float *) spCplxDest, (const float *) spCplxSrc,
1523 lCount);
1524 }
1525 else
1526 #endif
1527 {
1528 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1529 {
1530 CplxMul(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1531 }
1532 }
1533 #endif
1534 }
1535
1536
Mul(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)1537 void clDSPOp::Mul (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
1538 {
1539 #ifdef DSP_IPP
1540 ippsMul_64fc_I((Ipp64fc *) spCplxSrc, (Ipp64fc *) spCplxDest, lCount);
1541 #else
1542 long lLoopCntr;
1543
1544 #ifdef DSP_X86
1545 if (bHaveSSE)
1546 {
1547 dsp_x86_sse_cmul2((double *) spCplxDest, (const double *) spCplxSrc,
1548 lCount);
1549 }
1550 else
1551 #endif
1552 {
1553 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1554 {
1555 CplxMul(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1556 }
1557 }
1558 #endif
1559 }
1560
1561
Mul(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)1562 void clDSPOp::Mul (float *fpDest, const float *fpSrc1,
1563 const float *fpSrc2, long lCount)
1564 {
1565 #ifdef DSP_IPP
1566 ippsMul_32f(fpSrc1, fpSrc2, fpDest, lCount);
1567 #else
1568 long lLoopCntr;
1569
1570 #ifdef DSP_X86
1571 if (bHave3DNow)
1572 {
1573 dsp_x86_3dnow_mul3f(fpDest, fpSrc1, fpSrc2, lCount);
1574 }
1575 else if (bHaveSSE)
1576 {
1577 dsp_x86_sse_mul3f(fpDest, fpSrc1, fpSrc2, lCount);
1578 }
1579 else
1580 #endif
1581 {
1582 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1583 {
1584 fpDest[lLoopCntr] = fpSrc1[lLoopCntr] * fpSrc2[lLoopCntr];
1585 }
1586 }
1587 #endif
1588 }
1589
1590
Mul(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)1591 void clDSPOp::Mul (double *dpDest, const double *dpSrc1,
1592 const double *dpSrc2, long lCount)
1593 {
1594 #ifdef DSP_IPP
1595 ippsMul_64f(dpSrc1, dpSrc2, dpDest, lCount);
1596 #else
1597 long lLoopCntr;
1598
1599 #ifdef DSP_X86
1600 if (bHaveSSE)
1601 {
1602 dsp_x86_sse_mul3(dpDest, dpSrc1, dpSrc2, lCount);
1603 }
1604 else
1605 #endif
1606 {
1607 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1608 {
1609 dpDest[lLoopCntr] = dpSrc1[lLoopCntr] * dpSrc2[lLoopCntr];
1610 }
1611 }
1612 #endif
1613 }
1614
1615
Mul(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2,long lCount)1616 void clDSPOp::Mul (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
1617 const stpSCplx spCplxSrc2, long lCount)
1618 {
1619 #ifdef DSP_IPP
1620 ippsMul_64fc((Ipp64fc *) spCplxSrc1, (Ipp64fc *) spCplxSrc2,
1621 (Ipp64fc *) spCplxDest, lCount);
1622 #else
1623 long lLoopCntr;
1624
1625 #ifdef DSP_X86
1626 if (bHave3DNow)
1627 {
1628 dsp_x86_3dnow_cmul3f((float *) spCplxDest,
1629 (const float *) spCplxSrc1,
1630 (const float *) spCplxSrc2,
1631 lCount);
1632 }
1633 else if (bHaveSSE)
1634 {
1635 dsp_x86_sse_cmul3f((float *) spCplxDest,
1636 (const float *) spCplxSrc1,
1637 (const float *) spCplxSrc2,
1638 lCount);
1639 }
1640 else
1641 #endif
1642 {
1643 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1644 {
1645 CplxMul(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1646 &spCplxSrc2[lLoopCntr]);
1647 }
1648 }
1649 #endif
1650 }
1651
1652
Mul(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2,long lCount)1653 void clDSPOp::Mul (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
1654 const stpDCplx spCplxSrc2, long lCount)
1655 {
1656 #ifdef DSP_IPP
1657 ippsMul_64fc((Ipp64fc *) spCplxSrc1, (Ipp64fc *) spCplxSrc2,
1658 (Ipp64fc *) spCplxDest, lCount);
1659 #else
1660 long lLoopCntr;
1661
1662 #ifdef DSP_X86
1663 if (bHaveSSE)
1664 {
1665 dsp_x86_sse_cmul3((double *) spCplxDest,
1666 (const double *) spCplxSrc1,
1667 (const double *) spCplxSrc2,
1668 lCount);
1669 }
1670 else
1671 #endif
1672 {
1673 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1674 {
1675 CplxMul(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1676 &spCplxSrc2[lLoopCntr]);
1677 }
1678 }
1679 #endif
1680 }
1681
1682
MulC(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)1683 void clDSPOp::MulC (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
1684 {
1685 long lLoopCntr;
1686
1687 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1688 {
1689 CplxMulC(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1690 }
1691 }
1692
1693
MulC(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)1694 void clDSPOp::MulC (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
1695 {
1696 long lLoopCntr;
1697
1698 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1699 {
1700 CplxMulC(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1701 }
1702 }
1703
1704
MulC(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2,long lCount)1705 void clDSPOp::MulC (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
1706 const stpSCplx spCplxSrc2, long lCount)
1707 {
1708 long lLoopCntr;
1709
1710 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1711 {
1712 CplxMulC(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1713 &spCplxSrc2[lLoopCntr]);
1714 }
1715 }
1716
1717
MulC(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2,long lCount)1718 void clDSPOp::MulC (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
1719 const stpDCplx spCplxSrc2, long lCount)
1720 {
1721 long lLoopCntr;
1722
1723 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1724 {
1725 CplxMulC(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1726 &spCplxSrc2[lLoopCntr]);
1727 }
1728 }
1729
1730
Mul2(float * fpDst1,float * fpDst2,const float * fpSrc,long lCount)1731 void clDSPOp::Mul2 (float *fpDst1, float *fpDst2, const float *fpSrc,
1732 long lCount)
1733 {
1734 long lLoopCntr;
1735
1736 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1737 {
1738 fpDst1[lLoopCntr] *= fpSrc[lLoopCntr];
1739 fpDst2[lLoopCntr] *= fpSrc[lLoopCntr];
1740 }
1741 }
1742
1743
Mul2(double * dpDst1,double * dpDst2,const double * dpSrc,long lCount)1744 void clDSPOp::Mul2 (double *dpDst1, double *dpDst2, const double *dpSrc,
1745 long lCount)
1746 {
1747 long lLoopCntr;
1748
1749 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1750 {
1751 dpDst1[lLoopCntr] *= dpSrc[lLoopCntr];
1752 dpDst2[lLoopCntr] *= dpSrc[lLoopCntr];
1753 }
1754 }
1755
1756
Mul2(float * fpDst1,float * fpDst2,const float * fpSrc1,const float * fpSrc2,const float * fpMul,long lCount)1757 void clDSPOp::Mul2 (float *fpDst1, float *fpDst2, const float *fpSrc1,
1758 const float *fpSrc2, const float *fpMul, long lCount)
1759 {
1760 long lLoopCntr;
1761
1762 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1763 {
1764 fpDst1[lLoopCntr] = fpSrc1[lLoopCntr] * fpMul[lLoopCntr];
1765 fpDst2[lLoopCntr] = fpSrc2[lLoopCntr] * fpMul[lLoopCntr];
1766 }
1767 }
1768
1769
Mul2(double * dpDst1,double * dpDst2,const double * dpSrc1,const double * dpSrc2,const double * dpMul,long lCount)1770 void clDSPOp::Mul2 (double *dpDst1, double *dpDst2, const double *dpSrc1,
1771 const double *dpSrc2, const double *dpMul, long lCount)
1772 {
1773 long lLoopCntr;
1774
1775 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1776 {
1777 dpDst1[lLoopCntr] = dpSrc1[lLoopCntr] * dpMul[lLoopCntr];
1778 dpDst2[lLoopCntr] = dpSrc2[lLoopCntr] * dpMul[lLoopCntr];
1779 }
1780 }
1781
1782
Div(float * fpVect,float fSrc,long lCount)1783 void clDSPOp::Div (float *fpVect, float fSrc, long lCount)
1784 {
1785 #ifdef DSP_IPP
1786 ippsDivC_32f_I(fSrc, fpVect, lCount);
1787 #else
1788 long lLoopCntr;
1789
1790 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1791 {
1792 fpVect[lLoopCntr] /= fSrc;
1793 }
1794 #endif
1795 }
1796
1797
Div(double * dpVect,double dSrc,long lCount)1798 void clDSPOp::Div (double *dpVect, double dSrc, long lCount)
1799 {
1800 #ifdef DSP_IPP
1801 ippsDivC_64f_I(dSrc, dpVect, lCount);
1802 #else
1803 long lLoopCntr;
1804
1805 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1806 {
1807 dpVect[lLoopCntr] /= dSrc;
1808 }
1809 #endif
1810 }
1811
1812
Div(stpSCplx spCplxDest,stSCplx sCplxSrc,long lCount)1813 void clDSPOp::Div (stpSCplx spCplxDest, stSCplx sCplxSrc, long lCount)
1814 {
1815 #ifdef DSP_IPP
1816 ippsDivC_32fc_I(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest, lCount);
1817 #else
1818 long lLoopCntr;
1819
1820 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1821 {
1822 CplxDiv(&spCplxDest[lLoopCntr], &sCplxSrc);
1823 }
1824 #endif
1825 }
1826
1827
Div(stpDCplx spCplxDest,stDCplx sCplxSrc,long lCount)1828 void clDSPOp::Div (stpDCplx spCplxDest, stDCplx sCplxSrc, long lCount)
1829 {
1830 #ifdef DSP_IPP
1831 ippsDivC_64fc_I(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest, lCount);
1832 #else
1833 long lLoopCntr;
1834
1835 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1836 {
1837 CplxDiv(&spCplxDest[lLoopCntr], &sCplxSrc);
1838 }
1839 #endif
1840 }
1841
1842
Div(float * fpDest,const float * fpSrc,long lCount)1843 void clDSPOp::Div (float *fpDest, const float *fpSrc, long lCount)
1844 {
1845 #ifdef DSP_IPP
1846 ippsDiv_32f_I(fpSrc, fpDest, lCount);
1847 #else
1848 long lLoopCntr;
1849
1850 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1851 {
1852 fpDest[lLoopCntr] /= fpSrc[lLoopCntr];
1853 }
1854 #endif
1855 }
1856
1857
Div(double * dpDest,const double * dpSrc,long lCount)1858 void clDSPOp::Div (double *dpDest, const double *dpSrc, long lCount)
1859 {
1860 #ifdef DSP_IPP
1861 ippsDiv_64f_I(dpSrc, dpDest, lCount);
1862 #else
1863 long lLoopCntr;
1864
1865 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1866 {
1867 dpDest[lLoopCntr] /= dpSrc[lLoopCntr];
1868 }
1869 #endif
1870 }
1871
1872
Div(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)1873 void clDSPOp::Div (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
1874 {
1875 #ifdef DSP_IPP
1876 ippsDiv_32fc_I((Ipp32fc *) spCplxSrc, (Ipp32fc *) spCplxDest, lCount);
1877 #else
1878 long lLoopCntr;
1879
1880 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1881 {
1882 CplxDiv(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1883 }
1884 #endif
1885 }
1886
1887
Div(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)1888 void clDSPOp::Div (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
1889 {
1890 #ifdef DSP_IPP
1891 ippsDiv_64fc_I((Ipp64fc *) spCplxSrc, (Ipp64fc *) spCplxDest, lCount);
1892 #else
1893 long lLoopCntr;
1894
1895 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1896 {
1897 CplxDiv(&spCplxDest[lLoopCntr], &spCplxSrc[lLoopCntr]);
1898 }
1899 #endif
1900 }
1901
1902
Div(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)1903 void clDSPOp::Div (float *fpDest, const float *fpSrc1, const float *fpSrc2,
1904 long lCount)
1905 {
1906 #ifdef DSP_IPP
1907 ippsDiv_32f(fpSrc1, fpSrc2, fpDest, lCount);
1908 #else
1909 long lLoopCntr;
1910
1911 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1912 {
1913 fpDest[lLoopCntr] = fpSrc1[lLoopCntr] / fpSrc2[lLoopCntr];
1914 }
1915 #endif
1916 }
1917
1918
Div(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)1919 void clDSPOp::Div (double *dpDest, const double *dpSrc1, const double *dpSrc2,
1920 long lCount)
1921 {
1922 #ifdef DSP_IPP
1923 ippsDiv_64f(dpSrc1, dpSrc2, dpDest, lCount);
1924 #else
1925 long lLoopCntr;
1926
1927 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1928 {
1929 dpDest[lLoopCntr] = dpSrc1[lLoopCntr] / dpSrc2[lLoopCntr];
1930 }
1931 #endif
1932 }
1933
1934
Div(stpSCplx spCplxDest,const stpSCplx spCplxSrc1,const stpSCplx spCplxSrc2,long lCount)1935 void clDSPOp::Div (stpSCplx spCplxDest, const stpSCplx spCplxSrc1,
1936 const stpSCplx spCplxSrc2, long lCount)
1937 {
1938 #ifdef DSP_IPP
1939 ippsDiv_32fc((Ipp32fc *) spCplxSrc1, (Ipp32fc *) spCplxSrc2,
1940 (Ipp32fc *) spCplxDest, lCount);
1941 #else
1942 long lLoopCntr;
1943
1944 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1945 {
1946 CplxDiv(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1947 &spCplxSrc2[lLoopCntr]);
1948 }
1949 #endif
1950 }
1951
1952
Div(stpDCplx spCplxDest,const stpDCplx spCplxSrc1,const stpDCplx spCplxSrc2,long lCount)1953 void clDSPOp::Div (stpDCplx spCplxDest, const stpDCplx spCplxSrc1,
1954 const stpDCplx spCplxSrc2, long lCount)
1955 {
1956 #ifdef DSP_IPP
1957 ippsDiv_64fc((Ipp64fc *) spCplxSrc1, (Ipp64fc *) spCplxSrc2,
1958 (Ipp64fc *) spCplxDest, lCount);
1959 #else
1960 long lLoopCntr;
1961
1962 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1963 {
1964 CplxDiv(&spCplxDest[lLoopCntr], &spCplxSrc1[lLoopCntr],
1965 &spCplxSrc2[lLoopCntr]);
1966 }
1967 #endif
1968 }
1969
1970
Div1x(float * fpVect,long lCount)1971 void clDSPOp::Div1x (float *fpVect, long lCount)
1972 {
1973 long lLoopCntr;
1974
1975 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1976 {
1977 fpVect[lLoopCntr] = 1.0F / fpVect[lLoopCntr];
1978 }
1979 }
1980
1981
Div1x(double * dpVect,long lCount)1982 void clDSPOp::Div1x (double *dpVect, long lCount)
1983 {
1984 long lLoopCntr;
1985
1986 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1987 {
1988 dpVect[lLoopCntr] = 1.0 / dpVect[lLoopCntr];
1989 }
1990 }
1991
1992
Div1x(float * fpDest,const float * fpSrc,long lCount)1993 void clDSPOp::Div1x (float *fpDest, const float *fpSrc, long lCount)
1994 {
1995 long lLoopCntr;
1996
1997 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
1998 {
1999 fpDest[lLoopCntr] = 1.0F / fpSrc[lLoopCntr];
2000 }
2001 }
2002
2003
Div1x(double * dpDest,const double * dpSrc,long lCount)2004 void clDSPOp::Div1x (double *dpDest, const double *dpSrc, long lCount)
2005 {
2006 long lLoopCntr;
2007
2008 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2009 {
2010 dpDest[lLoopCntr] = 1.0 / dpSrc[lLoopCntr];
2011 }
2012 }
2013
2014
MulAdd(float * fpVect,float fMul,float fAdd,long lCount)2015 void clDSPOp::MulAdd (float *fpVect, float fMul, float fAdd, long lCount)
2016 {
2017 long lLoopCntr;
2018
2019 #ifdef DSP_X86
2020 if (bHave3DNow)
2021 {
2022 dsp_x86_3dnow_maf(fpVect, fMul, fAdd, lCount);
2023 }
2024 else if (bHaveSSE)
2025 {
2026 dsp_x86_sse_maf(fpVect, fMul, fAdd, lCount);
2027 }
2028 else
2029 #endif
2030 {
2031 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2032 {
2033 fpVect[lLoopCntr] = fpVect[lLoopCntr] * fMul + fAdd;
2034 }
2035 }
2036 }
2037
2038
MulAdd(double * dpVect,double dMul,double dAdd,long lCount)2039 void clDSPOp::MulAdd (double *dpVect, double dMul, double dAdd, long lCount)
2040 {
2041 long lLoopCntr;
2042
2043 #ifdef DSP_X86
2044 if (bHaveSSE)
2045 {
2046 dsp_x86_sse_ma(dpVect, dMul, dAdd, lCount);
2047 }
2048 else
2049 #endif
2050 {
2051 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2052 {
2053 dpVect[lLoopCntr] = dpVect[lLoopCntr] * dMul + dAdd;
2054 }
2055 }
2056 }
2057
2058
MulAdd(float * fpDest,const float * fpSrc,float fMul,float fAdd,long lCount)2059 void clDSPOp::MulAdd (float *fpDest, const float *fpSrc,
2060 float fMul, float fAdd, long lCount)
2061 {
2062 long lLoopCntr;
2063
2064 #ifdef DSP_X86
2065 if (bHave3DNow)
2066 {
2067 dsp_x86_3dnow_ma2f(fpDest, fpSrc, fMul, fAdd, lCount);
2068 }
2069 else if (bHaveSSE)
2070 {
2071 dsp_x86_sse_ma2f(fpDest, fpSrc, fMul, fAdd, lCount);
2072 }
2073 else
2074 #endif
2075 {
2076 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2077 {
2078 fpDest[lLoopCntr] = fpSrc[lLoopCntr] * fMul + fAdd;
2079 }
2080 }
2081 }
2082
2083
MulAdd(double * dpDest,const double * dpSrc,double dMul,double dAdd,long lCount)2084 void clDSPOp::MulAdd (double *dpDest, const double *dpSrc,
2085 double dMul, double dAdd, long lCount)
2086 {
2087 long lLoopCntr;
2088
2089 #ifdef DSP_X86
2090 if (bHaveSSE)
2091 {
2092 dsp_x86_sse_ma2(dpDest, dpSrc, dMul, dAdd, lCount);
2093 }
2094 else
2095 #endif
2096 {
2097 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2098 {
2099 dpDest[lLoopCntr] = dpSrc[lLoopCntr] * dMul + dAdd;
2100 }
2101 }
2102 }
2103
2104
MulAddC(stpSCplx spDest,const stpSCplx spSrc1,const stpSCplx spSrc2,long lCount)2105 void clDSPOp::MulAddC (stpSCplx spDest, const stpSCplx spSrc1,
2106 const stpSCplx spSrc2, long lCount)
2107 {
2108 long lLoopCntr;
2109 stSCplx sTemp;
2110
2111 #ifdef DSP_X86
2112 if (bHave3DNow)
2113 {
2114 dsp_x86_3dnow_cmaf((float *) spDest, (const float *) spSrc1,
2115 (const float *) spSrc2, lCount);
2116 }
2117 else if (bHaveSSE)
2118 {
2119 dsp_x86_sse_cmaf((float *) spDest, (const float *) spSrc1,
2120 (const float *) spSrc2, lCount);
2121 }
2122 else
2123 #endif
2124 {
2125 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2126 {
2127 CplxMul(&sTemp, &spSrc1[lLoopCntr], &spSrc2[lLoopCntr]);
2128 CplxAdd(&spDest[lLoopCntr], &sTemp);
2129 }
2130 }
2131 }
2132
2133
MulAddC(stpDCplx spDest,const stpDCplx spSrc1,const stpDCplx spSrc2,long lCount)2134 void clDSPOp::MulAddC (stpDCplx spDest, const stpDCplx spSrc1,
2135 const stpDCplx spSrc2, long lCount)
2136 {
2137 long lLoopCntr;
2138 stDCplx sTemp;
2139
2140 #ifdef DSP_X86
2141 if (bHaveSSE)
2142 {
2143 dsp_x86_sse_cma((double *) spDest, (const double *) spSrc1,
2144 (const double *) spSrc2, lCount);
2145 }
2146 else
2147 #endif
2148 {
2149 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2150 {
2151 CplxMul(&sTemp, &spSrc1[lLoopCntr], &spSrc2[lLoopCntr]);
2152 CplxAdd(&spDest[lLoopCntr], &sTemp);
2153 }
2154 }
2155 }
2156
2157
Abs(float * fpVect,long lCount)2158 void clDSPOp::Abs (float *fpVect, long lCount)
2159 {
2160 #ifdef DSP_IPP
2161 ippsAbs_32f_I(fpVect, lCount);
2162 #else
2163 long lLoopCntr;
2164
2165 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2166 {
2167 fpVect[lLoopCntr] = fabsf(fpVect[lLoopCntr]);
2168 }
2169 #endif
2170 }
2171
2172
Abs(double * dpVect,long lCount)2173 void clDSPOp::Abs (double *dpVect, long lCount)
2174 {
2175 #ifdef DSP_IPP
2176 ippsAbs_64f_I(dpVect, lCount);
2177 #else
2178 long lLoopCntr;
2179
2180 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2181 {
2182 dpVect[lLoopCntr] = fabs(dpVect[lLoopCntr]);
2183 }
2184 #endif
2185 }
2186
2187
Abs(float * fpDest,const float * fpSrc,long lCount)2188 void clDSPOp::Abs (float *fpDest, const float *fpSrc, long lCount)
2189 {
2190 #ifdef DSP_IPP
2191 ippsAbs_32f(fpSrc, fpDest, lCount);
2192 #else
2193 long lLoopCntr;
2194
2195 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2196 {
2197 fpDest[lLoopCntr] = fabsf(fpSrc[lLoopCntr]);
2198 }
2199 #endif
2200 }
2201
2202
Abs(double * dpDest,const double * dpSrc,long lCount)2203 void clDSPOp::Abs (double *dpDest, const double *dpSrc, long lCount)
2204 {
2205 #ifdef DSP_IPP
2206 ippsAbs_64f(dpSrc, dpDest, lCount);
2207 #else
2208 long lLoopCntr;
2209
2210 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2211 {
2212 dpDest[lLoopCntr] = fabs(dpSrc[lLoopCntr]);
2213 }
2214 #endif
2215 }
2216
2217
Sqrt(float * fpVect,long lCount)2218 void clDSPOp::Sqrt (float *fpVect, long lCount)
2219 {
2220 #ifdef DSP_IPP
2221 ippsSqrt_32f_I(fpVect, lCount);
2222 #else
2223 long lLoopCntr;
2224
2225 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2226 {
2227 fpVect[lLoopCntr] = sqrtf(fpVect[lLoopCntr]);
2228 }
2229 #endif
2230 }
2231
2232
Sqrt(double * dpVect,long lCount)2233 void clDSPOp::Sqrt (double *dpVect, long lCount)
2234 {
2235 #ifdef DSP_IPP
2236 ippsSqrt_64f_I(dpVect, lCount);
2237 #else
2238 long lLoopCntr;
2239
2240 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2241 {
2242 dpVect[lLoopCntr] = sqrt(dpVect[lLoopCntr]);
2243 }
2244 #endif
2245 }
2246
2247
Sqrt(float * fpDest,const float * fpSrc,long lCount)2248 void clDSPOp::Sqrt (float *fpDest, const float *fpSrc, long lCount)
2249 {
2250 #ifdef DSP_IPP
2251 ippsSqrt_32f(fpSrc, fpDest, lCount);
2252 #else
2253 long lLoopCntr;
2254
2255 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2256 {
2257 fpDest[lLoopCntr] = sqrtf(fpSrc[lLoopCntr]);
2258 }
2259 #endif
2260 }
2261
2262
Sqrt(double * dpDest,const double * dpSrc,long lCount)2263 void clDSPOp::Sqrt (double *dpDest, const double *dpSrc, long lCount)
2264 {
2265 #ifdef DSP_IPP
2266 ippsSqrt_64f(dpSrc, dpDest, lCount);
2267 #else
2268 long lLoopCntr;
2269
2270 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2271 {
2272 dpDest[lLoopCntr] = sqrt(dpSrc[lLoopCntr]);
2273 }
2274 #endif
2275 }
2276
2277
Zero(float * fpDest,long lCount)2278 void clDSPOp::Zero (float *fpDest, long lCount)
2279 {
2280 #ifdef DSP_IPP
2281 ippsZero_32f(fpDest, lCount);
2282 #else
2283 long lLoopCntr;
2284
2285 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2286 {
2287 fpDest[lLoopCntr] = 0.0F;
2288 }
2289 #endif
2290 }
2291
2292
Zero(double * dpDest,long lCount)2293 void clDSPOp::Zero (double *dpDest, long lCount)
2294 {
2295 #ifdef DSP_IPP
2296 ippsZero_64f(dpDest, lCount);
2297 #else
2298 long lLoopCntr;
2299
2300 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2301 {
2302 dpDest[lLoopCntr] = 0.0;
2303 }
2304 #endif
2305 }
2306
2307
Zero(stpSCplx spCplxDest,long lCount)2308 void clDSPOp::Zero (stpSCplx spCplxDest, long lCount)
2309 {
2310 #ifdef DSP_IPP
2311 ippsZero_32fc((Ipp32fc *) spCplxDest, lCount);
2312 #else
2313 long lLoopCntr;
2314
2315 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2316 {
2317 spCplxDest[lLoopCntr].R = 0.0F;
2318 spCplxDest[lLoopCntr].I = 0.0F;
2319 }
2320 #endif
2321 }
2322
2323
Zero(stpDCplx spCplxDest,long lCount)2324 void clDSPOp::Zero (stpDCplx spCplxDest, long lCount)
2325 {
2326 #ifdef DSP_IPP
2327 ippsZero_64fc((Ipp64fc *) spCplxDest, lCount);
2328 #else
2329 long lLoopCntr;
2330
2331 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2332 {
2333 spCplxDest[lLoopCntr].R = 0.0;
2334 spCplxDest[lLoopCntr].I = 0.0;
2335 }
2336 #endif
2337 }
2338
2339
Set(float * fpDest,float fSrc,long lCount)2340 void clDSPOp::Set (float *fpDest, float fSrc, long lCount)
2341 {
2342 #ifdef DSP_IPP
2343 ippsSet_32f(fSrc, fpDest, lCount);
2344 #else
2345 long lLoopCntr;
2346
2347 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2348 {
2349 fpDest[lLoopCntr] = fSrc;
2350 }
2351 #endif
2352 }
2353
2354
Set(double * dpDest,double dSrc,long lCount)2355 void clDSPOp::Set (double *dpDest, double dSrc, long lCount)
2356 {
2357 #ifdef DSP_IPP
2358 ippsSet_64f(dSrc, dpDest, lCount);
2359 #else
2360 long lLoopCntr;
2361
2362 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2363 {
2364 dpDest[lLoopCntr] = dSrc;
2365 }
2366 #endif
2367 }
2368
2369
Set(stpSCplx spCplxDest,stSCplx sCplxSrc,long lCount)2370 void clDSPOp::Set (stpSCplx spCplxDest, stSCplx sCplxSrc, long lCount)
2371 {
2372 #ifdef DSP_IPP
2373 ippsSet_32fc(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest, lCount);
2374 #else
2375 long lLoopCntr;
2376
2377 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2378 {
2379 spCplxDest[lLoopCntr].R = sCplxSrc.R;
2380 spCplxDest[lLoopCntr].I = sCplxSrc.I;
2381 }
2382 #endif
2383 }
2384
2385
Set(stpDCplx spCplxDest,stDCplx sCplxSrc,long lCount)2386 void clDSPOp::Set (stpDCplx spCplxDest, stDCplx sCplxSrc, long lCount)
2387 {
2388 #ifdef DSP_IPP
2389 ippsSet_64fc(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest, lCount);
2390 #else
2391 long lLoopCntr;
2392
2393 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2394 {
2395 spCplxDest[lLoopCntr].R = sCplxSrc.R;
2396 spCplxDest[lLoopCntr].I = sCplxSrc.I;
2397 }
2398 #endif
2399 }
2400
2401
Set(float * fpDest,float fSrc,long lStart,long lCount,long lLength)2402 void clDSPOp::Set (float *fpDest, float fSrc, long lStart, long lCount,
2403 long lLength)
2404 {
2405 #ifdef DSP_IPP
2406 ippsSet_32f(fSrc, &fpDest[lStart],
2407 ((lStart + lCount) > lLength) ? lLength - lStart : lCount);
2408 #else
2409 long lLoopCntr;
2410 long lEnd;
2411
2412 lEnd = ((lStart + lCount) > lLength) ? lLength : (lStart + lCount);
2413 for (lLoopCntr = 0L; lLoopCntr < lEnd; lLoopCntr++)
2414 {
2415 fpDest[lLoopCntr] = fSrc;
2416 }
2417 #endif
2418 }
2419
2420
Set(double * dpDest,double dSrc,long lStart,long lCount,long lLength)2421 void clDSPOp::Set (double *dpDest, double dSrc, long lStart, long lCount,
2422 long lLength)
2423 {
2424 #ifdef DSP_IPP
2425 ippsSet_64f(dSrc, &dpDest[lStart],
2426 ((lStart + lCount) > lLength) ? lLength - lStart : lCount);
2427 #else
2428 long lLoopCntr;
2429 long lEnd;
2430
2431 lEnd = ((lStart + lCount) > lLength) ? lLength : (lStart + lCount);
2432 for (lLoopCntr = 0L; lLoopCntr < lEnd; lLoopCntr++)
2433 {
2434 dpDest[lLoopCntr] = dSrc;
2435 }
2436 #endif
2437 }
2438
2439
Set(stpSCplx spCplxDest,stSCplx sCplxSrc,long lStart,long lCount,long lLength)2440 void clDSPOp::Set (stpSCplx spCplxDest, stSCplx sCplxSrc, long lStart,
2441 long lCount, long lLength)
2442 {
2443 #ifdef DSP_IPP
2444 ippsSet_32fc(*((Ipp32fc *) &sCplxSrc), (Ipp32fc *) spCplxDest,
2445 ((lStart + lCount) > lLength) ? lLength - lStart : lCount);
2446 #else
2447 long lLoopCntr;
2448 long lEnd;
2449
2450 lEnd = ((lStart + lCount) > lLength) ? lLength : (lStart + lCount);
2451 for (lLoopCntr = 0L; lLoopCntr < lEnd; lLoopCntr++)
2452 {
2453 spCplxDest[lLoopCntr].R = sCplxSrc.R;
2454 spCplxDest[lLoopCntr].I = sCplxSrc.I;
2455 }
2456 #endif
2457 }
2458
2459
Set(stpDCplx spCplxDest,stDCplx sCplxSrc,long lStart,long lCount,long lLength)2460 void clDSPOp::Set (stpDCplx spCplxDest, stDCplx sCplxSrc, long lStart,
2461 long lCount, long lLength)
2462 {
2463 #ifdef DSP_IPP
2464 ippsSet_64fc(*((Ipp64fc *) &sCplxSrc), (Ipp64fc *) spCplxDest,
2465 ((lStart + lCount) > lLength) ? lLength - lStart : lCount);
2466 #else
2467 long lLoopCntr;
2468 long lEnd;
2469
2470 lEnd = ((lStart + lCount) > lLength) ? lLength : (lStart + lCount);
2471 for (lLoopCntr = 0L; lLoopCntr < lEnd; lLoopCntr++)
2472 {
2473 spCplxDest[lLoopCntr].R = sCplxSrc.R;
2474 spCplxDest[lLoopCntr].I = sCplxSrc.I;
2475 }
2476 #endif
2477 }
2478
2479
Clip(float * fpVect,float fValue,long lCount)2480 void clDSPOp::Clip (float *fpVect, float fValue, long lCount)
2481 {
2482 #ifdef DSP_IPP
2483 ippsThreshold_GT_32f_I(fpVect, lCount, fValue);
2484 #else
2485 long lLoopCntr;
2486
2487 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2488 {
2489 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2490 if (fpVect[lLoopCntr] > fValue)
2491 {
2492 fpVect[lLoopCntr] = fValue;
2493 }
2494 #else
2495 if (isgreater(fpVect[lLoopCntr], fValue))
2496 {
2497 fpVect[lLoopCntr] = fValue;
2498 }
2499 #endif
2500 }
2501 #endif
2502 }
2503
2504
Clip(double * dpVect,double dValue,long lCount)2505 void clDSPOp::Clip (double *dpVect, double dValue, long lCount)
2506 {
2507 #ifdef DSP_IPP
2508 ippsThreshold_GT_64f_I(dpVect, lCount, dValue);
2509 #else
2510 long lLoopCntr;
2511
2512 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2513 {
2514 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2515 if (dpVect[lLoopCntr] > dValue)
2516 {
2517 dpVect[lLoopCntr] = dValue;
2518 }
2519 #else
2520 if (isgreater(dpVect[lLoopCntr], dValue))
2521 {
2522 dpVect[lLoopCntr] = dValue;
2523 }
2524 #endif
2525 }
2526 #endif
2527 }
2528
2529
Clip(float * fpDest,const float * fpSrc,float fValue,long lCount)2530 void clDSPOp::Clip (float *fpDest, const float *fpSrc, float fValue,
2531 long lCount)
2532 {
2533 #ifdef DSP_IPP
2534 ippsThreshold_GT_32f(fpSrc, fpDest, lCount, fValue);
2535 #else
2536 long lLoopCntr;
2537
2538 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2539 {
2540 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2541 fpDest[lLoopCntr] = (fpSrc[lLoopCntr] > fValue) ?
2542 fValue : fpSrc[lLoopCntr];
2543 #else
2544 fpDest[lLoopCntr] = (isgreater(fpSrc[lLoopCntr], fValue)) ?
2545 fValue : fpSrc[lLoopCntr];
2546 #endif
2547 }
2548 #endif
2549 }
2550
2551
Clip(double * dpDest,const double * dpSrc,double dValue,long lCount)2552 void clDSPOp::Clip (double *dpDest, const double *dpSrc, double dValue,
2553 long lCount)
2554 {
2555 #ifdef DSP_IPP
2556 ippsThreshold_GT_64f(dpSrc, dpDest, lCount, dValue);
2557 #else
2558 long lLoopCntr;
2559
2560 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2561 {
2562 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2563 dpDest[lLoopCntr] = (dpSrc[lLoopCntr] > dValue) ?
2564 dValue : dpSrc[lLoopCntr];
2565 #else
2566 dpDest[lLoopCntr] = (isgreater(dpSrc[lLoopCntr], dValue)) ?
2567 dValue : dpSrc[lLoopCntr];
2568 #endif
2569 }
2570 #endif
2571 }
2572
2573
Clip(float * fpVect,float fMin,float fMax,long lCount)2574 void clDSPOp::Clip (float *fpVect, float fMin, float fMax, long lCount)
2575 {
2576 #ifdef DSP_IPP
2577 ippsThreshold_LT_32f_I(fpVect, lCount, fMin);
2578 ippsThreshold_GT_32f_I(fpVect, lCount, fMax);
2579 #else
2580 long lLoopCntr;
2581
2582 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2583 {
2584 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2585 if (fpVect[lLoopCntr] < fMin)
2586 {
2587 fpVect[lLoopCntr] = fMin;
2588 }
2589 else if (fpVect[lLoopCntr] > fMax)
2590 {
2591 fpVect[lLoopCntr] = fMax;
2592 }
2593 #else
2594 if (isless(fpVect[lLoopCntr], fMin))
2595 {
2596 fpVect[lLoopCntr] = fMin;
2597 }
2598 else if (isgreater(fpVect[lLoopCntr], fMax))
2599 {
2600 fpVect[lLoopCntr] = fMax;
2601 }
2602 #endif
2603 }
2604 #endif
2605 }
2606
2607
Clip(double * dpVect,double dMin,double dMax,long lCount)2608 void clDSPOp::Clip (double *dpVect, double dMin, double dMax, long lCount)
2609 {
2610 #ifdef DSP_IPP
2611 ippsThreshold_LT_64f_I(dpVect, lCount, dMin);
2612 ippsThreshold_GT_64f_I(dpVect, lCount, dMax);
2613 #else
2614 long lLoopCntr;
2615
2616 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2617 {
2618 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2619 if (dpVect[lLoopCntr] < dMin)
2620 {
2621 dpVect[lLoopCntr] = dMin;
2622 }
2623 else if (dpVect[lLoopCntr] > dMax)
2624 {
2625 dpVect[lLoopCntr] = dMax;
2626 }
2627 #else
2628 if (isless(dpVect[lLoopCntr], dMin))
2629 {
2630 dpVect[lLoopCntr] = dMin;
2631 }
2632 else if (isgreater(dpVect[lLoopCntr], dMax))
2633 {
2634 dpVect[lLoopCntr] = dMax;
2635 }
2636 #endif
2637 }
2638 #endif
2639 }
2640
2641
Clip(float * fpDest,const float * fpSrc,float fMin,float fMax,long lCount)2642 void clDSPOp::Clip (float *fpDest, const float *fpSrc, float fMin,
2643 float fMax, long lCount)
2644 {
2645 #ifdef DSP_IPP
2646 ippsThreshold_LT_32f(fpSrc, fpDest, lCount, fMin);
2647 ippsThreshold_GT_32f_I(fpDest, lCount, fMax);
2648 #else
2649 long lLoopCntr;
2650
2651 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2652 {
2653 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2654 if (fpSrc[lLoopCntr] < fMin)
2655 {
2656 fpDest[lLoopCntr] = fMin;
2657 }
2658 else if (fpSrc[lLoopCntr] > fMax)
2659 {
2660 fpDest[lLoopCntr] = fMax;
2661 }
2662 else
2663 {
2664 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
2665 }
2666 #else
2667 if (isless(fpSrc[lLoopCntr], fMin))
2668 {
2669 fpDest[lLoopCntr] = fMin;
2670 }
2671 else if (isgreater(fpSrc[lLoopCntr], fMax))
2672 {
2673 fpDest[lLoopCntr] = fMax;
2674 }
2675 else
2676 {
2677 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
2678 }
2679 #endif
2680 }
2681 #endif
2682 }
2683
2684
Clip(double * dpDest,const double * dpSrc,double dMin,double dMax,long lCount)2685 void clDSPOp::Clip (double *dpDest, const double *dpSrc, double dMin,
2686 double dMax, long lCount)
2687 {
2688 #ifdef DSP_IPP
2689 ippsThreshold_LT_64f(dpSrc, dpDest, lCount, dMin);
2690 ippsThreshold_GT_64f_I(dpDest, lCount, dMin);
2691 #else
2692 long lLoopCntr;
2693
2694 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2695 {
2696 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2697 if (dpSrc[lLoopCntr] < dMin)
2698 {
2699 dpDest[lLoopCntr] = dMin;
2700 }
2701 else if (dpSrc[lLoopCntr] > dMax)
2702 {
2703 dpDest[lLoopCntr] = dMax;
2704 }
2705 else
2706 {
2707 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
2708 }
2709 #else
2710 if (isless(dpSrc[lLoopCntr], dMin))
2711 {
2712 dpDest[lLoopCntr] = dMin;
2713 }
2714 else if (isgreater(dpSrc[lLoopCntr], dMax))
2715 {
2716 dpDest[lLoopCntr] = dMax;
2717 }
2718 else
2719 {
2720 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
2721 }
2722 #endif
2723 }
2724 #endif
2725 }
2726
2727
ClipZero(float * fpVect,long lCount)2728 void clDSPOp::ClipZero (float *fpVect, long lCount)
2729 {
2730 #ifdef DSP_IPP
2731 ippsThreshold_LT_32f_I(fpVect, lCount, 0.0f);
2732 #else
2733 long lLoopCntr;
2734
2735 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2736 {
2737 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2738 if (fpVect[lLoopCntr] < 0.0F)
2739 {
2740 fpVect[lLoopCntr] = 0.0F;
2741 }
2742 #else
2743 if (isless(fpVect[lLoopCntr], 0.0F))
2744 {
2745 fpVect[lLoopCntr] = 0.0F;
2746 }
2747 #endif
2748 }
2749 #endif
2750 }
2751
2752
ClipZero(double * dpVect,long lCount)2753 void clDSPOp::ClipZero (double *dpVect, long lCount)
2754 {
2755 #ifdef DSP_IPP
2756 ippsThreshold_LT_64f_I(dpVect, lCount, 0.0);
2757 #else
2758 long lLoopCntr;
2759
2760 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2761 {
2762 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2763 if (dpVect[lLoopCntr] < 0.0)
2764 {
2765 dpVect[lLoopCntr] = 0.0;
2766 }
2767 #else
2768 if (isless(dpVect[lLoopCntr], 0.0))
2769 {
2770 dpVect[lLoopCntr] = 0.0;
2771 }
2772 #endif
2773 }
2774 #endif
2775 }
2776
2777
ClipZero(float * fpDest,const float * fpSrc,long lCount)2778 void clDSPOp::ClipZero (float *fpDest, const float *fpSrc, long lCount)
2779 {
2780 #ifdef DSP_IPP
2781 ippsThreshold_LT_32f(fpSrc, fpDest, lCount, 0.0f);
2782 #else
2783 long lLoopCntr;
2784
2785 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2786 {
2787 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2788 fpDest[lLoopCntr] = (fpSrc[lLoopCntr] < 0.0F) ?
2789 0.0F : fpSrc[lLoopCntr];
2790 #else
2791 fpDest[lLoopCntr] = (isless(fpSrc[lLoopCntr], 0.0F)) ?
2792 0.0F : fpSrc[lLoopCntr];
2793 #endif
2794 }
2795 #endif
2796 }
2797
2798
ClipZero(double * dpDest,const double * dpSrc,long lCount)2799 void clDSPOp::ClipZero (double *dpDest, const double *dpSrc, long lCount)
2800 {
2801 #ifdef DSP_IPP
2802 ippsThreshold_LT_64f(dpSrc, dpDest, lCount, 0.0);
2803 #else
2804 long lLoopCntr;
2805
2806 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2807 {
2808 #if (!defined(_ISOC9X_SOURCE) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)))
2809 dpDest[lLoopCntr] = (dpSrc[lLoopCntr] < 0.0) ?
2810 0.0 : dpSrc[lLoopCntr];
2811 #else
2812 dpDest[lLoopCntr] = (isless(dpSrc[lLoopCntr], 0.0)) ?
2813 0.0 : dpSrc[lLoopCntr];
2814 #endif
2815 }
2816 #endif
2817 }
2818
2819
Copy(float * fpDest,const float * fpSrc,long lCount)2820 void clDSPOp::Copy (float *fpDest, const float *fpSrc, long lCount)
2821 {
2822 #ifdef DSP_IPP
2823 ippsMove_32f(fpSrc, fpDest, lCount);
2824 #else
2825 #ifndef USE_MEMMOVE
2826 long lLoopCntr;
2827
2828 #ifdef DSP_X86
2829 if (bHave3DNow)
2830 {
2831 if (likely(fpDest <= fpSrc || abs(fpDest - fpSrc) > lCount))
2832 {
2833 dsp_x86_3dnow_copyf(fpDest, fpSrc, lCount);
2834 }
2835 else
2836 {
2837 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2838 {
2839 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
2840 }
2841 }
2842 }
2843 else
2844 #endif
2845 {
2846 if (likely(fpDest <= fpSrc || abs(fpDest - fpSrc) > lCount))
2847 {
2848 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2849 {
2850 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
2851 }
2852 }
2853 else
2854 {
2855 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2856 {
2857 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
2858 }
2859 }
2860 }
2861 #else
2862 #ifndef DSP_X86
2863 memmove(fpDest, fpSrc, lCount * sizeof(float));
2864 #else
2865 memmove(fpDest, fpSrc, (lCount << 2));
2866 #endif
2867 #endif
2868 #endif
2869 }
2870
2871
Copy(double * dpDest,const double * dpSrc,long lCount)2872 void clDSPOp::Copy (double *dpDest, const double *dpSrc, long lCount)
2873 {
2874 #ifdef DSP_IPP
2875 ippsMove_64f(dpSrc, dpDest, lCount);
2876 #else
2877 #ifndef USE_MEMMOVE
2878 long lLoopCntr;
2879
2880 #ifdef DSP_X86
2881 if (bHave3DNow)
2882 {
2883 if (likely(dpDest <= dpSrc || abs(dpDest - dpSrc) > lCount))
2884 {
2885 dsp_x86_3dnow_copyd(dpDest, dpSrc, lCount);
2886 }
2887 else
2888 {
2889 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2890 {
2891 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
2892 }
2893 }
2894 }
2895 else
2896 #endif
2897 {
2898 if (likely(dpDest <= dpSrc || abs(dpDest - dpSrc) > lCount))
2899 {
2900 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2901 {
2902 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
2903 }
2904 }
2905 else
2906 {
2907 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2908 {
2909 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
2910 }
2911 }
2912 }
2913 #else
2914 #ifndef DSP_X86
2915 memmove(dpDest, dpSrc, lCount * sizeof(double));
2916 #else
2917 memmove(dpDest, dpSrc, (lCount << 3));
2918 #endif
2919 #endif
2920 #endif
2921 }
2922
2923
Copy(stpSCplx spCplxDest,const stpSCplx spCplxSrc,long lCount)2924 void clDSPOp::Copy (stpSCplx spCplxDest, const stpSCplx spCplxSrc, long lCount)
2925 {
2926 #ifdef DSP_IPP
2927 ippsMove_32fc((Ipp32fc *) spCplxSrc, (Ipp32fc *) spCplxDest, lCount);
2928 #else
2929 #ifndef USE_MEMMOVE
2930 long lLoopCntr;
2931
2932 #ifdef DSP_X86
2933 if (bHave3DNow)
2934 {
2935 if (likely(spCplxDest <= spCplxSrc ||
2936 abs(spCplxDest - spCplxSrc) > lCount))
2937 {
2938 dsp_x86_3dnow_copyf((float *) spCplxDest,
2939 (const float *) spCplxSrc, (lCount << 1));
2940 }
2941 else
2942 {
2943 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2944 {
2945 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
2946 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
2947 }
2948 }
2949 }
2950 else
2951 #endif
2952 {
2953 if (likely(spCplxDest <= spCplxSrc ||
2954 abs(spCplxDest - spCplxSrc) > lCount))
2955 {
2956 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
2957 {
2958 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
2959 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
2960 }
2961 }
2962 else
2963 {
2964 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2965 {
2966 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
2967 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
2968 }
2969 }
2970 }
2971 #else
2972 memmove(spCplxDest, spCplxSrc, lCount * sizeof(stSCplx));
2973 #endif
2974 #endif
2975 }
2976
2977
Copy(stpDCplx spCplxDest,const stpDCplx spCplxSrc,long lCount)2978 void clDSPOp::Copy (stpDCplx spCplxDest, const stpDCplx spCplxSrc, long lCount)
2979 {
2980 #ifdef DSP_IPP
2981 ippsMove_64fc((Ipp64fc *) spCplxSrc, (Ipp64fc *) spCplxDest, lCount);
2982 #else
2983 #ifndef USE_MEMMOVE
2984 long lLoopCntr;
2985
2986 #ifdef DSP_X86
2987 if (bHave3DNow)
2988 {
2989 if (likely(spCplxDest <= spCplxSrc ||
2990 abs(spCplxDest - spCplxSrc) > lCount))
2991 {
2992 dsp_x86_3dnow_copyd((double *) spCplxDest,
2993 (const double *) spCplxSrc, (lCount << 1));
2994 }
2995 else
2996 {
2997 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
2998 {
2999 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
3000 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
3001 }
3002 }
3003 }
3004 else
3005 #endif
3006 {
3007 if (likely(spCplxDest <= spCplxSrc ||
3008 abs(spCplxDest - spCplxSrc) > lCount))
3009 {
3010 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3011 {
3012 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
3013 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
3014 }
3015 }
3016 else
3017 {
3018 for (lLoopCntr = lCount - 1L; lLoopCntr >= 0L; lLoopCntr--)
3019 {
3020 spCplxDest[lLoopCntr].R = spCplxSrc[lLoopCntr].R;
3021 spCplxDest[lLoopCntr].I = spCplxSrc[lLoopCntr].I;
3022 }
3023 }
3024 }
3025 #else
3026 memmove(spCplxDest, spCplxSrc, lCount * sizeof(stDCplx));
3027 #endif
3028 #endif
3029 }
3030
3031
Copy(float * fpDest1,float * fpDest2,const float * fpSrc,long lCount)3032 void clDSPOp::Copy (float *fpDest1, float *fpDest2, const float *fpSrc,
3033 long lCount)
3034 {
3035 #ifdef DSP_IPP
3036 ippsMove_32f(fpSrc, fpDest1, lCount);
3037 ippsMove_32f(fpSrc, fpDest2, lCount);
3038 #else
3039 long lLoopCntr;
3040
3041 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3042 {
3043 fpDest1[lLoopCntr] = fpDest2[lLoopCntr] = fpSrc[lLoopCntr];
3044 }
3045 #endif
3046 }
3047
3048
Copy(double * dpDest1,double * dpDest2,const double * dpSrc,long lCount)3049 void clDSPOp::Copy (double *dpDest1, double *dpDest2, const double *dpSrc,
3050 long lCount)
3051 {
3052 #ifdef DSP_IPP
3053 ippsMove_64f(dpSrc, dpDest1, lCount);
3054 ippsMove_64f(dpSrc, dpDest2, lCount);
3055 #else
3056 long lLoopCntr;
3057
3058 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3059 {
3060 dpDest1[lLoopCntr] = dpDest2[lLoopCntr] = dpSrc[lLoopCntr];
3061 }
3062 #endif
3063 }
3064
3065
Convolve(const float * fpSrc1,const float * fpSrc2,long lCount)3066 float clDSPOp::Convolve (const float *fpSrc1, const float *fpSrc2,
3067 long lCount)
3068 {
3069 long lLoopCntr;
3070 long lMax;
3071 float fConv = 0.0F;
3072
3073 lMax = lCount - 1L;
3074 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3075 {
3076 #ifndef _ISOC9X_SOURCE
3077 fConv += fpSrc1[lLoopCntr] * fpSrc2[lMax - lLoopCntr];
3078 #else
3079 fConv = fmaf(fpSrc1[lLoopCntr], fpSrc2[lMax - lLoopCntr], fConv);
3080 #endif
3081 }
3082 return fConv;
3083 }
3084
3085
Convolve(const double * dpSrc1,const double * dpSrc2,long lCount)3086 double clDSPOp::Convolve (const double *dpSrc1, const double *dpSrc2,
3087 long lCount)
3088 {
3089 long lLoopCntr;
3090 long lMax;
3091 double dConv = 0.0;
3092
3093 lMax = lCount - 1L;
3094 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3095 {
3096 #ifndef _ISOC9X_SOURCE
3097 dConv += dpSrc1[lLoopCntr] * dpSrc2[lMax - lLoopCntr];
3098 #else
3099 dConv = fma(dpSrc1[lLoopCntr], dpSrc2[lMax - lLoopCntr], dConv);
3100 #endif
3101 }
3102 return dConv;
3103 }
3104
3105
Convolve(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)3106 void clDSPOp::Convolve (float *fpDest, const float *fpSrc1,
3107 const float *fpSrc2, long lCount)
3108 {
3109 long lLoopDest;
3110 long lLoopConv;
3111 long lIdx;
3112 long lMax;
3113 float fConv;
3114
3115 lMax = lCount - 1L;
3116 for (lLoopDest = 0L; lLoopDest < lCount; lLoopDest++)
3117 {
3118 fConv = 0.0F;
3119 for (lLoopConv = 0L; lLoopConv <= lMax; lLoopConv++)
3120 {
3121 lIdx = ((lLoopConv - lLoopDest) < 0L) ?
3122 (lLoopConv - lLoopDest + lMax) : (lLoopConv - lLoopDest);
3123 #ifndef _ISOC9X_SOURCE
3124 fConv += fpSrc1[lMax - lIdx] * fpSrc2[lIdx];
3125 #else
3126 fConv = fmaf(fpSrc1[lMax - lIdx], fpSrc2[lIdx], fConv);
3127 #endif
3128 }
3129 fpDest[lLoopDest] = fConv;
3130 }
3131 }
3132
3133
Convolve(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)3134 void clDSPOp::Convolve (double *dpDest, const double *dpSrc1,
3135 const double *dpSrc2, long lCount)
3136 {
3137 long lLoopDest;
3138 long lLoopConv;
3139 long lIdx;
3140 long lMax;
3141 double dConv;
3142
3143 lMax = lCount - 1L;
3144 for (lLoopDest = 0L; lLoopDest < lCount; lLoopDest++)
3145 {
3146 dConv = 0.0;
3147 for (lLoopConv = 0L; lLoopConv <= lMax; lLoopConv++)
3148 {
3149 lIdx = ((lLoopConv - lLoopDest) < 0L) ?
3150 (lLoopConv - lLoopDest + lMax) : (lLoopConv - lLoopDest);
3151 #ifndef _ISOC9X_SOURCE
3152 dConv += dpSrc1[lMax - lIdx] * dpSrc2[lIdx];
3153 #else
3154 dConv = fma(dpSrc1[lMax - lIdx], dpSrc2[lIdx], dConv);
3155 #endif
3156 }
3157 dpDest[lLoopDest] = dConv;
3158 }
3159 }
3160
3161
Correlate(const float * fpSrc1,const float * fpSrc2,long lCount)3162 float clDSPOp::Correlate (const float *fpSrc1, const float *fpSrc2,
3163 long lCount)
3164 {
3165 long lLoopCntr;
3166 float fCorr = 0.0F;
3167
3168 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3169 {
3170 #ifndef _ISOC9X_SOURCE
3171 fCorr += fpSrc1[lLoopCntr] * fpSrc2[lLoopCntr];
3172 #else
3173 fCorr = fmaf(fpSrc1[lLoopCntr], fpSrc2[lLoopCntr], fCorr);
3174 #endif
3175 }
3176 fCorr /= (float) lCount;
3177 return fCorr;
3178 }
3179
3180
Correlate(const double * dpSrc1,const double * dpSrc2,long lCount)3181 double clDSPOp::Correlate (const double *dpSrc1, const double *dpSrc2,
3182 long lCount)
3183 {
3184 long lLoopCntr;
3185 double dCorr = 0.0;
3186
3187 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3188 {
3189 #ifndef _ISOC9X_SOURCE
3190 dCorr += dpSrc1[lLoopCntr] * dpSrc2[lLoopCntr];
3191 #else
3192 dCorr = fma(dpSrc1[lLoopCntr], dpSrc2[lLoopCntr], dCorr);
3193 #endif
3194 }
3195 dCorr /= (double) lCount;
3196 return dCorr;
3197 }
3198
3199
Correlate(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)3200 void clDSPOp::Correlate (float *fpDest, const float *fpSrc1,
3201 const float *fpSrc2, long lCount)
3202 {
3203 long lLoopDest;
3204 long lLoopCorr;
3205 long lMax;
3206 long lIdx;
3207 float fCorr;
3208
3209 lMax = lCount - 1L;
3210 for (lLoopDest = 0L; lLoopDest <= lMax; lLoopDest++)
3211 {
3212 fCorr = 0.0F;
3213 for (lLoopCorr = 0L; lLoopCorr <= lMax; lLoopCorr++)
3214 {
3215 lIdx = ((lLoopCorr + lLoopDest) > lMax) ?
3216 (lLoopCorr + lLoopDest - lMax) : (lLoopCorr + lLoopDest);
3217 #ifndef _ISOC9X_SOURCE
3218 fCorr += fpSrc1[lLoopCorr] * fpSrc2[lIdx];
3219 #else
3220 fCorr = fmaf(fpSrc1[lLoopCorr], fpSrc2[lIdx], fCorr);
3221 #endif
3222 }
3223 fpDest[lLoopDest] = fCorr / (float) lCount;
3224 }
3225 }
3226
3227
Correlate(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)3228 void clDSPOp::Correlate (double *dpDest, const double *dpSrc1,
3229 const double *dpSrc2, long lCount)
3230 {
3231 long lLoopDest;
3232 long lLoopCorr;
3233 long lMax;
3234 long lIdx;
3235 double dCorr;
3236
3237 lMax = lCount - 1L;
3238 for (lLoopDest = 0L; lLoopDest <= lMax; lLoopDest++)
3239 {
3240 dCorr = 0.0;
3241 for (lLoopCorr = 0L; lLoopCorr <= lMax; lLoopCorr++)
3242 {
3243 lIdx = ((lLoopCorr + lLoopDest) > lMax) ?
3244 (lLoopCorr + lLoopDest - lMax) : (lLoopCorr + lLoopDest);
3245 #ifndef _ISOC9X_SOURCE
3246 dCorr += dpSrc1[lLoopCorr] * dpSrc2[lIdx];
3247 #else
3248 dCorr = fma(dpSrc1[lLoopCorr], dpSrc2[lIdx], dCorr);
3249 #endif
3250 }
3251 dpDest[lLoopDest] = dCorr / (double) lCount;
3252 }
3253 }
3254
3255
AutoCorrelate(const float * fpSrc,long lCount)3256 float clDSPOp::AutoCorrelate (const float *fpSrc, long lCount)
3257 {
3258 long lLoopCntr;
3259 float fAutoCorr = 0.0F;
3260
3261 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3262 {
3263 #ifndef _ISOC9X_SOURCE
3264 fAutoCorr += fpSrc[lLoopCntr] * fpSrc[lLoopCntr];
3265 #else
3266 fAutoCorr = fmaf(fpSrc[lLoopCntr], fpSrc[lLoopCntr], fAutoCorr);
3267 #endif
3268 }
3269 fAutoCorr /= (float) lCount;
3270 return fAutoCorr;
3271 }
3272
3273
AutoCorrelate(const double * dpSrc,long lCount)3274 double clDSPOp::AutoCorrelate (const double *dpSrc, long lCount)
3275 {
3276 long lLoopCntr;
3277 double dAutoCorr = 0.0;
3278
3279 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3280 {
3281 #ifndef _ISOC9X_SOURCE
3282 dAutoCorr += dpSrc[lLoopCntr] * dpSrc[lLoopCntr];
3283 #else
3284 dAutoCorr = fma(dpSrc[lLoopCntr], dpSrc[lLoopCntr], dAutoCorr);
3285 #endif
3286 }
3287 dAutoCorr /= (double) lCount;
3288 return dAutoCorr;
3289 }
3290
3291
AutoCorrelate(float * fpDest,const float * fpSrc,long lCount)3292 void clDSPOp::AutoCorrelate (float *fpDest, const float *fpSrc, long lCount)
3293 {
3294 long lLoopDest;
3295 long lLoopCorr;
3296 long lMax;
3297 long lIdx;
3298 float fAutoCorr;
3299
3300 lMax = lCount - 1L;
3301 for (lLoopDest = 0L; lLoopDest <= lMax; lLoopDest++)
3302 {
3303 fAutoCorr = 0.0F;
3304 for (lLoopCorr = 0L; lLoopCorr <= lMax; lLoopCorr++)
3305 {
3306 lIdx = ((lLoopCorr + lLoopDest) > lMax) ?
3307 (lLoopCorr + lLoopDest - lCount) : (lLoopCorr + lLoopDest);
3308 #ifndef _ISOC9X_SOURCE
3309 fAutoCorr += fpSrc[lLoopCorr] * fpSrc[lIdx];
3310 #else
3311 fAutoCorr = fmaf(fpSrc[lLoopCorr], fpSrc[lIdx], fAutoCorr);
3312 #endif
3313 }
3314 fpDest[lLoopDest] = fAutoCorr / (float) lCount;
3315 }
3316 }
3317
3318
AutoCorrelate(double * dpDest,const double * dpSrc,long lCount)3319 void clDSPOp::AutoCorrelate (double *dpDest, const double *dpSrc, long lCount)
3320 {
3321 long lLoopDest;
3322 long lLoopCorr;
3323 long lMax;
3324 long lIdx;
3325 double dAutoCorr;
3326
3327 lMax = lCount - 1L;
3328 for (lLoopDest = 0L; lLoopDest <= lMax; lLoopDest++)
3329 {
3330 dAutoCorr = 0.0;
3331 for (lLoopCorr = 0L; lLoopCorr <= lMax; lLoopCorr++)
3332 {
3333 lIdx = ((lLoopCorr + lLoopDest) > lMax) ?
3334 (lLoopCorr + lLoopDest - lCount) : (lLoopCorr + lLoopDest);
3335 #ifndef _ISOC9X_SOURCE
3336 dAutoCorr += dpSrc[lLoopCorr] * dpSrc[lIdx];
3337 #else
3338 dAutoCorr = fma(dpSrc[lLoopCorr], dpSrc[lIdx], dAutoCorr);
3339 #endif
3340 }
3341 dpDest[lLoopDest] = dAutoCorr / (double) lCount;
3342 }
3343 }
3344
3345
DotProduct(const float * fpSrc1,const float * fpSrc2,long lCount)3346 float clDSPOp::DotProduct (const float *fpSrc1, const float *fpSrc2,
3347 long lCount)
3348 {
3349 #ifdef DSP_IPP
3350 float fDotProd;
3351
3352 ippsDotProd_32f(fpSrc1, fpSrc2, lCount, &fDotProd);
3353 #else
3354 long lLoopCntr;
3355 float fDotProd = 0.0F;
3356
3357 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3358 {
3359 #ifndef _ISOC9X_SOURCE
3360 fDotProd += fpSrc1[lLoopCntr] * fpSrc2[lLoopCntr];
3361 #else
3362 fDotProd = fmaf(fpSrc1[lLoopCntr], fpSrc2[lLoopCntr], fDotProd);
3363 #endif
3364 }
3365 #endif
3366 return fDotProd;
3367 }
3368
3369
DotProduct(const double * dpSrc1,const double * dpSrc2,long lCount)3370 double clDSPOp::DotProduct (const double *dpSrc1, const double *dpSrc2,
3371 long lCount)
3372 {
3373 #ifdef DSP_IPP
3374 double dDotProd;
3375
3376 ippsDotProd_64f(dpSrc1, dpSrc2, lCount, &dDotProd);
3377 #else
3378 long lLoopCntr;
3379 double dDotProd = 0.0;
3380
3381 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3382 {
3383 #ifndef _ISOC9X_SOURCE
3384 dDotProd += dpSrc1[lLoopCntr] * dpSrc2[lLoopCntr];
3385 #else
3386 dDotProd = fma(dpSrc1[lLoopCntr], dpSrc2[lLoopCntr], dDotProd);
3387 #endif
3388 }
3389 #endif
3390 return dDotProd;
3391 }
3392
3393
MinMax(float * fpMin,float * fpMax,const float * fpSrc,long lCount)3394 void clDSPOp::MinMax (float *fpMin, float *fpMax, const float *fpSrc,
3395 long lCount)
3396 {
3397 #ifdef DSP_IPP
3398 ippsMin_32f(fpSrc, lCount, fpMin);
3399 ippsMax_32f(fpSrc, lCount, fpMax);
3400 #else
3401
3402 #ifdef DSP_X86
3403 if (bHave3DNow)
3404 {
3405 dsp_x86_3dnow_minmaxf(fpMin, fpMax, fpSrc, lCount);
3406 }
3407 else if (bHaveSSE)
3408 {
3409 dsp_x86_sse_minmaxf(fpMin, fpMax, fpSrc, lCount);
3410 }
3411 else
3412 #endif
3413 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
3414 dsp_x86_64_minmaxf(fpMin, fpMax, fpSrc, lCount);
3415 #else
3416 {
3417 long lLoopCntr;
3418 float fTempVal;
3419 float fTempMin = FLT_MAX;
3420 float fTempMax = -FLT_MAX;
3421
3422 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3423 {
3424 fTempVal = fpSrc[lLoopCntr];
3425 #ifndef _ISOC9X_SOURCE
3426 if (fTempVal < fTempMin)
3427 {
3428 fTempMin = fTempVal;
3429 }
3430 if (fTempVal > fTempMax)
3431 {
3432 fTempMax = fTempVal;
3433 }
3434 #else
3435 fTempMin = fminf(fTempVal, fTempMin);
3436 fTempMax = fmaxf(fTempVal, fTempMax);
3437 #endif
3438 }
3439 *fpMin = fTempMin;
3440 *fpMax = fTempMax;
3441 }
3442 #endif
3443 #endif
3444 }
3445
3446
MinMax(double * dpMin,double * dpMax,const double * dpSrc,long lCount)3447 void clDSPOp::MinMax (double *dpMin, double *dpMax, const double *dpSrc,
3448 long lCount)
3449 {
3450 #ifdef DSP_IPP
3451 ippsMin_64f(dpSrc, lCount, dpMin);
3452 ippsMax_64f(dpSrc, lCount, dpMax);
3453 #else
3454
3455 #ifdef DSP_X86
3456 if (bHaveSSE)
3457 {
3458 dsp_x86_sse_minmax(dpMin, dpMax, dpSrc, lCount);
3459 }
3460 else
3461 #endif
3462 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
3463 dsp_x86_64_minmax(dpMin, dpMax, dpSrc, lCount);
3464 #else
3465 {
3466 long lLoopCntr;
3467 double dTempVal;
3468 double dTempMin = DBL_MAX;
3469 double dTempMax = -DBL_MAX;
3470
3471 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3472 {
3473 dTempVal = dpSrc[lLoopCntr];
3474 #ifndef _ISOC9X_SOURCE
3475 if (dTempVal < dTempMin)
3476 {
3477 dTempMin = dTempVal;
3478 }
3479 if (dTempVal > dTempMax)
3480 {
3481 dTempMax = dTempVal;
3482 }
3483 #else
3484 dTempMin = fmin(dTempVal, dTempMin);
3485 dTempMax = fmax(dTempVal, dTempMax);
3486 #endif
3487 }
3488 *dpMin = dTempMin;
3489 *dpMax = dTempMax;
3490 }
3491 #endif
3492 #endif
3493 }
3494
3495
Mean(const float * fpSrc,long lCount)3496 float clDSPOp::Mean (const float *fpSrc, long lCount)
3497 {
3498 #ifdef DSP_IPP
3499 float fMean;
3500
3501 ippsMean_32f(fpSrc, lCount, &fMean, ippAlgHintFast);
3502 #else
3503 long lLoopCntr;
3504 float fMean = 0.0F;
3505
3506 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3507 {
3508 fMean += fpSrc[lLoopCntr];
3509 }
3510 fMean /= (float) lCount;
3511 #endif
3512 return fMean;
3513 }
3514
3515
Mean(const double * dpSrc,long lCount)3516 double clDSPOp::Mean (const double *dpSrc, long lCount)
3517 {
3518 #ifdef DSP_IPP
3519 double dMean;
3520
3521 ippsMean_64f(dpSrc, lCount, &dMean);
3522 #else
3523 long lLoopCntr;
3524 double dMean = 0.0;
3525
3526 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3527 {
3528 dMean += dpSrc[lLoopCntr];
3529 }
3530 dMean /= (double) lCount;
3531 #endif
3532 return dMean;
3533 }
3534
3535
Median(const float * fpSrc,long lCount)3536 float clDSPOp::Median (const float *fpSrc, long lCount)
3537 {
3538 long lMax;
3539 float fMedian = 0.0F;
3540 float *fpTemp;
3541 clDSPAlloc Temp(lCount * sizeof(float));
3542
3543 fpTemp = Temp;
3544 lMax = lCount - 1L;
3545 if (fpTemp != NULL)
3546 {
3547 #ifdef DSP_IPP
3548 ippsCopy_32f(fpSrc, fpTemp, lCount);
3549 ippsSortAscend_32f_I(fpTemp, lCount);
3550 #else
3551 Copy(fpTemp, fpSrc, lCount);
3552 Sort(fpTemp, lCount);
3553 #endif
3554 fMedian = ((lCount % 2L) != 0L) ?
3555 fpTemp[lMax / 2L] :
3556 (0.5F * (fpTemp[lCount / 2L - 1L] + fpTemp[lCount / 2L]));
3557 }
3558 return fMedian;
3559 }
3560
3561
Median(const double * dpSrc,long lCount)3562 double clDSPOp::Median (const double *dpSrc, long lCount)
3563 {
3564 long lMax;
3565 double dMedian = 0.0;
3566 double *dpTemp;
3567 clDSPAlloc Temp(lCount * sizeof(double));
3568
3569 dpTemp = Temp;
3570 lMax = lCount - 1L;
3571 if (dpTemp != NULL)
3572 {
3573 #ifdef DSP_IPP
3574 ippsCopy_64f(dpSrc, dpTemp, lCount);
3575 ippsSortAscend_64f_I(dpTemp, lCount);
3576 #else
3577 Copy(dpTemp, dpSrc, lCount);
3578 Sort(dpTemp, lCount);
3579 #endif
3580 dMedian = ((lCount % 2L) != 0L) ?
3581 dpTemp[lMax / 2L] :
3582 (0.5 * (dpTemp[lCount / 2L - 1L] + dpTemp[lCount / 2L]));
3583 }
3584 return dMedian;
3585 }
3586
3587
Negate(float * fpVect,long lCount)3588 void clDSPOp::Negate (float *fpVect, long lCount)
3589 {
3590 long lLoopCntr;
3591
3592 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3593 {
3594 fpVect[lLoopCntr] = -(fpVect[lLoopCntr]);
3595 }
3596 }
3597
3598
Negate(double * dpVect,long lCount)3599 void clDSPOp::Negate (double *dpVect, long lCount)
3600 {
3601 long lLoopCntr;
3602
3603 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3604 {
3605 dpVect[lLoopCntr] = -(dpVect[lLoopCntr]);
3606 }
3607 }
3608
3609
Negate(float * fpDest,const float * fpSrc,long lCount)3610 void clDSPOp::Negate (float *fpDest, const float *fpSrc, long lCount)
3611 {
3612 long lLoopCntr;
3613
3614 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3615 {
3616 fpDest[lLoopCntr] = -(fpSrc[lLoopCntr]);
3617 }
3618 }
3619
3620
Negate(double * dpDest,const double * dpSrc,long lCount)3621 void clDSPOp::Negate (double *dpDest, const double *dpSrc, long lCount)
3622 {
3623 long lLoopCntr;
3624
3625 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3626 {
3627 dpDest[lLoopCntr] = -(dpSrc[lLoopCntr]);
3628 }
3629 }
3630
3631
Normalize(float * fpVect,long lCount)3632 void clDSPOp::Normalize (float *fpVect, long lCount)
3633 {
3634 long lLoopCntr;
3635 float fMean;
3636 float fStdDev;
3637
3638 StdDev(&fStdDev, &fMean, fpVect, lCount);
3639 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3640 {
3641 fpVect[lLoopCntr] = (fpVect[lLoopCntr] - fMean) / fStdDev;
3642 }
3643 }
3644
3645
Normalize(double * dpVect,long lCount)3646 void clDSPOp::Normalize (double *dpVect, long lCount)
3647 {
3648 long lLoopCntr;
3649 double dMean;
3650 double dStdDev;
3651
3652 StdDev(&dStdDev, &dMean, dpVect, lCount);
3653 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3654 {
3655 dpVect[lLoopCntr] = (dpVect[lLoopCntr] - dMean) / dStdDev;
3656 }
3657 }
3658
3659
Normalize(float * fpDest,const float * fpSrc,long lCount)3660 void clDSPOp::Normalize (float *fpDest, const float *fpSrc, long lCount)
3661 {
3662 long lLoopCntr;
3663 float fMean;
3664 float fStdDev;
3665
3666 StdDev(&fStdDev, &fMean, fpSrc, lCount);
3667 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3668 {
3669 fpDest[lLoopCntr] = (fpSrc[lLoopCntr] - fMean) / fStdDev;
3670 }
3671 }
3672
3673
Normalize(double * dpDest,const double * dpSrc,long lCount)3674 void clDSPOp::Normalize (double *dpDest, const double *dpSrc, long lCount)
3675 {
3676 long lLoopCntr;
3677 double dMean;
3678 double dStdDev;
3679
3680 StdDev(&dStdDev, &dMean, dpSrc, lCount);
3681 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3682 {
3683 dpDest[lLoopCntr] = (dpSrc[lLoopCntr] - dMean) / dStdDev;
3684 }
3685 }
3686
3687
Product(const float * fpSrc,long lCount)3688 float clDSPOp::Product (const float *fpSrc, long lCount)
3689 {
3690 long lLoopCntr;
3691 float fProd = 1.0F;
3692
3693 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3694 {
3695 fProd *= fpSrc[lLoopCntr];
3696 }
3697 return fProd;
3698 }
3699
3700
Product(const double * dpSrc,long lCount)3701 double clDSPOp::Product (const double *dpSrc, long lCount)
3702 {
3703 long lLoopCntr;
3704 double dProd = 1.0;
3705
3706 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3707 {
3708 dProd *= dpSrc[lLoopCntr];
3709 }
3710 return dProd;
3711 }
3712
3713
Reverse(float * fpVect,long lCount)3714 void clDSPOp::Reverse (float *fpVect, long lCount)
3715 {
3716 #ifdef DSP_IPP
3717 ippsFlip_32f_I(fpVect, lCount);
3718 #else
3719 long lFwdIdx;
3720 long lRevIdx;
3721 long lMax;
3722 float fTemp1;
3723 float fTemp2;
3724
3725 lMax = (lCount >> 1);
3726 lFwdIdx = 0;
3727 lRevIdx = lCount;
3728 while (lFwdIdx < lMax)
3729 {
3730 lRevIdx--;
3731 fTemp1 = fpVect[lFwdIdx];
3732 fTemp2 = fpVect[lRevIdx];
3733 fpVect[lFwdIdx] = fTemp2;
3734 fpVect[lRevIdx] = fTemp1;
3735 lFwdIdx++;
3736 }
3737 #endif
3738 }
3739
3740
Reverse(double * dpVect,long lCount)3741 void clDSPOp::Reverse (double *dpVect, long lCount)
3742 {
3743 #ifdef DSP_IPP
3744 ippsFlip_64f_I(dpVect, lCount);
3745 #else
3746 long lFwdIdx;
3747 long lRevIdx;
3748 long lMax;
3749 double dTemp1;
3750 double dTemp2;
3751
3752 lMax = (lCount >> 1);
3753 lFwdIdx = 0;
3754 lRevIdx = lCount;
3755 while (lFwdIdx < lMax)
3756 {
3757 lRevIdx--;
3758 dTemp1 = dpVect[lFwdIdx];
3759 dTemp2 = dpVect[lRevIdx];
3760 dpVect[lFwdIdx] = dTemp2;
3761 dpVect[lRevIdx] = dTemp1;
3762 lFwdIdx++;
3763 }
3764 #endif
3765 }
3766
3767
Reverse(stpSCplx spVect,long lCount)3768 void clDSPOp::Reverse (stpSCplx spVect, long lCount)
3769 {
3770 #ifdef DSP_IPP
3771 Ipp32fc *spTemp;
3772
3773 spTemp = ippsMalloc_32fc(lCount);
3774 ippsConjFlip_32fc((Ipp32fc *) spVect, spTemp, lCount);
3775 ippsCopy_32fc(spTemp, (Ipp32fc *) spVect, lCount);
3776 ippsFree(spTemp);
3777 #else
3778 long lFwdIdx;
3779 long lRevIdx;
3780 long lMax;
3781 stSCplx sTemp1;
3782 stSCplx sTemp2;
3783
3784 lMax = (lCount >> 1);
3785 lFwdIdx = 0;
3786 lRevIdx = lCount;
3787 while (lFwdIdx < lMax)
3788 {
3789 lRevIdx--;
3790 sTemp1.R = spVect[lFwdIdx].R;
3791 sTemp1.I = spVect[lFwdIdx].I;
3792 sTemp2.R = spVect[lRevIdx].R;
3793 sTemp2.I = spVect[lRevIdx].I;
3794 CplxConj(&sTemp1);
3795 CplxConj(&sTemp2);
3796 spVect[lFwdIdx].R = sTemp2.R;
3797 spVect[lFwdIdx].I = sTemp2.I;
3798 spVect[lRevIdx].R = sTemp1.R;
3799 spVect[lRevIdx].I = sTemp1.I;
3800 lFwdIdx++;
3801 }
3802 #endif
3803 }
3804
3805
Reverse(stpDCplx spVect,long lCount)3806 void clDSPOp::Reverse (stpDCplx spVect, long lCount)
3807 {
3808 #ifdef DSP_IPP
3809 Ipp64fc *spTemp;
3810
3811 spTemp = ippsMalloc_64fc(lCount);
3812 ippsConjFlip_64fc((Ipp64fc *) spVect, spTemp, lCount);
3813 ippsCopy_64fc(spTemp, (Ipp64fc *) spVect, lCount);
3814 ippsFree(spTemp);
3815 #else
3816 long lFwdIdx;
3817 long lRevIdx;
3818 long lMax;
3819 stDCplx sTemp1;
3820 stDCplx sTemp2;
3821
3822 lMax = (lCount >> 1);
3823 lFwdIdx = 0;
3824 lRevIdx = lCount;
3825 while (lFwdIdx < lMax)
3826 {
3827 lRevIdx--;
3828 sTemp1.R = spVect[lFwdIdx].R;
3829 sTemp1.I = spVect[lFwdIdx].I;
3830 sTemp2.R = spVect[lRevIdx].R;
3831 sTemp2.I = spVect[lRevIdx].I;
3832 CplxConj(&sTemp1);
3833 CplxConj(&sTemp2);
3834 spVect[lFwdIdx].R = sTemp2.R;
3835 spVect[lFwdIdx].I = sTemp2.I;
3836 spVect[lRevIdx].R = sTemp1.R;
3837 spVect[lRevIdx].I = sTemp1.I;
3838 lFwdIdx++;
3839 }
3840 #endif
3841 }
3842
3843
Reverse(float * fpDest,const float * fpSrc,long lCount)3844 void clDSPOp::Reverse (float *fpDest, const float *fpSrc, long lCount)
3845 {
3846 #ifdef DSP_IPP
3847 ippsFlip_32f(fpSrc, fpDest, lCount);
3848 #else
3849 long lLoopCntr;
3850 long lMax;
3851
3852 lMax = lCount - 1L;
3853 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3854 {
3855 fpDest[lLoopCntr] = fpSrc[lMax - lLoopCntr];
3856 }
3857 #endif
3858 }
3859
3860
Reverse(double * dpDest,const double * dpSrc,long lCount)3861 void clDSPOp::Reverse (double *dpDest, const double *dpSrc, long lCount)
3862 {
3863 #ifdef DSP_IPP
3864 ippsFlip_64f(dpSrc, dpDest, lCount);
3865 #else
3866 long lLoopCntr;
3867 long lMax;
3868
3869 lMax = lCount - 1L;
3870 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3871 {
3872 dpDest[lLoopCntr] = dpSrc[lMax - lLoopCntr];
3873 }
3874 #endif
3875 }
3876
3877
Reverse(stpSCplx spDest,const stpSCplx spSrc,long lCount)3878 void clDSPOp::Reverse (stpSCplx spDest, const stpSCplx spSrc, long lCount)
3879 {
3880 #ifdef DSP_IPP
3881 ippsConjFlip_32fc((Ipp32fc *) spSrc, (Ipp32fc *) spDest, lCount);
3882 #else
3883 long lLoopCntr;
3884 long lMax;
3885
3886 lMax = lCount - 1L;
3887 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3888 {
3889 CplxConj(&spDest[lLoopCntr], &spSrc[lMax - lLoopCntr]);
3890 }
3891 #endif
3892 }
3893
3894
Reverse(stpDCplx spDest,const stpDCplx spSrc,long lCount)3895 void clDSPOp::Reverse (stpDCplx spDest, const stpDCplx spSrc, long lCount)
3896 {
3897 #ifdef DSP_IPP
3898 ippsConjFlip_64fc((Ipp64fc *) spSrc, (Ipp64fc *) spDest, lCount);
3899 #else
3900 long lLoopCntr;
3901 long lMax;
3902
3903 lMax = lCount - 1L;
3904 for (lLoopCntr = 0L; lLoopCntr <= lMax; lLoopCntr++)
3905 {
3906 CplxConj(&spDest[lLoopCntr], &spSrc[lMax - lLoopCntr]);
3907 }
3908 #endif
3909 }
3910
3911
Scale(float * fpVect,long lCount)3912 void clDSPOp::Scale (float *fpVect, long lCount)
3913 {
3914 #ifdef DSP_IPP
3915 float fMin;
3916 float fMax;
3917
3918 ippsMin_32f(fpVect, lCount, &fMin);
3919 ippsMax_32f(fpVect, lCount, &fMax);
3920 ippsNormalize_32f(fpVect, fpVect, lCount, fMin, (fMax - fMin) * 0.5F);
3921 ippsAddC_32f_I(-1.0F, fpVect, lCount);
3922 #else
3923 long lLoopCntr;
3924 float fMin;
3925 float fMax;
3926 float fScale;
3927 float fOffset;
3928
3929 MinMax(&fMin, &fMax, fpVect, lCount);
3930 fScale = 2.0F / (fMax - fMin);
3931 fOffset = 1.0F - fMax * fScale;
3932 #ifdef DSP_X86
3933 if (bHave3DNow)
3934 {
3935 dsp_x86_3dnow_maf(fpVect, fScale, fOffset, lCount);
3936 }
3937 else if (bHaveSSE)
3938 {
3939 dsp_x86_sse_maf(fpVect, fScale, fOffset, lCount);
3940 }
3941 else
3942 #endif
3943 {
3944 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3945 {
3946 #ifndef _ISOC9X_SOURCE
3947 fpVect[lLoopCntr] = fpVect[lLoopCntr] * fScale + fOffset;
3948 #else
3949 fpVect[lLoopCntr] =
3950 fmaf(fpVect[lLoopCntr], fScale, fOffset);
3951 #endif
3952 }
3953 }
3954 #endif
3955 }
3956
3957
Scale(double * dpVect,long lCount)3958 void clDSPOp::Scale (double *dpVect, long lCount)
3959 {
3960 #ifdef DSP_IPP
3961 double dMin;
3962 double dMax;
3963
3964 ippsMin_64f(dpVect, lCount, &dMin);
3965 ippsMax_64f(dpVect, lCount, &dMax);
3966 ippsNormalize_64f(dpVect, dpVect, lCount, dMin, (dMax - dMin) * 0.5);
3967 ippsAddC_64f_I(-1.0, dpVect, lCount);
3968 #else
3969 long lLoopCntr;
3970 double dMin;
3971 double dMax;
3972 double dScale;
3973 double dOffset;
3974
3975 MinMax(&dMin, &dMax, dpVect, lCount);
3976 dScale = 2.0 / (dMax - dMin);
3977 dOffset = 1.0 - dMax * dScale;
3978 #ifdef DSP_X86
3979 if (bHaveSSE)
3980 {
3981 dsp_x86_sse_ma(dpVect, dScale, dOffset, lCount);
3982 }
3983 else
3984 #endif
3985 {
3986 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
3987 {
3988 #ifndef _ISOC9X_SOURCE
3989 dpVect[lLoopCntr] = dpVect[lLoopCntr] * dScale + dOffset;
3990 #else
3991 dpVect[lLoopCntr] =
3992 fma(dpVect[lLoopCntr], dScale, dOffset);
3993 #endif
3994 }
3995 }
3996 #endif
3997 }
3998
3999
Scale(float * fpDest,const float * fpSrc,long lCount)4000 void clDSPOp::Scale (float *fpDest, const float *fpSrc, long lCount)
4001 {
4002 #ifdef DSP_IPP
4003 float fMin;
4004 float fMax;
4005
4006 ippsMin_32f(fpSrc, lCount, &fMin);
4007 ippsMax_32f(fpSrc, lCount, &fMax);
4008 ippsNormalize_32f(fpSrc, fpDest, lCount, fMin, (fMax - fMin) * 0.5F);
4009 ippsAddC_32f_I(1.0F, fpDest, lCount);
4010 #else
4011 long lLoopCntr;
4012 float fMin;
4013 float fMax;
4014 float fScale;
4015 float fOffset;
4016
4017 MinMax(&fMin, &fMax, fpSrc, lCount);
4018 fScale = 2.0F / (fMax - fMin);
4019 fOffset = 1.0F - fMax * fScale;
4020 #ifdef DSP_X86
4021 if (bHave3DNow)
4022 {
4023 dsp_x86_3dnow_ma2f(fpDest, fpSrc, fScale, fOffset, lCount);
4024 }
4025 else if (bHaveSSE)
4026 {
4027 dsp_x86_sse_ma2f(fpDest, fpSrc, fScale, fOffset, lCount);
4028 }
4029 else
4030 #endif
4031 {
4032 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4033 {
4034 #ifndef _ISOC9X_SOURCE
4035 fpDest[lLoopCntr] = fpSrc[lLoopCntr] * fScale + fOffset;
4036 #else
4037 fpDest[lLoopCntr] =
4038 fmaf(fpSrc[lLoopCntr], fScale, fOffset);
4039 #endif
4040 }
4041 }
4042 #endif
4043 }
4044
4045
Scale(double * dpDest,const double * dpSrc,long lCount)4046 void clDSPOp::Scale (double *dpDest, const double *dpSrc, long lCount)
4047 {
4048 #ifdef DSP_IPP
4049 double dMin;
4050 double dMax;
4051
4052 ippsMin_64f(dpSrc, lCount, &dMin);
4053 ippsMax_64f(dpSrc, lCount, &dMax);
4054 ippsNormalize_64f(dpSrc, dpDest, lCount, dMin, (dMax - dMin) * 0.5);
4055 ippsAddC_64f_I(-1.0, dpDest, lCount);
4056 #else
4057 long lLoopCntr;
4058 double dMin;
4059 double dMax;
4060 double dScale;
4061 double dOffset;
4062
4063 MinMax(&dMin, &dMax, dpSrc, lCount);
4064 dScale = 2.0 / (dMax - dMin);
4065 dOffset = 1.0 - dMax * dScale;
4066 #ifdef DSP_X86
4067 if (bHaveSSE)
4068 {
4069 dsp_x86_sse_ma2(dpDest, dpSrc, dScale, dOffset, lCount);
4070 }
4071 else
4072 #endif
4073 {
4074 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4075 {
4076 #ifndef _ISOC9X_SOURCE
4077 dpDest[lLoopCntr] = dpSrc[lLoopCntr] * dScale + dOffset;
4078 #else
4079 dpDest[lLoopCntr] =
4080 fma(dpSrc[lLoopCntr], dScale, dOffset);
4081 #endif
4082 }
4083 }
4084 #endif
4085 }
4086
4087
Scale01(float * fpVect,long lCount)4088 void clDSPOp::Scale01 (float *fpVect, long lCount)
4089 {
4090 #ifdef DSP_IPP
4091 float fMin;
4092 float fMax;
4093
4094 ippsMin_32f(fpVect, lCount, &fMin);
4095 ippsMax_32f(fpVect, lCount, &fMax);
4096 ippsNormalize_32f(fpVect, fpVect, lCount, fMin, fMax - fMin);
4097 #else
4098 long lLoopCntr;
4099 float fMin;
4100 float fMax;
4101 float fScale;
4102 float fOffset;
4103
4104 MinMax(&fMin, &fMax, fpVect, lCount);
4105 fScale = 1.0F / (fMax - fMin);
4106 fOffset = -fMin * fScale;
4107 #ifdef DSP_X86
4108 if (bHave3DNow)
4109 {
4110 dsp_x86_3dnow_maf(fpVect, fScale, fOffset, lCount);
4111 }
4112 else if (bHaveSSE)
4113 {
4114 dsp_x86_sse_maf(fpVect, fScale, fOffset, lCount);
4115 }
4116 else
4117 #endif
4118 {
4119 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4120 {
4121 #ifndef _ISOC9X_SOURCE
4122 fpVect[lLoopCntr] = fpVect[lLoopCntr] * fScale + fOffset;
4123 #else
4124 fpVect[lLoopCntr] = fmaf(fpVect[lLoopCntr], fScale, fOffset);
4125 #endif
4126 }
4127 }
4128 #endif
4129 }
4130
4131
Scale01(double * dpVect,long lCount)4132 void clDSPOp::Scale01 (double *dpVect, long lCount)
4133 {
4134 #ifdef DSP_IPP
4135 double dMin;
4136 double dMax;
4137
4138 ippsMin_64f(dpVect, lCount, &dMin);
4139 ippsMax_64f(dpVect, lCount, &dMax);
4140 ippsNormalize_64f(dpVect, dpVect, lCount, dMin, dMax - dMin);
4141 #else
4142 long lLoopCntr;
4143 double dMin;
4144 double dMax;
4145 double dScale;
4146 double dOffset;
4147
4148 MinMax(&dMin, &dMax, dpVect, lCount);
4149 dScale = 1.0 / (dMax - dMin);
4150 dOffset = -dMin * dScale;
4151 #ifdef DSP_X86
4152 if (bHaveSSE)
4153 {
4154 dsp_x86_sse_ma(dpVect, dScale, dOffset, lCount);
4155 }
4156 else
4157 #endif
4158 {
4159 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4160 {
4161 #ifndef _ISOC9X_SOURCE
4162 dpVect[lLoopCntr] = dpVect[lLoopCntr] * dScale + dOffset;
4163 #else
4164 dpVect[lLoopCntr] = fma(dpVect[lLoopCntr], dScale, dOffset);
4165 #endif
4166 }
4167 }
4168 #endif
4169 }
4170
4171
Scale01(float * fpDest,const float * fpSrc,long lCount)4172 void clDSPOp::Scale01 (float *fpDest, const float *fpSrc, long lCount)
4173 {
4174 #ifdef DSP_IPP
4175 float fMin;
4176 float fMax;
4177
4178 ippsMin_32f(fpSrc, lCount, &fMin);
4179 ippsMax_32f(fpSrc, lCount, &fMax);
4180 ippsNormalize_32f(fpSrc, fpDest, lCount, fMin, fMax - fMin);
4181 #else
4182 long lLoopCntr;
4183 float fMin;
4184 float fMax;
4185 float fScale;
4186 float fOffset;
4187
4188 MinMax(&fMin, &fMax, fpSrc, lCount);
4189 fScale = 1.0F / (fMax - fMin);
4190 fOffset = -fMin * fScale;
4191 #ifdef DSP_X86
4192 if (bHave3DNow)
4193 {
4194 dsp_x86_3dnow_ma2f(fpDest, fpSrc, fScale, fOffset, lCount);
4195 }
4196 else if (bHaveSSE)
4197 {
4198 dsp_x86_sse_ma2f(fpDest, fpSrc, fScale, fOffset, lCount);
4199 }
4200 else
4201 #endif
4202 {
4203 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4204 {
4205 #ifndef _ISOC9X_SOURCE
4206 fpDest[lLoopCntr] = fpSrc[lLoopCntr] * fScale + fOffset;
4207 #else
4208 fpDest[lLoopCntr] = fmaf(fpSrc[lLoopCntr], fScale, fOffset);
4209 #endif
4210 }
4211 }
4212 #endif
4213 }
4214
4215
Scale01(double * dpDest,const double * dpSrc,long lCount)4216 void clDSPOp::Scale01 (double *dpDest, const double *dpSrc, long lCount)
4217 {
4218 #ifdef DSP_IPP
4219 double dMin;
4220 double dMax;
4221
4222 ippsMin_64f(dpSrc, lCount, &dMin);
4223 ippsMax_64f(dpSrc, lCount, &dMax);
4224 ippsNormalize_64f(dpSrc, dpDest, lCount, dMin, dMax - dMin);
4225 #else
4226 long lLoopCntr;
4227 double dMin;
4228 double dMax;
4229 double dScale;
4230 double dOffset;
4231
4232 MinMax(&dMin, &dMax, dpSrc, lCount);
4233 dScale = 1.0 / (dMax - dMin);
4234 dOffset = -dMin * dScale;
4235 #ifdef DSP_X86
4236 if (bHaveSSE)
4237 {
4238 dsp_x86_sse_ma2(dpDest, dpSrc, dScale, dOffset, lCount);
4239 }
4240 else
4241 #endif
4242 {
4243 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4244 {
4245 #ifndef _ISOC9X_SOURCE
4246 dpDest[lLoopCntr] = dpSrc[lLoopCntr] * dScale + dOffset;
4247 #else
4248 dpDest[lLoopCntr] = fma(dpSrc[lLoopCntr], dScale, dOffset);
4249 #endif
4250 }
4251 }
4252 #endif
4253 }
4254
4255
Sort(float * fpVect,long lCount)4256 void clDSPOp::Sort (float *fpVect, long lCount)
4257 {
4258 #ifdef DSP_IPP
4259 ippsSortAscend_32f_I(fpVect, lCount);
4260 #else
4261 qsort(fpVect, (size_t) lCount, sizeof(float), FloatCompare);
4262 #endif
4263 }
4264
4265
Sort(double * dpVect,long lCount)4266 void clDSPOp::Sort (double *dpVect, long lCount)
4267 {
4268 #ifdef DSP_IPP
4269 ippsSortAscend_64f_I(dpVect, lCount);
4270 #else
4271 qsort(dpVect, (size_t) lCount, sizeof(double), DoubleCompare);
4272 #endif
4273 }
4274
4275
Sort(long * lpVect,long lCount)4276 void clDSPOp::Sort (long *lpVect, long lCount)
4277 {
4278 #ifdef DSP_IPP
4279 ippsSortAscend_32s_I((Ipp32s *) lpVect, lCount);
4280 #else
4281 qsort(lpVect, (size_t) lCount, sizeof(long), LongCompare);
4282 #endif
4283 }
4284
4285
StdDev(float * fpStdDev,float * fpMean,const float * fpSrc,long lCount)4286 void clDSPOp::StdDev (float *fpStdDev, float *fpMean, const float *fpSrc,
4287 long lCount)
4288 {
4289 #ifdef DSP_IPP
4290 ippsStdDev_32f(fpSrc, lCount, fpStdDev, ippAlgHintFast);
4291 ippsMean_32f(fpSrc, lCount, fpMean, ippAlgHintFast);
4292 #else
4293 long lLoopCntr;
4294 float fMean = 0.0F;
4295 float fTempVal;
4296 float fTemp = 0.0F;
4297 float fStdDev;
4298
4299 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4300 {
4301 fMean += fpSrc[lLoopCntr];
4302 }
4303 fMean /= (float) lCount;
4304 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4305 {
4306 fTempVal = fpSrc[lLoopCntr] - fMean;
4307 #ifndef _ISOC9X_SOURCE
4308 fTemp += fTempVal * fTempVal;
4309 #else
4310 fTemp = fmaf(fTempVal, fTempVal, fTemp);
4311 #endif
4312 }
4313 fStdDev = sqrtf(fTemp / (float) lCount);
4314 *fpStdDev = fStdDev;
4315 *fpMean = fMean;
4316 #endif
4317 }
4318
4319
StdDev(double * dpStdDev,double * dpMean,const double * dpSrc,long lCount)4320 void clDSPOp::StdDev (double *dpStdDev, double *dpMean, const double *dpSrc,
4321 long lCount)
4322 {
4323 #ifdef DSP_IPP
4324 ippsStdDev_64f(dpSrc, lCount, dpStdDev);
4325 ippsStdDev_64f(dpSrc, lCount, dpMean);
4326 #else
4327 long lLoopCntr;
4328 double dMean = 0.0;
4329 double dTempVal;
4330 double dTemp = 0.0;
4331 double dStdDev;
4332
4333 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4334 {
4335 dMean += dpSrc[lLoopCntr];
4336 }
4337 dMean /= (double) lCount;
4338 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4339 {
4340 dTempVal = dpSrc[lLoopCntr] - dMean;
4341 #ifndef _ISOC9X_SOURCE
4342 dTemp += dTempVal * dTempVal;
4343 #else
4344 dTemp = fma(dTempVal, dTempVal, dTemp);
4345 #endif
4346 }
4347 dStdDev = sqrt(dTemp / (double) lCount);
4348 *dpStdDev = dStdDev;
4349 *dpMean = dMean;
4350 #endif
4351 }
4352
4353
Sum(const float * fpSrc,long lCount)4354 float clDSPOp::Sum (const float *fpSrc, long lCount)
4355 {
4356 #ifdef DSP_IPP
4357 float fSum;
4358
4359 ippsSum_32f(fpSrc, lCount, &fSum, ippAlgHintFast);
4360 #else
4361 long lLoopCntr;
4362 float fSum = 0.0F;
4363
4364 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4365 {
4366 fSum += fpSrc[lLoopCntr];
4367 }
4368 #endif
4369 return fSum;
4370 }
4371
4372
Sum(const double * dpSrc,long lCount)4373 double clDSPOp::Sum (const double *dpSrc, long lCount)
4374 {
4375 #ifdef DSP_IPP
4376 double dSum;
4377
4378 ippsSum_64f(dpSrc, lCount, &dSum);
4379 #else
4380 long lLoopCntr;
4381 double dSum = 0.0;
4382
4383 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4384 {
4385 dSum += dpSrc[lLoopCntr];
4386 }
4387 #endif
4388 return dSum;
4389 }
4390
4391
Square(float * fpVect,long lCount)4392 void clDSPOp::Square (float *fpVect, long lCount)
4393 {
4394 #ifdef DSP_IPP
4395 ippsSqr_32f_I(fpVect, lCount);
4396 #else
4397 long lLoopCntr;
4398
4399 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4400 {
4401 fpVect[lLoopCntr] *= fpVect[lLoopCntr];
4402 }
4403 #endif
4404 }
4405
4406
Square(double * dpVect,long lCount)4407 void clDSPOp::Square (double *dpVect, long lCount)
4408 {
4409 #ifdef DSP_IPP
4410 ippsSqr_64f_I(dpVect, lCount);
4411 #else
4412 long lLoopCntr;
4413
4414 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4415 {
4416 dpVect[lLoopCntr] *= dpVect[lLoopCntr];
4417 }
4418 #endif
4419 }
4420
4421
Square(float * fpDest,const float * fpSrc,long lCount)4422 void clDSPOp::Square (float *fpDest, const float *fpSrc, long lCount)
4423 {
4424 #ifdef DSP_IPP
4425 ippsSqr_32f(fpSrc, fpDest, lCount);
4426 #else
4427 long lLoopCntr;
4428
4429 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4430 {
4431 fpDest[lLoopCntr] = fpSrc[lLoopCntr] * fpSrc[lLoopCntr];
4432 }
4433 #endif
4434 }
4435
4436
Square(double * dpDest,const double * dpSrc,long lCount)4437 void clDSPOp::Square (double *dpDest, const double *dpSrc, long lCount)
4438 {
4439 #ifdef DSP_IPP
4440 ippsSqr_64f(dpSrc, dpDest, lCount);
4441 #else
4442 long lLoopCntr;
4443
4444 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4445 {
4446 dpDest[lLoopCntr] = dpSrc[lLoopCntr] * dpSrc[lLoopCntr];
4447 }
4448 #endif
4449 }
4450
4451
Convert(float * fpDest,const unsigned char * ucpSrc,long lCount)4452 void clDSPOp::Convert (float *fpDest, const unsigned char *ucpSrc, long lCount)
4453 {
4454 long lLoopCntr;
4455 float fMult;
4456
4457 fMult = 1.0F / (float) UCHAR_MAX;
4458 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4459 {
4460 fpDest[lLoopCntr] = (ucpSrc[lLoopCntr] * fMult - 0.5F) * 2.0F;
4461 }
4462 }
4463
4464
Convert(float * fpDest,const signed short * sspSrc,long lCount,bool b12bit)4465 void clDSPOp::Convert (float *fpDest, const signed short *sspSrc, long lCount,
4466 bool b12bit)
4467 {
4468 #ifdef DSP_IPP
4469 ippsConvert_16s32f_Sfs(sspSrc, fpDest, lCount,
4470 (b12bit) ? 11 : 15);
4471 #else
4472 long lLoopCntr;
4473 float fMult;
4474
4475 #ifdef DSP_X86
4476 if (bHave3DNow)
4477 {
4478 dsp_x86_3dnow_i16tof(fpDest, sspSrc, lCount,
4479 ((b12bit) ? 0x1000 : SHRT_MAX));
4480 }
4481 else
4482 #endif
4483 {
4484 fMult = (b12bit) ? (1.0F / (float) 0x1000) : (1.0F / (float) SHRT_MAX);
4485 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4486 {
4487 fpDest[lLoopCntr] = sspSrc[lLoopCntr] * fMult;
4488 }
4489 }
4490 #endif
4491 }
4492
4493
Convert(float * fpDest,const signed int * sipSrc,long lCount,bool b24bit)4494 void clDSPOp::Convert (float *fpDest, const signed int *sipSrc, long lCount,
4495 bool b24bit)
4496 {
4497 #ifdef DSP_IPP
4498 ippsConvert_32s32f_Sfs(sipSrc, fpDest, lCount, 31);
4499 ippsMulC_32f_I((float) 0x7fffffff / (float) 0x7fffff00, fpDest, lCount);
4500 #else
4501 long lLoopCntr;
4502 float fMult;
4503
4504 #ifdef DSP_X86
4505 if (bHave3DNow)
4506 {
4507 dsp_x86_3dnow_i32tof(fpDest, sipSrc, lCount,
4508 ((b24bit) ? 0x7fffff00 : INT_MAX));
4509 }
4510 else
4511 #endif
4512 {
4513 fMult = (b24bit) ?
4514 (1.0F / (float) 0x7fffff00) :
4515 (1.0F / (float) INT_MAX);
4516 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4517 {
4518 fpDest[lLoopCntr] = sipSrc[lLoopCntr] * fMult;
4519 }
4520 }
4521 #endif
4522 }
4523
4524
Convert(float * fpDest,const double * dpSrc,long lCount)4525 void clDSPOp::Convert (float *fpDest, const double *dpSrc, long lCount)
4526 {
4527 #ifdef DSP_IPP
4528 ippsConvert_64f32f(dpSrc, fpDest, lCount);
4529 #else
4530 long lLoopCntr;
4531
4532 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4533 {
4534 fpDest[lLoopCntr] = (float) dpSrc[lLoopCntr];
4535 }
4536 #endif
4537 }
4538
4539
Convert(double * dpDest,const unsigned char * ucpSrc,long lCount)4540 void clDSPOp::Convert (double *dpDest, const unsigned char *ucpSrc,
4541 long lCount)
4542 {
4543 long lLoopCntr;
4544 double dMult;
4545
4546 dMult = 1.0 / (double) UCHAR_MAX;
4547 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4548 {
4549 dpDest[lLoopCntr] = (ucpSrc[lLoopCntr] * dMult - 0.5) * 2.0;
4550 }
4551 }
4552
4553
Convert(double * dpDest,const signed short * sspSrc,long lCount,bool b12bit)4554 void clDSPOp::Convert (double *dpDest, const signed short *sspSrc, long lCount,
4555 bool b12bit)
4556 {
4557 #ifdef DSP_IPP
4558 ippsConvert_16s64f_Sfs(sspSrc, dpDest, lCount,
4559 (b12bit) ? 11 : 15);
4560 #else
4561 long lLoopCntr;
4562 double dMult;
4563
4564 dMult = (b12bit) ? (1.0 / (double) 0x1000) : (1.0 / (double) SHRT_MAX);
4565 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4566 {
4567 dpDest[lLoopCntr] = sspSrc[lLoopCntr] * dMult;
4568 }
4569 #endif
4570 }
4571
4572
Convert(double * dpDest,const signed int * sipSrc,long lCount,bool b24bit)4573 void clDSPOp::Convert (double *dpDest, const signed int *sipSrc, long lCount,
4574 bool b24bit)
4575 {
4576 #ifdef DSP_IPP
4577 ippsConvert_32s64f_Sfs(sipSrc, dpDest, lCount, 31);
4578 ippsMulC_64f_I((double) 0x7fffffff / (double) 0x7fffff00, dpDest, lCount);
4579 #else
4580 long lLoopCntr;
4581 double dMult;
4582
4583 dMult = (b24bit) ?
4584 (1.0 / (double) 0x7fffff00) :
4585 (1.0 / (double) INT_MAX);
4586 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4587 {
4588 dpDest[lLoopCntr] = sipSrc[lLoopCntr] * dMult;
4589 }
4590 #endif
4591 }
4592
4593
Convert(double * dpDest,const float * fpSrc,long lCount)4594 void clDSPOp::Convert (double *dpDest, const float *fpSrc, long lCount)
4595 {
4596 #ifdef DSP_IPP
4597 ippsConvert_32f64f(fpSrc, dpDest, lCount);
4598 #else
4599 long lLoopCntr;
4600
4601 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4602 {
4603 dpDest[lLoopCntr] = (double) fpSrc[lLoopCntr];
4604 }
4605 #endif
4606 }
4607
4608
Convert(unsigned char * ucpDest,const float * fpSrc,long lCount)4609 void clDSPOp::Convert (unsigned char *ucpDest, const float *fpSrc, long lCount)
4610 {
4611 long lLoopCntr;
4612
4613 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4614 {
4615 ucpDest[lLoopCntr] = (unsigned char)
4616 Round((fpSrc[lLoopCntr] + 1.0F) / 2.0F * (float) UCHAR_MAX);
4617 }
4618 }
4619
4620
Convert(unsigned char * ucpDest,const double * dpSrc,long lCount)4621 void clDSPOp::Convert (unsigned char *ucpDest, const double *dpSrc,
4622 long lCount)
4623 {
4624 long lLoopCntr;
4625
4626 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4627 {
4628 ucpDest[lLoopCntr] = (unsigned char)
4629 Round((dpSrc[lLoopCntr] + 1.0) / 2.0 * (double) UCHAR_MAX);
4630 }
4631 }
4632
4633
Convert(signed short * sspDest,const float * fpSrc,long lCount,bool b12bit)4634 void clDSPOp::Convert (signed short *sspDest, const float *fpSrc, long lCount,
4635 bool b12bit)
4636 {
4637 #ifdef DSP_IPP
4638 ippsConvert_32f16s_Sfs(fpSrc, sspDest, lCount, ippRndNear,
4639 (b12bit) ? -11 : -15);
4640 #else
4641 long lLoopCntr;
4642 float fMult;
4643
4644 fMult = (b12bit) ? (float) 0x1000 : (float) SHRT_MAX;
4645 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4646 {
4647 sspDest[lLoopCntr] = (signed short)
4648 Round(fpSrc[lLoopCntr] * fMult);
4649 }
4650 #endif
4651 }
4652
4653
Convert(signed short * sspDest,const double * dpSrc,long lCount,bool b12bit)4654 void clDSPOp::Convert (signed short *sspDest, const double *dpSrc, long lCount,
4655 bool b12bit)
4656 {
4657 long lLoopCntr;
4658 double dMult;
4659
4660 dMult = (b12bit) ? (double) 0x1000 : (double) SHRT_MAX;
4661 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4662 {
4663 sspDest[lLoopCntr] = (signed short)
4664 Round(dpSrc[lLoopCntr] * dMult);
4665 }
4666 }
4667
4668
Convert(signed int * sipDest,const float * fpSrc,long lCount,bool b24bit)4669 void clDSPOp::Convert (signed int *sipDest, const float *fpSrc, long lCount,
4670 bool b24bit)
4671 {
4672 #ifdef DSP_IPP
4673 ippsConvert_32f32s_Sfs(fpSrc, sipDest, lCount, ippRndNear, -31);
4674 #else
4675 long lLoopCntr;
4676 float fMult;
4677
4678 fMult = (b24bit) ? ((float) 0x7fffff00) : ((float) INT_MAX);
4679 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4680 {
4681 sipDest[lLoopCntr] = (signed int)
4682 Round(fpSrc[lLoopCntr] * fMult);
4683 }
4684 #endif
4685 }
4686
4687
Convert(signed int * sipDest,const double * dpSrc,long lCount,bool b24bit)4688 void clDSPOp::Convert (signed int *sipDest, const double *dpSrc, long lCount,
4689 bool b24bit)
4690 {
4691 #ifdef DSP_IPP
4692 ippsConvert_64f32s_Sfs(dpSrc, sipDest, lCount, ippRndNear, -31);
4693 #else
4694 long lLoopCntr;
4695 double dMult;
4696
4697 dMult = (b24bit) ? ((double) 0x7fffff00) : ((double) INT_MAX);
4698 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4699 {
4700 sipDest[lLoopCntr] = (signed int)
4701 Round(dpSrc[lLoopCntr] * dMult);
4702 }
4703 #endif
4704 }
4705
4706
CartToPolar(float * fpMagn,float * fpPhase,const float * fpReal,const float * fpImag,long lCount)4707 void clDSPOp::CartToPolar (float *fpMagn, float *fpPhase,
4708 const float *fpReal, const float *fpImag, long lCount)
4709 {
4710 #ifdef DSP_IPP
4711 ippsCartToPolar_32f(fpReal, fpImag, fpMagn, fpPhase, lCount);
4712 #else
4713 long lLoopCntr;
4714
4715 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4716 {
4717 Cart2Polar(&fpMagn[lLoopCntr], &fpPhase[lLoopCntr],
4718 fpReal[lLoopCntr], fpImag[lLoopCntr]);
4719 }
4720 #endif
4721 }
4722
4723
CartToPolar(double * dpMagn,double * dpPhase,const double * dpReal,const double * dpImag,long lCount)4724 void clDSPOp::CartToPolar (double *dpMagn, double *dpPhase,
4725 const double *dpReal, const double *dpImag, long lCount)
4726 {
4727 #ifdef DSP_IPP
4728 ippsCartToPolar_64f(dpReal, dpImag, dpMagn, dpPhase, lCount);
4729 #else
4730 long lLoopCntr;
4731
4732 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4733 {
4734 Cart2Polar(&dpMagn[lLoopCntr], &dpPhase[lLoopCntr],
4735 dpReal[lLoopCntr], dpImag[lLoopCntr]);
4736 }
4737 #endif
4738 }
4739
4740
CartToPolar(float * fpMagn,float * fpPhase,const stpSCplx spCart,long lCount)4741 void clDSPOp::CartToPolar (float *fpMagn, float *fpPhase,
4742 const stpSCplx spCart, long lCount)
4743 {
4744 #ifdef DSP_IPP
4745 ippsCartToPolar_32fc((Ipp32fc *) spCart, fpMagn, fpPhase, lCount);
4746 #else
4747 long lLoopCntr;
4748
4749 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4750 {
4751 Cart2Polar(&fpMagn[lLoopCntr], &fpPhase[lLoopCntr],
4752 &spCart[lLoopCntr]);
4753 }
4754 #endif
4755 }
4756
4757
CartToPolar(double * dpMagn,double * dpPhase,const stpDCplx spCart,long lCount)4758 void clDSPOp::CartToPolar (double *dpMagn, double *dpPhase,
4759 const stpDCplx spCart, long lCount)
4760 {
4761 #ifdef DSP_IPP
4762 ippsCartToPolar_64fc((Ipp64fc *) spCart, dpMagn, dpPhase, lCount);
4763 #else
4764 long lLoopCntr;
4765
4766 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4767 {
4768 Cart2Polar(&dpMagn[lLoopCntr], &dpPhase[lLoopCntr],
4769 &spCart[lLoopCntr]);
4770 }
4771 #endif
4772 }
4773
4774
CartToPolar(stpSPolar spPolar,const stpSCplx spCart,long lCount)4775 void clDSPOp::CartToPolar (stpSPolar spPolar, const stpSCplx spCart,
4776 long lCount)
4777 {
4778 long lLoopCntr;
4779
4780 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4781 {
4782 Cart2Polar(&spPolar[lLoopCntr], &spCart[lLoopCntr]);
4783 }
4784 }
4785
4786
CartToPolar(stpDPolar spPolar,const stpDCplx spCart,long lCount)4787 void clDSPOp::CartToPolar (stpDPolar spPolar, const stpDCplx spCart,
4788 long lCount)
4789 {
4790 long lLoopCntr;
4791
4792 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4793 {
4794 Cart2Polar(&spPolar[lLoopCntr], &spCart[lLoopCntr]);
4795 }
4796 }
4797
4798
CartToPolar(utpSCoord upCoord,long lCount)4799 void clDSPOp::CartToPolar (utpSCoord upCoord, long lCount)
4800 {
4801 long lLoopCntr;
4802
4803 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4804 {
4805 Cart2Polar(&upCoord[lLoopCntr]);
4806 }
4807 }
4808
4809
CartToPolar(utpDCoord upCoord,long lCount)4810 void clDSPOp::CartToPolar (utpDCoord upCoord, long lCount)
4811 {
4812 long lLoopCntr;
4813
4814 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4815 {
4816 Cart2Polar(&upCoord[lLoopCntr]);
4817 }
4818 }
4819
4820
PolarToCart(float * fpReal,float * fpImag,const float * fpMagn,const float * fpPhase,long lCount)4821 void clDSPOp::PolarToCart (float *fpReal, float *fpImag,
4822 const float *fpMagn, const float *fpPhase, long lCount)
4823 {
4824 #ifdef DSP_IPP
4825 ippsPolarToCart_32f(fpMagn, fpPhase, fpReal, fpImag, lCount);
4826 #else
4827 long lLoopCntr;
4828
4829 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4830 {
4831 Polar2Cart(&fpReal[lLoopCntr], &fpImag[lLoopCntr],
4832 fpMagn[lLoopCntr], fpPhase[lLoopCntr]);
4833 }
4834 #endif
4835 }
4836
4837
PolarToCart(double * dpReal,double * dpImag,const double * dpMagn,const double * dpPhase,long lCount)4838 void clDSPOp::PolarToCart (double *dpReal, double *dpImag,
4839 const double *dpMagn, const double *dpPhase, long lCount)
4840 {
4841 #ifdef DSP_IPP
4842 ippsPolarToCart_64f(dpMagn, dpPhase, dpReal, dpImag, lCount);
4843 #else
4844 long lLoopCntr;
4845
4846 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4847 {
4848 Polar2Cart(&dpReal[lLoopCntr], &dpImag[lLoopCntr],
4849 dpMagn[lLoopCntr], dpPhase[lLoopCntr]);
4850 }
4851 #endif
4852 }
4853
4854
PolarToCart(stpSCplx spCart,const float * fpMagn,const float * fpPhase,long lCount)4855 void clDSPOp::PolarToCart (stpSCplx spCart, const float *fpMagn,
4856 const float *fpPhase, long lCount)
4857 {
4858 #ifdef DSP_IPP
4859 ippsPolarToCart_32fc(fpMagn, fpPhase, (Ipp32fc *) spCart, lCount);
4860 #else
4861 long lLoopCntr;
4862
4863 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4864 {
4865 Polar2Cart(&spCart[lLoopCntr], fpMagn[lLoopCntr], fpPhase[lLoopCntr]);
4866 }
4867 #endif
4868 }
4869
4870
PolarToCart(stpDCplx spCart,const double * dpMagn,const double * dpPhase,long lCount)4871 void clDSPOp::PolarToCart (stpDCplx spCart, const double *dpMagn,
4872 const double *dpPhase, long lCount)
4873 {
4874 #ifdef DSP_IPP
4875 ippsPolarToCart_64fc(dpMagn, dpPhase, (Ipp64fc *) spCart, lCount);
4876 #else
4877 long lLoopCntr;
4878
4879 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4880 {
4881 Polar2Cart(&spCart[lLoopCntr], dpMagn[lLoopCntr], dpPhase[lLoopCntr]);
4882 }
4883 #endif
4884 }
4885
4886
PolarToCart(stpSCplx spCart,const stpSPolar spPolar,long lCount)4887 void clDSPOp::PolarToCart (stpSCplx spCart, const stpSPolar spPolar,
4888 long lCount)
4889 {
4890 long lLoopCntr;
4891
4892 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4893 {
4894 Polar2Cart(&spCart[lLoopCntr], &spPolar[lLoopCntr]);
4895 }
4896 }
4897
4898
PolarToCart(stpDCplx spCart,const stpDPolar spPolar,long lCount)4899 void clDSPOp::PolarToCart (stpDCplx spCart, const stpDPolar spPolar,
4900 long lCount)
4901 {
4902 long lLoopCntr;
4903
4904 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4905 {
4906 Polar2Cart(&spCart[lLoopCntr], &spPolar[lLoopCntr]);
4907 }
4908 }
4909
4910
PolarToCart(utpSCoord upCoord,long lCount)4911 void clDSPOp::PolarToCart (utpSCoord upCoord, long lCount)
4912 {
4913 long lLoopCntr;
4914
4915 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4916 {
4917 Polar2Cart(&upCoord[lLoopCntr]);
4918 }
4919 }
4920
4921
PolarToCart(utpDCoord upCoord,long lCount)4922 void clDSPOp::PolarToCart (utpDCoord upCoord, long lCount)
4923 {
4924 long lLoopCntr;
4925
4926 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4927 {
4928 Polar2Cart(&upCoord[lLoopCntr]);
4929 }
4930 }
4931
4932
CrossCorr(const float * fpSrc1,const float * fpSrc2,long lCount)4933 float clDSPOp::CrossCorr (const float *fpSrc1, const float *fpSrc2,
4934 long lCount)
4935 {
4936 #ifdef DSP_X86
4937 if (bHave3DNow)
4938 {
4939 return dsp_x86_3dnow_crosscorrf(fpSrc1, fpSrc2, lCount);
4940 }
4941 #if ((__GNUC__ > 1) && (__GNUC__ < 4))
4942 else if (bHaveSSE)
4943 {
4944 return dsp_x86_sse_crosscorrf(fpSrc1, fpSrc2, lCount);
4945 }
4946 #endif
4947 else
4948 #endif
4949 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
4950 return dsp_x86_64_crosscorrf(fpSrc1, fpSrc2, lCount);
4951 #else
4952 {
4953 long lLoopCntr;
4954 #ifndef DSP_EXTPREC
4955 float fScale;
4956 float fNormFact;
4957 float fProdSum = 0.0F;
4958 float fSqSum1 = 0.0F;
4959 float fSqSum2 = 0.0F;
4960 #else
4961 double fScale;
4962 double fNormFact;
4963 double fProdSum = 0.0;
4964 double fSqSum1 = 0.0;
4965 double fSqSum2 = 0.0;
4966 #endif
4967
4968 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
4969 {
4970 #ifndef _ISOC9X_SOURCE
4971 fProdSum += fpSrc1[lLoopCntr] * fpSrc2[lLoopCntr];
4972 fSqSum1 += fpSrc1[lLoopCntr] * fpSrc1[lLoopCntr];
4973 fSqSum2 += fpSrc2[lLoopCntr] * fpSrc2[lLoopCntr];
4974 #else
4975 #ifndef DSP_EXTPREC
4976 fProdSum = fmaf(fpSrc1[lLoopCntr], fpSrc2[lLoopCntr], fProdSum);
4977 fSqSum1 = fmaf(fpSrc1[lLoopCntr], fpSrc1[lLoopCntr], fSqSum1);
4978 fSqSum2 = fmaf(fpSrc2[lLoopCntr], fpSrc2[lLoopCntr], fSqSum2);
4979 #else
4980 fProdSum = fma(fpSrc1[lLoopCntr], fpSrc2[lLoopCntr], fProdSum);
4981 fSqSum1 = fma(fpSrc1[lLoopCntr], fpSrc1[lLoopCntr], fSqSum1);
4982 fSqSum2 = fma(fpSrc2[lLoopCntr], fpSrc2[lLoopCntr], fSqSum2);
4983 #endif
4984 #endif
4985 }
4986 #ifndef DSP_EXTPREC
4987 fScale = 1.0F / lCount;
4988 fNormFact = sqrtf(fSqSum1 * fSqSum2) * fScale;
4989 #else
4990 fScale = 1.0 / lCount;
4991 fNormFact = sqrt(fSqSum1 * fSqSum2) * fScale;
4992 #endif
4993 return ((fProdSum * fScale) / fNormFact);
4994 }
4995 #endif
4996 }
4997
4998
CrossCorr(const double * dpSrc1,const double * dpSrc2,long lCount)4999 double clDSPOp::CrossCorr (const double *dpSrc1, const double *dpSrc2,
5000 long lCount)
5001 {
5002 #ifdef DSP_X86
5003 #if ((__GNUC__ > 1) && (__GNUC__ < 4))
5004 if (bHaveSSE)
5005 {
5006 return dsp_x86_sse_crosscorr(dpSrc1, dpSrc2, lCount);
5007 }
5008 else
5009 #endif
5010 #endif
5011 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
5012 return dsp_x86_64_crosscorr(dpSrc1, dpSrc2, lCount);
5013 #else
5014 {
5015 long lLoopCntr;
5016 #ifndef DSP_EXTPREC
5017 double dScale;
5018 double dNormFact;
5019 double dProdSum = 0.0;
5020 double dSqSum1 = 0.0;
5021 double dSqSum2 = 0.0;
5022 #else
5023 long double dScale;
5024 long double dNormFact;
5025 long double dProdSum = 0.0L;
5026 long double dSqSum1 = 0.0L;
5027 long double dSqSum2 = 0.0L;
5028 #endif
5029
5030 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5031 {
5032 #ifndef _ISOC9X_SOURCE
5033 dProdSum += dpSrc1[lLoopCntr] * dpSrc2[lLoopCntr];
5034 dSqSum1 += dpSrc1[lLoopCntr] * dpSrc1[lLoopCntr];
5035 dSqSum2 += dpSrc2[lLoopCntr] * dpSrc2[lLoopCntr];
5036 #else
5037 #ifndef DSP_EXTPREC
5038 dProdSum = fma(dpSrc1[lLoopCntr], dpSrc2[lLoopCntr], dProdSum);
5039 dSqSum1 = fma(dpSrc1[lLoopCntr], dpSrc1[lLoopCntr], dSqSum1);
5040 dSqSum2 = fma(dpSrc2[lLoopCntr], dpSrc2[lLoopCntr], dSqSum2);
5041 #else
5042 dProdSum = fmal(dpSrc1[lLoopCntr], dpSrc2[lLoopCntr], dProdSum);
5043 dSqSum1 = fmal(dpSrc1[lLoopCntr], dpSrc1[lLoopCntr], dSqSum1);
5044 dSqSum2 = fmal(dpSrc2[lLoopCntr], dpSrc2[lLoopCntr], dSqSum2);
5045 #endif
5046 #endif
5047 }
5048 #ifndef DSP_EXTPREC
5049 dScale = 1.0 / lCount;
5050 dNormFact = sqrt(dSqSum1 * dSqSum2) * dScale;
5051 #else
5052 dScale = 1.0L / lCount;
5053 dNormFact = sqrtl(dSqSum1 * dSqSum2) * dScale;
5054 #endif
5055 return ((dProdSum * dScale) / dNormFact);
5056 }
5057 #endif
5058 }
5059
5060
DelCrossCorr(const float * fpSrc1,const float * fpSrc2,long lDelay,long lCount)5061 float clDSPOp::DelCrossCorr (const float *fpSrc1, const float *fpSrc2,
5062 long lDelay, long lCount)
5063 {
5064 long lMax;
5065
5066 lMax = lCount - lDelay;
5067 #ifdef DSP_X86
5068 if (bHave3DNow)
5069 {
5070 return dsp_x86_3dnow_crosscorrf(fpSrc1, &fpSrc2[lDelay], lMax);
5071 }
5072 #if ((__GNUC__ > 1) && (__GNUC__ < 4))
5073 else if (bHaveSSE)
5074 {
5075 return dsp_x86_sse_crosscorrf(fpSrc1, &fpSrc2[lDelay], lMax);
5076 }
5077 #endif
5078 else
5079 #endif
5080 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
5081 return dsp_x86_64_crosscorrf(fpSrc1, &fpSrc2[lDelay], lMax);
5082 #else
5083 {
5084 long lLoopCntr;
5085 long lIdx2;
5086 float fScale;
5087 float fNormFact;
5088 float fProdSum = 0.0F;
5089 float fSqSum1 = 0.0F;
5090 float fSqSum2 = 0.0F;
5091
5092 for (lLoopCntr = 0L; lLoopCntr < lMax; lLoopCntr++)
5093 {
5094 lIdx2 = lLoopCntr + lDelay;
5095 #ifndef _ISOC9X_SOURCE
5096 fProdSum += fpSrc1[lLoopCntr] * fpSrc2[lIdx2];
5097 fSqSum1 += fpSrc1[lLoopCntr] * fpSrc1[lLoopCntr];
5098 fSqSum2 += fpSrc2[lIdx2] * fpSrc2[lIdx2];
5099 #else
5100 fProdSum = fmaf(fpSrc1[lLoopCntr], fpSrc2[lIdx2], fProdSum);
5101 fSqSum1 = fmaf(fpSrc1[lLoopCntr], fpSrc1[lLoopCntr], fSqSum1);
5102 fSqSum2 = fmaf(fpSrc2[lIdx2], fpSrc2[lIdx2], fSqSum2);
5103 #endif
5104 }
5105 fScale = 1.0F / (float) lMax;
5106 fNormFact = sqrtf(fSqSum1 * fSqSum2) * fScale;
5107 return ((fProdSum * fScale) / fNormFact);
5108 }
5109 #endif
5110 }
5111
5112
DelCrossCorr(const double * dpSrc1,const double * dpSrc2,long lDelay,long lCount)5113 double clDSPOp::DelCrossCorr (const double *dpSrc1, const double *dpSrc2,
5114 long lDelay, long lCount)
5115 {
5116 long lMax;
5117
5118 lMax = lCount - lDelay;
5119 #ifdef DSP_X86
5120 #if ((__GNUC__ > 1) && (__GNUC__ < 4))
5121 if (bHaveSSE)
5122 {
5123 return dsp_x86_sse_crosscorr(dpSrc1, &dpSrc2[lDelay], lMax);
5124 }
5125 else
5126 #endif
5127 #endif
5128 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
5129 return dsp_x86_64_crosscorr(dpSrc1, &dpSrc2[lDelay], lMax);
5130 #else
5131 {
5132 long lLoopCntr;
5133 long lIdx2;
5134 double dScale;
5135 double dNormFact;
5136 double dProdSum = 0.0;
5137 double dSqSum1 = 0.0;
5138 double dSqSum2 = 0.0;
5139
5140 for (lLoopCntr = 0L; lLoopCntr < lMax; lLoopCntr++)
5141 {
5142 lIdx2 = lLoopCntr + lDelay;
5143 #ifndef _ISOC9X_SOURCE
5144 dProdSum += dpSrc1[lLoopCntr] * dpSrc2[lIdx2];
5145 dSqSum1 += dpSrc1[lLoopCntr] * dpSrc1[lLoopCntr];
5146 dSqSum2 += dpSrc2[lIdx2] * dpSrc2[lIdx2];
5147 #else
5148 dProdSum = fma(dpSrc1[lLoopCntr], dpSrc2[lIdx2], dProdSum);
5149 dSqSum1 = fma(dpSrc1[lLoopCntr], dpSrc1[lLoopCntr], dSqSum1);
5150 dSqSum2 = fma(dpSrc2[lIdx2], dpSrc2[lIdx2], dSqSum2);
5151 #endif
5152 }
5153 dScale = 1.0 / (double) lMax;
5154 dNormFact = sqrt(dSqSum1 * dSqSum2) * dScale;
5155 return ((dProdSum * dScale) / dNormFact);
5156 }
5157 #endif
5158 }
5159
5160
DelCrossCorr(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount,const long * lpDelay,long lDelayCount)5161 void clDSPOp::DelCrossCorr (float *fpDest, const float *fpSrc1,
5162 const float *fpSrc2, long lCount, const long *lpDelay, long lDelayCount)
5163 {
5164 long lLoopDelay;
5165 long lLoopCorr;
5166 long lDelay;
5167 long lMax;
5168 long lIdx2;
5169 float fScale;
5170 float fNormFact;
5171 float fProdSum;
5172 float fSqSum1;
5173 float fSqSum2;
5174
5175 for (lLoopDelay = 0L; lLoopDelay < lDelayCount; lLoopDelay++)
5176 {
5177 fProdSum = 0.0F;
5178 fSqSum1 = 0.0F;
5179 fSqSum2 = 0.0F;
5180 lDelay = lpDelay[lLoopDelay];
5181 lMax = lCount - lDelay;
5182 for (lLoopCorr = 0L; lLoopCorr < lMax; lLoopCorr++)
5183 {
5184 lIdx2 = lLoopCorr + lDelay;
5185 #ifndef _ISOC9X_SOURCE
5186 fProdSum += fpSrc1[lLoopCorr] * fpSrc2[lIdx2];
5187 fSqSum1 += fpSrc1[lLoopCorr] * fpSrc1[lLoopCorr];
5188 fSqSum2 += fpSrc2[lIdx2] * fpSrc2[lIdx2];
5189 #else
5190 fProdSum = fmaf(fpSrc1[lLoopCorr], fpSrc2[lIdx2], fProdSum);
5191 fSqSum1 = fmaf(fpSrc1[lLoopCorr], fpSrc1[lLoopCorr], fSqSum1);
5192 fSqSum2 = fmaf(fpSrc2[lIdx2], fpSrc2[lIdx2], fSqSum2);
5193 #endif
5194 }
5195 fScale = 1.0F / (float) lMax;
5196 fNormFact = sqrtf(fSqSum1 * fSqSum2) * fScale;
5197 fpDest[lLoopDelay] = (fProdSum * fScale) / fNormFact;
5198 }
5199 }
5200
5201
DelCrossCorr(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount,const long * lpDelay,long lDelayCount)5202 void clDSPOp::DelCrossCorr (double *dpDest, const double *dpSrc1,
5203 const double *dpSrc2, long lCount, const long *lpDelay, long lDelayCount)
5204 {
5205 long lLoopDelay;
5206 long lLoopCorr;
5207 long lDelay;
5208 long lMax;
5209 long lIdx2;
5210 double dScale;
5211 double dNormFact;
5212 double dProdSum;
5213 double dSqSum1;
5214 double dSqSum2;
5215
5216 for (lLoopDelay = 0L; lLoopDelay < lDelayCount; lLoopDelay++)
5217 {
5218 dProdSum = 0.0;
5219 dSqSum1 = 0.0;
5220 dSqSum2 = 0.0;
5221 lDelay = lpDelay[lLoopDelay];
5222 lMax = lCount - lDelay;
5223 for (lLoopCorr = 0L; lLoopCorr < lMax; lLoopCorr++)
5224 {
5225 lIdx2 = lLoopCorr + lDelay;
5226 #ifndef _ISOC9X_SOURCE
5227 dProdSum += dpSrc1[lLoopCorr] * dpSrc2[lIdx2];
5228 dSqSum1 += dpSrc1[lLoopCorr] * dpSrc1[lLoopCorr];
5229 dSqSum2 += dpSrc2[lIdx2] * dpSrc2[lIdx2];
5230 #else
5231 dProdSum = fma(dpSrc1[lLoopCorr], dpSrc2[lIdx2], dProdSum);
5232 dSqSum1 = fma(dpSrc1[lLoopCorr], dpSrc1[lLoopCorr], dSqSum1);
5233 dSqSum2 = fma(dpSrc2[lIdx2], dpSrc2[lIdx2], dSqSum2);
5234 #endif
5235 }
5236 dScale = 1.0 / (double) lMax;
5237 dNormFact = sqrt(dSqSum1 * dSqSum2) * dScale;
5238 dpDest[lLoopDelay] = (dProdSum * dScale) / dNormFact;
5239 }
5240 }
5241
5242
Energy(const float * fpSrc,long lCount)5243 float clDSPOp::Energy (const float *fpSrc, long lCount)
5244 {
5245 long lLoopCntr;
5246 float fEnergy = 0.0F;
5247
5248 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5249 {
5250 #ifndef _ISOC9X_SOURCE
5251 fEnergy += fpSrc[lLoopCntr] * fpSrc[lLoopCntr];
5252 #else
5253 fEnergy = fmaf(fpSrc[lLoopCntr], fpSrc[lLoopCntr], fEnergy);
5254 #endif
5255 }
5256 return fEnergy;
5257 }
5258
5259
Energy(const double * dpSrc,long lCount)5260 double clDSPOp::Energy (const double *dpSrc, long lCount)
5261 {
5262 long lLoopCntr;
5263 double dEnergy = 0.0;
5264
5265 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5266 {
5267 #ifndef _ISOC9X_SOURCE
5268 dEnergy += dpSrc[lLoopCntr] * dpSrc[lLoopCntr];
5269 #else
5270 dEnergy = fma(dpSrc[lLoopCntr], dpSrc[lLoopCntr], dEnergy);
5271 #endif
5272 }
5273 return dEnergy;
5274 }
5275
5276
Magnitude(float * fpMagn,const stpSCplx spCplx,long lCount)5277 void clDSPOp::Magnitude (float *fpMagn, const stpSCplx spCplx, long lCount)
5278 {
5279 #ifdef DSP_IPP
5280 ippsMagnitude_32fc((Ipp32fc *) spCplx, fpMagn, lCount);
5281 #else
5282 long lLoopCntr;
5283
5284 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5285 {
5286 #ifndef _ISOC9X_SOURCE
5287 fpMagn[lLoopCntr] = sqrtf(
5288 spCplx[lLoopCntr].R * spCplx[lLoopCntr].R +
5289 spCplx[lLoopCntr].I * spCplx[lLoopCntr].I);
5290 #else
5291 fpMagn[lLoopCntr] =
5292 hypotf(spCplx[lLoopCntr].R, spCplx[lLoopCntr].I);
5293 #endif
5294 }
5295 #endif
5296 }
5297
5298
Magnitude(double * dpMagn,const stpDCplx spCplx,long lCount)5299 void clDSPOp::Magnitude (double *dpMagn, const stpDCplx spCplx, long lCount)
5300 {
5301 #ifdef DSP_IPP
5302 ippsMagnitude_64fc((Ipp64fc *) spCplx, dpMagn, lCount);
5303 #else
5304 long lLoopCntr;
5305
5306 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5307 {
5308 #ifndef _ISOC9X_SOURCE
5309 dpMagn[lLoopCntr] = sqrt(
5310 spCplx[lLoopCntr].R * spCplx[lLoopCntr].R +
5311 spCplx[lLoopCntr].I * spCplx[lLoopCntr].I);
5312 #else
5313 dpMagn[lLoopCntr] =
5314 hypot(spCplx[lLoopCntr].R, spCplx[lLoopCntr].I);
5315 #endif
5316 }
5317 #endif
5318 }
5319
5320
Power(float * fpPower,const stpSCplx spCplx,long lCount)5321 void clDSPOp::Power (float *fpPower, const stpSCplx spCplx, long lCount)
5322 {
5323 long lLoopCntr;
5324
5325 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5326 {
5327 #ifndef _ISOC9X_SOURCE
5328 fpPower[lLoopCntr] = 20.0F * log10f(sqrtf(
5329 spCplx[lLoopCntr].R * spCplx[lLoopCntr].R +
5330 spCplx[lLoopCntr].I * spCplx[lLoopCntr].I));
5331 #else
5332 fpPower[lLoopCntr] = 20.0F * log10f(
5333 hypotf(spCplx[lLoopCntr].R, spCplx[lLoopCntr].I));
5334 #endif
5335 }
5336 }
5337
5338
Power(double * dpPower,const stpDCplx spCplx,long lCount)5339 void clDSPOp::Power (double *dpPower, const stpDCplx spCplx, long lCount)
5340 {
5341 long lLoopCntr;
5342
5343 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5344 {
5345 #ifndef _ISOC9X_SOURCE
5346 dpPower[lLoopCntr] = 20.0 * log10(sqrt(
5347 spCplx[lLoopCntr].R * spCplx[lLoopCntr].R +
5348 spCplx[lLoopCntr].I * spCplx[lLoopCntr].I));
5349 #else
5350 dpPower[lLoopCntr] = 20.0 * log10(
5351 hypot(spCplx[lLoopCntr].R, spCplx[lLoopCntr].I));
5352 #endif
5353 }
5354 }
5355
5356
Phase(float * fpPhase,const stpSCplx spCplx,long lCount)5357 void clDSPOp::Phase (float *fpPhase, const stpSCplx spCplx, long lCount)
5358 {
5359 #ifdef DSP_IPP
5360 ippsPhase_32fc((Ipp32fc *) spCplx, fpPhase, lCount);
5361 #else
5362 long lLoopCntr;
5363
5364 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5365 {
5366 fpPhase[lLoopCntr] =
5367 atan2f(spCplx[lLoopCntr].I, spCplx[lLoopCntr].R);
5368 }
5369 #endif
5370 }
5371
5372
Phase(double * dpPhase,const stpDCplx spCplx,long lCount)5373 void clDSPOp::Phase (double *dpPhase, const stpDCplx spCplx, long lCount)
5374 {
5375 #ifdef DSP_IPP
5376 ippsPhase_64fc((Ipp64fc *) spCplx, dpPhase, lCount);
5377 #else
5378 long lLoopCntr;
5379
5380 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5381 {
5382 dpPhase[lLoopCntr] =
5383 atan2(spCplx[lLoopCntr].I, spCplx[lLoopCntr].R);
5384 }
5385 #endif
5386 }
5387
5388
5389
PowerPhase(float * fpPower,float * fpPhase,const stpSCplx spCplx,long lCount)5390 void clDSPOp::PowerPhase (float *fpPower, float *fpPhase,
5391 const stpSCplx spCplx, long lCount)
5392 {
5393 long lLoopCntr;
5394 float fReal;
5395 float fImag;
5396
5397 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5398 {
5399 fReal = spCplx[lLoopCntr].R;
5400 fImag = spCplx[lLoopCntr].I;
5401 #ifndef _ISOC9X_SOURCE
5402 fpPower[lLoopCntr] =
5403 20.0F * log10f(sqrtf(fReal * fReal + fImag * fImag));
5404 #else
5405 fpPower[lLoopCntr] =
5406 20.0F * log10f(hypotf(fReal, fImag));
5407 #endif
5408 fpPhase[lLoopCntr] = atan2f(fImag, fReal);
5409 }
5410 }
5411
5412
PowerPhase(double * dpPower,double * dpPhase,const stpDCplx spCplx,long lCount)5413 void clDSPOp::PowerPhase (double *dpPower, double *dpPhase,
5414 const stpDCplx spCplx, long lCount)
5415 {
5416 long lLoopCntr;
5417 double dReal;
5418 double dImag;
5419
5420 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5421 {
5422 dReal = spCplx[lLoopCntr].R;
5423 dImag = spCplx[lLoopCntr].I;
5424 #ifndef _ISOC9X_SOURCE
5425 dpPower[lLoopCntr] =
5426 20.0 * log10(sqrt(dReal * dReal + dImag * dImag));
5427 #else
5428 dpPower[lLoopCntr] =
5429 20.0 * log10(hypot(dReal, dImag));
5430 #endif
5431 dpPhase[lLoopCntr] = atan2(dImag, dReal);
5432 }
5433 }
5434
5435
Decimate(float * fpDest,const float * fpSrc,long lFactor,long lCount)5436 void clDSPOp::Decimate (float *fpDest, const float *fpSrc, long lFactor,
5437 long lCount)
5438 {
5439 #ifdef DSP_IPP
5440 int iDestCount = lCount / lFactor;
5441 int iPhase = 0;
5442
5443 ippsSampleDown_32f(fpSrc, lCount, fpDest, &iDestCount, lFactor, &iPhase);
5444 #else
5445 long lLoopCntr;
5446 long lMax;
5447
5448 lMax = lCount / lFactor;
5449 for (lLoopCntr = 0L; lLoopCntr < lMax; lLoopCntr++)
5450 {
5451 fpDest[lLoopCntr] = fpSrc[lLoopCntr * lFactor];
5452 }
5453 #endif
5454 }
5455
5456
Decimate(double * dpDest,const double * dpSrc,long lFactor,long lCount)5457 void clDSPOp::Decimate (double *dpDest, const double *dpSrc, long lFactor,
5458 long lCount)
5459 {
5460 #ifdef DSP_IPP
5461 int iDestCount = lCount / lFactor;
5462 int iPhase = 0;
5463
5464 ippsSampleDown_64f(dpSrc, lCount, dpDest, &iDestCount, lFactor, &iPhase);
5465 #else
5466 long lLoopCntr;
5467 long lMax;
5468
5469 lMax = lCount / lFactor;
5470 for (lLoopCntr = 0L; lLoopCntr < lMax; lLoopCntr++)
5471 {
5472 dpDest[lLoopCntr] = dpSrc[lLoopCntr * lFactor];
5473 }
5474 #endif
5475 }
5476
5477
DecimateAvg(float * fpDest,const float * fpSrc,long lFactor,long lCount)5478 void clDSPOp::DecimateAvg (float *fpDest, const float *fpSrc, long lFactor,
5479 long lCount)
5480 {
5481 long lLoopDest;
5482 long lLoopAvg;
5483 long lMax;
5484 float fAvg;
5485
5486 lMax = lCount / lFactor;
5487 for (lLoopDest = 0L; lLoopDest < lMax; lLoopDest++)
5488 {
5489 fAvg = 0.0F;
5490 for (lLoopAvg = 0L; lLoopAvg < lFactor; lLoopAvg++)
5491 {
5492 fAvg += fpSrc[lLoopDest * lFactor + lLoopAvg];
5493 }
5494 fpDest[lLoopDest] = fAvg / (float) lFactor;
5495 }
5496 }
5497
5498
DecimateAvg(double * dpDest,const double * dpSrc,long lFactor,long lCount)5499 void clDSPOp::DecimateAvg (double *dpDest, const double *dpSrc, long lFactor,
5500 long lCount)
5501 {
5502 long lLoopDest;
5503 long lLoopAvg;
5504 long lMax;
5505 double dAvg;
5506
5507 lMax = lCount / lFactor;
5508 for (lLoopDest = 0L; lLoopDest < lMax; lLoopDest++)
5509 {
5510 dAvg = 0.0;
5511 for (lLoopAvg = 0L; lLoopAvg < lFactor; lLoopAvg++)
5512 {
5513 dAvg += dpSrc[lLoopDest * lFactor + lLoopAvg];
5514 }
5515 dpDest[lLoopDest] = dAvg / (double) lFactor;
5516 }
5517 }
5518
5519
Interpolate(float * fpDest,const float * fpSrc,long lFactor,long lCount)5520 void clDSPOp::Interpolate (float *fpDest, const float *fpSrc, long lFactor,
5521 long lCount)
5522 {
5523 #ifdef DSP_IPP
5524 int iDestCount = lCount * lFactor;
5525 int iPhase = 0;
5526
5527 ippsSampleUp_32f(fpSrc, lCount, fpDest, &iDestCount, lFactor, &iPhase);
5528 #else
5529 long lLoopSrc;
5530 long lLoopInt;
5531
5532 for (lLoopSrc = 0L; lLoopSrc < lCount; lLoopSrc++)
5533 {
5534 fpDest[lLoopSrc * lFactor] = fpSrc[lLoopSrc];
5535 for (lLoopInt = 1L; lLoopInt < lFactor; lLoopInt++)
5536 {
5537 fpDest[lLoopSrc * lFactor + lLoopInt] = 0.0F;
5538 }
5539 }
5540 #endif
5541 }
5542
5543
Interpolate(double * dpDest,const double * dpSrc,long lFactor,long lCount)5544 void clDSPOp::Interpolate (double *dpDest, const double *dpSrc, long lFactor,
5545 long lCount)
5546 {
5547 #ifdef DSP_IPP
5548 int iDestCount = lCount * lFactor;
5549 int iPhase = 0;
5550
5551 ippsSampleUp_64f(dpSrc, lCount, dpDest, &iDestCount, lFactor, &iPhase);
5552 #else
5553 long lLoopSrc;
5554 long lLoopInt;
5555
5556 for (lLoopSrc = 0L; lLoopSrc < lCount; lLoopSrc++)
5557 {
5558 dpDest[lLoopSrc * lFactor] = dpSrc[lLoopSrc];
5559 for (lLoopInt = 1L; lLoopInt < lFactor; lLoopInt++)
5560 {
5561 dpDest[lLoopSrc * lFactor + lLoopInt] = 0.0;
5562 }
5563 }
5564 #endif
5565 }
5566
5567
InterpolateAvg(float * fpDest,const float * fpSrc,long lFactor,long lCount)5568 void clDSPOp::InterpolateAvg (float *fpDest, const float *fpSrc,
5569 long lFactor, long lCount)
5570 {
5571 long lSrcCntr;
5572 long lIntCntr;
5573 long lX;
5574 long lX0;
5575 long lX1;
5576 float fF0;
5577 float fF1;
5578 float fL0;
5579 float fL1;
5580 float fP1;
5581
5582 for (lSrcCntr = 0L; lSrcCntr < lCount; lSrcCntr++)
5583 {
5584 lX0 = lSrcCntr * lFactor;
5585 lX1 = (lSrcCntr + 1L) * lFactor;
5586 if (lSrcCntr != (lCount - 1L))
5587 {
5588 fF0 = fpSrc[lSrcCntr];
5589 fF1 = fpSrc[lSrcCntr + 1L];
5590 }
5591 else
5592 {
5593 fF0 = fpSrc[lSrcCntr];
5594 fF1 = fpSrc[lSrcCntr] - (fpSrc[lSrcCntr - 1L] - fpSrc[lSrcCntr]);
5595 }
5596 fpDest[lSrcCntr * lFactor] = fF0;
5597 for (lIntCntr = 1L; lIntCntr < lFactor; lIntCntr++)
5598 {
5599 lX = lSrcCntr * lFactor + lIntCntr;
5600 fL0 = (float) (lX - lX1) / (float) (lX0 - lX1);
5601 fL1 = (float) (lX - lX0) / (float) (lX1 - lX0);
5602 fP1 = fL0 * fF0 + fL1 * fF1;
5603 fpDest[lX] = fP1;
5604 }
5605 }
5606 }
5607
5608
InterpolateAvg(double * dpDest,const double * dpSrc,long lFactor,long lCount)5609 void clDSPOp::InterpolateAvg (double *dpDest, const double *dpSrc,
5610 long lFactor, long lCount)
5611 {
5612 long lSrcCntr;
5613 long lIntCntr;
5614 long lX;
5615 long lX0;
5616 long lX1;
5617 double dF0;
5618 double dF1;
5619 double dL0;
5620 double dL1;
5621 double dP1;
5622
5623 for (lSrcCntr = 0L; lSrcCntr < lCount; lSrcCntr++)
5624 {
5625 lX0 = lSrcCntr * lFactor;
5626 lX1 = (lSrcCntr + 1L) * lFactor;
5627 if (lSrcCntr != (lCount - 1L))
5628 {
5629 dF0 = dpSrc[lSrcCntr];
5630 dF1 = dpSrc[lSrcCntr + 1L];
5631 }
5632 else
5633 {
5634 dF0 = dpSrc[lSrcCntr];
5635 dF1 = dpSrc[lSrcCntr] - (dpSrc[lSrcCntr - 1L] - dpSrc[lSrcCntr]);
5636 }
5637 dpDest[lSrcCntr * lFactor] = dF0;
5638 for (lIntCntr = 1L; lIntCntr < lFactor; lIntCntr++)
5639 {
5640 lX = lSrcCntr * lFactor + lIntCntr;
5641 dL0 = (double) (lX - lX1) / (double) (lX0 - lX1);
5642 dL1 = (double) (lX - lX0) / (double) (lX1 - lX0);
5643 dP1 = dL0 * dF0 + dL1 * dF1;
5644 dpDest[lX] = dP1;
5645 }
5646 }
5647 }
5648
5649
Resample(float * fpDest,long lDestCount,const float * fpSrc,long lSrcCount)5650 void clDSPOp::Resample (float *fpDest, long lDestCount,
5651 const float *fpSrc, long lSrcCount)
5652 {
5653 long lDestCntr;
5654 long lSrcIdx;
5655 float fScale;
5656
5657 fScale = (float) lSrcCount / (float) lDestCount;
5658 for (lDestCntr = 0; lDestCntr < lDestCount; lDestCntr++)
5659 {
5660 lSrcIdx = (long) ((float) lDestCntr * fScale + 0.5F);
5661 if (unlikely(lSrcIdx >= lSrcCount))
5662 lSrcIdx = lSrcCount - 1;
5663 fpDest[lDestCntr] = fpSrc[lSrcIdx];
5664 }
5665 }
5666
5667
Resample(double * dpDest,long lDestCount,const double * dpSrc,long lSrcCount)5668 void clDSPOp::Resample (double *dpDest, long lDestCount,
5669 const double *dpSrc, long lSrcCount)
5670 {
5671 long lDestCntr;
5672 long lSrcIdx;
5673 double dScale;
5674
5675 dScale = (double) lSrcCount / (double) lDestCount;
5676 for (lDestCntr = 0; lDestCntr < lDestCount; lDestCntr++)
5677 {
5678 lSrcIdx = (long) ((double) lDestCntr * dScale + 0.5);
5679 if (unlikely(lSrcIdx >= lSrcCount))
5680 lSrcIdx = lSrcCount - 1;
5681 dpDest[lDestCntr] = dpSrc[lSrcIdx];
5682 }
5683 }
5684
5685
ResampleAvg(float * fpDest,long lDestCount,const float * fpSrc,long lSrcCount)5686 void clDSPOp::ResampleAvg (float *fpDest, long lDestCount,
5687 const float *fpSrc, long lSrcCount)
5688 {
5689 long lDestCntr;
5690 long lSrcCntr;
5691 long lSrcIdx1;
5692 long lSrcIdx2;
5693 long lDist;
5694 float fScale;
5695 float fValue;
5696
5697 fScale = (float) lSrcCount / (float) lDestCount;
5698 if (lDestCount < lSrcCount)
5699 {
5700 for (lDestCntr = 0; lDestCntr < lDestCount; lDestCntr++)
5701 {
5702 lSrcIdx1 = (long) ((float) lDestCntr * fScale + 0.5F);
5703 lSrcIdx2 = (long) ((float) (lDestCntr + 1) * fScale + 0.5F);
5704 if (unlikely(lSrcIdx1 >= lSrcCount))
5705 lSrcIdx1 = lSrcCount - 1;
5706 if (unlikely(lSrcIdx2 >= lSrcCount))
5707 lSrcIdx2 = lSrcCount - 1;
5708 lDist = lSrcIdx2 - lSrcIdx1;
5709 if (lDist > 0)
5710 {
5711 fValue = 0.0f;
5712 for (lSrcCntr = lSrcIdx1; lSrcCntr < lSrcIdx2; lSrcCntr++)
5713 fValue += fpSrc[lSrcCntr];
5714 fValue /= (float) lDist;
5715 }
5716 else fValue = fpSrc[lSrcIdx1];
5717 fpDest[lDestCntr] = fValue;
5718 }
5719 }
5720 else if (lDestCount > lSrcCount)
5721 {
5722 fpDest[0] = fpSrc[0];
5723 for (lDestCntr = 1; lDestCntr < lDestCount; lDestCntr++)
5724 {
5725 lSrcIdx1 = (long) ((float) lDestCntr * fScale + 0.5F);
5726 lSrcIdx2 = (long) ((float) (lDestCntr + 1) * fScale + 0.5F);
5727 if (unlikely(lSrcIdx1 >= lSrcCount))
5728 lSrcIdx1 = lSrcCount - 1;
5729 if (unlikely(lSrcIdx2 >= lSrcCount))
5730 lSrcIdx2 = lSrcCount - 1;
5731 fpDest[lDestCntr] = fpSrc[lSrcIdx1] +
5732 ((fpSrc[lSrcIdx2] - fpSrc[lSrcIdx1]) * fScale);
5733 }
5734 }
5735 else Copy(fpDest, fpSrc, lDestCount);
5736 }
5737
5738
ResampleAvg(double * dpDest,long lDestCount,const double * dpSrc,long lSrcCount)5739 void clDSPOp::ResampleAvg (double *dpDest, long lDestCount,
5740 const double *dpSrc, long lSrcCount)
5741 {
5742 long lDestCntr;
5743 long lSrcCntr;
5744 long lSrcIdx1;
5745 long lSrcIdx2;
5746 long lDist;
5747 double dScale;
5748 double dValue;
5749
5750 dScale = (double) lSrcCount / (double) lDestCount;
5751 if (lDestCount < lSrcCount)
5752 {
5753 for (lDestCntr = 0; lDestCntr < lDestCount; lDestCntr++)
5754 {
5755 lSrcIdx1 = (long) ((double) lDestCntr * dScale + 0.5);
5756 lSrcIdx2 = (long) ((double) (lDestCntr + 1) * dScale + 0.5);
5757 if (unlikely(lSrcIdx1 >= lSrcCount))
5758 lSrcIdx1 = lSrcCount - 1;
5759 if (unlikely(lSrcIdx2 >= lSrcCount))
5760 lSrcIdx2 = lSrcCount - 1;
5761 lDist = lSrcIdx2 - lSrcIdx1;
5762 if (lDist > 0)
5763 {
5764 dValue = 0.0;
5765 for (lSrcCntr = lSrcIdx1; lSrcCntr < lSrcIdx2; lSrcCntr++)
5766 dValue += dpSrc[lSrcCntr];
5767 dValue /= (double) lDist;
5768 }
5769 else dValue = dpSrc[lSrcIdx1];
5770 dpDest[lDestCntr] = dValue;
5771 }
5772 }
5773 else if (lDestCount > lSrcCount)
5774 {
5775 dpDest[0] = dpSrc[0];
5776 for (lDestCntr = 1; lDestCntr < lDestCount; lDestCntr++)
5777 {
5778 lSrcIdx1 = (long) ((double) lDestCntr * dScale + 0.5);
5779 lSrcIdx2 = (long) ((double) (lDestCntr + 1) * dScale + 0.5);
5780 if (unlikely(lSrcIdx1 >= lSrcCount))
5781 lSrcIdx1 = lSrcCount - 1;
5782 if (unlikely(lSrcIdx2 >= lSrcCount))
5783 lSrcIdx2 = lSrcCount - 1;
5784 dpDest[lDestCntr] = dpSrc[lSrcIdx1] +
5785 ((dpSrc[lSrcIdx2] - dpSrc[lSrcIdx1]) * dScale);
5786 }
5787 }
5788 else Copy(dpDest, dpSrc, lDestCount);
5789 }
5790
5791
RMS(const float * fpSrc,long lCount)5792 float clDSPOp::RMS (const float *fpSrc, long lCount)
5793 {
5794 long lLoopCntr;
5795 float fSqSum = 0.0F;
5796
5797 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5798 {
5799 #ifndef _ISOC9X_SOURCE
5800 fSqSum += fpSrc[lLoopCntr] * fpSrc[lLoopCntr];
5801 #else
5802 fSqSum = fmaf(fpSrc[lLoopCntr], fpSrc[lLoopCntr], fSqSum);
5803 #endif
5804 }
5805 return ((float) sqrtf(fSqSum / (float) lCount));
5806 }
5807
5808
RMS(const double * dpSrc,long lCount)5809 double clDSPOp::RMS (const double *dpSrc, long lCount)
5810 {
5811 long lLoopCntr;
5812 double dSqSum = 0.0;
5813
5814 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5815 {
5816 #ifndef _ISOC9X_SOURCE
5817 dSqSum += dpSrc[lLoopCntr] * dpSrc[lLoopCntr];
5818 #else
5819 dSqSum = fma(dpSrc[lLoopCntr], dpSrc[lLoopCntr], dSqSum);
5820 #endif
5821 }
5822 return (sqrt(dSqSum / (double) lCount));
5823 }
5824
5825
Variance(float * fpVariance,float * fpMean,const float * fpSrc,long lCount)5826 float clDSPOp::Variance (float *fpVariance, float *fpMean,
5827 const float *fpSrc, long lCount)
5828 {
5829 long lLoopCntr;
5830 float fMean = 0.0F;
5831 float fVariance = 0.0F;
5832
5833 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5834 {
5835 fMean += fpSrc[lLoopCntr];
5836 }
5837 fMean /= (float) lCount;
5838 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5839 {
5840 fVariance += (float) powf(fpSrc[lLoopCntr] - fMean, 2.0F);
5841 }
5842 fVariance /= (float) lCount;
5843 if (fpVariance != NULL)
5844 {
5845 *fpVariance = fVariance;
5846 }
5847 if (fpMean != NULL)
5848 {
5849 *fpMean = fMean;
5850 }
5851 return fVariance;
5852 }
5853
5854
Variance(double * dpVariance,double * dpMean,const double * dpSrc,long lCount)5855 double clDSPOp::Variance (double *dpVariance, double *dpMean,
5856 const double *dpSrc, long lCount)
5857 {
5858 long lLoopCntr;
5859 double dMean = 0.0;
5860 double dVariance = 0.0;
5861
5862 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5863 {
5864 dMean += dpSrc[lLoopCntr];
5865 }
5866 dMean /= (double) lCount;
5867 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
5868 {
5869 dVariance += (double) pow(dpSrc[lLoopCntr] - dMean, 2.0);
5870 }
5871 dVariance /= (double) lCount;
5872 if (dpVariance != NULL)
5873 {
5874 *dpVariance = dVariance;
5875 }
5876 if (dpMean != NULL)
5877 {
5878 *dpMean = dMean;
5879 }
5880 return dVariance;
5881 }
5882
5883
PeakLevel(const float * fpSrc,long lSize)5884 float clDSPOp::PeakLevel (const float *fpSrc, long lSize)
5885 {
5886 float fMin;
5887 float fMax;
5888 float fLinMax;
5889
5890 MinMax(&fMin, &fMax, fpSrc, lSize);
5891 fMin = fabsf(fMin);
5892 fMax = fabsf(fMax);
5893 #ifndef _ISOC9X_SOURCE
5894 fLinMax = (fMax >= fMin) ? fMax : fMin;
5895 #else
5896 fLinMax = fmaxf(fMin, fMax);
5897 #endif
5898 return (20.0F * log10f(fLinMax));
5899 }
5900
5901
PeakLevel(const double * dpSrc,long lSize)5902 double clDSPOp::PeakLevel (const double *dpSrc, long lSize)
5903 {
5904 double dMin;
5905 double dMax;
5906 double dLinMax;
5907
5908 MinMax(&dMin, &dMax, dpSrc, lSize);
5909 dMin = fabs(dMin);
5910 dMax = fabs(dMax);
5911 #ifndef _ISOC9X_SOURCE
5912 dLinMax = (dMax >= dMin) ? dMax : dMin;
5913 #else
5914 dLinMax = fmax(dMin, dMax);
5915 #endif
5916 return (20.0 * log10(dLinMax));
5917 }
5918
5919
WinBartlett(float * fpDest,long lSize)5920 void clDSPOp::WinBartlett (float *fpDest, long lSize)
5921 {
5922 #ifdef DSP_IPP
5923 ippsSet_32f(1.0F, fpDest, lSize);
5924 ippsWinBartlett_32f_I(fpDest, lSize);
5925 #else
5926 long lLoopCntr;
5927
5928 for (lLoopCntr = 0L; lLoopCntr <= ((lSize - 1L) / 2L); lLoopCntr++)
5929 {
5930 fpDest[lLoopCntr] = 2.0F * (float) lLoopCntr / (float) (lSize - 1L);
5931 }
5932 for (lLoopCntr = ((lSize - 1L) / 2L + 1L); lLoopCntr < lSize; lLoopCntr++)
5933 {
5934 fpDest[lLoopCntr] =
5935 2.0F - 2.0F * (float) lLoopCntr / (float) (lSize - 1L);
5936 }
5937 #endif
5938 }
5939
5940
WinBartlett(double * dpDest,long lSize)5941 void clDSPOp::WinBartlett (double *dpDest, long lSize)
5942 {
5943 #ifdef DSP_IPP
5944 ippsSet_64f(1.0, dpDest, lSize);
5945 ippsWinBartlett_64f_I(dpDest, lSize);
5946 #else
5947 long lLoopCntr;
5948
5949 for (lLoopCntr = 0L; lLoopCntr <= ((lSize - 1L) / 2L); lLoopCntr++)
5950 {
5951 dpDest[lLoopCntr] = 2.0 * (double) lLoopCntr / (double) (lSize - 1L);
5952 }
5953 for (lLoopCntr = ((lSize - 1L) / 2L + 1L); lLoopCntr < lSize; lLoopCntr++)
5954 {
5955 dpDest[lLoopCntr] =
5956 2.0 - 2.0 * (double) lLoopCntr / (double) (lSize - 1L);
5957 }
5958 #endif
5959 }
5960
5961
WinBlackman(float * fpDest,long lSize)5962 void clDSPOp::WinBlackman (float *fpDest, long lSize)
5963 {
5964 #ifdef DSP_IPP
5965 ippsSet_32f(1.0F, fpDest, lSize);
5966 ippsWinBlackmanStd_32f_I(fpDest, lSize);
5967 #else
5968 long lLoopCntr;
5969
5970 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
5971 {
5972 fpDest[lLoopCntr] = 0.42F -
5973 0.5F * cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize) +
5974 0.08F * cos((4.0F * fPI * (float) lLoopCntr) / (float) lSize);
5975 }
5976 #endif
5977 }
5978
5979
WinBlackman(double * dpDest,long lSize)5980 void clDSPOp::WinBlackman (double *dpDest, long lSize)
5981 {
5982 #ifdef DSP_IPP
5983 ippsSet_64f(1.0, dpDest, lSize);
5984 ippsWinBlackmanStd_64f_I(dpDest, lSize);
5985 #else
5986 long lLoopCntr;
5987
5988 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
5989 {
5990 dpDest[lLoopCntr] = 0.42 -
5991 0.5 * cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize) +
5992 0.08 * cos((4.0 * dPI * (double) lLoopCntr) / (double) lSize);
5993 }
5994 #endif
5995 }
5996
5997
WinBlackman(float * fpDest,long lSize,float fAlphaP)5998 void clDSPOp::WinBlackman (float *fpDest, long lSize, float fAlphaP)
5999 {
6000 #ifdef DSP_IPP
6001 ippsSet_32f(1.0F, fpDest, lSize);
6002 if (fAlphaP != 0.0F)
6003 ippsWinBlackman_32f_I(fpDest, lSize, fAlphaP);
6004 else
6005 ippsWinBlackmanOpt_32f_I(fpDest, lSize);
6006 #else
6007 long lLoopCntr;
6008 float fAlpha;
6009
6010 fAlpha = (fAlphaP != 0.0F) ?
6011 fAlphaP :
6012 (0.5F / (1.0F + cos((2.0F * fPI) / (float) (lSize - 1))));
6013 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6014 {
6015 fpDest[lLoopCntr] = ((fAlpha + 1.0F) / 2.0F) - 0.5F *
6016 cos((2.0F * fPI * (float) lLoopCntr) / ((float) (lSize - 1))) -
6017 (fAlpha / 2.0F) *
6018 cos((4.0F * fPI * (float) lLoopCntr) / ((float) (lSize - 1)));
6019 }
6020 #endif
6021 }
6022
6023
WinBlackman(double * dpDest,long lSize,double dAlphaP)6024 void clDSPOp::WinBlackman (double *dpDest, long lSize, double dAlphaP)
6025 {
6026 #ifdef DSP_IPP
6027 ippsSet_64f(1.0, dpDest, lSize);
6028 if (dAlphaP != 0.0)
6029 ippsWinBlackman_64f_I(dpDest, lSize, dAlphaP);
6030 else
6031 ippsWinBlackmanOpt_64f_I(dpDest, lSize);
6032 #else
6033 long lLoopCntr;
6034 double dAlpha;
6035
6036 dAlpha = (dAlphaP != 0.0) ?
6037 dAlphaP :
6038 (0.5 / (1.0 + cos((2.0 * dPI) / (double) (lSize - 1))));
6039 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6040 {
6041 dpDest[lLoopCntr] = ((dAlpha + 1.0) / 2.0) - 0.5 *
6042 cos((2.0 * dPI * (double) lLoopCntr) / ((double) (lSize - 1))) -
6043 (dAlpha / 2.0) *
6044 cos((4.0 * dPI * (double) lLoopCntr) / ((double) (lSize - 1)));
6045 }
6046 #endif
6047 }
6048
6049
WinBlackmanHarris(float * fpDest,long lSize)6050 void clDSPOp::WinBlackmanHarris (float *fpDest, long lSize)
6051 {
6052 long lLoopCntr;
6053
6054 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6055 {
6056 fpDest[lLoopCntr] = 0.42323F -
6057 0.49855F *
6058 cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize) +
6059 0.07922F *
6060 cos((4.0F * fPI * (float) lLoopCntr) / (float) lSize);
6061 }
6062 }
6063
6064
WinBlackmanHarris(double * dpDest,long lSize)6065 void clDSPOp::WinBlackmanHarris (double *dpDest, long lSize)
6066 {
6067 long lLoopCntr;
6068
6069 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6070 {
6071 dpDest[lLoopCntr] = 0.42323 -
6072 0.49855 *
6073 cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize) +
6074 0.07922 *
6075 cos((4.0 * dPI * (double) lLoopCntr) / (double) lSize);
6076 }
6077 }
6078
6079
WinCosTapered(float * fpDest,long lSize)6080 void clDSPOp::WinCosTapered (float *fpDest, long lSize)
6081 {
6082 long lLoopCntr;
6083 long lM;
6084
6085 lM = Round((float) lSize / 10.0F);
6086 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6087 {
6088 if ((lLoopCntr < lM) || (lLoopCntr > (lSize - lM - 1L)))
6089 {
6090 fpDest[lLoopCntr] = 0.5F * (1.0F -
6091 cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize));
6092 }
6093 else
6094 {
6095 fpDest[lLoopCntr] = 1.0F;
6096 }
6097 }
6098 }
6099
6100
WinCosTapered(double * dpDest,long lSize)6101 void clDSPOp::WinCosTapered (double *dpDest, long lSize)
6102 {
6103 long lLoopCntr;
6104 long lM;
6105
6106 lM = Round((double) lSize / 10.0);
6107 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6108 {
6109 if ((lLoopCntr < lM) || (lLoopCntr > (lSize - lM - 1L)))
6110 {
6111 dpDest[lLoopCntr] = 0.5 * (1.0 -
6112 cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize));
6113 }
6114 else
6115 {
6116 dpDest[lLoopCntr] = 1.0;
6117 }
6118 }
6119 }
6120
6121
WinCosTaperedA(float * fpVect,long lSize)6122 void clDSPOp::WinCosTaperedA (float *fpVect, long lSize)
6123 {
6124 long lLoopCntr;
6125 long lM;
6126
6127 lM = Round((float) lSize / 10.0F);
6128 for (lLoopCntr = 0L; lLoopCntr < lM; lLoopCntr++)
6129 {
6130 fpVect[lLoopCntr] = 0.5F * fpVect[lLoopCntr] *
6131 (1.0F - cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize));
6132 }
6133 for (lLoopCntr = (lSize - lM); lLoopCntr < lSize; lLoopCntr++)
6134 {
6135 fpVect[lLoopCntr] = 0.5F * fpVect[lLoopCntr] *
6136 (1.0F - cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize));
6137 }
6138 }
6139
6140
WinCosTaperedA(double * dpVect,long lSize)6141 void clDSPOp::WinCosTaperedA (double *dpVect, long lSize)
6142 {
6143 long lLoopCntr;
6144 long lM;
6145
6146 lM = Round((double) lSize / 10.0);
6147 for (lLoopCntr = 0L; lLoopCntr < lM; lLoopCntr++)
6148 {
6149 dpVect[lLoopCntr] = 0.5 * dpVect[lLoopCntr] *
6150 (1.0 - cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize));
6151 }
6152 for (lLoopCntr = (lSize - lM); lLoopCntr < lSize; lLoopCntr++)
6153 {
6154 dpVect[lLoopCntr] = 0.5 * dpVect[lLoopCntr] *
6155 (1.0 - cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize));
6156 }
6157 }
6158
6159
WinCosTaperedA(float * fpDest,const float * fpSrc,long lSize)6160 void clDSPOp::WinCosTaperedA (float *fpDest, const float *fpSrc, long lSize)
6161 {
6162 long lLoopCntr;
6163 long lM;
6164
6165 lM = Round((float) lSize / 10.0F);
6166 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6167 {
6168 if ((lLoopCntr < lM) || (lLoopCntr > (lSize - lM)))
6169 {
6170 fpDest[lLoopCntr] = 0.5F * fpSrc[lLoopCntr] * (1.0F -
6171 cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize));
6172 }
6173 else
6174 {
6175 fpDest[lLoopCntr] = fpSrc[lLoopCntr];
6176 }
6177 }
6178 }
6179
6180
WinCosTaperedA(double * dpDest,const double * dpSrc,long lSize)6181 void clDSPOp::WinCosTaperedA (double *dpDest, const double *dpSrc, long lSize)
6182 {
6183 long lLoopCntr;
6184 long lM;
6185
6186 lM = Round((double) lSize / 10.0);
6187 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6188 {
6189 if ((lLoopCntr < lM) || (lLoopCntr > (lSize - lM)))
6190 {
6191 dpDest[lLoopCntr] = 0.5 * dpSrc[lLoopCntr] * (1.0 -
6192 cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize));
6193 }
6194 else
6195 {
6196 dpDest[lLoopCntr] = dpSrc[lLoopCntr];
6197 }
6198 }
6199 }
6200
6201
WinExactBlackman(float * fpDest,long lSize)6202 void clDSPOp::WinExactBlackman (float *fpDest, long lSize)
6203 {
6204 long lLoopCntr;
6205 float fA0;
6206 float fA1;
6207 float fA2;
6208
6209 fA0 = 7938.0F / 18608.0F;
6210 fA1 = 9240.0F / 18608.0F;
6211 fA2 = 1430.0F / 18608.0F;
6212 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6213 {
6214 fpDest[lLoopCntr] = fA0 -
6215 fA1 * cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize) +
6216 fA2 * cos((4.0F * fPI * (float) lLoopCntr) / (float) lSize);
6217 }
6218 }
6219
6220
WinExactBlackman(double * dpDest,long lSize)6221 void clDSPOp::WinExactBlackman (double *dpDest, long lSize)
6222 {
6223 long lLoopCntr;
6224 double dA0;
6225 double dA1;
6226 double dA2;
6227
6228 dA0 = 7938.0 / 18608.0;
6229 dA1 = 9240.0 / 18608.0;
6230 dA2 = 1430.0 / 18608.0;
6231 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6232 {
6233 dpDest[lLoopCntr] = dA0 -
6234 dA1 * cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize) +
6235 dA2 * cos((4.0 * dPI * (double) lLoopCntr) / (double) lSize);
6236 }
6237 }
6238
6239
WinExp(float * fpDest,float fFinal,long lSize)6240 void clDSPOp::WinExp (float *fpDest, float fFinal, long lSize)
6241 {
6242 long lLoopCntr;
6243 float fA;
6244
6245 fA = log(fFinal + 1.0F) / ((float) lSize / 2.0F);
6246 for (lLoopCntr = 0L; lLoopCntr < (lSize / 2L + 1L); lLoopCntr++)
6247 {
6248 fpDest[lLoopCntr] = fpDest[lSize - lLoopCntr - 1L] =
6249 exp(fA * (float) lLoopCntr) - 1.0F;
6250 }
6251 }
6252
6253
WinExp(double * dpDest,double dFinal,long lSize)6254 void clDSPOp::WinExp (double *dpDest, double dFinal, long lSize)
6255 {
6256 long lLoopCntr;
6257 double dA;
6258
6259 dA = log(dFinal + 1.0) / ((double) lSize / 2.0);
6260 for (lLoopCntr = 0L; lLoopCntr < (lSize / 2L + 1L); lLoopCntr++)
6261 {
6262 dpDest[lLoopCntr] = dpDest[lSize - lLoopCntr - 1L] =
6263 exp(dA * (double) lLoopCntr) - 1.0;
6264 }
6265 }
6266
6267
WinFlatTop(float * fpDest,long lSize)6268 void clDSPOp::WinFlatTop (float *fpDest, long lSize)
6269 {
6270 long lLoopCntr;
6271
6272 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6273 {
6274 fpDest[lLoopCntr] = 0.2810639F -
6275 0.5208972F *
6276 cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize) +
6277 0.1980399F *
6278 cos((4.0F * fPI * (float) lLoopCntr) / (float) lSize);
6279 }
6280 }
6281
6282
WinFlatTop(double * dpDest,long lSize)6283 void clDSPOp::WinFlatTop (double *dpDest, long lSize)
6284 {
6285 long lLoopCntr;
6286
6287 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6288 {
6289 dpDest[lLoopCntr] = 0.2810639 -
6290 0.5208972 *
6291 cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize) +
6292 0.1980399 *
6293 cos((4.0 * dPI * (double) lLoopCntr) / (double) lSize);
6294 }
6295 }
6296
6297
WinGenericCos(float * fpDest,long lSize,const float * fpCoeff,long lCoeffCount)6298 void clDSPOp::WinGenericCos (float *fpDest, long lSize,
6299 const float *fpCoeff, long lCoeffCount)
6300 {
6301 long lLoopWin;
6302 long lLoopCoeff;
6303 float fWinCoeff;
6304
6305 for (lLoopWin = 0L; lLoopWin < lSize; lLoopWin++)
6306 {
6307 fWinCoeff = 0.0F;
6308 for (lLoopCoeff = 0L; lLoopCoeff < lCoeffCount; lLoopCoeff++)
6309 {
6310 fWinCoeff += pow(-1.0F, (float) lLoopCoeff) *
6311 fpCoeff[lLoopCoeff] * cos(
6312 (2.0F * fPI * (float) lLoopCoeff * (float) lLoopWin) /
6313 (float) lSize);
6314 }
6315 fpDest[lLoopWin] = fWinCoeff;
6316 }
6317 }
6318
6319
WinGenericCos(double * dpDest,long lSize,const double * dpCoeff,long lCoeffCount)6320 void clDSPOp::WinGenericCos (double *dpDest, long lSize,
6321 const double *dpCoeff, long lCoeffCount)
6322 {
6323 long lLoopWin;
6324 long lLoopCoeff;
6325 double dWinCoeff;
6326
6327 for (lLoopWin = 0L; lLoopWin < lSize; lLoopWin++)
6328 {
6329 dWinCoeff = 0.0;
6330 for (lLoopCoeff = 0L; lLoopCoeff < lCoeffCount; lLoopCoeff++)
6331 {
6332 dWinCoeff += pow(-1.0, (double) lLoopCoeff) *
6333 dpCoeff[lLoopCoeff] * cos(
6334 (2.0 * dPI * (double) lLoopCoeff * (double) lLoopWin) /
6335 (double) lSize);
6336 }
6337 dpDest[lLoopWin] = dWinCoeff;
6338 }
6339 }
6340
6341
WinHamming(float * fpDest,long lSize)6342 void clDSPOp::WinHamming (float *fpDest, long lSize)
6343 {
6344 #ifdef DSP_IPP
6345 ippsSet_32f(1.0F, fpDest, lSize);
6346 ippsWinHamming_32f_I(fpDest, lSize);
6347 #else
6348 long lLoopCntr;
6349
6350 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6351 {
6352 fpDest[lLoopCntr] = 0.54F -
6353 0.46F * cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize);
6354 }
6355 #endif
6356 }
6357
6358
WinHamming(double * dpDest,long lSize)6359 void clDSPOp::WinHamming (double *dpDest, long lSize)
6360 {
6361 #ifdef DSP_IPP
6362 ippsSet_64f(1.0, dpDest, lSize);
6363 ippsWinHamming_64f_I(dpDest, lSize);
6364 #else
6365 long lLoopCntr;
6366
6367 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6368 {
6369 dpDest[lLoopCntr] = 0.54 -
6370 0.46 * cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize);
6371 }
6372 #endif
6373 }
6374
6375
WinHanning(float * fpDest,long lSize)6376 void clDSPOp::WinHanning (float *fpDest, long lSize)
6377 {
6378 #ifdef DSP_IPP
6379 ippsSet_32f(1.0F, fpDest, lSize);
6380 ippsWinHann_32f_I(fpDest, lSize);
6381 #else
6382 long lLoopCntr;
6383
6384 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6385 {
6386 fpDest[lLoopCntr] = 0.5F -
6387 0.5F * cos((2.0F * fPI * (float) lLoopCntr) / (float) lSize);
6388 }
6389 #endif
6390 }
6391
6392
WinHanning(double * dpDest,long lSize)6393 void clDSPOp::WinHanning (double *dpDest, long lSize)
6394 {
6395 #ifdef DPS_IPP
6396 ippsSet_64f(1.0, dpDest, lSize);
6397 ippsWinHann_64f_I(dpDest, lSize);
6398 #else
6399 long lLoopCntr;
6400
6401 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6402 {
6403 dpDest[lLoopCntr] = 0.5 -
6404 0.5 * cos((2.0 * dPI * (double) lLoopCntr) / (double) lSize);
6405 }
6406 #endif
6407 }
6408
6409
WinKaiser(float * fpDest,float fBeta,long lSize)6410 void clDSPOp::WinKaiser (float *fpDest, float fBeta, long lSize)
6411 {
6412 #ifdef DSP_IPP
6413 ippsSet_32f(1.0F, fpDest, lSize);
6414 ippsWinKaiser_32f_I(fpDest, lSize,
6415 fBeta * (1.0f / ((float) (lSize - 1) / 2.0f)));
6416 #else
6417 long lLoopCntr;
6418 float fA;
6419
6420 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6421 {
6422 fA = fabs(1.0F - (2.0F * (float) lLoopCntr) / (float) lSize);
6423 fpDest[lLoopCntr] =
6424 ModZeroBessel(fBeta * sqrt(1.0F - fA * fA)) /
6425 ModZeroBessel(fBeta);
6426 }
6427 #endif
6428 }
6429
6430
WinKaiser(double * dpDest,double dBeta,long lSize)6431 void clDSPOp::WinKaiser (double *dpDest, double dBeta, long lSize)
6432 {
6433 #ifdef DSP_IPP
6434 ippsSet_64f(1.0, dpDest, lSize);
6435 ippsWinKaiser_64f_I(dpDest, lSize,
6436 dBeta * (1.0 / ((double) (lSize - 1) / 2.0)));
6437 #else
6438 long lLoopCntr;
6439 double dA;
6440
6441 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6442 {
6443 dA = fabs(1.0 - (2.0 * (double) lLoopCntr) / (double) lSize);
6444 dpDest[lLoopCntr] =
6445 ModZeroBessel(dBeta * sqrt(1.0 - dA * dA)) /
6446 ModZeroBessel(dBeta);
6447 }
6448 #endif
6449 }
6450
6451
WinKaiserBessel(float * fpDest,float fAlpha,long lSize)6452 void clDSPOp::WinKaiserBessel (float *fpDest, float fAlpha, long lSize)
6453 {
6454 long lLoopCntr;
6455 float fHalfN;
6456 float fPiAlpha;
6457
6458 fHalfN = (float) lSize / 2.0F;
6459 fPiAlpha = fPI * fAlpha;
6460 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6461 {
6462 fpDest[lLoopCntr] =
6463 ModZeroBessel(fPiAlpha *
6464 sqrt(1.0F - pow(((float) lLoopCntr - fHalfN) / fHalfN, 2.0F))) /
6465 ModZeroBessel(fPiAlpha);
6466 }
6467 }
6468
6469
WinKaiserBessel(double * dpDest,double dAlpha,long lSize)6470 void clDSPOp::WinKaiserBessel (double *dpDest, double dAlpha, long lSize)
6471 {
6472 long lLoopCntr;
6473 double dHalfN;
6474 double dPiAlpha;
6475
6476 dHalfN = (double) lSize / 2.0;
6477 dPiAlpha = dPI * dAlpha;
6478 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6479 {
6480 dpDest[lLoopCntr] =
6481 ModZeroBessel(dPiAlpha *
6482 sqrt(1.0 - pow(((double) lLoopCntr - dHalfN) / dHalfN, 2.0))) /
6483 ModZeroBessel(dPiAlpha);
6484 }
6485 }
6486
6487
WinTukey(float * fpDest,long lSize)6488 void clDSPOp::WinTukey (float *fpDest, long lSize)
6489 {
6490 long lLoopCntr;
6491 long lHalfSize;
6492
6493 lHalfSize = lSize / 2L;
6494 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6495 {
6496 fpDest[lLoopCntr] = 0.5F *
6497 (1.0F + cos((float) (lLoopCntr - lHalfSize) * fPI / lHalfSize));
6498 }
6499 }
6500
6501
WinTukey(double * dpDest,long lSize)6502 void clDSPOp::WinTukey (double *dpDest, long lSize)
6503 {
6504 long lLoopCntr;
6505 long lHalfSize;
6506
6507 lHalfSize = lSize / 2L;
6508 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6509 {
6510 dpDest[lLoopCntr] = 0.5 *
6511 (1.0 + cos((float) (lLoopCntr - lHalfSize) * dPI / lHalfSize));
6512 }
6513 }
6514
6515
WinDolphChebyshev(float * fpDest,float fGamma,long lSize)6516 void clDSPOp::WinDolphChebyshev (float *fpDest, float fGamma, long lSize)
6517 {
6518 long lHalfSize;
6519 long lLoopCntr;
6520 long lSumCntr;
6521 float fScale;
6522 float fInvGamma;
6523 float fX0;
6524 float fThetaS;
6525 float fChebyshevSum;
6526 float fTheta;
6527 float fTheta2;
6528 float fMin;
6529 float fMax;
6530
6531 lHalfSize = lSize / 2L;
6532 fScale = 1.0F / (float) lSize;
6533 fInvGamma = 1.0F / fGamma;
6534 fX0 = coshf((1.0F / (float) (lSize - 1)) * acoshf(fInvGamma));
6535 fThetaS = 2.0F * acosf(1.0F / fX0);
6536 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6537 {
6538 fChebyshevSum = 0.0F;
6539 for (lSumCntr = 1L; lSumCntr <= lHalfSize; lSumCntr++)
6540 {
6541 fTheta = (2.0F * fPI * (float) lSumCntr) / (float) lSize;
6542 fTheta2 = (fPI * (float) (2L * lLoopCntr - lSize + 1L)) /
6543 (float) lSize;
6544 fChebyshevSum +=
6545 ChebyshevPolynom((float) (lSize - 1L),
6546 (float) (fX0 * cosf(fTheta / 2.0F))) *
6547 cosf((float) lSumCntr * fTheta2);
6548 }
6549 fpDest[lLoopCntr] = fScale *
6550 (1.0F + 2.0F * fGamma * fChebyshevSum);
6551 }
6552
6553 MinMax(&fMin, &fMax, fpDest, lSize);
6554 fScale = 1.0F / fMax;
6555 Mul(fpDest, fScale, lSize);
6556 }
6557
6558
WinDolphChebyshev(double * dpDest,double dGamma,long lSize)6559 void clDSPOp::WinDolphChebyshev (double *dpDest, double dGamma, long lSize)
6560 {
6561 long lHalfSize;
6562 long lLoopCntr;
6563 long lSumCntr;
6564 double dScale;
6565 double dInvGamma;
6566 double dX0;
6567 double dThetaS;
6568 double dChebyshevSum;
6569 double dTheta;
6570 double dTheta2;
6571 double dMin;
6572 double dMax;
6573
6574 lHalfSize = lSize / 2L;
6575 dScale = 1.0F / (double) lSize;
6576 dInvGamma = 1.0F / dGamma;
6577 dX0 = cosh((1.0 / (double) (lSize - 1)) * acosh(dInvGamma));
6578 dThetaS = 2.0 * acos(1.0 / dX0);
6579 for (lLoopCntr = 0L; lLoopCntr < lSize; lLoopCntr++)
6580 {
6581 dChebyshevSum = 0.0;
6582 for (lSumCntr = 1L; lSumCntr <= lHalfSize; lSumCntr++)
6583 {
6584 dTheta = (2.0 * dPI * (double) lSumCntr) / (double) lSize;
6585 dTheta2 = (dPI * (double) (2L * lLoopCntr - lSize + 1L)) /
6586 (double) lSize;
6587 dChebyshevSum +=
6588 ChebyshevPolynom((double) (lSize - 1L),
6589 dX0 * cos(dTheta / 2.0)) *
6590 cos((double) lSumCntr * dTheta2);
6591 }
6592 dpDest[lLoopCntr] = dScale *
6593 (1.0 + 2.0 * dGamma * dChebyshevSum);
6594 }
6595
6596 MinMax(&dMin, &dMax, dpDest, lSize);
6597 dScale = 1.0 / dMax;
6598 Mul(dpDest, dScale, lSize);
6599 }
6600
6601
Mix(float * fpDest,const float * fpSrc,long lCount)6602 void clDSPOp::Mix (float *fpDest, const float *fpSrc, long lCount)
6603 {
6604 long lLoopCntr;
6605 long lSrcIdx;
6606
6607 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6608 {
6609 lSrcIdx = lLoopCntr << 1;
6610 fpDest[lLoopCntr] = (fpSrc[lSrcIdx] + fpSrc[lSrcIdx + 1L]) * 0.5F;
6611 }
6612 }
6613
6614
Mix(double * dpDest,const double * dpSrc,long lCount)6615 void clDSPOp::Mix (double *dpDest, const double *dpSrc, long lCount)
6616 {
6617 long lLoopCntr;
6618 long lSrcIdx;
6619
6620 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6621 {
6622 lSrcIdx = lLoopCntr << 1;
6623 dpDest[lLoopCntr] = (dpSrc[lSrcIdx] + dpSrc[lSrcIdx + 1L]) * 0.5;
6624 }
6625 }
6626
6627
Mix(float * fpDest,const float * fpSrc1,const float * fpSrc2,long lCount)6628 void clDSPOp::Mix (float *fpDest, const float *fpSrc1, const float *fpSrc2,
6629 long lCount)
6630 {
6631 long lLoopCntr;
6632
6633 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6634 {
6635 fpDest[lLoopCntr] = (fpSrc1[lLoopCntr] + fpSrc2[lLoopCntr]) * 0.5F;
6636 }
6637 }
6638
6639
Mix(double * dpDest,const double * dpSrc1,const double * dpSrc2,long lCount)6640 void clDSPOp::Mix (double *dpDest, const double *dpSrc1, const double *dpSrc2,
6641 long lCount)
6642 {
6643 long lLoopCntr;
6644
6645 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6646 {
6647 dpDest[lLoopCntr] = (dpSrc1[lLoopCntr] + dpSrc2[lLoopCntr]) * 0.5;
6648 }
6649 }
6650
6651
Mix(float * fpDest,const float * fpSrc,long lChCount,long lDestCount)6652 void clDSPOp::Mix (float *fpDest, const float *fpSrc, long lChCount,
6653 long lDestCount)
6654 {
6655 long lDestCntr;
6656 long lSrcCntr;
6657 long lSrcMax;
6658 float fMix;
6659 float fScaler;
6660
6661 fScaler = 1.0F / (float) lChCount;
6662 for (lDestCntr = 0L; lDestCntr < lDestCount; lDestCntr++)
6663 {
6664 fMix = 0.0F;
6665 lSrcMax = lDestCntr * lChCount + lChCount;
6666 for (lSrcCntr = lDestCntr * lChCount; lSrcCntr < lSrcMax; lSrcCntr++)
6667 {
6668 fMix += fpSrc[lSrcCntr];
6669 }
6670 fpDest[lDestCntr] = fMix * fScaler;
6671 }
6672 }
6673
6674
Mix(double * dpDest,const double * dpSrc,long lChCount,long lDestCount)6675 void clDSPOp::Mix (double *dpDest, const double *dpSrc, long lChCount,
6676 long lDestCount)
6677 {
6678 long lDestCntr;
6679 long lSrcCntr;
6680 long lSrcMax;
6681 double dMix;
6682 double dScaler;
6683
6684 dScaler = 1.0 / (double) lChCount;
6685 for (lDestCntr = 0L; lDestCntr < lDestCount; lDestCntr++)
6686 {
6687 dMix = 0.0;
6688 lSrcMax = lDestCntr * lChCount + lChCount;
6689 for (lSrcCntr = lDestCntr * lChCount; lSrcCntr < lSrcMax; lSrcCntr++)
6690 {
6691 dMix += dpSrc[lSrcCntr];
6692 }
6693 dpDest[lDestCntr] = dMix * dScaler;
6694 }
6695 }
6696
6697
Spatialize(float * fpDest1,float * fpDest2,const float * fpSrc,long lCount)6698 void clDSPOp::Spatialize (float *fpDest1, float *fpDest2,
6699 const float *fpSrc, long lCount)
6700 {
6701 long lLoopCntr;
6702 float fTemp;
6703
6704 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6705 {
6706 fTemp = fpSrc[lLoopCntr];
6707 fpDest1[lLoopCntr] = fTemp;
6708 fpDest2[lLoopCntr] = -fTemp;
6709 }
6710 }
6711
6712
Spatialize(double * dpDest1,double * dpDest2,const double * dpSrc,long lCount)6713 void clDSPOp::Spatialize (double *dpDest1, double *dpDest2,
6714 const double *dpSrc, long lCount)
6715 {
6716 long lLoopCntr;
6717 double dTemp;
6718
6719 for (lLoopCntr = 0L; lLoopCntr < lCount; lLoopCntr++)
6720 {
6721 dTemp = dpSrc[lLoopCntr];
6722 dpDest1[lLoopCntr] = dTemp;
6723 dpDest2[lLoopCntr] = -dTemp;
6724 }
6725 }
6726
6727
Spatialize(float * fpDest,const float * fpSrc,long lCount)6728 void clDSPOp::Spatialize (float *fpDest, const float *fpSrc, long lCount)
6729 {
6730 long lSrcCntr;
6731 long lDestIdx;
6732 float fTemp;
6733
6734 for (lSrcCntr = 0L; lSrcCntr < lCount; lSrcCntr++)
6735 {
6736 fTemp = fpSrc[lSrcCntr];
6737 lDestIdx = lSrcCntr << 1;
6738 fpDest[lDestIdx] = fTemp;
6739 fpDest[lDestIdx + 1L] = -fTemp;
6740 }
6741 }
6742
6743
Spatialize(double * dpDest,const double * dpSrc,long lCount)6744 void clDSPOp::Spatialize (double *dpDest, const double *dpSrc, long lCount)
6745 {
6746 long lSrcCntr;
6747 long lDestIdx;
6748 double dTemp;
6749
6750 for (lSrcCntr = 0L; lSrcCntr < lCount; lSrcCntr++)
6751 {
6752 dTemp = dpSrc[lSrcCntr];
6753 lDestIdx = lSrcCntr << 1;
6754 dpDest[lDestIdx] = dTemp;
6755 dpDest[lDestIdx + 1L] = -dTemp;
6756 }
6757 }
6758
6759
Extract(float * fpDest,const float * fpSrc,long lChannel,long lChCount,long lSrcLength)6760 void clDSPOp::Extract (float *fpDest, const float *fpSrc, long lChannel,
6761 long lChCount, long lSrcLength)
6762 {
6763 long lLoopCntr;
6764 long lMax;
6765
6766 lMax = lSrcLength / lChCount;
6767 for (lLoopCntr = 0; lLoopCntr < lMax; lLoopCntr++)
6768 {
6769 fpDest[lLoopCntr] = fpSrc[lLoopCntr * lChCount + lChannel];
6770 }
6771 }
6772
6773
Extract(double * dpDest,const double * dpSrc,long lChannel,long lChCount,long lSrcLength)6774 void clDSPOp::Extract (double *dpDest, const double *dpSrc, long lChannel,
6775 long lChCount, long lSrcLength)
6776 {
6777 long lLoopCntr;
6778 long lMax;
6779
6780 lMax = lSrcLength / lChCount;
6781 for (lLoopCntr = 0; lLoopCntr < lMax; lLoopCntr++)
6782 {
6783 dpDest[lLoopCntr] = dpSrc[lLoopCntr * lChCount + lChannel];
6784 }
6785 }
6786
6787
Pack(float * fpDest,const float * fpSrc,long lChannel,long lChCount,long lSrcLength)6788 void clDSPOp::Pack (float *fpDest, const float *fpSrc, long lChannel,
6789 long lChCount, long lSrcLength)
6790 {
6791 long lLoopCntr;
6792
6793 for (lLoopCntr = 0; lLoopCntr < lSrcLength; lLoopCntr++)
6794 {
6795 fpDest[lLoopCntr * lChCount + lChannel] = fpSrc[lLoopCntr];
6796 }
6797 }
6798
6799
Pack(double * dpDest,const double * dpSrc,long lChannel,long lChCount,long lSrcLength)6800 void clDSPOp::Pack (double *dpDest, const double *dpSrc, long lChannel,
6801 long lChCount, long lSrcLength)
6802 {
6803 long lLoopCntr;
6804
6805 for (lLoopCntr = 0; lLoopCntr < lSrcLength; lLoopCntr++)
6806 {
6807 dpDest[lLoopCntr * lChCount + lChannel] = dpSrc[lLoopCntr];
6808 }
6809 }
6810
6811
ReBuffer(float * fpDest,const float * fpSrc,long lDestSize,long lSrcSize)6812 long clDSPOp::ReBuffer (float *fpDest, const float *fpSrc, long lDestSize,
6813 long lSrcSize)
6814 {
6815 long lDestCount;
6816 long lSrcCount;
6817 long lCopyCount;
6818
6819 lDestCount = lDestSize - lPrevDestCount;
6820 lSrcCount = lSrcSize - lPrevSrcCount;
6821 lCopyCount = (lDestCount < lSrcCount) ? lDestCount : lSrcCount;
6822 Copy(&fpDest[lPrevDestCount], &fpSrc[lPrevSrcCount], lCopyCount);
6823 lPrevDestCount += lCopyCount;
6824 lPrevSrcCount += lCopyCount;
6825 if ((lPrevDestCount == lDestSize) && (lPrevSrcCount == lSrcSize))
6826 {
6827 lPrevDestCount = 0L;
6828 lPrevSrcCount = 0L;
6829 return 1;
6830 }
6831 else if (lPrevDestCount == lDestSize)
6832 {
6833 lPrevDestCount = 0L;
6834 return 2;
6835 }
6836 else if (lPrevSrcCount == lSrcSize)
6837 {
6838 lPrevSrcCount = 0L;
6839 return 0;
6840 }
6841 else
6842 {
6843 fprintf(stderr, "clDSPOp::ReBuffer(): Fatal error; bug found\n");
6844 }
6845 return 0;
6846 }
6847
6848
ReBuffer(double * dpDest,const double * dpSrc,long lDestSize,long lSrcSize)6849 long clDSPOp::ReBuffer (double *dpDest, const double *dpSrc, long lDestSize,
6850 long lSrcSize)
6851 {
6852 long lDestCount;
6853 long lSrcCount;
6854 long lCopyCount;
6855
6856 lDestCount = lDestSize - lPrevDestCount;
6857 lSrcCount = lSrcSize - lPrevSrcCount;
6858 lCopyCount = (lDestCount < lSrcCount) ? lDestCount : lSrcCount;
6859 Copy(&dpDest[lPrevDestCount], &dpSrc[lPrevSrcCount], lCopyCount);
6860 lPrevDestCount += lCopyCount;
6861 lPrevSrcCount += lCopyCount;
6862 if (lPrevDestCount == lDestSize && lPrevSrcCount == lSrcSize)
6863 {
6864 lPrevDestCount = 0L;
6865 lPrevSrcCount = 0L;
6866 return 1;
6867 }
6868 else if (lPrevDestCount == lDestSize)
6869 {
6870 lPrevDestCount = 0L;
6871 return 2;
6872 }
6873 else if (lPrevSrcCount == lSrcSize)
6874 {
6875 lPrevSrcCount = 0L;
6876 return 0;
6877 }
6878 else
6879 {
6880 fprintf(stderr, "clDSPOp::ReBuffer(): Fatal error; bug found\n");
6881 }
6882 return 0;
6883 }
6884
6885
6886 /* I know, here we actually play with one unneccessary value in FIRBuf,
6887 but it makes code a lot cleaner, small price for one extra value! */
6888
FIRAllocate(const float * fpCoeff,long lCount)6889 void clDSPOp::FIRAllocate (const float *fpCoeff, long lCount)
6890 {
6891 #ifdef DSP_IPP
6892 iFIRDlyIdx = 0;
6893 lFIRLength = lCount;
6894 FIRCoeff.Size(lCount * sizeof(float));
6895 FIRBuf.Size(lCount * 2 * sizeof(float));
6896 Copy((float *) FIRCoeff, fpCoeff, lCount);
6897 Zero((float *) FIRBuf, lCount * 2);
6898 #else
6899 lFIRLength = lCount;
6900 FIRCoeff.Size(lCount * sizeof(float));
6901 FIRBuf.Size(lCount * sizeof(float));
6902 Copy((float *) FIRCoeff, fpCoeff, lCount);
6903 Zero((float *) FIRBuf, lCount);
6904 #endif
6905 }
6906
6907
FIRAllocate(const double * dpCoeff,long lCount)6908 void clDSPOp::FIRAllocate (const double *dpCoeff, long lCount)
6909 {
6910 #ifdef DSP_IPP
6911 iFIRDlyIdx = 0;
6912 lFIRLength = lCount;
6913 FIRCoeff.Size(lCount * sizeof(double));
6914 FIRBuf.Size(lCount * 2 * sizeof(double));
6915 Copy((double *) FIRCoeff, dpCoeff, lCount);
6916 Zero((double *) FIRBuf, lCount * 2);
6917 #else
6918 lFIRLength = lCount;
6919 FIRCoeff.Size(lCount * sizeof(double));
6920 FIRBuf.Size(lCount * sizeof(double));
6921 Copy((double *) FIRCoeff, dpCoeff, lCount);
6922 Zero((double *) FIRBuf, lCount);
6923 #endif
6924 }
6925
6926
FIRFilter(float * fpVect,long lCount)6927 void clDSPOp::FIRFilter (float *fpVect, long lCount)
6928 {
6929 #ifdef DSP_IPP
6930 ippsFIR_Direct_32f_I(fpVect, lCount, FIRCoeff, lFIRLength,
6931 FIRBuf, &iFIRDlyIdx);
6932 #else
6933 long lMax;
6934 float *fpFIRCoeff = FIRCoeff;
6935 float *fpFIRBuf = FIRBuf;
6936 float *fpFIRWork;
6937
6938 fpFIRWork = (float *) FIRWork.Size((lCount + lFIRLength) * sizeof(float));
6939 Copy(fpFIRWork, fpFIRBuf, lFIRLength);
6940 Copy(&fpFIRWork[lFIRLength], fpVect, lCount);
6941 lMax = lCount + lFIRLength;
6942 #ifdef DSP_X86
6943 if (bHave3DNow)
6944 {
6945 dsp_x86_3dnow_firf(fpVect, fpFIRWork, lCount,
6946 fpFIRCoeff, lFIRLength);
6947 }
6948 else if (bHaveSSE)
6949 {
6950 dsp_x86_sse_firf(fpVect, fpFIRWork, lCount,
6951 fpFIRCoeff, lFIRLength);
6952 }
6953 else
6954 #endif
6955 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
6956 dsp_x86_64_firf(fpVect, fpFIRWork, lCount, fpFIRCoeff, lFIRLength);
6957 #else
6958 {
6959 long lSrcCntr;
6960 long lConvCntr;
6961 long lDestCntr;
6962 float fTempVal;
6963
6964 lDestCntr = 0L;
6965 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
6966 {
6967 fTempVal = 0.0F;
6968 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
6969 {
6970 #ifndef _ISOC9X_SOURCE
6971 fTempVal += fpFIRCoeff[lConvCntr] *
6972 fpFIRWork[lSrcCntr - lConvCntr];
6973 #else
6974 fTempVal = fmaf(fpFIRCoeff[lConvCntr],
6975 fpFIRWork[lSrcCntr - lConvCntr], fTempVal);
6976 #endif
6977 }
6978 fpVect[lDestCntr++] = fTempVal;
6979 }
6980 }
6981 #endif
6982 Copy(fpFIRBuf, &fpFIRWork[lMax - lFIRLength], lFIRLength);
6983 #endif
6984 }
6985
6986
FIRFilter(double * dpVect,long lCount)6987 void clDSPOp::FIRFilter (double *dpVect, long lCount)
6988 {
6989 #ifdef DSP_IPP
6990 ippsFIR_Direct_64f_I(dpVect, lCount, FIRCoeff, lFIRLength,
6991 FIRBuf, &iFIRDlyIdx);
6992 #else
6993 long lMax;
6994 double *dpFIRCoeff = FIRCoeff;
6995 double *dpFIRBuf = FIRBuf;
6996 double *dpFIRWork;
6997
6998 lMax = lCount + lFIRLength;
6999 dpFIRWork = (double *) FIRWork.Size((lCount + lFIRLength) * sizeof(double));
7000 Copy(dpFIRWork, dpFIRBuf, lFIRLength);
7001 Copy(&dpFIRWork[lFIRLength], dpVect, lCount);
7002 #ifdef DSP_X86
7003 if (bHaveSSE)
7004 {
7005 dsp_x86_sse_fir(dpVect, dpFIRWork, lCount,
7006 dpFIRCoeff, lFIRLength);
7007 }
7008 else
7009 #endif
7010 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7011 dsp_x86_64_fir(dpVect, dpFIRWork, lCount, dpFIRCoeff, lFIRLength);
7012 #else
7013 {
7014 long lSrcCntr;
7015 long lConvCntr;
7016 long lDestCntr;
7017 double dTempVal;
7018
7019 lDestCntr = 0L;
7020 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
7021 {
7022 dTempVal = 0.0;
7023 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
7024 {
7025 #ifndef _ISOC9X_SOURCE
7026 dTempVal += dpFIRCoeff[lConvCntr] *
7027 dpFIRWork[lSrcCntr - lConvCntr];
7028 #else
7029 dTempVal = fma(dpFIRCoeff[lConvCntr],
7030 dpFIRWork[lSrcCntr - lConvCntr], dTempVal);
7031 #endif
7032 }
7033 dpVect[lDestCntr++] = dTempVal;
7034 }
7035 }
7036 #endif
7037 Copy(dpFIRBuf, &dpFIRWork[lMax - lFIRLength], lFIRLength);
7038 #endif
7039 }
7040
7041
FIRFilter(float * fpDest,const float * fpSrc,long lCount)7042 void clDSPOp::FIRFilter (float *fpDest, const float *fpSrc, long lCount)
7043 {
7044 #ifdef DSP_IPP
7045 ippsFIR_Direct_32f(fpSrc, fpDest, lCount, FIRCoeff, lFIRLength,
7046 FIRBuf, &iFIRDlyIdx);
7047 #else
7048 long lMax;
7049 float *fpFIRCoeff = FIRCoeff;
7050 float *fpFIRBuf = FIRBuf;
7051 float *fpFIRWork;
7052
7053 fpFIRWork = (float *) FIRWork.Size((lCount + lFIRLength) * sizeof(float));
7054 Copy(fpFIRWork, fpFIRBuf, lFIRLength);
7055 Copy(&fpFIRWork[lFIRLength], fpSrc, lCount);
7056 lMax = lCount + lFIRLength;
7057 #ifdef DSP_X86
7058 if (bHave3DNow)
7059 {
7060 dsp_x86_3dnow_firf(fpDest, fpFIRWork, lCount,
7061 fpFIRCoeff, lFIRLength);
7062 }
7063 else if (bHaveSSE)
7064 {
7065 dsp_x86_sse_firf(fpDest, fpFIRWork, lCount,
7066 fpFIRCoeff, lFIRLength);
7067 }
7068 else
7069 #endif
7070 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7071 dsp_x86_64_firf(fpDest, fpFIRWork, lCount, fpFIRCoeff, lFIRLength);
7072 #else
7073 {
7074 long lSrcCntr;
7075 long lConvCntr;
7076 long lDestCntr;
7077 float fTempVal;
7078
7079 lDestCntr = 0L;
7080 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
7081 {
7082 fTempVal = 0.0F;
7083 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
7084 {
7085 #ifndef _ISOC9X_SOURCE
7086 fTempVal += fpFIRCoeff[lConvCntr] *
7087 fpFIRWork[lSrcCntr - lConvCntr];
7088 #else
7089 fTempVal = fmaf(fpFIRCoeff[lConvCntr],
7090 fpFIRWork[lSrcCntr - lConvCntr], fTempVal);
7091 #endif
7092 }
7093 fpDest[lDestCntr++] = fTempVal;
7094 }
7095 }
7096 #endif
7097 Copy(fpFIRBuf, &fpFIRWork[lMax - lFIRLength], lFIRLength);
7098 #endif
7099 }
7100
7101
FIRFilter(double * dpDest,const double * dpSrc,long lCount)7102 void clDSPOp::FIRFilter (double *dpDest, const double *dpSrc, long lCount)
7103 {
7104 #ifdef DSP_IPP
7105 ippsFIR_Direct_64f(dpSrc, dpDest, lCount, FIRCoeff, lFIRLength,
7106 FIRBuf, &iFIRDlyIdx);
7107 #else
7108 long lMax;
7109 double *dpFIRCoeff = FIRCoeff;
7110 double *dpFIRBuf = FIRBuf;
7111 double *dpFIRWork;
7112
7113 lMax = lCount + lFIRLength;
7114 dpFIRWork = (double *) FIRWork.Size((lCount + lFIRLength) * sizeof(double));
7115 Copy(dpFIRWork, dpFIRBuf, lFIRLength);
7116 Copy(&dpFIRWork[lFIRLength], dpSrc, lCount);
7117 #ifdef DSP_X86
7118 if (bHaveSSE)
7119 {
7120 dsp_x86_sse_fir(dpDest, dpFIRWork, lCount,
7121 dpFIRCoeff, lFIRLength);
7122 }
7123 else
7124 #endif
7125 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7126 dsp_x86_64_fir(dpDest, dpFIRWork, lCount, dpFIRCoeff, lFIRLength);
7127 #else
7128 {
7129 long lSrcCntr;
7130 long lConvCntr;
7131 long lDestCntr;
7132 double dTempVal;
7133
7134 lDestCntr = 0L;
7135 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
7136 {
7137 dTempVal = 0.0;
7138 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
7139 {
7140 #ifndef _ISOC9X_SOURCE
7141 dTempVal += dpFIRCoeff[lConvCntr] *
7142 dpFIRWork[lSrcCntr - lConvCntr];
7143 #else
7144 dTempVal = fma(dpFIRCoeff[lConvCntr],
7145 dpFIRWork[lSrcCntr - lConvCntr], dTempVal);
7146 #endif
7147 }
7148 dpDest[lDestCntr++] = dTempVal;
7149 }
7150 }
7151 #endif
7152 Copy(dpFIRBuf, &dpFIRWork[lMax - lFIRLength], lFIRLength);
7153 #endif
7154 }
7155
7156
FIRFilterF(float * fpDest,float * fpSrc,long lCount)7157 void clDSPOp::FIRFilterF (float *fpDest, float *fpSrc, long lCount)
7158 {
7159 long lSrcCntr;
7160 long lConvCntr;
7161 long lDestCntr;
7162 long lMax;
7163 float fTempVal;
7164 float *fpFIRCoeff = FIRCoeff;
7165
7166 lDestCntr = 0L;
7167 lMax = lCount + lFIRLength;
7168 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
7169 {
7170 fTempVal = 0.0F;
7171 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
7172 {
7173 #ifndef _ISOC9X_SOURCE
7174 fTempVal += fpFIRCoeff[lConvCntr] *
7175 fpSrc[lSrcCntr - lConvCntr];
7176 #else
7177 fTempVal = fmaf(fpFIRCoeff[lConvCntr],
7178 fpSrc[lSrcCntr - lConvCntr], fTempVal);
7179 #endif
7180 }
7181 fpDest[lDestCntr++] = fTempVal;
7182 }
7183 Copy(fpSrc, &fpSrc[lMax - lFIRLength], lFIRLength);
7184 }
7185
7186
FIRFilterF(double * dpDest,double * dpSrc,long lCount)7187 void clDSPOp::FIRFilterF (double *dpDest, double *dpSrc, long lCount)
7188 {
7189 long lSrcCntr;
7190 long lConvCntr;
7191 long lDestCntr;
7192 long lMax;
7193 double dTempVal;
7194 double *dpFIRCoeff = FIRCoeff;
7195
7196 lDestCntr = 0L;
7197 lMax = lCount + lFIRLength;
7198 for (lSrcCntr = lFIRLength; lSrcCntr < lMax; lSrcCntr++)
7199 {
7200 dTempVal = 0.0;
7201 for (lConvCntr = 0L; lConvCntr < lFIRLength; lConvCntr++)
7202 {
7203 #ifndef _ISOC9X_SOURCE
7204 dTempVal += dpFIRCoeff[lConvCntr] *
7205 dpSrc[lSrcCntr - lConvCntr];
7206 #else
7207 dTempVal = fma(dpFIRCoeff[lConvCntr],
7208 dpSrc[lSrcCntr - lConvCntr], dTempVal);
7209 #endif
7210 }
7211 dpDest[lDestCntr++] = dTempVal;
7212 }
7213 Copy(dpSrc, &dpSrc[lMax - lFIRLength], lFIRLength);
7214 }
7215
7216
FIRFree()7217 void clDSPOp::FIRFree ()
7218 {
7219 FIRCoeff.Free();
7220 FIRBuf.Free();
7221 }
7222
7223
IIRInitialize(const float * fpCoeffs)7224 void clDSPOp::IIRInitialize (const float *fpCoeffs)
7225 {
7226 Copy(fpIIR_C, fpCoeffs, 5);
7227 }
7228
7229
IIRInitialize(const double * dpCoeffs)7230 void clDSPOp::IIRInitialize (const double *dpCoeffs)
7231 {
7232 Copy(dpIIR_C, dpCoeffs, 5);
7233 }
7234
7235
IIRFilter(float * fpVect,long lCount)7236 void clDSPOp::IIRFilter (float *fpVect, long lCount)
7237 {
7238 #ifdef DSP_X86
7239 if (bHave3DNow)
7240 {
7241 dsp_x86_3dnow_iirf(fpVect, lCount, fpIIR_C, fpIIR_X, fpIIR_Y);
7242 }
7243 else if (bHaveSSE)
7244 {
7245 dsp_x86_sse_iirf(fpVect, lCount, fpIIR_C, fpIIR_X, fpIIR_Y);
7246 }
7247 else
7248 #endif
7249 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7250 dsp_x86_64_iirf(fpVect, lCount, fpIIR_C, fpIIR_X, fpIIR_Y);
7251 #else
7252 {
7253 long lLoopCntr;
7254 float fBXk;
7255 float fAYk;
7256
7257 for (lLoopCntr = 0; lLoopCntr < lCount; lLoopCntr++)
7258 {
7259 fpIIR_X[0] = fpIIR_X[1];
7260 fpIIR_X[1] = fpIIR_X[2];
7261 fpIIR_X[2] = fpVect[lLoopCntr];
7262 fBXk =
7263 fpIIR_C[0] * fpIIR_X[2] +
7264 fpIIR_C[1] * fpIIR_X[1] +
7265 fpIIR_C[2] * fpIIR_X[0];
7266 fAYk =
7267 fpIIR_C[3] * fpIIR_Y[1] +
7268 fpIIR_C[4] * fpIIR_Y[0];
7269 fpVect[lLoopCntr] = fAYk + fBXk;
7270 fpIIR_Y[0] = fpIIR_Y[1];
7271 fpIIR_Y[1] = fpVect[lLoopCntr];
7272 }
7273 }
7274 #endif
7275 }
7276
7277
IIRFilter(double * dpVect,long lCount)7278 void clDSPOp::IIRFilter (double *dpVect, long lCount)
7279 {
7280 #ifdef DSP_X86
7281 if (bHaveSSE)
7282 {
7283 dsp_x86_sse_iir(dpVect, lCount, dpIIR_C, dpIIR_X, dpIIR_Y);
7284 }
7285 else
7286 #endif
7287 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7288 dsp_x86_64_iir(dpVect, lCount, dpIIR_C, dpIIR_X, dpIIR_Y);
7289 #else
7290 {
7291 long lLoopCntr;
7292 double dBXk;
7293 double dAYk;
7294
7295 for (lLoopCntr = 0; lLoopCntr < lCount; lLoopCntr++)
7296 {
7297 dpIIR_X[0] = dpIIR_X[1];
7298 dpIIR_X[1] = dpIIR_X[2];
7299 dpIIR_X[2] = dpVect[lLoopCntr];
7300 dBXk =
7301 dpIIR_C[0] * dpIIR_X[2] +
7302 dpIIR_C[1] * dpIIR_X[1] +
7303 dpIIR_C[2] * dpIIR_X[0];
7304 dAYk =
7305 dpIIR_C[3] * dpIIR_Y[1] +
7306 dpIIR_C[4] * dpIIR_Y[0];
7307 dpVect[lLoopCntr] = dAYk + dBXk;
7308 dpIIR_Y[0] = dpIIR_Y[1];
7309 dpIIR_Y[1] = dpVect[lLoopCntr];
7310 }
7311 }
7312 #endif
7313 }
7314
7315
IIRFilter(float * fpDest,const float * fpSrc,long lCount)7316 void clDSPOp::IIRFilter (float *fpDest, const float *fpSrc, long lCount)
7317 {
7318 #ifdef DSP_X86
7319 if (bHave3DNow)
7320 {
7321 dsp_x86_3dnow_iirf_nip(fpDest, fpSrc, lCount,
7322 fpIIR_C, fpIIR_X, fpIIR_Y);
7323 }
7324 else if (bHaveSSE)
7325 {
7326 dsp_x86_sse_iirf_nip(fpDest, fpSrc, lCount,
7327 fpIIR_C, fpIIR_X, fpIIR_Y);
7328 }
7329 else
7330 #endif
7331 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7332 dsp_x86_64_iirf_nip(fpDest, fpSrc, lCount, fpIIR_C, fpIIR_X, fpIIR_Y);
7333 #else
7334 {
7335 long lLoopCntr;
7336 float fBXk;
7337 float fAYk;
7338
7339 for (lLoopCntr = 0; lLoopCntr < lCount; lLoopCntr++)
7340 {
7341 fpIIR_X[0] = fpIIR_X[1];
7342 fpIIR_X[1] = fpIIR_X[2];
7343 fpIIR_X[2] = fpSrc[lLoopCntr];
7344 fBXk =
7345 fpIIR_C[0] * fpIIR_X[2] +
7346 fpIIR_C[1] * fpIIR_X[1] +
7347 fpIIR_C[2] * fpIIR_X[0];
7348 fAYk =
7349 fpIIR_C[3] * fpIIR_Y[1] +
7350 fpIIR_C[4] * fpIIR_Y[0];
7351 fpDest[lLoopCntr] = fAYk + fBXk;
7352 fpIIR_Y[0] = fpIIR_Y[1];
7353 fpIIR_Y[1] = fpDest[lLoopCntr];
7354 }
7355 }
7356 #endif
7357 }
7358
7359
IIRFilter(double * dpDest,const double * dpSrc,long lCount)7360 void clDSPOp::IIRFilter (double *dpDest, const double *dpSrc, long lCount)
7361 {
7362 #ifdef DSP_X86
7363 if (bHaveSSE)
7364 {
7365 dsp_x86_sse_iir_nip(dpDest, dpSrc, lCount, dpIIR_C, dpIIR_X, dpIIR_Y);
7366 }
7367 else
7368 #endif
7369 #if (defined(DSP_X86_64) && (!defined(DSP_X86)))
7370 dsp_x86_64_iir_nip(dpDest, dpSrc, lCount, dpIIR_C, dpIIR_X, dpIIR_Y);
7371 #else
7372 {
7373 long lLoopCntr;
7374 double dBXk;
7375 double dAYk;
7376
7377 for (lLoopCntr = 0; lLoopCntr < lCount; lLoopCntr++)
7378 {
7379 dpIIR_X[0] = dpIIR_X[1];
7380 dpIIR_X[1] = dpIIR_X[2];
7381 dpIIR_X[2] = dpSrc[lLoopCntr];
7382 dBXk =
7383 dpIIR_C[0] * dpIIR_X[2] +
7384 dpIIR_C[1] * dpIIR_X[1] +
7385 dpIIR_C[2] * dpIIR_X[0];
7386 dAYk =
7387 dpIIR_C[3] * dpIIR_Y[1] +
7388 dpIIR_C[4] * dpIIR_Y[0];
7389 dpDest[lLoopCntr] = dAYk + dBXk;
7390 dpIIR_Y[0] = dpIIR_Y[1];
7391 dpIIR_Y[1] = dpDest[lLoopCntr];
7392 }
7393 }
7394 #endif
7395 }
7396
7397
IIRClear()7398 void clDSPOp::IIRClear ()
7399 {
7400 Zero(fpIIR_X, 3);
7401 Zero(fpIIR_Y, 2);
7402 Zero(dpIIR_X, 3);
7403 Zero(dpIIR_Y, 2);
7404 }
7405
7406
FFTInitialize(long lSize,bool bIsReal)7407 void clDSPOp::FFTInitialize(long lSize, bool bIsReal)
7408 {
7409 #if defined(DSP_IPP)
7410 int iSWorkSize;
7411 int iDWorkSize;
7412 int iOrder;
7413
7414 iOrder = (int) (log((double) lSize) / log(2.0) + 0.5);
7415 if (bIsReal)
7416 {
7417 IppsFFTSpec_R_32f *pSFFTSpec;
7418 IppsFFTSpec_R_64f *pDFFTSpec;
7419 ippsFFTInitAlloc_R_32f(&pSFFTSpec, iOrder, IPP_FFT_DIV_FWD_BY_N,
7420 ippAlgHintFast);
7421 ippsFFTInitAlloc_R_64f(&pDFFTSpec, iOrder, IPP_FFT_DIV_FWD_BY_N,
7422 ippAlgHintFast);
7423 ippsFFTGetBufSize_R_32f(pSFFTSpec, &iSWorkSize);
7424 ippsFFTGetBufSize_R_64f(pDFFTSpec, &iDWorkSize);
7425 SBitRevWork.Size(iSWorkSize);
7426 DBitRevWork.Size(iDWorkSize);
7427 vpSTfrm = (void *) pSFFTSpec;
7428 vpDTfrm = (void *) pDFFTSpec;
7429 }
7430 else
7431 {
7432 IppsFFTSpec_C_32fc *pSFFTSpec;
7433 IppsFFTSpec_C_64fc *pDFFTSpec;
7434 ippsFFTInitAlloc_C_32fc(&pSFFTSpec, iOrder, IPP_FFT_DIV_FWD_BY_N,
7435 ippAlgHintFast);
7436 ippsFFTInitAlloc_C_64fc(&pDFFTSpec, iOrder, IPP_FFT_DIV_FWD_BY_N,
7437 ippAlgHintFast);
7438 ippsFFTGetBufSize_C_32fc(pSFFTSpec, &iSWorkSize);
7439 ippsFFTGetBufSize_C_64fc(pDFFTSpec, &iDWorkSize);
7440 SBitRevWork.Size(iSWorkSize);
7441 DBitRevWork.Size(iDWorkSize);
7442 vpSTfrm = (void *) pSFFTSpec;
7443 vpDTfrm = (void *) pDFFTSpec;
7444 }
7445 #elif defined(DSP_USE_FFTW)
7446 if (bIsReal)
7447 {
7448 clDSPAlloc FFTBufS(lSize * sizeof(float));
7449 clDSPAlloc FFTBufD(lSize * sizeof(double));
7450 clDSPAlloc FFTBufSC((lSize / 2 + 1) * sizeof(fftwf_complex));
7451 clDSPAlloc FFTBufDC((lSize / 2 + 1) * sizeof(fftw_complex));
7452 fftwpSPlan = fftwf_plan_dft_r2c_1d(lSize, FFTBufS, FFTBufSC,
7453 FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7454 fftwpSIPlan = fftwf_plan_dft_c2r_1d(lSize, FFTBufSC, FFTBufS,
7455 FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7456 fftwpDPlan = fftw_plan_dft_r2c_1d(lSize, FFTBufD, FFTBufDC,
7457 FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7458 fftwpDIPlan = fftw_plan_dft_c2r_1d(lSize, FFTBufDC, FFTBufD,
7459 FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7460 FFTBuf.Size(lSize * sizeof(double));
7461 }
7462 else
7463 {
7464 clDSPAlloc FFTBufSI(lSize * sizeof(fftwf_complex));
7465 clDSPAlloc FFTBufSO(lSize * sizeof(fftwf_complex));
7466 clDSPAlloc FFTBufDI(lSize * sizeof(fftw_complex));
7467 clDSPAlloc FFTBufDO(lSize * sizeof(fftw_complex));
7468
7469 fftwpSPlan = fftwf_plan_dft_1d(lSize, FFTBufSI, FFTBufSO,
7470 FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7471 fftwpSIPlan = fftwf_plan_dft_1d(lSize, FFTBufSO, FFTBufSI,
7472 FFTW_BACKWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7473 fftwpDPlan = fftw_plan_dft_1d(lSize, FFTBufDI, FFTBufDO,
7474 FFTW_FORWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7475 fftwpDIPlan = fftw_plan_dft_1d(lSize, FFTBufDO, FFTBufDI,
7476 FFTW_BACKWARD, FFTW_ESTIMATE|FFTW_PRESERVE_INPUT|FFTW_UNALIGNED);
7477 FFTBuf.Size(lSize * 2 * sizeof(double));
7478 }
7479 fFFTScale = 1.0F / (float) lSize;
7480 dFFTScale = 1.0 / (double) lSize;
7481 #else
7482 float *fpFFTBuf;
7483 double *dpFFTBuf;
7484 clDSPAlloc FFTBufS(lSize * 2 * sizeof(float));
7485 clDSPAlloc FFTBufD(lSize * 2 * sizeof(double));
7486
7487 fpFFTBuf = FFTBufS;
7488 dpFFTBuf = FFTBufD;
7489 if (bIsReal)
7490 {
7491 fFFTScale = 2.0F / (float) lSize;
7492 dFFTScale = 2.0 / (double) lSize;
7493 }
7494 else
7495 {
7496 fFFTScale = 1.0F / (float) lSize;
7497 dFFTScale = 1.0 / (double) lSize;
7498 }
7499 lpSBitRevWork = (long *)
7500 SBitRevWork.Size(((size_t) ceil(2.0 + sqrt(lSize))) * sizeof(long));
7501 lpDBitRevWork = (long *)
7502 DBitRevWork.Size(((size_t) ceil(2.0 + sqrt(lSize))) * sizeof(long));
7503 fpCosSinTable = (float *)
7504 SCosSinTable.Size((lSize / 2 + 1) * sizeof(float));
7505 dpCosSinTable = (double *)
7506 DCosSinTable.Size((lSize / 2 + 1) * sizeof(double));
7507 lpSBitRevWork[0] = 0;
7508 lpSBitRevWork[1] = 0;
7509 lpDBitRevWork[0] = 0;
7510 lpDBitRevWork[1] = 0;
7511 if (bIsReal)
7512 {
7513 Tfrm.rdft(lSize, 1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7514 Tfrm.rdft(lSize, 1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7515 FFTBuf.Size(lSize * sizeof(double));
7516 }
7517 else
7518 {
7519 Tfrm.cdft(lSize * 2, 1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7520 Tfrm.cdft(lSize * 2, 1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7521 FFTBuf.Size(lSize * 2 * sizeof(double));
7522 }
7523 #endif
7524 bFFTInitialized = true;
7525 bRealTransform = bIsReal;
7526 lFFTLength = lSize;
7527 }
7528
7529
FFTUninitialize()7530 void clDSPOp::FFTUninitialize()
7531 {
7532 #if defined(DSP_IPP)
7533 if (bFFTInitialized)
7534 {
7535 if (bRealTransform)
7536 {
7537 ippsFFTFree_R_32f((IppsFFTSpec_R_32f *) vpSTfrm);
7538 ippsFFTFree_R_64f((IppsFFTSpec_R_64f *) vpDTfrm);
7539 }
7540 else
7541 {
7542 ippsFFTFree_C_32f((IppsFFTSpec_C_32f *) vpSTfrm);
7543 ippsFFTFree_C_64f((IppsFFTSpec_C_64f *) vpDTfrm);
7544 }
7545 }
7546 #elif defined(DSP_USE_FFTW)
7547 if (bFFTInitialized)
7548 {
7549 fftwf_destroy_plan(fftwpSPlan);
7550 fftwf_destroy_plan(fftwpSIPlan);
7551 fftw_destroy_plan(fftwpDPlan);
7552 fftw_destroy_plan(fftwpDIPlan);
7553 }
7554 #else
7555 // NOP
7556 #endif
7557 SBitRevWork.Free();
7558 DBitRevWork.Free();
7559 SCosSinTable.Free();
7560 DCosSinTable.Free();
7561 FFTBuf.Free();
7562 bFFTInitialized = false;
7563 }
7564
7565
FFTi(stpSCplx spDest,float * fpSrc)7566 void clDSPOp::FFTi(stpSCplx spDest, float *fpSrc)
7567 {
7568 #if defined(DSP_IPP)
7569 ippsFFTFwd_RToCCS_32f(fpSrc, (Ipp32f *) spDest,
7570 (IppsFFTSpec_R_32f *) vpSTfrm, SBitRevWork);
7571 #elif defined(DSP_USE_FFTW)
7572 Mul(fpSrc, fFFTScale, lFFTLength);
7573 fftwf_execute_dft_r2c(fftwpSPlan, fpSrc, (fftwf_complex *) spDest);
7574 #else
7575 long lLoopCntr;
7576 long lMax;
7577
7578 Mul(fpSrc, fFFTScale, lFFTLength);
7579 Tfrm.rdft(lFFTLength, 1, fpSrc, lpSBitRevWork, fpCosSinTable);
7580 lMax = lFFTLength / 2 - 1;
7581 spDest[0].R = fpSrc[0];
7582 spDest[0].I = 0.0F;
7583 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7584 {
7585 spDest[lLoopCntr].R = fpSrc[lLoopCntr * 2];
7586 spDest[lLoopCntr].I = fpSrc[lLoopCntr * 2 + 1];
7587 }
7588 spDest[lMax + 1].R = fpSrc[1];
7589 spDest[lMax + 1].I = 0.0F;
7590 #endif
7591 }
7592
7593
FFTi(stpDCplx spDest,double * dpSrc)7594 void clDSPOp::FFTi(stpDCplx spDest, double *dpSrc)
7595 {
7596 #if defined(DSP_IPP)
7597 ippsFFTFwd_RToCCS_64f(dpSrc, (Ipp64f *) spDest,
7598 (IppsFFTSpec_R_64f *) vpDTfrm, DBitRevWork);
7599 #elif defined(DSP_USE_FFTW)
7600 Mul(dpSrc, dFFTScale, lFFTLength);
7601 fftw_execute_dft_r2c(fftwpDPlan, dpSrc, (fftw_complex *) spDest);
7602 #else
7603 long lLoopCntr;
7604 long lMax;
7605
7606 Mul(dpSrc, dFFTScale, lFFTLength);
7607 Tfrm.rdft(lFFTLength, 1, dpSrc, lpDBitRevWork, dpCosSinTable);
7608 lMax = lFFTLength / 2 - 1;
7609 spDest[0].R = dpSrc[0];
7610 spDest[0].I = 0.0;
7611 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7612 {
7613 spDest[lLoopCntr].R = dpSrc[lLoopCntr * 2];
7614 spDest[lLoopCntr].I = dpSrc[lLoopCntr * 2 + 1];
7615 }
7616 spDest[lMax + 1].R = dpSrc[1];
7617 spDest[lMax + 1].I = 0.0;
7618 #endif
7619 }
7620
7621
FFTo(stpSCplx spDest,const float * fpSrc)7622 void clDSPOp::FFTo(stpSCplx spDest, const float *fpSrc)
7623 {
7624 #if defined(DSP_IPP)
7625 ippsFFTFwd_RToCCS_32f(fpSrc, (Ipp32f *) spDest,
7626 (IppsFFTSpec_R_32f *) vpSTfrm, SBitRevWork);
7627 #elif defined(DSP_USE_FFTW)
7628 float *fpFFTBuf;
7629
7630 fpFFTBuf = FFTBuf;
7631 Mul(fpFFTBuf, fpSrc, fFFTScale, lFFTLength);
7632 fftwf_execute_dft_r2c(fftwpSPlan, fpFFTBuf, (fftwf_complex *) spDest);
7633 #else
7634 long lLoopCntr;
7635 long lMax;
7636 float *fpFFTBuf;
7637
7638 fpFFTBuf = FFTBuf;
7639 Mul(fpFFTBuf, fpSrc, fFFTScale, lFFTLength);
7640 Tfrm.rdft(lFFTLength, 1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7641 lMax = lFFTLength / 2 - 1;
7642 spDest[0].R = fpFFTBuf[0];
7643 spDest[0].I = 0.0F;
7644 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7645 {
7646 spDest[lLoopCntr].R = fpFFTBuf[lLoopCntr * 2];
7647 spDest[lLoopCntr].I = fpFFTBuf[lLoopCntr * 2 + 1];
7648 }
7649 spDest[lMax + 1].R = fpFFTBuf[1];
7650 spDest[lMax + 1].I = 0.0F;
7651 #endif
7652 }
7653
7654
FFTo(stpDCplx spDest,const double * dpSrc)7655 void clDSPOp::FFTo(stpDCplx spDest, const double *dpSrc)
7656 {
7657 #if defined(DSP_IPP)
7658 ippsFFTFwd_RToCCS_64f(dpSrc, (Ipp64f *) spDest,
7659 (IppsFFTSpec_R_64f *) vpDTfrm, DBitRevWork);
7660 #elif defined(DSP_USE_FFTW)
7661 double *dpFFTBuf;
7662
7663 dpFFTBuf = FFTBuf;
7664 Mul(dpFFTBuf, dpSrc, dFFTScale, lFFTLength);
7665 fftw_execute_dft_r2c(fftwpDPlan, dpFFTBuf, (fftw_complex *) spDest);
7666 #else
7667 long lLoopCntr;
7668 long lMax;
7669 double *dpFFTBuf;
7670
7671 dpFFTBuf = FFTBuf;
7672 Mul(dpFFTBuf, dpSrc, dFFTScale, lFFTLength);
7673 Tfrm.rdft(lFFTLength, 1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7674 lMax = lFFTLength / 2 - 1;
7675 spDest[0].R = dpFFTBuf[0];
7676 spDest[0].I = 0.0;
7677 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7678 {
7679 spDest[lLoopCntr].R = dpFFTBuf[lLoopCntr * 2];
7680 spDest[lLoopCntr].I = dpFFTBuf[lLoopCntr * 2 + 1];
7681 }
7682 spDest[lMax + 1].R = dpFFTBuf[1];
7683 spDest[lMax + 1].I = 0.0;
7684 #endif
7685 }
7686
7687
FFTo(stpSCplx spDest,const stpSCplx spSrc)7688 void clDSPOp::FFTo(stpSCplx spDest, const stpSCplx spSrc)
7689 {
7690 #if defined(DSP_IPP)
7691 ippsFFTFwd_CToC_32fc((Ipp32fc *) spSrc, (Ipp32fc *) spDest,
7692 (IppsFFTSpec_C_32fc *) vpSTfrm, SBitRevWork);
7693 #elif defined(DSP_USE_FFTW)
7694 Mul((float *) FFTBuf, (const float *) spSrc, fFFTScale, lFFTLength * 2);
7695 fftwf_execute_dft(fftwpSPlan, FFTBuf, (fftwf_complex *) spDest);
7696 #else
7697 long lLoopCntr;
7698 float *fpFFTBuf;
7699
7700 fpFFTBuf = FFTBuf;
7701 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7702 {
7703 fpFFTBuf[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7704 fpFFTBuf[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7705 }
7706 Mul(fpFFTBuf, fFFTScale, lFFTLength * 2);
7707 Tfrm.cdft(lFFTLength * 2, 1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7708 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7709 {
7710 spDest[lLoopCntr].R = fpFFTBuf[lLoopCntr * 2];
7711 spDest[lLoopCntr].I = fpFFTBuf[lLoopCntr * 2 + 1];
7712 }
7713 #endif
7714 }
7715
7716
FFTo(stpDCplx spDest,const stpDCplx spSrc)7717 void clDSPOp::FFTo(stpDCplx spDest, const stpDCplx spSrc)
7718 {
7719 #if defined(DSP_IPP)
7720 ippsFFTFwd_CToC_64fc((Ipp64fc *) spSrc, (Ipp64fc *) spDest,
7721 (IppsFFTSpec_C_64fc *) vpDTfrm, DBitRevWork);
7722 #elif defined(DSP_USE_FFTW)
7723 Mul((double *) FFTBuf, (const double *) spSrc, dFFTScale, lFFTLength * 2);
7724 fftw_execute_dft(fftwpDPlan, FFTBuf, (fftw_complex *) spDest);
7725 #else
7726 long lLoopCntr;
7727 double *dpFFTBuf;
7728
7729 dpFFTBuf = FFTBuf;
7730 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7731 {
7732 dpFFTBuf[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7733 dpFFTBuf[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7734 }
7735 Mul(dpFFTBuf, dFFTScale, lFFTLength * 2);
7736 Tfrm.cdft(lFFTLength * 2, 1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7737 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7738 {
7739 spDest[lLoopCntr].R = dpFFTBuf[lLoopCntr * 2];
7740 spDest[lLoopCntr].I = dpFFTBuf[lLoopCntr * 2 + 1];
7741 }
7742 #endif
7743 }
7744
7745
IFFTo(float * fpDest,const stpSCplx spSrc)7746 void clDSPOp::IFFTo(float *fpDest, const stpSCplx spSrc)
7747 {
7748 #if defined(DSP_IPP)
7749 ippsFFTInv_CCSToR_32f((Ipp32f *) spSrc, fpDest,
7750 (IppsFFTSpec_R_32f *) vpSTfrm, SBitRevWork);
7751 #elif defined(DSP_USE_FFTW)
7752 fftwf_execute_dft_c2r(fftwpSIPlan, (fftwf_complex *) spSrc, fpDest);
7753 #else
7754 long lLoopCntr;
7755 long lMax;
7756
7757 lMax = lFFTLength / 2 - 1;
7758 fpDest[0] = spSrc[0].R;
7759 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7760 {
7761 fpDest[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7762 fpDest[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7763 }
7764 fpDest[1] = spSrc[lMax + 1].R;
7765 Tfrm.rdft(lFFTLength, -1, fpDest, lpSBitRevWork, fpCosSinTable);
7766 #endif
7767 }
7768
7769
IFFTo(double * dpDest,const stpDCplx spSrc)7770 void clDSPOp::IFFTo(double *dpDest, const stpDCplx spSrc)
7771 {
7772 #if defined(DSP_IPP)
7773 ippsFFTInv_CCSToR_64f((Ipp64f *) spSrc, dpDest,
7774 (IppsFFTSpec_R_64f *) vpDTfrm, DBitRevWork);
7775 #elif defined(DSP_USE_FFTW)
7776 fftw_execute_dft_c2r(fftwpDIPlan, (fftw_complex *) spSrc, dpDest);
7777 #else
7778 long lLoopCntr;
7779 long lMax;
7780
7781 lMax = lFFTLength / 2 - 1;
7782 dpDest[0] = spSrc[0].R;
7783 for (lLoopCntr = 1; lLoopCntr <= lMax; lLoopCntr++)
7784 {
7785 dpDest[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7786 dpDest[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7787 }
7788 dpDest[1] = spSrc[lMax + 1].R;
7789 Tfrm.rdft(lFFTLength, -1, dpDest, lpDBitRevWork, dpCosSinTable);
7790 #endif
7791 }
7792
7793
IFFTo(stpSCplx spDest,const stpSCplx spSrc)7794 void clDSPOp::IFFTo(stpSCplx spDest, const stpSCplx spSrc)
7795 {
7796 #if defined(DSP_IPP)
7797 ippsFFTInv_CToC_32fc((Ipp32fc *) spSrc, (Ipp32fc *) spDest,
7798 (IppsFFTSpec_C_32fc *) vpSTfrm, SBitRevWork);
7799 #elif defined(DSP_USE_FFTW)
7800 fftwf_execute_dft(fftwpSIPlan, (fftwf_complex *) spSrc,
7801 (fftwf_complex *) spDest);
7802 #else
7803 long lLoopCntr;
7804 float fScale;
7805 float *fpFFTBuf;
7806
7807 fpFFTBuf = FFTBuf;
7808 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7809 {
7810 fpFFTBuf[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7811 fpFFTBuf[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7812 }
7813 Tfrm.cdft(lFFTLength * 2, -1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7814 fScale = 1.0F / (float) lFFTLength;
7815 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7816 {
7817 spDest[lLoopCntr].R = fpFFTBuf[lLoopCntr * 2] * fScale;
7818 spDest[lLoopCntr].I = fpFFTBuf[lLoopCntr * 2 + 1] * fScale;
7819 }
7820 #endif
7821 }
7822
7823
IFFTo(stpDCplx spDest,const stpDCplx spSrc)7824 void clDSPOp::IFFTo(stpDCplx spDest, const stpDCplx spSrc)
7825 {
7826 #if defined(DSP_IPP)
7827 ippsFFTInv_CToC_64fc((Ipp64fc *) spSrc, (Ipp64fc *) spDest,
7828 (IppsFFTSpec_C_64fc *) vpDTfrm, DBitRevWork);
7829 #elif defined(DSP_USE_FFTW)
7830 fftw_execute_dft(fftwpDIPlan, (fftw_complex *) spSrc,
7831 (fftw_complex *) spDest);
7832 #else
7833 long lLoopCntr;
7834 double dScale;
7835 double *dpFFTBuf;
7836
7837 dpFFTBuf = FFTBuf;
7838 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7839 {
7840 dpFFTBuf[lLoopCntr * 2] = spSrc[lLoopCntr].R;
7841 dpFFTBuf[lLoopCntr * 2 + 1] = spSrc[lLoopCntr].I;
7842 }
7843 Tfrm.cdft(lFFTLength * 2, -1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7844 dScale = 1.0 / (double) lFFTLength;
7845 for (lLoopCntr = 0; lLoopCntr < lFFTLength; lLoopCntr++)
7846 {
7847 spDest[lLoopCntr].R = dpFFTBuf[lLoopCntr * 2] * dScale;
7848 spDest[lLoopCntr].I = dpFFTBuf[lLoopCntr * 2 + 1] * dScale;
7849 }
7850 #endif
7851 }
7852
7853
DCTInitialize(long lSize)7854 void clDSPOp::DCTInitialize (long lSize)
7855 {
7856 float *fpFFTBuf;
7857 double *dpFFTBuf;
7858 clDSPAlloc FFTBufS(lSize * sizeof(float));
7859 clDSPAlloc FFTBufD(lSize * sizeof(double));
7860
7861 fpFFTBuf = FFTBufS;
7862 dpFFTBuf = FFTBufD;
7863 fFFTScale = 2.0F / (float) lSize;
7864 dFFTScale = 2.0 / (double) lSize;
7865 lpSBitRevWork = (long *)
7866 SBitRevWork.Size(((size_t) ceil(2.0 + sqrt(lSize / 2))) * sizeof(long));
7867 lpDBitRevWork = (long *)
7868 DBitRevWork.Size(((size_t) ceil(2.0 + sqrt(lSize / 2))) * sizeof(long));
7869 fpCosSinTable = (float *)
7870 SCosSinTable.Size((lSize * 5 / 4) * sizeof(float));
7871 dpCosSinTable = (double *)
7872 DCosSinTable.Size((lSize * 5 / 4) * sizeof(double));
7873 lpSBitRevWork[0] = 0;
7874 lpSBitRevWork[1] = 0;
7875 lpDBitRevWork[0] = 0;
7876 lpDBitRevWork[1] = 0;
7877 Tfrm.ddct(lSize, 1, fpFFTBuf, lpSBitRevWork, fpCosSinTable);
7878 Tfrm.ddct(lSize, 1, dpFFTBuf, lpDBitRevWork, dpCosSinTable);
7879 FFTBuf.Size(lSize * sizeof(double));
7880
7881 bFFTInitialized = true;
7882 lFFTLength = lSize;
7883 }
7884
7885
DCTUninitialize()7886 void clDSPOp::DCTUninitialize ()
7887 {
7888 SBitRevWork.Free();
7889 DBitRevWork.Free();
7890 SCosSinTable.Free();
7891 DCosSinTable.Free();
7892 FFTBuf.Free();
7893 bFFTInitialized = false;
7894 }
7895
7896
DCTi(float * fpVect)7897 void clDSPOp::DCTi (float *fpVect)
7898 {
7899 Tfrm.ddct(lFFTLength, 1, fpVect, lpSBitRevWork, fpCosSinTable);
7900 }
7901
7902
DCTi(double * dpVect)7903 void clDSPOp::DCTi (double *dpVect)
7904 {
7905 Tfrm.ddct(lFFTLength, 1, dpVect, lpDBitRevWork, dpCosSinTable);
7906 }
7907
7908
DCTo(float * fpDest,const float * fpSrc)7909 void clDSPOp::DCTo (float *fpDest, const float *fpSrc)
7910 {
7911 Copy(fpDest, fpSrc, lFFTLength);
7912 Tfrm.ddct(lFFTLength, 1, fpDest, lpSBitRevWork, fpCosSinTable);
7913 }
7914
7915
DCTo(double * dpDest,const double * dpSrc)7916 void clDSPOp::DCTo (double *dpDest, const double *dpSrc)
7917 {
7918 Copy(dpDest, dpSrc, lFFTLength);
7919 Tfrm.ddct(lFFTLength, 1, dpDest, lpDBitRevWork, dpCosSinTable);
7920 }
7921
7922
IDCTi(float * fpVect)7923 void clDSPOp::IDCTi (float *fpVect)
7924 {
7925 fpVect[0] *= 0.5F;
7926 Mul(&fpVect[1], fFFTScale, lFFTLength - 1);
7927 Tfrm.ddct(lFFTLength, -1, fpVect, lpSBitRevWork, fpCosSinTable);
7928 }
7929
7930
IDCTi(double * dpVect)7931 void clDSPOp::IDCTi (double *dpVect)
7932 {
7933 dpVect[0] *= 0.5;
7934 Mul(&dpVect[1], dFFTScale, lFFTLength - 1);
7935 Tfrm.ddct(lFFTLength, -1, dpVect, lpDBitRevWork, dpCosSinTable);
7936 }
7937
7938
IDCTo(float * fpDest,const float * fpSrc)7939 void clDSPOp::IDCTo (float *fpDest, const float *fpSrc)
7940 {
7941 fpDest[0] = fpSrc[0] * 0.5F;
7942 Mul(&fpDest[1], &fpSrc[1], fFFTScale, lFFTLength - 1);
7943 Tfrm.ddct(lFFTLength, -1, fpDest, lpSBitRevWork, fpCosSinTable);
7944 }
7945
7946
IDCTo(double * dpDest,const double * dpSrc)7947 void clDSPOp::IDCTo (double *dpDest, const double *dpSrc)
7948 {
7949 dpDest[0] = dpSrc[0] * 0.5;
7950 Mul(&dpDest[1], &dpSrc[1], dFFTScale, lFFTLength - 1);
7951 Tfrm.ddct(lFFTLength, -1, dpDest, lpDBitRevWork, dpCosSinTable);
7952 }
7953
7954
FFTWConvert(stpSCplx spDest,const float * fpSrc,long lLength)7955 void clDSPOp::FFTWConvert(stpSCplx spDest, const float *fpSrc, long lLength)
7956 {
7957 long lLoopCntr;
7958 long lMax;
7959
7960 lMax = lLength / 2;
7961 spDest[0].R = fpSrc[0];
7962 spDest[0].I = 0.0F;
7963 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
7964 {
7965 spDest[lLoopCntr].R = fpSrc[lLoopCntr];
7966 spDest[lLoopCntr].I = fpSrc[lLength - lLoopCntr];
7967 }
7968 spDest[lMax].R = fpSrc[lMax];
7969 spDest[lMax].I = 0.0F;
7970 }
7971
7972
FFTWConvert(stpDCplx spDest,const float * fpSrc,long lLength)7973 void clDSPOp::FFTWConvert(stpDCplx spDest, const float *fpSrc, long lLength)
7974 {
7975 long lLoopCntr;
7976 long lMax;
7977
7978 lMax = lLength / 2;
7979 spDest[0].R = fpSrc[0];
7980 spDest[0].I = 0.0;
7981 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
7982 {
7983 spDest[lLoopCntr].R = fpSrc[lLoopCntr];
7984 spDest[lLoopCntr].I = fpSrc[lLength - lLoopCntr];
7985 }
7986 spDest[lMax].R = fpSrc[lMax];
7987 spDest[lMax].I = 0.0;
7988 }
7989
7990
FFTWConvert(stpSCplx spDest,const double * dpSrc,long lLength)7991 void clDSPOp::FFTWConvert(stpSCplx spDest, const double *dpSrc, long lLength)
7992 {
7993 long lLoopCntr;
7994 long lMax;
7995
7996 lMax = lLength / 2;
7997 spDest[0].R = dpSrc[0];
7998 spDest[0].I = 0.0F;
7999 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8000 {
8001 spDest[lLoopCntr].R = dpSrc[lLoopCntr];
8002 spDest[lLoopCntr].I = dpSrc[lLength - lLoopCntr];
8003 }
8004 spDest[lMax].R = dpSrc[lMax];
8005 spDest[lMax].I = 0.0F;
8006 }
8007
8008
FFTWConvert(stpDCplx spDest,const double * dpSrc,long lLength)8009 void clDSPOp::FFTWConvert(stpDCplx spDest, const double *dpSrc, long lLength)
8010 {
8011 long lLoopCntr;
8012 long lMax;
8013
8014 lMax = lLength / 2;
8015 spDest[0].R = dpSrc[0];
8016 spDest[0].I = 0.0;
8017 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8018 {
8019 spDest[lLoopCntr].R = dpSrc[lLoopCntr];
8020 spDest[lLoopCntr].I = dpSrc[lLength - lLoopCntr];
8021 }
8022 spDest[lMax].R = dpSrc[lMax];
8023 spDest[lMax].I = 0.0;
8024 }
8025
8026
FFTWConvert(float * fpDest,const stpSCplx spSrc,long lLength)8027 void clDSPOp::FFTWConvert(float *fpDest, const stpSCplx spSrc, long lLength)
8028 {
8029 long lLoopCntr;
8030 long lMax;
8031
8032 lMax = lLength / 2;
8033 fpDest[0] = spSrc[0].R;
8034 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8035 {
8036 fpDest[lLoopCntr] = spSrc[lLoopCntr].R;
8037 fpDest[lLength - lLoopCntr] = spSrc[lLoopCntr].I;
8038 }
8039 fpDest[lMax] = spSrc[lMax].R;
8040 }
8041
8042
FFTWConvert(float * fpDest,const stpDCplx spSrc,long lLength)8043 void clDSPOp::FFTWConvert(float *fpDest, const stpDCplx spSrc, long lLength)
8044 {
8045 long lLoopCntr;
8046 long lMax;
8047
8048 lMax = lLength / 2;
8049 fpDest[0] = spSrc[0].R;
8050 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8051 {
8052 fpDest[lLoopCntr] = spSrc[lLoopCntr].R;
8053 fpDest[lLength - lLoopCntr] = spSrc[lLoopCntr].I;
8054 }
8055 fpDest[lMax] = spSrc[lMax].R;
8056 }
8057
8058
FFTWConvert(double * dpDest,const stpSCplx spSrc,long lLength)8059 void clDSPOp::FFTWConvert(double *dpDest, const stpSCplx spSrc, long lLength)
8060 {
8061 long lLoopCntr;
8062 long lMax;
8063
8064 lMax = lLength / 2;
8065 dpDest[0] = spSrc[0].R;
8066 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8067 {
8068 dpDest[lLoopCntr] = spSrc[lLoopCntr].R;
8069 dpDest[lLength - lLoopCntr] = spSrc[lLoopCntr].I;
8070 }
8071 dpDest[lMax] = spSrc[lMax].R;
8072 }
8073
8074
FFTWConvert(double * dpDest,const stpDCplx spSrc,long lLength)8075 void clDSPOp::FFTWConvert(double *dpDest, const stpDCplx spSrc, long lLength)
8076 {
8077 long lLoopCntr;
8078 long lMax;
8079
8080 lMax = lLength / 2;
8081 dpDest[0] = spSrc[0].R;
8082 for (lLoopCntr = 1; lLoopCntr < lMax; lLoopCntr++)
8083 {
8084 dpDest[lLoopCntr] = spSrc[lLoopCntr].R;
8085 dpDest[lLength - lLoopCntr] = spSrc[lLoopCntr].I;
8086 }
8087 dpDest[lMax] = spSrc[lMax].R;
8088 }
8089
8090
8091 /*INLINE double DegToRad (double dSrc)
8092 {
8093 return (M_PI / 180.0) * dSrc;
8094 }*/
8095
8096
8097 /*INLINE double RadToDeg (double dSrc)
8098 {
8099 return (180.0 / M_PI) * dSrc;
8100 }*/
8101
8102