Commit 2d590812 authored by Pranay Gupta's avatar Pranay Gupta

double precision changes to pique and pd~ class

parent 30c5f8a3
Pipeline #1358 failed with stage
in 0 seconds
......@@ -39,6 +39,7 @@ typedef int socklen_t;
#include "ext_proto.h"
#include "ext_obex.h"
typedef float t_float;
typedef double t_floatarg;
#define w_symbol w_sym
#define A_SYMBOL A_SYM
......
......@@ -19,11 +19,11 @@ typedef struct _pique
{
t_object x_obj;
int x_n;
float x_errthresh;
float *x_freq;
float *x_amp;
float *x_ampre;
float *x_ampim;
t_float x_errthresh;
t_float *x_freq;
t_float *x_amp;
t_float *x_ampre;
t_float *x_ampim;
} t_pique;
static void *pique_new(t_floatarg f)
......@@ -41,9 +41,9 @@ static void *pique_new(t_floatarg f)
return (x);
}
static float hanning(float pidetune, float sinpidetune)
static t_float hanning(t_float pidetune, t_float sinpidetune)
{
float pi = 3.14159;
t_float pi = 3.14159;
if (pidetune < 0.01 && pidetune > -0.01) return (1);
else if (pidetune > 3.14 && pidetune < 3.143) return (0.5);
else if (pidetune < -3.14 && pidetune > -3.143) return (0.5);
......@@ -51,21 +51,21 @@ static float hanning(float pidetune, float sinpidetune)
(sinpidetune/(pidetune+pi) + sinpidetune/(pidetune-pi)));
}
static float peakerror(t_word *fpreal, t_word *fpimag, float pidetune,
float norm, float peakreal, float peakimag)
static t_float peakerror(t_word *fpreal, t_word *fpimag, t_float pidetune,
t_float norm, t_float peakreal, t_float peakimag)
{
float sinpidetune = sin(pidetune);
float cospidetune = cos(pidetune);
float windowshould = hanning(pidetune, sinpidetune);
float realshould = windowshould * (
t_float sinpidetune = sin(pidetune);
t_float cospidetune = cos(pidetune);
t_float windowshould = hanning(pidetune, sinpidetune);
t_float realshould = windowshould * (
peakreal * cospidetune + peakimag * sinpidetune);
float imagshould = windowshould * (
t_float imagshould = windowshould * (
peakimag * cospidetune - peakreal * sinpidetune);
float realgot = norm * (fpreal[0].w_float -
t_float realgot = norm * (fpreal[0].w_float -
0.5 * (fpreal[1].w_float + fpreal[-1].w_float));
float imaggot = norm * (fpimag[0].w_float -
t_float imaggot = norm * (fpimag[0].w_float -
0.5 * (fpimag[1].w_float + fpimag[-1].w_float));
float realdev = realshould - realgot, imagdev = imagshould - imaggot;
t_float realdev = realshould - realgot, imagdev = imagshould - imaggot;
/* post("real %f->%f; imag %f->%f", realshould, realgot,
imagshould, imaggot); */
......@@ -74,16 +74,16 @@ static float peakerror(t_word *fpreal, t_word *fpimag, float pidetune,
static void pique_doit(int npts, t_word *fpreal, t_word *fpimag,
int npeak, int *nfound, t_float *fpfreq, t_float *fpamp,
t_float *fpampre, t_float *fpampim, float errthresh)
t_float *fpampre, t_float *fpampim, t_float errthresh)
{
float srate = sys_getsr(); /* not sure how to get this correctly */
float oneovern = 1.0/ (float)npts;
float fperbin = srate * oneovern;
float pow1, pow2 = 0, pow3 = 0, pow4 = 0, pow5 = 0;
float re1, re2 = 0, re3 = fpreal->w_float;
float im1, im2 = 0, im3 = 0, powthresh, relativeerror;
t_float srate = sys_getsr(); /* not sure how to get this correctly */
t_float oneovern = 1.0/ (t_float)npts;
t_float fperbin = srate * oneovern;
t_float pow1, pow2 = 0, pow3 = 0, pow4 = 0, pow5 = 0;
t_float re1, re2 = 0, re3 = fpreal->w_float;
t_float im1, im2 = 0, im3 = 0, powthresh, relativeerror;
int count, peakcount = 0, n2 = (npts >> 1);
float *fp1, *fp2;
t_float *fp1, *fp2;
t_word *wp1, *wp2;
for (count = n2, wp1 = fpreal, wp2 = fpimag, powthresh = 0;
count--; wp1++, wp2++)
......@@ -92,12 +92,12 @@ static void pique_doit(int npts, t_word *fpreal, t_word *fpimag,
powthresh *= 0.00001;
for (count = 1; count < n2; count++)
{
float windreal, windimag, pi = 3.14159;
float detune, pidetune, sinpidetune, cospidetune,
t_float windreal, windimag, pi = 3.14159;
t_float detune, pidetune, sinpidetune, cospidetune,
ampcorrect, freqout, ampout, ampoutreal, ampoutimag;
float rpeak, rpeaknext, rpeakprev;
float ipeak, ipeaknext, ipeakprev;
float errleft, errright;
t_float rpeak, rpeaknext, rpeakprev;
t_float ipeak, ipeaknext, ipeakprev;
t_float errleft, errright;
fpreal++;
fpimag++;
re1 = re2;
......@@ -140,7 +140,7 @@ static void pique_doit(int npts, t_word *fpreal, t_word *fpimag,
/* if (count < 30) post("detune %f", detune); */
if (detune > 0.7 || detune < -0.7) continue;
/* the frequency is the sum of the bin frequency and detuning */
freqout = fperbin * ((float)(count-3) + detune);
freqout = fperbin * ((t_float)(count-3) + detune);
pidetune = pi * detune;
sinpidetune = sin(pidetune);
cospidetune = cos(pidetune);
......@@ -198,16 +198,16 @@ static void pique_list(t_pique *x, t_symbol *s, int argc, t_atom *argv)
else
{
int nfound, i;
float *fpfreq = x->x_freq;
float *fpamp = x->x_amp;
float *fpampre = x->x_ampre;
float *fpampim = x->x_ampim;
t_float *fpfreq = x->x_freq;
t_float *fpamp = x->x_amp;
t_float *fpampre = x->x_ampre;
t_float *fpampim = x->x_ampim;
pique_doit(npts, fpreal, fpimag, npeak,
&nfound, fpfreq, fpamp, fpampre, fpampim, x->x_errthresh);
for (i = 0; i < nfound; i++, fpamp++, fpfreq++, fpampre++, fpampim++)
{
t_atom at[5];
SETFLOAT(at, (float)i);
SETFLOAT(at, (t_float)i);
SETFLOAT(at+1, *fpfreq);
SETFLOAT(at+2, *fpamp);
SETFLOAT(at+3, *fpampre);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment