aboutsummaryrefslogtreecommitdiff
path: root/weightonset
diff options
context:
space:
mode:
Diffstat (limited to 'weightonset')
-rw-r--r--weightonset/help-weightonset.pd255
-rwxr-xr-xweightonset/makefile106
-rwxr-xr-xweightonset/stink.wavbin0 -> 213234 bytes
-rw-r--r--weightonset/weightonset.c102
-rwxr-xr-xweightonset/weightonset.pd_linuxbin0 -> 3016 bytes
5 files changed, 463 insertions, 0 deletions
diff --git a/weightonset/help-weightonset.pd b/weightonset/help-weightonset.pd
new file mode 100644
index 0000000..375bacd
--- /dev/null
+++ b/weightonset/help-weightonset.pd
@@ -0,0 +1,255 @@
+#N canvas 31 64 901 594 10;
+#N canvas 1901 230 450 300 hasc 0;
+#X obj 65 62 inlet~;
+#X obj 196 184 block~ 1024;
+#X obj 55 106 rfft~;
+#X obj 56 150 hasc~;
+#X obj 56 188 outlet;
+#X obj 179 60 inlet;
+#X text 153 42 threshold (0-10+);
+#X text 43 -1 ...get a "highest apparent spectral component" value
+from the FFT;
+#X connect 0 0 2 0;
+#X connect 2 0 3 0;
+#X connect 2 1 3 1;
+#X connect 3 0 4 0;
+#X connect 5 0 3 2;
+#X restore 44 418 pd hasc;
+#X obj 128 346 bonk~;
+#N canvas 0 0 450 300 (subpatch) 0;
+#X array \$0-input 106595 float 0;
+#X coords 0 1 106594 -1 200 51 1;
+#X restore 287 309 graph;
+#X obj 128 370 t b b;
+#X obj 81 506 f;
+#X floatatom 96 487 5 0 0 0 - - -;
+#X floatatom 168 348 5 0 99 0 - - -;
+#X obj 81 526 print end-value;
+#X obj 43 324 tabplay~ \$0-input;
+#X floatatom 75 354 5 0 100 0 - - -;
+#X floatatom 75 396 5 0 0 0 - - -;
+#X obj 75 374 * 0.1;
+#N canvas 0 0 450 300 tw 0;
+#X obj 274 70 inlet;
+#X msg 274 91 0;
+#X obj 191 158 cup;
+#X obj 110 55 inlet;
+#X obj 110 80 t f b;
+#X obj 115 207 tabwrite \$0-hasc;
+#X obj 301 158 cup;
+#X obj 220 55 inlet;
+#X obj 220 80 t f b;
+#X obj 225 207 tabwrite \$0-weightonset;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 0 6 0;
+#X connect 2 0 5 1;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 4 1 2 0;
+#X connect 6 0 9 1;
+#X connect 7 0 8 0;
+#X connect 8 0 9 0;
+#X connect 8 1 6 0;
+#X restore 39 519 pd tw;
+#N canvas 0 0 450 300 (subpatch) 0;
+#X array \$0-hasc 1 float 3;
+#A 0 0;
+#X coords 0 511 1 -1 200 51 1;
+#X restore 287 380 graph;
+#N canvas 0 0 450 300 adapt 0;
+#X obj 128 44 inlet;
+#X obj 127 74 / 100;
+#X obj 129 108 t b f;
+#X msg 126 139 1;
+#X obj 132 170 -;
+#X obj 134 205 outlet;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 2 0 3 0;
+#X connect 2 1 4 1;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X restore 168 367 pd adapt;
+#X floatatom 168 401 5 0 0 1 influence - -;
+#X obj 168 308 loadbang;
+#X obj 88 276 bng 15 250 50 0 empty empty load 17 7 0 10 -262144 -1
+-1;
+#N canvas 211 176 325 300 loadfile 0;
+#X obj 44 28 openpanel;
+#X obj 44 47 t a b;
+#X obj 44 90 pack s s;
+#X msg 44 109 read -resize \$1 \$2;
+#X obj 44 128 soundfiler;
+#X obj 71 66 symbol \$0-input;
+#X floatatom 44 186 0 0 0 0 - - -;
+#X obj 44 166 i;
+#X msg 44 206 resize \$1;
+#X obj 44 226 s \$0-hasc;
+#X obj 44 147 / 1024;
+#X obj 44 5 inlet;
+#X obj 113 227 s \$0-weightonset;
+#X obj 243 27 loadbang;
+#X msg 119 27 ../sound/stink.wav;
+#X connect 0 0 1 0;
+#X connect 1 0 2 0;
+#X connect 1 1 5 0;
+#X connect 2 0 3 0;
+#X connect 3 0 4 0;
+#X connect 4 0 10 0;
+#X connect 5 0 2 1;
+#X connect 6 0 8 0;
+#X connect 7 0 6 0;
+#X connect 8 0 9 0;
+#X connect 8 0 12 0;
+#X connect 10 0 7 0;
+#X connect 11 0 0 0;
+#X connect 13 0 14 0;
+#X connect 14 0 1 0;
+#X restore 88 295 pd loadfile;
+#X obj 43 276 bng 12 250 50 0 empty empty play 15 6 0 10 -262144 -1
+-1;
+#X obj 43 291 t b b;
+#N canvas 0 0 450 300 (subpatch) 0;
+#X array \$0-weightonset 1 float 3;
+#A 0 0;
+#X coords 0 511 1 -1 200 51 1;
+#X restore 287 450 graph;
+#X obj 116 407 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-257985 -1;
+#X text 56 49 The second value is multipled by the value in the second
+inlet (range 0-1) and added to the first value. Then \, the divider
+value (in order to work out the weighted average) is also multiplied
+by this value \, and added to it.;
+#X text 46 8 This object makes a moving average with successively less
+important values. The calculation initiates when the object is banged
+\, and the first value is the most influential.;
+#X msg 65 444 1;
+#X obj 130 445 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X obj 195 500 print data;
+#X text 78 161 When the object is banged the right outlet sends a list
+of all the values that influenced the result since the last bang \,
+up to a limit of 1024 values.;
+#X obj 477 73 weightonset;
+#X text 476 58 V;
+#X text 476 54 |;
+#X text 476 44 |;
+#X text 476 34 |;
+#X text 452 20 floats in;
+#X text 506 58 V;
+#X text 506 54 |;
+#X text 506 44 |;
+#X text 685 338 ^;
+#X text 684 342 |;
+#X text 684 351 |;
+#X text 738 338 ^;
+#X text 737 342 |;
+#X text 737 351 |;
+#X text 801 338 ^;
+#X text 800 342 |;
+#X text 800 351 |;
+#X text 671 377 of successive inputs;
+#X text 475 89 |;
+#X text 475 99 |;
+#X text 475 109 |;
+#X text 475 119 V;
+#X text 452 141 influenced;
+#X text 464 130 onset-;
+#X text 465 153 value;
+#X text 538 89 |;
+#X text 538 99 |;
+#X text 538 109 |;
+#X text 538 119 V;
+#X text 531 132 data dump;
+#X text 537 143 on bang;
+#X text 616 389 1: accumulated average (up to 1024 elements);
+#X msg 49 354 5;
+#X text 212 411 factor;
+#X text 202 387 successive;
+#X text 64 101 The influence of successive values is lessened by the
+inverse of the factor on the right inlet. So \, a value of 0.2 in the
+second inlet means that the second value after the bang is 20% as influential
+as the first \, and the third value is 20% of 20% (4%) as influential
+as the first.;
+#X floatatom 195 437 5 0 10 1 attack - -;
+#X text 509 200 influence factor = 0 : 1st float output only;
+#X text 510 188 attack length = 0 \,;
+#X text 535 166 EXAMPLES:;
+#X text 520 226 attack length = 0 \,;
+#X text 519 238 influence factor = 1: successive values are;
+#X text 232 447 phase;
+#X text 232 461 0-100;
+#X text 508 252 equally influential to the total \, but the list;
+#X text 492 31 successive influence factor (0-1);
+#X text 538 58 V;
+#X text 538 54 |;
+#X text 525 43 attack phase (1-100+);
+#X text 514 265 grows longer as the numbers are added. Therefore;
+#X text 506 278 the output responds less and less to input values.
+;
+#X text 513 291 This is an accumulating average between bangs.;
+#X text 511 313 attack length = 0 \,;
+#X text 634 366 (w) = weightings (influence values);
+#X text 509 405 the output is onset-weighted e.g. the most influential
+values are at the start of the series.;
+#X text 700 462 ^;
+#X text 699 466 |;
+#X text 699 475 |;
+#X text 760 462 ^;
+#X text 759 466 |;
+#X text 759 475 |;
+#X text 824 462 ^;
+#X text 823 466 |;
+#X text 823 475 |;
+#X text 680 501 of successive inputs;
+#X text 622 513 1: accumulated average (up to 1024 elements);
+#X text 656 490 (w) = weightings (influence values);
+#X text 515 529 the output is onset-weighted e.g. the most influential
+values are at the start of the series.;
+#X text 517 437 attack length = 3 \,;
+#X text 513 451 influence factor = 0.5: v1 w 0.25 \, v2 w 0.5 \, v3
+w 0.75 \, v4 w 1 \, v5 w 0.5 \, v6 w 0.25...;
+#X text 509 327 influence factor = 0.5: v1 w 1 \, v2 w 0.5 \, v3 w
+0.25 \, v4 w 0.125;
+#X text 86 200 If the attack phase is greater than 0 \, the values
+become successively more influential to the weighted average \, until
+the number of values is equal to the attack+1. The next value after
+the attack phase is the most influential \, then the influence factor
+kicks in and successive values become less influential.;
+#X text 552 73 creation args: influence factor \, attack;
+#X obj 96 467 weightonset 0.8 0;
+#X obj 10 361 dac~;
+#X msg 168 328 80;
+#X connect 0 0 12 0;
+#X connect 0 0 103 0;
+#X connect 1 0 3 0;
+#X connect 3 0 22 0;
+#X connect 3 0 103 0;
+#X connect 3 1 4 0;
+#X connect 4 0 7 0;
+#X connect 5 0 4 1;
+#X connect 5 0 12 1;
+#X connect 6 0 14 0;
+#X connect 8 0 0 0;
+#X connect 8 0 1 0;
+#X connect 8 0 104 0;
+#X connect 8 0 104 1;
+#X connect 9 0 11 0;
+#X connect 10 0 0 1;
+#X connect 11 0 10 0;
+#X connect 14 0 15 0;
+#X connect 14 0 103 1;
+#X connect 16 0 105 0;
+#X connect 16 0 62 0;
+#X connect 17 0 18 0;
+#X connect 19 0 20 0;
+#X connect 20 0 8 0;
+#X connect 20 1 12 2;
+#X connect 25 0 103 0;
+#X connect 26 0 103 0;
+#X connect 62 0 9 0;
+#X connect 66 0 103 2;
+#X connect 103 0 5 0;
+#X connect 103 1 27 0;
+#X connect 105 0 6 0;
diff --git a/weightonset/makefile b/weightonset/makefile
new file mode 100755
index 0000000..a530dea
--- /dev/null
+++ b/weightonset/makefile
@@ -0,0 +1,106 @@
+current:
+ echo make pd_linux, pd_nt, pd_irix5, pd_irix6 or pd_darwin
+
+clean: ; rm -f *.pd_* *.o
+
+# ----------------------- NT -----------------------
+
+pd_nt: weightonset.dll
+
+.SUFFIXES: .obj .dll
+
+PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo
+VC="D:\Program Files\Microsoft Visual Studio\Vc98"
+
+PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include
+
+PDNTLDIR = $(VC)\lib
+PDNTLIB = $(PDNTLDIR)\libc.lib \
+ $(PDNTLDIR)\oldnames.lib \
+ $(PDNTLDIR)\kernel32.lib \
+ ..\..\bin\pd.lib
+
+.c.dll:
+ cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c
+ link /dll /export:$*_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: weightonset.pd_irix5
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_irix5
+.SUFFIXES: .pd_irix5
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+
+SGIINCLUDE = -I/usr/local/include
+
+.c.pd_irix5:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o
+ rm $*.o
+
+# ----------------------- IRIX 6.x -----------------------
+
+pd_irix6: weightonset.pd_irix6
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_irix6
+.SUFFIXES: .pd_irix6
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+
+SGIINCLUDE = -I/usr/local/include
+
+.c.pd_irix6:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix6 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: weightonset.pd_linux
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_linux
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXINCLUDE = -I/usr/local/include
+
+.c.pd_linux:
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ ld --export-dynamic -shared -o $*.pd_linux $*.o -lc -lm
+ strip --strip-unneeded $*.pd_linux
+ rm $*.o
+
+# ----------------------- Mac OSX -----------------------
+
+pd_darwin: weightonset.pd_darwin
+
+INSTALL_PREFIX=/usr/local
+EXT=pd_darwin
+.SUFFIXES: .pd_darwin
+
+DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+.c.pd_darwin:
+ cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o
+ rm -f $*.o
+
+# ----------------------------------------------
+
+install::
+ install -d $(INSTALL_PREFIX)/lib/pd/extra
+# install -m 644 *.$(EXT) $(INSTALL_PREFIX)/lib/pd/externs
+ -install -m 644 weightonset.$(EXT) $(INSTALL_PREFIX)/lib/pd/extra
+ install -m 644 *.pd $(INSTALL_PREFIX)/lib/pd/doc/5.reference
+ install -m 644 *.wav $(INSTALL_PREFIX)/lib/pd/doc/sound
diff --git a/weightonset/stink.wav b/weightonset/stink.wav
new file mode 100755
index 0000000..aec9986
--- /dev/null
+++ b/weightonset/stink.wav
Binary files differ
diff --git a/weightonset/weightonset.c b/weightonset/weightonset.c
new file mode 100644
index 0000000..0117b84
--- /dev/null
+++ b/weightonset/weightonset.c
@@ -0,0 +1,102 @@
+#include "m_pd.h"
+#include <math.h>
+
+typedef struct _datachunk
+{
+ t_atom data[1024];
+} t_datachunk;
+
+typedef struct _weightonset
+{
+ t_object x_obj;
+ t_float multiplier, accumulator, divider, divaccum, weighted, increment;
+ t_float length, attack;
+ t_datachunk x_datachunk;
+ t_outlet *waverage, *datachunk;
+} t_weightonset;
+
+t_class *weightonset_class;
+
+void weightonset_float (t_weightonset *x, t_floatarg fin)
+{
+ if(x->length < 1024)
+ {
+ int len = (int)x->length;
+ SETFLOAT(&x->x_datachunk.data[len], fin);
+ if(x->length < x->attack)
+ {
+ x->increment = 1 / (x->attack + 1);
+ x->accumulator += fin*(x->length + 1)*x->increment;
+// x->increment*len substitutes for the divider
+// during the attack phase
+ x->divaccum += x->increment*(x->length + 1);
+ x->weighted = x->accumulator / x->divaccum;
+ outlet_float(x->waverage, x->weighted);
+ }
+ else if(x->length == x->attack)
+ {
+ x->divider = 1;
+ x->divaccum += 1;
+ x->accumulator += fin*x->divider;
+ x->weighted = x->accumulator / x->divaccum;
+ x->divider *= x->multiplier;
+ x->divaccum += x->divider;
+ outlet_float(x->waverage, x->weighted);
+ }
+ else
+ {
+ x->accumulator += fin*x->divider;
+ x->weighted = x->accumulator / x->divaccum;
+ x->divider *= x->multiplier;
+ x->divaccum += x->divider;
+ outlet_float(x->waverage, x->weighted);
+ }
+ x->length += 1;
+ }
+}
+
+void weightonset_bang (t_weightonset *x)
+{
+ int (len) = (int)x->length;
+ outlet_list(x->datachunk, gensym("list"), len, x->x_datachunk.data);
+ x->accumulator = 0;
+ x->length = 0;
+ if(x->attack > 0)
+ {
+ x->divider = 1;
+ x->divaccum = 1;
+ }
+ else if (x->attack == 0)
+ {
+ x->divider = 0;
+ x->divaccum = 0;
+ }
+}
+
+void *weightonset_new(t_floatarg f1, t_floatarg f2)
+{
+ t_weightonset *x = (t_weightonset *)pd_new(weightonset_class);
+ x->multiplier = f1 != 0 ? f1 : 0.5;
+ x->accumulator = 0;
+ x->divider = f2 > 0 ? 1 : 0;
+ x->divaccum = f2 > 0 ? 1 : 0;
+ x->length = 0;
+ x->attack = f2;
+ floatinlet_new(&x->x_obj, &x->multiplier);
+ floatinlet_new(&x->x_obj, &x->attack);
+ x->waverage = outlet_new(&x->x_obj, &s_float);
+ x->datachunk = outlet_new(&x->x_obj, &s_list);
+ return (void *)x;
+}
+
+void weightonset_setup(void) {
+ weightonset_class = class_new(gensym("weightonset"),
+ (t_newmethod)weightonset_new,
+ 0, sizeof(t_weightonset),
+ 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ post("input values become less and less important");
+ post("as entropy brings alternative rewards");
+ class_sethelpsymbol(weightonset_class, gensym("help-weightonset"));
+ class_addbang(weightonset_class, weightonset_bang);
+ class_addfloat(weightonset_class, weightonset_float);
+}
diff --git a/weightonset/weightonset.pd_linux b/weightonset/weightonset.pd_linux
new file mode 100755
index 0000000..ec673ec
--- /dev/null
+++ b/weightonset/weightonset.pd_linux
Binary files differ