1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/* (C) Guenter Geiger <geiger@epy.co.at> */
#include <m_pd.h>
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
/* ------------------------ shuffle ----------------------------- */
static t_class *shuffle_class;
typedef struct _shuffle
{
t_object x_obj;
t_float x;
} t_shuffle;
void shuffle_float(t_shuffle *x, t_floatarg f)
{
post("float %f",f);
x->x = f;
}
static t_int *shuffle_perform(t_int *w)
{
t_shuffle* x = (t_shuffle*)(w[1]);
t_float* in1 = (t_float*) w[2];
t_float* in2 = (t_float*) w[3];
t_float* out = (t_float*) w[4];
int n = w[5];
if (x->x <= 0) {
while (n--) {
*out++ = *in1++;
}
return w+6;
}
if (x->x < 0.5) {
t_int index = 1/x->x;
while (n--) {
if (n%index){
*out++ = *in1++;
in2++;
}
else {
*out++ = *in2++;
in1++;
}
}
return w+6;
}
if (x->x > 1.0) {
while (n--) {
*out++ = *in2++;
}
return w+6;
}
if (x->x >= 0.5) {
t_int index = 1/(1.0- x->x);
while (n--) {
if (n%index) {
*out++ = *in2++;
in1++;
}
else {
*out++ = *in1++;
in2++;
}
}
}
return w+6;
}
static void shuffle_dsp(t_shuffle *x, t_signal **sp)
{
dsp_add(shuffle_perform, 5, x, sp[0]->s_vec,
sp[1]->s_vec,sp[2]->s_vec, sp[0]->s_n);
}
static void *shuffle_new()
{
t_shuffle *x = (t_shuffle *)pd_new(shuffle_class);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
outlet_new(&x->x_obj, gensym("signal"));
return (x);
}
void shuffle_setup(void)
{
shuffle_class = class_new(gensym("shuffle~"), (t_newmethod)shuffle_new, 0,
sizeof(t_shuffle), 0,0);
class_addmethod(shuffle_class, nullfn, gensym("signal"), 0);
class_addmethod(shuffle_class, (t_method) shuffle_dsp, gensym("dsp"), 0);
class_addfloat(shuffle_class,shuffle_float);
}
|