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

« back to all changes in this revision

Viewing changes to decimator.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
/*--------------- decimator ---------------*/
 
4
 
 
5
static t_class *decimator_class;
 
6
 
 
7
typedef struct _decimator
 
8
{
 
9
    t_object x_obj;
 
10
        int m_state;
 
11
        int m_factor;
 
12
} t_decimator;
 
13
 
 
14
static void decimator_perform(t_decimator *x, t_float in)
 
15
{
 
16
        if (!x->m_state)
 
17
        {
 
18
                outlet_float(x->x_obj.ob_outlet, in);
 
19
                x->m_state=x->m_factor;
 
20
        }
 
21
        else
 
22
        {
 
23
                x->m_state--;
 
24
        }
 
25
 
 
26
}
 
27
 
 
28
static void decimator_setFactor(t_decimator *x, t_float factor)
 
29
{
 
30
        x->m_factor=(int)factor - 1;
 
31
}
 
32
 
 
33
static void decimator_clear(t_decimator *x)
 
34
{
 
35
        x->m_state=0;
 
36
}
 
37
 
 
38
 
 
39
static void *decimator_new(t_float factor)
 
40
{
 
41
 
 
42
        t_decimator *x=(t_decimator *)pd_new(decimator_class);
 
43
        outlet_new(&x->x_obj, gensym("float"));
 
44
 
 
45
        if (factor<1) factor=2;
 
46
 
 
47
        decimator_setFactor(x, factor);
 
48
        decimator_clear(x);
 
49
        return (void *)x;
 
50
}
 
51
 
 
52
 
 
53
void decimator_setup(void)
 
54
{
 
55
    decimator_class = class_new(gensym("decimator"),
 
56
        (t_newmethod)decimator_new, 0,
 
57
                sizeof(t_decimator), 
 
58
                CLASS_DEFAULT,
 
59
            A_DEFFLOAT, 0);
 
60
    class_addfloat(decimator_class, (t_method)decimator_perform);
 
61
        class_addmethod(decimator_class, (t_method)decimator_clear,
 
62
        gensym("clear"), A_GIMME, NULL);
 
63
        class_addmethod(decimator_class, (t_method)decimator_setFactor,
 
64
        gensym("factor"), A_DEFFLOAT, NULL);
 
65
}
 
66