diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/noise~.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/intern/noise~.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/noise~.c b/apps/plugins/pdbox/PDa/intern/noise~.c new file mode 100644 index 0000000000..2f61b9d395 --- /dev/null +++ b/apps/plugins/pdbox/PDa/intern/noise~.c | |||
@@ -0,0 +1,110 @@ | |||
1 | #include <m_pd.h> | ||
2 | #include <m_fixed.h> | ||
3 | |||
4 | |||
5 | static t_class *noise_class; | ||
6 | |||
7 | typedef struct _noise | ||
8 | { | ||
9 | t_object x_obj; | ||
10 | int x_val; | ||
11 | } t_noise; | ||
12 | |||
13 | static void *noise_new(void) | ||
14 | { | ||
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); | ||
20 | } | ||
21 | |||
22 | static t_int *noise_perform(t_int *w) | ||
23 | { | ||
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--) | ||
29 | { | ||
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; | ||
37 | |||
38 | } | ||
39 | *vp = val; | ||
40 | return (w+4); | ||
41 | } | ||
42 | |||
43 | static void noise_dsp(t_noise *x, t_signal **sp) | ||
44 | { | ||
45 | dsp_add(noise_perform, 3, sp[0]->s_vec, &x->x_val, sp[0]->s_n); | ||
46 | } | ||
47 | |||
48 | void noise_tilde_setup(void) | ||
49 | { | ||
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); | ||
53 | } | ||
54 | |||
55 | |||
56 | #include <m_pd.h> | ||
57 | #include <m_fixed.h> | ||
58 | |||
59 | |||
60 | static t_class *noise_class; | ||
61 | |||
62 | typedef struct _noise | ||
63 | { | ||
64 | t_object x_obj; | ||
65 | int x_val; | ||
66 | } t_noise; | ||
67 | |||
68 | static void *noise_new(void) | ||
69 | { | ||
70 | t_noise *x = (t_noise *)pd_new(noise_class); | ||
71 | static int init = 307; | ||
72 | x->x_val = (init *= 1319); | ||
73 | outlet_new(&x->x_obj, gensym("signal")); | ||
74 | return (x); | ||
75 | } | ||
76 | |||
77 | static t_int *noise_perform(t_int *w) | ||
78 | { | ||
79 | t_sample *out = (t_sample *)(w[1]); | ||
80 | int *vp = (int *)(w[2]); | ||
81 | int n = (int)(w[3]); | ||
82 | int val = *vp; | ||
83 | while (n--) | ||
84 | { | ||
85 | #ifndef FIXEDPOINT | ||
86 | *out++ = ((t_sample)((val & 0x7fffffff) - 0x40000000)) * | ||
87 | (t_sample)(1.0 / 0x40000000); | ||
88 | #else | ||
89 | *out++=val>>(32-fix1); | ||
90 | #endif | ||
91 | val = val * 435898247 + 382842987; | ||
92 | |||
93 | } | ||
94 | *vp = val; | ||
95 | return (w+4); | ||
96 | } | ||
97 | |||
98 | static void noise_dsp(t_noise *x, t_signal **sp) | ||
99 | { | ||
100 | dsp_add(noise_perform, 3, sp[0]->s_vec, &x->x_val, sp[0]->s_n); | ||
101 | } | ||
102 | |||
103 | void noise_tilde_setup(void) | ||
104 | { | ||
105 | noise_class = class_new(gensym("noise~"), (t_newmethod)noise_new, 0, | ||
106 | sizeof(t_noise), 0, 0); | ||
107 | class_addmethod(noise_class, (t_method)noise_dsp, gensym("dsp"), 0); | ||
108 | } | ||
109 | |||
110 | |||