aboutsummaryrefslogtreecommitdiff
path: root/logistictilde.c
blob: 72aa59237a1d5f3998ec4c12c4134f9b3a25fd08 (plain)
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
/*
* Trying logistic function for audio processing
*/

#include "m_pd.h"

static t_class *logistic_tilde_class;

typedef struct _logistic_tilde {
t_object x_obj;
t_sample f_logistic;
t_sample f;
t_float a;
} t_logistic_tilde;

t_sample logistic(t_sample x,t_float a) {
	return a*x*(1-x);
}

t_int *logistic_tilde_perform(t_int *w)
{
t_logistic_tilde *x = (t_logistic_tilde *)(w[1]);
//t_sample *in1 = (t_sample *)(w[2]);
//t_sample *in2 = (t_sample *)(w[3]);
t_sample *out = (t_sample *)(w[2]);
int n = (int)(w[3]);
//t_sample f_logistic = (x->f_logistic<0)?0.0:(x->f_logistic>1)?1.0:x->f_logistic;
while (n--){
	  x->f_logistic = logistic(x->f_logistic,x->a);
	 *out++ = x->f_logistic - 0.5;
	 }

return (w+4);
}



void logistic_tilde_dsp(t_logistic_tilde *x, t_signal **sp)
{
dsp_add(logistic_tilde_perform, 3, x,
sp[0]->s_vec, 
//sp[1]->s_vec, 
//sp[2]->s_vec,
sp[0]->s_n);
}

void *logistic_tilde_new(t_floatarg f)
{
t_logistic_tilde *x = (t_logistic_tilde *)pd_new(logistic_tilde_class);
x->f_logistic = 0.5;
x->a = 3.7;
if (x->a < 0) x->a = 1;
if (x->a > 4) x->a = 4;
//inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
floatinlet_new (&x->x_obj, &x->a);
outlet_new(&x->x_obj, &s_signal);
return (void *)x;
}