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

/*--------------- vmtof ----------------*/

static t_class *vmtof_class;

typedef struct _vmtof
{
    t_object x_obj;
} t_vmtof;

t_float mtof(t_float f)
{
    if (f <= -1500) return(0);
    else if (f > 1499) return(mtof(1499));
    else return (t_float)(8.17579891564 * exp(.0577622650 * f));
}

static void vmtof_perform(t_vmtof *x, t_symbol *s, int argc, t_atom *argv)
{
	int i;
	t_atom *ap,*app;
    ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
	app=ap;

	for (i = 0; i < argc; i++)
	{
		SETFLOAT(app, mtof(atom_getfloat(argv++)));
		app++;
	}
	outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
    freebytes(ap,argc);
}

static void *vmtof_new()
{
	t_vmtof *x=(t_vmtof *)pd_new(vmtof_class);
	outlet_new(&x->x_obj, gensym("list"));
	return (void *)x;
}

void vmtof_setup(void)
{
    vmtof_class = class_new(gensym("vmtof"),
    	(t_newmethod)vmtof_new, 0,
		sizeof(t_vmtof), 
		CLASS_DEFAULT,
	    0);
    class_addlist(vmtof_class, (t_method)vmtof_perform);
}