aboutsummaryrefslogtreecommitdiff
path: root/synapseA~.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2004-04-07 14:32:29 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2004-04-07 14:32:29 +0000
commit1baf1d957e195290cfd59089767ca63a547a9917 (patch)
tree38a48f9bffeb97d2f69934447be073a1728bf779 /synapseA~.c
This commit was generated by cvs2svn to compensate for changes in r1560,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/mjlib/; revision=1561
Diffstat (limited to 'synapseA~.c')
-rw-r--r--synapseA~.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/synapseA~.c b/synapseA~.c
new file mode 100644
index 0000000..5498c41
--- /dev/null
+++ b/synapseA~.c
@@ -0,0 +1,118 @@
+#include "m_pd.h"
+#ifdef NT
+#include "stdafx.h"
+#include <io.h>
+#endif
+#include <stdlib.h>
+#include<time.h>
+
+#include "synapseA~.h"
+
+/* ------------------------ synapseA_tilde~ ----------------------------- */
+
+static t_class *synapseA_tilde_class;
+
+/**
+* do an average and see if it is bigger than our threshold
+* then check for state change and output accordingly
+*/
+
+t_int *synapseA_tilde_perform(t_int *w)
+{
+ float *in = (float *)(w[1]);
+ t_synapseA_tilde *x = (t_synapseA_tilde *)(w[2]);
+ int n = (t_int)(w[3]);
+
+ t_float buf = 0.;
+
+ while (n--)
+ {
+ buf += *in++;
+ }
+ if ( buf*x->n_inv > x->x_threshold )
+ {
+ if( !x->x_state )
+ {
+ x->x_state = 1;
+ outlet_float( x->x_obj.ob_outlet , x->x_state );
+ outlet_bang( x->x_onbang );
+ }
+ }
+ else
+ {
+ if( x->x_state )
+ {
+ x->x_state = 0;
+ outlet_float( x->x_obj.ob_outlet , x->x_state );
+ outlet_bang( x->x_offbang );
+ }
+ }
+ return (w+4);
+}
+
+/**
+* set up our dsp perform routine - it takes parameters
+* the input channel, the output channels ( left and right),
+* the pin object and the number of samples in the array
+*/
+
+static void synapseA_tilde_dsp(t_synapseA_tilde *x, t_signal **sp)
+{
+ x->n_inv=1./sp[0]->s_n;
+ dsp_add(synapseA_tilde_perform, 3,sp[0]->s_vec , x ,sp[0]->s_n);
+}
+
+/**
+* free up the tilde object - for now we only need
+* to get rid of the clock
+*/
+
+static void synapseA_tilde_free(t_synapseA_tilde *x)
+{
+
+}
+
+static void synapseA_tilde_threshold(t_synapseA_tilde *x, t_float f )
+{
+ if ( f > 0 )
+ {
+ x->x_threshold = f;
+ }
+ else
+ {
+ post( "Threshold must be bigger than 0 - setting to 0");
+ x->x_threshold = 0;
+ }
+}
+
+/**
+* make a new object - set up out internal variables
+* and add our inlets and outlets
+*/
+
+static void *synapseA_tilde_new(t_floatarg prob , t_floatarg tick)
+{
+ // set up our inlets
+ t_synapseA_tilde *x = (t_synapseA_tilde *)pd_new(synapseA_tilde_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("threshold"));
+ outlet_new(&x->x_obj, gensym("float"));
+ x->x_onbang = outlet_new(&x->x_obj, gensym("bang"));
+ x->x_offbang = outlet_new(&x->x_obj, gensym("bang"));
+ return (x);
+}
+
+
+/**
+* setup - add our methods and seed the random number generator
+*/
+
+ void synapseA_tilde_setup(void)
+{
+ synapseA_tilde_class = class_new(gensym("synapseA~"), (t_newmethod) synapseA_tilde_new, (t_method) synapseA_tilde_free,
+ sizeof(t_synapseA_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN( synapseA_tilde_class, t_synapseA_tilde, x_f);
+ class_addmethod(synapseA_tilde_class, (t_method) synapseA_tilde_dsp, gensym("dsp"), (t_atomtype)0);
+ class_addmethod(synapseA_tilde_class, (t_method) synapseA_tilde_threshold, gensym("threshold") , A_DEFFLOAT , (t_atomtype)0 );
+ class_sethelpsymbol(synapseA_tilde_class, gensym("mjLib/synapseA~"));
+}
+