aboutsummaryrefslogtreecommitdiff
path: root/externals/vanilla/clip~.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-11-10 01:47:02 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2009-11-10 01:47:02 +0000
commit386b0b74b0133acb7caddc0f31f5ebbf255efc00 (patch)
treef922b267aa3fc030b29e3d27901e56e205a86839 /externals/vanilla/clip~.c
parent5bdf08d2c08687f7e13c69d3405f7ff110759bca (diff)
split out d_math.c into standalone objects
svn path=/trunk/; revision=12736
Diffstat (limited to 'externals/vanilla/clip~.c')
-rw-r--r--externals/vanilla/clip~.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/externals/vanilla/clip~.c b/externals/vanilla/clip~.c
new file mode 100644
index 00000000..e53ad31a
--- /dev/null
+++ b/externals/vanilla/clip~.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 1997-2001 Miller Puckette 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 <math.h>
+
+static t_class *clip_class;
+
+typedef struct _clip
+{
+ t_object x_obj;
+ t_float x_f;
+ t_float x_lo;
+ t_float x_hi;
+} t_clip;
+
+static void *clip_new(t_floatarg lo, t_floatarg hi)
+{
+ t_clip *x = (t_clip *)pd_new(clip_class);
+ x->x_lo = lo;
+ x->x_hi = hi;
+ outlet_new(&x->x_obj, gensym("signal"));
+ floatinlet_new(&x->x_obj, &x->x_lo);
+ floatinlet_new(&x->x_obj, &x->x_hi);
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *clip_perform(t_int *w)
+{
+ t_clip *x = (t_clip *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out = (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ while (n--)
+ {
+ t_sample f = *in++;
+ if (f < x->x_lo) f = x->x_lo;
+ if (f > x->x_hi) f = x->x_hi;
+ *out++ = f;
+ }
+ return (w+5);
+}
+
+static void clip_dsp(t_clip *x, t_signal **sp)
+{
+ dsp_add(clip_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+static void clip_tilde_setup(void)
+{
+ clip_class = class_new(gensym("clip~"), (t_newmethod)clip_new, 0,
+ sizeof(t_clip), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(clip_class, t_clip, x_f);
+ class_addmethod(clip_class, (t_method)clip_dsp, gensym("dsp"), 0);
+}