2010-05-25 15:03:14 -04:00
|
|
|
#ifndef __DESA2_H__
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <float.h>
|
|
|
|
#define ISNAN(x) (!!(_isnan(x)))
|
|
|
|
#else
|
|
|
|
#define ISNAN(x) (isnan(x))
|
|
|
|
#endif
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "desa2.h"
|
|
|
|
#include "options.h"
|
|
|
|
|
2016-03-20 23:58:45 +00:00
|
|
|
#ifdef AVMD_FAST_MATH
|
2010-05-25 15:03:14 -04:00
|
|
|
#include "fast_acosf.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern double desa2(circ_buffer_t *b, size_t i)
|
|
|
|
{
|
|
|
|
double d;
|
|
|
|
double n;
|
|
|
|
double x0;
|
|
|
|
double x1;
|
|
|
|
double x2;
|
|
|
|
double x3;
|
|
|
|
double x4;
|
|
|
|
double x2sq;
|
|
|
|
double result;
|
|
|
|
|
|
|
|
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-02-04 23:14:19 +00:00
|
|
|
if (d == 0.0) return 0.0;
|
2010-05-25 15:03:14 -04:00
|
|
|
|
|
|
|
n = ((x2sq) - (x0 * x4)) - ((x1 * x1) - (x0 * x2)) - ((x3 * x3) - (x2 * x4));
|
|
|
|
|
|
|
|
|
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-02-04 23:14:19 +00:00
|
|
|
if (ISNAN(result)) result = 0.0;
|
2010-05-25 15:03:14 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|