aboutsummaryrefslogtreecommitdiff
path: root/cyclone/sickle/delta.c
blob: 145d6b7e4b23a9a65b43ce7e3930eaba0639a663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Copyright (c) 2002-2003 krzYszcz and others.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#include "m_pd.h"
#include "sickle/sic.h"

typedef struct _delta
{
    t_sic    x_sic;
    t_float  x_last;
} t_delta;

static t_class *delta_class;

static t_int *delta_perform(t_int *w)
{
    t_delta *x = (t_delta *)(w[1]);
    int nblock = (int)(w[2]);
    t_float *in = (t_float *)(w[3]);
    t_float *out = (t_float *)(w[4]);
    t_float last = x->x_last;
    while (nblock--)
    {
	t_float f = *in++;
    	*out++ = f - last;
	last = f;
    }
    x->x_last = last;
    return (w + 5);
}

static void delta_dsp(t_delta *x, t_signal **sp)
{
    dsp_add(delta_perform, 4, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec);
}

static void *delta_new(void)
{
    t_delta *x = (t_delta *)pd_new(delta_class);
    outlet_new((t_object *)x, &s_signal);
    x->x_last = 0;
    return (x);
}

void delta_tilde_setup(void)
{
    delta_class = class_new(gensym("delta~"),
			    (t_newmethod)delta_new, 0,
			    sizeof(t_delta), 0, 0);
    sic_setup(delta_class, delta_dsp, SIC_FLOATTOSIGNAL);
}