File: lmax.c

package info (click to toggle)
pd-smlib 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 828 kB
  • ctags: 642
  • sloc: ansic: 2,982; makefile: 345
file content (57 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (2)
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
#include "defines.h"

/*--------------- lmax ---------------*/

static t_class *lmax_class;

typedef struct _lmax
{
    t_object x_obj;
	t_float m_max;
	t_float m_leak;
	t_float m_c_leak;
} t_lmax;


static void lmax_perform(t_lmax *x, t_float in)
{
	x->m_max=(in > x->m_max) ? in : x->m_max * x->m_c_leak + in * x->m_leak;
    outlet_float(x->x_obj.ob_outlet, x->m_max);
}

static void lmax_setHalfDecay(t_lmax *x, t_float halfDecayTime)
{
	x->m_c_leak=(t_float)powf(.5,(1.0/halfDecayTime));
	x->m_leak=1.0-x->m_c_leak;
}

static void lmax_clear(t_lmax *x)
{
	x->m_max= - MAXFLOAT;
}

static void *lmax_new( t_float halfDecayTime)
{
	t_lmax *x=(t_lmax *)pd_new(lmax_class);
	outlet_new(&x->x_obj, gensym("float"));

	lmax_setHalfDecay(x, halfDecayTime);
	lmax_clear(x);
	return (void *)x;
}


void lmax_setup(void)
{
    lmax_class = class_new(gensym("lmax"),
    	(t_newmethod)lmax_new, 0,
		sizeof(t_lmax), 
		CLASS_DEFAULT,
	    A_DEFFLOAT, 0);
    class_addfloat(lmax_class, (t_method)lmax_perform);
	class_addmethod(lmax_class, (t_method)lmax_clear,
    	gensym("clear"), A_GIMME, NULL);
	class_addmethod(lmax_class, (t_method)lmax_setHalfDecay,
    	gensym("decay"), A_DEFFLOAT, NULL);
}