2016-06-24 18:36:55 +01:00
|
|
|
/*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Eric des Courtis <eric.des.courtis@benbria.com>
|
|
|
|
* Piotr Gregor <piotrgregor@rsyncme.org>
|
|
|
|
*/
|
2016-03-27 20:39:53 +01:00
|
|
|
|
2010-05-25 15:03:14 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <float.h>
|
|
|
|
#define ISNAN(x) (!!(_isnan(x)))
|
2016-05-12 01:09:12 +01:00
|
|
|
#define ISINF(x) (isinf(x))
|
2010-05-25 15:03:14 -04:00
|
|
|
#else
|
2016-05-12 01:09:12 +01:00
|
|
|
int __isnan(double);
|
|
|
|
#define ISNAN(x) (__isnan(x))
|
|
|
|
#define ISINF(x) (__isinf(x))
|
2010-05-25 15:03:14 -04:00
|
|
|
#endif
|
2016-03-29 20:53:31 +01:00
|
|
|
#include "avmd_buffer.h"
|
|
|
|
#include "avmd_desa2.h"
|
|
|
|
#include "avmd_options.h"
|
2010-05-25 15:03:14 -04:00
|
|
|
|
2016-03-20 23:58:45 +00:00
|
|
|
#ifdef AVMD_FAST_MATH
|
2016-03-29 20:53:31 +01:00
|
|
|
#include "avmd_fast_acosf.h"
|
2010-05-25 15:03:14 -04:00
|
|
|
#endif
|
|
|
|
|
2016-07-04 16:26:08 +01:00
|
|
|
|
|
|
|
double avmd_desa2(circ_buffer_t *b, size_t i, double *amplitude) {
|
2010-05-25 15:03:14 -04:00
|
|
|
double d;
|
|
|
|
double n;
|
|
|
|
double x0;
|
|
|
|
double x1;
|
|
|
|
double x2;
|
|
|
|
double x3;
|
|
|
|
double x4;
|
|
|
|
double x2sq;
|
|
|
|
double result;
|
2016-07-04 16:26:08 +01:00
|
|
|
double PSI_Xn, PSI_Yn, NEEDED;
|
2010-05-25 15:03:14 -04:00
|
|
|
|
|
|
|
x0 = GET_SAMPLE((b), (i));
|
|
|
|
x1 = GET_SAMPLE((b), ((i) + 1));
|
|
|
|
x2 = GET_SAMPLE((b), ((i) + 2));
|
|
|
|
x3 = GET_SAMPLE((b), ((i) + 3));
|
|
|
|
x4 = GET_SAMPLE((b), ((i) + 4));
|
|
|
|
|
|
|
|
x2sq = x2 * x2;
|
|
|
|
d = 2.0 * ((x2sq) - (x1 * x3));
|
2016-07-04 16:26:08 +01:00
|
|
|
if (d == 0.0) {
|
|
|
|
*amplitude = 0.0;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
PSI_Xn = ((x2sq) - (x0 * x4));
|
|
|
|
NEEDED = ((x1 * x1) - (x0 * x2)) + ((x3 * x3) - (x2 * x4));
|
|
|
|
n = ((x2sq) - (x0 * x4)) - NEEDED;
|
|
|
|
PSI_Yn = NEEDED + PSI_Xn;
|
2010-05-25 15:03:14 -04:00
|
|
|
|
2016-03-20 23:58:45 +00:00
|
|
|
#ifdef AVMD_FAST_MATH
|
2010-05-25 15:03:14 -04:00
|
|
|
result = 0.5 * (double)fast_acosf((float)n/d);
|
|
|
|
#else
|
|
|
|
result = 0.5 * acos(n/d);
|
|
|
|
#endif
|
|
|
|
|
2016-07-04 16:26:08 +01:00
|
|
|
if (ISNAN(result)) {
|
|
|
|
result = 0.0;
|
|
|
|
}
|
|
|
|
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
|
2010-05-25 15:03:14 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|