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

« back to all changes in this revision

Viewing changes to lavg.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
/*--------------- lavg ---------------*/
 
4
 
 
5
static t_class *lavg_class;
 
6
 
 
7
typedef struct _lavg
 
8
{
 
9
    t_object x_obj;
 
10
        float m_avg;
 
11
        float m_c_leak;
 
12
        float m_leak;
 
13
} t_lavg;
 
14
 
 
15
 
 
16
static void lavg_perform(t_lavg *x, t_float in)
 
17
{
 
18
        x->m_avg= x->m_avg * x->m_c_leak + in * x->m_leak;
 
19
    outlet_float(x->x_obj.ob_outlet, x->m_avg);
 
20
}
 
21
 
 
22
static void lavg_clear(t_lavg *x)
 
23
{
 
24
        x->m_avg=0.0f;
 
25
}
 
26
 
 
27
static void lavg_setHalfDecay(t_lavg *x, t_float halfDecayTime)
 
28
{
 
29
        x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
 
30
        x->m_leak=1.0f-x->m_c_leak;
 
31
}
 
32
 
 
33
static void *lavg_new( t_float halfDecayTime)
 
34
{
 
35
        t_lavg *x=(t_lavg *)pd_new(lavg_class);
 
36
        outlet_new(&x->x_obj, gensym("float"));
 
37
 
 
38
        lavg_setHalfDecay(x, halfDecayTime);
 
39
        return (void *)x;
 
40
}
 
41
 
 
42
void lavg_setup(void)
 
43
{
 
44
    lavg_class = class_new(gensym("lavg"),
 
45
        (t_newmethod)lavg_new, 0,
 
46
                sizeof(t_lavg), 
 
47
                CLASS_DEFAULT,
 
48
            A_DEFFLOAT, 0);
 
49
    class_addfloat(lavg_class, (t_method)lavg_perform);
 
50
        class_addmethod(lavg_class, (t_method)lavg_setHalfDecay,
 
51
        gensym("decay"), A_DEFFLOAT, NULL);
 
52
        class_addmethod(lavg_class, (t_method)lavg_clear,
 
53
        gensym("clear"), 0);
 
54
}
 
55