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

« back to all changes in this revision

Viewing changes to hip.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
/*--------------- hip ---------------*/
 
4
 
 
5
typedef struct hipctl
 
6
{
 
7
    float c_x;
 
8
    float c_coef;
 
9
} t_hipctl;
 
10
 
 
11
typedef struct hip
 
12
{
 
13
    t_object x_obj;
 
14
    float x_sr;
 
15
    float x_hz;
 
16
    t_hipctl x_cspace;
 
17
    t_hipctl *x_ctl;
 
18
    float x_f;
 
19
} t_hip;
 
20
 
 
21
t_class *hip_class;
 
22
 
 
23
static void hip_ft1(t_hip *x, t_floatarg f);
 
24
 
 
25
static void *hip_new(t_floatarg f)
 
26
{
 
27
    t_hip *x = (t_hip *)pd_new(hip_class);
 
28
    inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
 
29
    outlet_new(&x->x_obj, gensym("float"));
 
30
    x->x_ctl = &x->x_cspace;
 
31
    x->x_cspace.c_x = 0;
 
32
    hip_ft1(x, f);
 
33
    x->x_f = 0;
 
34
    return (x);
 
35
}
 
36
 
 
37
static void hip_ft1(t_hip *x, t_floatarg f)
 
38
{
 
39
    if (f < 0.001) f = 10;
 
40
    x->x_hz = f;
 
41
    x->x_ctl->c_coef = 1 - f * (2 * 3.14159f);
 
42
    if (x->x_ctl->c_coef < 0) x->x_ctl->c_coef = 0;
 
43
}
 
44
 
 
45
static void hip_perform(t_hip *x, t_float in)
 
46
{
 
47
    t_hipctl *c = x->x_ctl;
 
48
    float last = c->c_x;
 
49
    float coef = c->c_coef;
 
50
        float out;
 
51
 
 
52
        float new = in + coef * last;
 
53
        out = new - last;
 
54
        last = new;
 
55
 
 
56
        /* NAN protect */
 
57
    if (!((last <= 0) || (last >= 0)))
 
58
        last = 0;
 
59
    c->c_x = last;
 
60
 
 
61
    outlet_float(x->x_obj.ob_outlet, out);
 
62
}
 
63
 
 
64
static void hip_clear(t_hip *x, t_floatarg q)
 
65
{
 
66
    x->x_cspace.c_x = 0;
 
67
}
 
68
 
 
69
void hip_setup(void)
 
70
{
 
71
    hip_class = class_new(gensym("hip"), (t_newmethod)hip_new, 0,
 
72
        sizeof(t_hip), 0, A_DEFFLOAT, 0);
 
73
        class_addfloat(hip_class, (t_method)hip_perform);
 
74
    class_addmethod(hip_class, (t_method)hip_ft1,
 
75
        gensym("ft1"), A_FLOAT, 0);
 
76
    class_addmethod(hip_class, (t_method)hip_clear, gensym("clear"), 0);
 
77
}
 
 
b'\\ No newline at end of file'