aboutsummaryrefslogtreecommitdiff
path: root/decimator.c
blob: d7f93f37f35b4895db73238da4f6264b753c464a (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
60
61
62
63
64
65
66
#include "defines.h"

/*--------------- decimator ---------------*/

static t_class *decimator_class;

typedef struct _decimator
{
    t_object x_obj;
	int m_state;
	int m_factor;
} t_decimator;

static void decimator_perform(t_decimator *x, t_float in)
{
	if (!x->m_state)
	{
		outlet_float(x->x_obj.ob_outlet, in);
		x->m_state=x->m_factor;
	}
	else
	{
		x->m_state--;
	}

}

static void decimator_setFactor(t_decimator *x, t_float factor)
{
	x->m_factor=(int)factor - 1;
}

static void decimator_clear(t_decimator *x)
{
	x->m_state=0;
}


static void *decimator_new(t_float factor)
{

	t_decimator *x=(t_decimator *)pd_new(decimator_class);
	outlet_new(&x->x_obj, gensym("float"));

	if (factor<1) factor=2;

	decimator_setFactor(x, factor);
	decimator_clear(x);
	return (void *)x;
}


void decimator_setup(void)
{
    decimator_class = class_new(gensym("decimator"),
    	(t_newmethod)decimator_new, 0,
		sizeof(t_decimator), 
		CLASS_DEFAULT,
	    A_DEFFLOAT, 0);
    class_addfloat(decimator_class, (t_method)decimator_perform);
	class_addmethod(decimator_class, (t_method)decimator_clear,
    	gensym("clear"), A_GIMME, NULL);
	class_addmethod(decimator_class, (t_method)decimator_setFactor,
    	gensym("factor"), A_DEFFLOAT, NULL);
}