~ubuntu-branches/ubuntu/saucy/pd-smlib/saucy

« back to all changes in this revision

Viewing changes to vrmstodb.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans-Christoph Steiner
  • Date: 2010-11-10 15:17:58 UTC
  • Revision ID: james.westby@ubuntu.com-20101110151758-3acjf69kiudo3gh4
Tags: upstream-0.12.1
ImportĀ upstreamĀ versionĀ 0.12.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "defines.h"
 
2
 
 
3
/*--------------- vrmstodb ----------------*/
 
4
 
 
5
static t_class *vrmstodb_class;
 
6
 
 
7
typedef struct _vrmstodb
 
8
{
 
9
    t_object x_obj;
 
10
} t_vrmstodb;
 
11
 
 
12
float rmstodb(float f)
 
13
{
 
14
    if (f <= 0) return (0);
 
15
    else
 
16
    {
 
17
        float val = (float)(100 + 20./LOGTEN * log(f));
 
18
        return (val < 0 ? 0 : val);
 
19
    }
 
20
}
 
21
 
 
22
static void vrmstodb_perform(t_vrmstodb *x, t_symbol *s, int argc, t_atom *argv)
 
23
{
 
24
        int i;
 
25
        t_atom *ap,*app;
 
26
    ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
 
27
        app=ap;
 
28
 
 
29
        for (i = 0; i < argc; i++)
 
30
        {
 
31
                SETFLOAT(app, rmstodb(atom_getfloat(argv++)));
 
32
                app++;
 
33
        }
 
34
        outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
 
35
    freebytes(ap,argc);
 
36
}
 
37
 
 
38
static void *vrmstodb_new()
 
39
{
 
40
        t_vrmstodb *x=(t_vrmstodb *)pd_new(vrmstodb_class);
 
41
        outlet_new(&x->x_obj, gensym("list"));
 
42
        return (void *)x;
 
43
}
 
44
 
 
45
void vrmstodb_setup(void)
 
46
{
 
47
    vrmstodb_class = class_new(gensym("vrmstodb"),
 
48
        (t_newmethod)vrmstodb_new, 0,
 
49
                sizeof(t_vrmstodb), 
 
50
                CLASS_DEFAULT,
 
51
            0);
 
52
    class_addlist(vrmstodb_class, (t_method)vrmstodb_perform);
 
53
}
 
54