Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
nerrons
purr-data
Commits
d5837d3c
Commit
d5837d3c
authored
Jul 21, 2018
by
Jonathan Wilkes
Browse files
Merge branch 'pranay_36/purr-data-pd-l2ork_double_secondary'
parents
30c5f8a3
e61affa0
Changes
2
Hide whitespace changes
Inline
Side-by-side
pd/extra/pd~/pd~.c
View file @
d5837d3c
...
...
@@ -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
...
...
pd/extra/pique/pique.c
View file @
d5837d3c
...
...
@@ -13,17 +13,25 @@ combustible materiel, or as part of any life support system or weapon. */
#pragma warning( disable : 4305 )
#endif
#if PD_FLOATSIZE == 32
#define PI 3.14159
#elif PD_FLOATSIZE == 64
#define PI 3.141592653589793
#else
#error invalid PD_FLOATSIZE must be 32 or 64
#endif
static
t_class
*
pique_class
;
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,31 +49,30 @@ 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
;
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
);
else
return
(
sinpidetune
/
pidetune
-
0
.
5
*
(
sinpidetune
/
(
pidetune
+
pi
)
+
sinpidetune
/
(
pidetune
-
pi
)));
(
sinpidetune
/
(
pidetune
+
+
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 +81,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 +99,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
;
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,8 +147,8 @@ 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
);
pidetune
=
pi
*
detune
;
freqout
=
fperbin
*
((
t_
float
)(
count
-
3
)
+
detune
);
pidetune
=
PI
*
detune
;
sinpidetune
=
sin
(
pidetune
);
cospidetune
=
cos
(
pidetune
);
ampcorrect
=
1
.
0
/
hanning
(
pidetune
,
sinpidetune
);
...
...
@@ -158,9 +165,9 @@ static void pique_doit(int npts, t_word *fpreal, t_word *fpimag,
if
(
errthresh
>
0
)
{
/* post("peak %f %f", freqout, ampout); */
errleft
=
peakerror
(
fpreal
-
4
,
fpimag
-
4
,
pidetune
+
pi
,
errleft
=
peakerror
(
fpreal
-
4
,
fpimag
-
4
,
pidetune
+
PI
,
2
.
*
oneovern
,
ampoutreal
,
ampoutimag
);
errright
=
peakerror
(
fpreal
-
2
,
fpimag
-
2
,
pidetune
-
pi
,
errright
=
peakerror
(
fpreal
-
2
,
fpimag
-
2
,
pidetune
-
PI
,
2
.
*
oneovern
,
ampoutreal
,
ampoutimag
);
relativeerror
=
(
errleft
+
errright
)
/
(
ampout
*
ampout
);
if
(
relativeerror
>
errthresh
)
continue
;
...
...
@@ -198,16 +205,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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment