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

« back to all changes in this revision

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