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

« back to all changes in this revision

Viewing changes to lmin.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
/*--------------- lmin ---------------*/
 
4
 
 
5
static t_class *lmin_class;
 
6
 
 
7
typedef struct _lmin
 
8
{
 
9
    t_object x_obj;
 
10
        float m_min;
 
11
        float m_leak;
 
12
        float m_c_leak;
 
13
} t_lmin;
 
14
 
 
15
 
 
16
static void lmin_perform(t_lmin *x, t_float in)
 
17
{
 
18
        x->m_min=(in < x->m_min) ? in : x->m_min * x->m_c_leak + in * x->m_leak;
 
19
    outlet_float(x->x_obj.ob_outlet, x->m_min);
 
20
}
 
21
 
 
22
static void lmin_setHalfDecay(t_lmin *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 lmin_clear(t_lmin *x)
 
29
{
 
30
        x->m_min= MAXFLOAT;
 
31
}
 
32
 
 
33
static void *lmin_new( t_float halfDecayTime)
 
34
{
 
35
        t_lmin *x=(t_lmin *)pd_new(lmin_class);
 
36
        outlet_new(&x->x_obj, gensym("float"));
 
37
 
 
38
        lmin_setHalfDecay(x, halfDecayTime);
 
39
        lmin_clear(x);
 
40
        return (void *)x;
 
41
}
 
42
 
 
43
 
 
44
void lmin_setup(void)
 
45
{
 
46
    lmin_class = class_new(gensym("lmin"),
 
47
        (t_newmethod)lmin_new, 0,
 
48
                sizeof(t_lmin), 
 
49
                CLASS_DEFAULT,
 
50
            A_DEFFLOAT, 0);
 
51
    class_addfloat(lmin_class, (t_method)lmin_perform);
 
52
        class_addmethod(lmin_class, (t_method)lmin_clear,
 
53
        gensym("clear"), A_GIMME, NULL);
 
54
        class_addmethod(lmin_class, (t_method)lmin_setHalfDecay,
 
55
        gensym("decay"), A_DEFFLOAT, NULL);
 
56
}
 
57