File: vstd.c

package info (click to toggle)
pd-smlib 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: ansic: 3,010; makefile: 63
file content (46 lines) | stat: -rw-r--r-- 891 bytes parent folder | download
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
#include "defines.h"

/*--------------- vstd ---------------*/

static t_class *vstd_class;

typedef struct _vstd
{
    t_object x_obj;
} t_vstd;


static void vstd_perform(t_vstd *x, t_symbol *s, int argc, t_atom *argv)
{
	t_float sumsq=0.0f;
	t_float sum=0.0f;
	int i;
	for (i = 0; i < argc; i++)
	{
		t_float tmp=atom_getfloat(&argv[i]);
		sumsq+= tmp*tmp;
		sum+=tmp;
	}
	sumsq/=argc;
	sum/=argc;
	outlet_float(x->x_obj.ob_outlet, (t_float)sqrtf(sumsq-sum*sum));
    if (s) {} // prevent compiler complaint
}

static void *vstd_new()
{
	t_vstd *x=(t_vstd *)pd_new(vstd_class);
	outlet_new(&x->x_obj, gensym("float"));
	return (void *)x;
}

void vstd_setup(void)
{
    vstd_class = class_new(gensym("vstd"),
    	(t_newmethod)vstd_new, 0,
		sizeof(t_vstd), 
		CLASS_DEFAULT,
	    0);
    class_addlist(vstd_class, (t_method)vstd_perform);
}