1 #define DUMTAB1SIZE 256
2 #define DUMTAB2SIZE 1024
7 /* sigsqrt - square root good to 8 mantissa bits */
9 static float rsqrt_exptab
[DUMTAB1SIZE
], rsqrt_mantissatab
[DUMTAB2SIZE
];
11 static void init_rsqrt(void)
14 for (i
= 0; i
< DUMTAB1SIZE
; i
++)
17 long l
= (i
? (i
== DUMTAB1SIZE
-1 ? DUMTAB1SIZE
-2 : i
) : 1)<< 23;
19 rsqrt_exptab
[i
] = 1./sqrt(f
);
21 for (i
= 0; i
< DUMTAB2SIZE
; i
++)
23 float f
= 1 + (1./DUMTAB2SIZE
) * i
;
24 rsqrt_mantissatab
[i
] = 1./sqrt(f
);
28 typedef struct sigsqrt
34 static t_class
*sigsqrt_class
;
36 static void *sigsqrt_new(void)
38 t_sigsqrt
*x
= (t_sigsqrt
*)pd_new(sigsqrt_class
);
39 outlet_new(&x
->x_obj
, gensym("signal"));
44 t_int
*sigsqrt_perform(t_int
*w
) /* not static; also used in d_fft.c */
46 float *in
= *(t_float
**)(w
+1), *out
= *(t_float
**)(w
+2);
47 t_int n
= *(t_int
*)(w
+3);
51 long l
= *(long *)(in
++);
52 if (f
< 0) *out
++ = 0;
55 float g
= rsqrt_exptab
[(l
>> 23) & 0xff] *
56 rsqrt_mantissatab
[(l
>> 13) & 0x3ff];
57 *out
++ = f
* (1.5 * g
- 0.5 * g
* g
* g
* f
);
63 static void sigsqrt_dsp(t_sigsqrt
*x
, t_signal
**sp
)
65 dsp_add(sigsqrt_perform
, 3, sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[0]->s_n
);
68 void sqrt_tilde_setup(void)
71 sigsqrt_class
= class_new(gensym("sqrt~"), (t_newmethod
)sigsqrt_new
, 0,
72 sizeof(t_sigsqrt
), 0, 0);
73 class_addcreator(sigsqrt_new
, gensym("q8_sqrt~"), 0); /* old name */
74 CLASS_MAINSIGNALIN(sigsqrt_class
, t_sigsqrt
, x_f
);
75 class_addmethod(sigsqrt_class
, (t_method
)sigsqrt_dsp
, gensym("dsp"), 0);
78 #define DUMTAB1SIZE 256
79 #define DUMTAB2SIZE 1024
84 /* sigsqrt - square root good to 8 mantissa bits */
86 static float rsqrt_exptab
[DUMTAB1SIZE
], rsqrt_mantissatab
[DUMTAB2SIZE
];
88 static void init_rsqrt(void)
91 for (i
= 0; i
< DUMTAB1SIZE
; i
++)
94 long l
= (i
? (i
== DUMTAB1SIZE
-1 ? DUMTAB1SIZE
-2 : i
) : 1)<< 23;
96 rsqrt_exptab
[i
] = 1./sqrt(f
);
98 for (i
= 0; i
< DUMTAB2SIZE
; i
++)
100 float f
= 1 + (1./DUMTAB2SIZE
) * i
;
101 rsqrt_mantissatab
[i
] = 1./sqrt(f
);
105 typedef struct sigsqrt
111 static t_class
*sigsqrt_class
;
113 static void *sigsqrt_new(void)
115 t_sigsqrt
*x
= (t_sigsqrt
*)pd_new(sigsqrt_class
);
116 outlet_new(&x
->x_obj
, gensym("signal"));
121 t_int
*sigsqrt_perform(t_int
*w
) /* not static; also used in d_fft.c */
123 float *in
= *(t_float
**)(w
+1), *out
= *(t_float
**)(w
+2);
124 t_int n
= *(t_int
*)(w
+3);
128 long l
= *(long *)(in
++);
129 if (f
< 0) *out
++ = 0;
132 float g
= rsqrt_exptab
[(l
>> 23) & 0xff] *
133 rsqrt_mantissatab
[(l
>> 13) & 0x3ff];
134 *out
++ = f
* (1.5 * g
- 0.5 * g
* g
* g
* f
);
140 static void sigsqrt_dsp(t_sigsqrt
*x
, t_signal
**sp
)
142 dsp_add(sigsqrt_perform
, 3, sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[0]->s_n
);
145 void sqrt_tilde_setup(void)
148 sigsqrt_class
= class_new(gensym("sqrt~"), (t_newmethod
)sigsqrt_new
, 0,
149 sizeof(t_sigsqrt
), 0, 0);
150 class_addcreator(sigsqrt_new
, gensym("q8_sqrt~"), 0); /* old name */
151 CLASS_MAINSIGNALIN(sigsqrt_class
, t_sigsqrt
, x_f
);
152 class_addmethod(sigsqrt_class
, (t_method
)sigsqrt_dsp
, gensym("dsp"), 0);