aboutsummaryrefslogtreecommitdiff
path: root/vrms.c
blob: ff7f33e672be9e8aa648002f0eb3a879f78470b6 (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
#include "defines.h"

/*--------------- vrms ---------------*/

static t_class *vrms_class;

typedef struct _vrms
{
    t_object x_obj;
} t_vrms;


static void vrms_perform(t_vrms *x, t_symbol *s, int argc, t_atom *argv)
{
	t_float sum=0.;
	int i;
	for (i = 0; i < argc; i++)
	{
		t_float tmp=atom_getfloat(&argv[i]);
		sum+= tmp*tmp;
	}
	outlet_float(x->x_obj.ob_outlet, (t_float)sqrtf(sum/argc));
}

static void *vrms_new( t_float halfDecayTime)
{
	t_vrms *x=(t_vrms *)pd_new(vrms_class);
	outlet_new(&x->x_obj, gensym("float"));
	return (void *)x;
}

void vrms_setup(void)
{
    vrms_class = class_new(gensym("vrms"),
    	(t_newmethod)vrms_new, 0,
		sizeof(t_vrms), 
		CLASS_DEFAULT,
	    0);
    class_addlist(vrms_class, (t_method)vrms_perform);
}