aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Kelly <edkelly@users.sourceforge.net>2011-01-22 22:22:20 +0000
committerEd Kelly <edkelly@users.sourceforge.net>2011-01-22 22:22:20 +0000
commit47b7b9152485d52775e1f25774bd3102494e0087 (patch)
tree501e6c9444d14b6f2fb647494e54832ebe458070
parentad54658b2b123d1b61a7efa207ec8a868d9f8c95 (diff)
Added ihisto Integer histogram external
svn path=/trunk/externals/ekext/; revision=14775
-rw-r--r--Makefile2
-rw-r--r--ihisto-help.pd71
-rw-r--r--ihisto.c147
3 files changed, 219 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 307076f..28a0ef2 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ LIBRARY_NAME = ekext
# add your .c source files, one object per file, to the SOURCES
# variable, help files will be included automatically
-SOURCES = bmt~.c cup.c cupd.c doubledelta.c framescore~.c framespect~.c hasc~.c hssc~.c listmoses.c list_sum.c lpc~.c lpreson~.c maskxor.c peakit~.c polymap.c polystat.c sieve.c simile~.c simile.c steady.c valve.c voicing_detector~.c weightonset.c zeroxpos~.c
+SOURCES = bmt~.c cup.c cupd.c doubledelta.c framescore~.c framespect~.c hasc~.c hssc~.c ihisto.c listmoses.c list_sum.c lpc~.c lpreson~.c maskxor.c peakit~.c polymap.c polystat.c sieve.c simile~.c simile.c steady.c valve.c voicing_detector~.c weightonset.c zeroxpos~.c
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
diff --git a/ihisto-help.pd b/ihisto-help.pd
new file mode 100644
index 0000000..7a0be3c
--- /dev/null
+++ b/ihisto-help.pd
@@ -0,0 +1,71 @@
+#N canvas 0 0 622 435 10;
+#X obj 226 160 ihisto 128;
+#X obj 182 88 random 128;
+#X obj 182 69 metro 100;
+#N canvas 0 0 450 300 (subpatch) 0;
+#X array histogram 128 float 2;
+#X coords 0 100 128 -1 512 140 1;
+#X restore 53 265 graph;
+#X obj 182 107 t b f;
+#X floatatom 264 229 5 0 0 0 current_peak - -;
+#X msg 264 136 mode \$1;
+#X obj 264 115 hradio 17 1 0 3 empty empty highest 0 -8 0 10 -262144
+-1 -1 0;
+#X msg 182 126 get;
+#N canvas 0 0 450 300 (subpatch) 0;
+#X msg 79 179 label latest;
+#X msg 98 203 label highest;
+#X msg 115 229 label lowest;
+#X obj 94 107 inlet;
+#X obj 82 146 sel 0 1 2;
+#X obj 81 250 outlet;
+#X connect 0 0 5 0;
+#X connect 1 0 5 0;
+#X connect 2 0 5 0;
+#X connect 3 0 4 0;
+#X connect 4 0 0 0;
+#X connect 4 1 1 0;
+#X connect 4 2 2 0;
+#X restore 239 115 pd;
+#X text 318 114 <--- which to output if two or more;
+#X text 348 125 are of equal frequency;
+#X floatatom 194 199 5 0 0 0 peak - -;
+#X floatatom 229 214 5 0 0 0 frequency - -;
+#X obj 182 51 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 285 55 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X text 302 55 <--- output peak and frequency then reset object;
+#X msg 285 74 poll;
+#X text 316 75 <--- output peak and frequency but do not reset;
+#X msg 285 13 exclude 64;
+#X text 351 13 <--- exclude value (reset when banged);
+#X text 52 127 rightmost outlet --->;
+#X text 60 117 output list on;
+#X text 38 42 Integer histogram;
+#X text 35 58 (c) 2011 Edward Kelly;
+#X text 38 73 GNU GPL;
+#X obj 302 195 tabset histogram;
+#X floatatom 299 244 5 0 0 0 current_frequency - -;
+#X obj 182 13 loadbang;
+#X msg 182 32 1;
+#X connect 0 0 12 0;
+#X connect 0 1 13 0;
+#X connect 0 2 5 0;
+#X connect 0 3 27 0;
+#X connect 0 4 26 0;
+#X connect 1 0 4 0;
+#X connect 2 0 1 0;
+#X connect 4 0 8 0;
+#X connect 4 1 0 0;
+#X connect 6 0 0 0;
+#X connect 7 0 6 0;
+#X connect 7 0 9 0;
+#X connect 8 0 0 0;
+#X connect 9 0 7 0;
+#X connect 14 0 2 0;
+#X connect 15 0 0 0;
+#X connect 17 0 0 0;
+#X connect 19 0 0 0;
+#X connect 28 0 29 0;
+#X connect 29 0 14 0;
diff --git a/ihisto.c b/ihisto.c
new file mode 100644
index 0000000..07cf95a
--- /dev/null
+++ b/ihisto.c
@@ -0,0 +1,147 @@
+/* Histogram for integers - copyright 2011 Edward Kelly */
+/* released under the GNU GPL license */
+#include "m_pd.h"
+
+#define MAXENTRIES 13823
+#define LASTENTRY 13822
+
+static t_class *ihisto_class;
+
+/* mode = 0: most recent when equal, 1: highest, 2: lowest */
+
+typedef struct _hist
+{
+ t_atom histogram[MAXENTRIES];
+} t_hist;
+
+typedef struct _ihisto
+{
+ t_object x_obj;
+ t_hist histog;
+ int intinput, size;
+ t_float max, maxvalue, count, exclude, mode;
+ t_outlet *peak, *counted, *current, *counting, *histo;
+} t_ihisto;
+
+void ihisto_float(t_ihisto *x, t_floatarg fin)
+{
+ x->intinput = fin > 0 ? (int)fin < x->size ? (int)fin : x->size - 1 : 0;
+ x->count = atom_getfloatarg(x->intinput, MAXENTRIES, x->histog.histogram);
+ x->count++;
+ SETFLOAT(&x->histog.histogram[x->intinput],x->count);
+
+ if(x->mode == 0)
+ {
+ if(x->count >= x->maxvalue && x->intinput != (int)x->exclude)
+ {
+ x->max = (float)x->intinput;
+ x->maxvalue = x->count;
+ }
+ }
+ else if (x->mode == 1)
+ {
+ if(x->count >= x->maxvalue && x->intinput >= (int)x->max && x->intinput != (int)x->exclude || x->count > x->maxvalue && x->intinput != (int)x->exclude)
+ {
+ x->max = (float)x->intinput;
+ x->maxvalue = x->count;
+ }
+ }
+ else if (x->mode == 2)
+ {
+ if(x->count >= x->maxvalue && x->intinput <= (int)x->max && x->intinput != (int)x->exclude || x->count > x->maxvalue && x->intinput != (int)x->exclude)
+ {
+ x->max = (float)x->intinput;
+ x->maxvalue = x->count;
+ }
+ }
+
+ outlet_float(x->current, x->max);
+ outlet_float(x->counting, x->maxvalue);
+}
+
+void ihisto_bang(t_ihisto *x)
+{
+ if(x->max)
+ {
+ outlet_float(x->counted, x->maxvalue);
+ outlet_float(x->peak, x->max);
+ }
+
+ int i;
+ for(i=0;i<x->size;i++)
+ {
+ SETFLOAT(x->histog.histogram+i, 0);
+ }
+
+ x->max = -1;
+ x->maxvalue = 0;
+ x->count = 0;
+ x->intinput = -1;
+ x->exclude = -1;
+}
+
+void ihisto_poll(t_ihisto *x)
+{
+ if(x->max)
+ {
+ outlet_float(x->counted, x->maxvalue);
+ outlet_float(x->peak, x->max);
+ }
+}
+
+void ihisto_mode(t_ihisto *x, t_floatarg f)
+{
+ x->mode = f < 0 ? 0 : f > 2 ? 2 : (int)f;
+}
+
+void ihisto_get(t_ihisto *x)
+{
+ outlet_list(x->histo, gensym("list"), x->size, x->histog.histogram);
+}
+
+void ihisto_exclude(t_ihisto *x, t_floatarg f)
+{
+ x->exclude = f;
+}
+
+void *ihisto_new(t_floatarg f)
+{
+ t_ihisto *x = (t_ihisto *)pd_new(ihisto_class);
+ int init = (int)f;
+ x->size = init > MAXENTRIES ? MAXENTRIES : init <= 0 ? 128 : init;
+
+ x->max = -1;
+ x->maxvalue = 0;
+ x->count = 0;
+ x->intinput = 0;
+ x->exclude = -1;
+
+ int i;
+ for(i=0;i<MAXENTRIES;i++)
+ {
+ SETFLOAT(x->histog.histogram+i, 0);
+ }
+ x->peak = outlet_new(&x->x_obj, &s_float);
+ x->counted = outlet_new(&x->x_obj, &s_float);
+ x->current = outlet_new(&x->x_obj, &s_float);
+ x->counting = outlet_new(&x->x_obj, &s_float);
+ x->histo = outlet_new(&x->x_obj, &s_list);
+
+ return (void *)x;
+}
+
+void ihisto_setup(void)
+{
+ ihisto_class = class_new(gensym("ihisto"),
+ (t_newmethod)ihisto_new,
+ 0, sizeof(t_ihisto),
+ 0, A_DEFFLOAT, 0);
+ post("Integer Histogram by Ed Kelly 2011");
+
+ class_addfloat(ihisto_class, ihisto_float);
+ class_addbang(ihisto_class, ihisto_bang);
+ class_addmethod(ihisto_class, (t_method)ihisto_poll, gensym("poll"), A_DEFFLOAT, 0);
+ class_addmethod(ihisto_class, (t_method)ihisto_mode, gensym("mode"), A_DEFFLOAT, 0);
+ class_addmethod(ihisto_class, (t_method)ihisto_get, gensym("get"), A_GIMME, 0);
+ class_addmethod(ihisto_class, (t_method)ihisto_exclude, gensym("exclude"), A_DEFFLOAT, 0);
+}