Add the identifying header
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / noise~.c
blobeca2fc430ed92b31053e6bb289377ab04703567f
1 #include "../src/m_pd.h"
2 #include <../src/m_fixed.h>
5 static t_class *noise_class;
7 typedef struct _noise
9 t_object x_obj;
10 int x_val;
11 } t_noise;
13 static void *noise_new(void)
15 t_noise *x = (t_noise *)pd_new(noise_class);
16 static int init = 307;
17 x->x_val = (init *= 1319);
18 outlet_new(&x->x_obj, gensym("signal"));
19 return (x);
22 static t_int *noise_perform(t_int *w)
24 t_sample *out = (t_sample *)(w[1]);
25 int *vp = (int *)(w[2]);
26 int n = (int)(w[3]);
27 int val = *vp;
28 while (n--)
30 #ifndef FIXEDPOINT
31 *out++ = ((t_sample)((val & 0x7fffffff) - 0x40000000)) *
32 (t_sample)(1.0 / 0x40000000);
33 #else
34 *out++=val>>(32-fix1);
35 #endif
36 val = val * 435898247 + 382842987;
39 *vp = val;
40 return (w+4);
43 static void noise_dsp(t_noise *x, t_signal **sp)
45 dsp_add(noise_perform, 3, sp[0]->s_vec, &x->x_val, sp[0]->s_n);
48 void noise_tilde_setup(void)
50 noise_class = class_new(gensym("noise~"), (t_newmethod)noise_new, 0,
51 sizeof(t_noise), 0, 0);
52 class_addmethod(noise_class, (t_method)noise_dsp, gensym("dsp"), 0);