From 992bd94dddb021b297fcf28cb5248cc94f48aaf3 Mon Sep 17 00:00:00 2001 From: jdl Date: Tue, 2 Jul 2002 20:32:59 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r24, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/cxc/; revision=25 --- ENV.c | 85 ++++++ README | 79 ++++++ REFERENCES | 4 + TODO | 42 +++ VERSION | 1 + ascseq.c | 144 ++++++++++ ascwave.c | 141 ++++++++++ bangfilt.c | 52 ++++ bangfilt2.c | 53 ++++ binshift.c | 81 ++++++ counter.c | 226 ++++++++++++++++ cx.c | 103 +++++++ gpl.txt | 340 +++++++++++++++++++++++ hex2dec.c | 47 ++++ ixprint.c | 88 ++++++ makefile | 44 +++ mean.c | 434 ++++++++++++++++++++++++++++++ microtime.c | 54 ++++ prepend.c | 121 +++++++++ proc.c | 223 ++++++++++++++++ randomix.c | 682 +++++++++++++++++++++++++++++++++++++++++++++++ reference/ENV.pd | 34 +++ reference/ascseq.pd | 12 + reference/ascwave.pd | 65 +++++ reference/bfilt.pd | 23 ++ reference/cxc.prepend.pd | 13 + reference/delta.pd | 63 +++++ reference/proc.pd | 75 ++++++ reference/randomix.pd | 181 +++++++++++++ reference/serialize.pd | 10 + reference/statistics.pd | 120 +++++++++ reference/utime.pd | 9 + reson.c | 156 +++++++++++ sigdelta.c | 56 ++++ x_connective_pd034.diff | 22 ++ x_connective_pd035.diff | 14 + 36 files changed, 3897 insertions(+) create mode 100644 ENV.c create mode 100644 README create mode 100644 REFERENCES create mode 100644 TODO create mode 100644 VERSION create mode 100644 ascseq.c create mode 100644 ascwave.c create mode 100644 bangfilt.c create mode 100644 bangfilt2.c create mode 100644 binshift.c create mode 100644 counter.c create mode 100644 cx.c create mode 100644 gpl.txt create mode 100644 hex2dec.c create mode 100644 ixprint.c create mode 100644 makefile create mode 100644 mean.c create mode 100644 microtime.c create mode 100644 prepend.c create mode 100644 proc.c create mode 100644 randomix.c create mode 100644 reference/ENV.pd create mode 100644 reference/ascseq.pd create mode 100644 reference/ascwave.pd create mode 100644 reference/bfilt.pd create mode 100644 reference/cxc.prepend.pd create mode 100644 reference/delta.pd create mode 100644 reference/proc.pd create mode 100644 reference/randomix.pd create mode 100644 reference/serialize.pd create mode 100644 reference/statistics.pd create mode 100644 reference/utime.pd create mode 100644 reson.c create mode 100644 sigdelta.c create mode 100644 x_connective_pd034.diff create mode 100644 x_connective_pd035.diff diff --git a/ENV.c b/ENV.c new file mode 100644 index 0000000..d80331b --- /dev/null +++ b/ENV.c @@ -0,0 +1,85 @@ +/* + cxc@web.fm, 2002 02 + */ + +#include "m_pd.h" +#include + +#ifndef RAND_MAX +#define RAND_MAX 2147483647 +#endif + +t_class *ENV_class; + +typedef struct ENV +{ + t_object x_obj; + t_float x_RM; + t_atom x_at[1]; +} t_ENV; + +void ENV_float(t_ENV *x, t_floatarg f) +{ + post("cxc/ENV.c: a float %f", f); +} + +void ENV_RAND_MAX(t_ENV *x) +{ + SETFLOAT(x->x_at, x->x_RM); +#ifdef DEBUG + post("cxc/ENV.c: %f",atom_getfloat(x->x_at)); +#endif + outlet_list(x->x_obj.ob_outlet, &s_list, 1,x->x_at); +} + +void ENV_getenv(t_ENV *x, t_symbol *s) +{ + char *env; + env = getenv(s->s_name); +#ifdef DEBUG + post("cxc/ENV.c: %s",env); +#endif + if(env!=NULL) + SETSYMBOL(x->x_at,gensym(env)); + else + SETFLOAT(x->x_at,-1); + outlet_list(x->x_obj.ob_outlet, &s_list, 1,x->x_at); +} + +void ENV_setenv(t_ENV *x, t_symbol *s, t_symbol *t) +{ + //t_symbol *t = atom_getsymbol(a); + // post("cxc/ENV.c: %s=%s",s->s_name,t->s_name); + if(setenv(s->s_name,t->s_name,1)!=-1) + post("cxc/ENV.c: set %s=%s",s->s_name,t->s_name); + else + post("cxc/ENV.c: set failed"); +} + +void *ENV_new(void) +{ + t_ENV *x = (t_ENV *)pd_new(ENV_class); + x->x_RM = RAND_MAX; + //x->x_at = (t_atom; + outlet_new(&x->x_obj, &s_float); + //post("ENV_new"); + return (void *)x; +} + +void ENV_help(void) +{ + post("cxc/ENV.c: get + set ENVironment variables"); +} + +void ENV_setup(void) +{ + // post("ENV_setup"); + ENV_class = class_new(gensym("ENV"), (t_newmethod)ENV_new, 0, + sizeof(t_ENV), 0, 0); + class_addmethod(ENV_class, (t_method)ENV_RAND_MAX, gensym("RAND_MAX"), 0); + class_addmethod(ENV_class, (t_method)ENV_getenv, gensym("getenv"), A_SYMBOL); + class_addmethod(ENV_class, (t_method)ENV_setenv, gensym("setenv"), A_SYMBOL, A_SYMBOL); + class_addfloat(ENV_class, ENV_float); + class_sethelpsymbol(ENV_class, gensym("cxc/ENV")); +} + diff --git a/README b/README new file mode 100644 index 0000000..5f672d2 --- /dev/null +++ b/README @@ -0,0 +1,79 @@ +-------------------------- + cxc stuffy pd eternals + powered by zt0ln d4ta +-------------------------- + +USE AT YOUR OWN RISK! +NO WARRANTY WHATSOEVER! +THIS IS GPL SOFTWARE. +see gpl.txt in this directory or http://www.gnu.org/licenses/gpl.txt + +install: +adjust makefile settings + +then type +$ make +$ make install + +(install cxc.pd_linux in $PREFIX/lib/pd/externs +and in $PREFIX/lib/pd/doc/5.refernce/cxc + + +included objects: + +ixprint: print data on console without prefix (needed for ascwave) +======== + +binshift: binary shift objects (<<,>>) +========= + +ascseq: ascii-sequencer: input anything, which is output again sequentially +======= character by character with a given delay + +ascwave: print funny ascii constructions on console +======== + +bfilt alias bangfilter: re-output every argumen-th event +======================= useful for modulo-sequencers + internal: modulo x -> sel 0 + +bfilt2: features internal counter, input just bangs +======= + +counter: cloned out of markex so i dont need to load gem to have these +======== +reson: same as above +====== + +prepend aka cxc.prepend: prepend stuff with another symbol +======================== + +utime: output seconds since epoch and microsecond fraction +====== + +random1, random_fl, random_icg, random_tw, dist_normal: +======================================================= + various PRNG algorithms from http://remus.rutgers.edu/~rhoads/Code + +ENV: get and set environment variables and certain defines like RAND_MAX +==== + +proc: get stuff out of the linux proc directory (so far: +===== cpuinfo,loadavg,version,uptime) + +delta~: emit distance to last sample as signal. +========== + +cx.mean, cx.avgdev, cx.stddev: calculate mean, standard and average deviation +============================== of a signal in an array ... + +x_connective*.diffs: patch for pd-src to make receives have inlets and set +==================== method. + + +see reference folder for objects in action + + +jdl@xdv.org, 20020702 +------------------------------ +references see REFERENCES file diff --git a/REFERENCES b/REFERENCES new file mode 100644 index 0000000..84305f7 --- /dev/null +++ b/REFERENCES @@ -0,0 +1,4 @@ +-www,dspguide.com +-lena.ucsd.edu/~msp/ +-gige.xdv.org/pd +-ftp://iem.kug.ac.at/pd/Externals/ZEXY diff --git a/TODO b/TODO new file mode 100644 index 0000000..62adc95 --- /dev/null +++ b/TODO @@ -0,0 +1,42 @@ + +-scaler + +-event_quantize + +-autosequ + +-htget/curl + +-/dev/random +-/proc + other system data // done 20020321 + * handle SMP systems (cpuinfo) + +-eth (network device statistics) + +-distribution: + randomix.c: add double gaussrand() to that file with + callback or something .. ? + +-libpcap wrapper + +-statistics + *mean + *average + standard deviation (sliced (param) for non-stationary signals?) + *histogram + *ascii2sig + + *delta~ (difference between last 2 samples) + + *sigrandomix + +-serialize seems to have bug on resize .. + + + + +----- +-delta~ +-histo (pmf,pdf,mean,ad,sd) +-random~ + +-rand swap~: byteshuffle~ or byteshift~ ... diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..a9d7c18 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.04 diff --git a/ascseq.c b/ascseq.c new file mode 100644 index 0000000..1cdc6d5 --- /dev/null +++ b/ascseq.c @@ -0,0 +1,144 @@ +/* ascii-sequencer + input lists, strings, anythings, output every characters ascii code + jdl@xdv.org 2002 +*/ + +#include "m_pd.h" +#include +#include +#include + +#define MAXMSGLEN 1024 +#define LISTSEL "list" + +t_class *ascseq_class; + +typedef struct ascseq +{ + t_object x_obj; + t_clock *x_clock; + double x_targettime; + double x_prevtime; + t_float x_grain; + char x_bla[MAXMSGLEN]; + int x_toklen; + int x_tokcur; +} t_ascseq; + +static void ascseq_tick(t_ascseq *x) +{ + double timenow = clock_getsystime(); + double msectogo = - clock_gettimesince(x->x_targettime); + int chr; + // post("ascseq: timenow: %f",timenow); + if(x->x_tokcur >= x->x_toklen) { + clock_unset(x->x_clock); + x->x_tokcur = 0; + return; + } else { + chr = x->x_bla[x->x_tokcur]; + // post("tokcur: %c",chr); + x->x_tokcur++; + outlet_float(x->x_obj.ob_outlet, chr); + clock_delay(x->x_clock,x->x_grain); + } +} + +void ascseq_anything(t_ascseq *x,t_symbol* s,t_int argc,t_atom* argv) +{ + int i = argc; + int chr, cnt, len; + char tmp[MAXMSGLEN]; + double timenow = clock_getlogicaltime(); + + chr = 0; + cnt = 0; + len = 0; + x->x_bla[0] = '\0'; + + //symbol_string(s->s_name, tmp, 1024); + if(!strstr(s->s_name,LISTSEL)) { + strcat(x->x_bla,s->s_name); + // post("tmp: %s",x->x_bla); + } + + while (i--) { + atom_string(argv, tmp, 1024); + strcat(x->x_bla,tmp); + // post("ascseq.c: argsize: %d",cnt); + // post("ascseq.c: bla: %s",bla); + argv++; + } + x->x_prevtime = timenow; + x->x_targettime = clock_getsystimeafter(x->x_grain); + + x->x_toklen = strlen(x->x_bla); + ascseq_tick(x); + +/* for(cnt=0;cntx_bla[cnt]; */ +/* outlet_float(x->x_obj.ob_outlet, chr); */ +/* } */ +} + +void ascseq_float(t_ascseq *x, t_floatarg f) +{ + int chr, cnt, len; + double timenow = clock_getlogicaltime(); + + chr = 0; + cnt = 0; + len = 0; + x->x_bla[0] = '\0'; + + x->x_prevtime = timenow; + x->x_targettime = clock_getsystimeafter(x->x_grain); + + sprintf(x->x_bla,"%f",f); + x->x_toklen = strlen(x->x_bla); + + ascseq_tick(x); + +/* for(cnt=0;cntx_bla[cnt]; */ +/* outlet_float(x->x_obj.ob_outlet, chr); */ +/* // clock_delay(x->x_clock,1000.); */ + /* } */ +} + +static void ascseq_ft1(t_ascseq *x, t_floatarg g) +{ + if (g < 0) g = 0; + if (!g) g = 0; + x->x_grain = g; +} + +void ascseq_free(t_ascseq *x) +{ + clock_free(x->x_clock); + // post("ascseq_free"); +} + +void *ascseq_new(t_floatarg f) +{ + t_ascseq *x = (t_ascseq *)pd_new(ascseq_class); + ascseq_ft1(x,f); + x->x_clock = clock_new(x, (t_method)ascseq_tick); + x->x_targettime = x->x_prevtime = clock_getlogicaltime(); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); + outlet_new(&x->x_obj, &s_float); + return (void *)x; +} + +void ascseq_setup(void) +{ + // post("ascseq_setup"); + ascseq_class = class_new(gensym("ascseq"), (t_newmethod)ascseq_new, + (t_method)ascseq_free, sizeof(t_ascseq), 0, A_DEFFLOAT, 0); + class_addlist(ascseq_class, ascseq_anything); + class_addanything(ascseq_class,ascseq_anything); + class_addfloat(ascseq_class, ascseq_float); + class_addmethod(ascseq_class, (t_method)ascseq_ft1, gensym("ft1"), A_FLOAT, 0); +} diff --git a/ascwave.c b/ascwave.c new file mode 100644 index 0000000..8003db5 --- /dev/null +++ b/ascwave.c @@ -0,0 +1,141 @@ +/* code for foo1 pd class */ + +#include "m_pd.h" +#include +#include + +#ifndef RAND_MAX +#define RAND_MAX 21 +#endif + +t_class *ascwave_class; + +typedef struct ascwave +{ + t_object t_ob; + t_symbol* filename; + FILE* x_file; + // width vertical, sort of useless + t_float x_jodel; + // width horizontal + t_float x_julp; + // fill or not flag + t_float x_fill; + // chr to use for draw + t_float x_chr; + // chr to use 4 fill +} t_ascwave; + +void ascwave_bang(t_ascwave *x, t_floatarg f) +{ + // post("cxc/ascwave.c: bang %f", x->x_jodel); + outlet_float(x->t_ob.ob_outlet, x->x_jodel + x->x_jodel); +} + +/* fill or line toggle */ +static void ascwave_fill(t_ascwave *x, t_floatarg f) +{ + x->x_fill = f; + // post("ascwave: fill %f", x->x_fill); +} + + +/* open a file to put ascii output into */ +static void ascwave_open(t_ascwave *x, t_symbol *filename) +{ + post("ascwave: open"); + x->filename = filename; + post("ascwave: filename = %s",x->filename->s_name); + if ((x->x_file = fopen(x->filename->s_name,"w")) < 0) + { + error("can't create %s",filename->s_name); + return; + } +} + + +void ascwave_ft1(t_ascwave *x, t_floatarg g) +{ + int sz = x->x_julp; + int lchr = x->x_chr; + int schr = 32; + char xip[sz+1]; + char xap[sz+1]; + int i = 0; + for (i = 0;i <= sz; ++i) { + if (i == sz-1) { + xip[i] = lchr; + } else { + if (!x->x_fill) { + xip[i] = schr; + } else { + xip[i] = lchr; + /* if (rand() > 20) + xip[i] = '\n'; */ + } + } + if (i == 0 || i == sz-1) + xap[i] = lchr; + else + xap[i] = i % 80 + 33; + } + // xip[sz] = schr;//'\n'; + xip[sz+1] = '\0'; + //xap[sz] = schr;//'\n'; + xap[sz+1] = '\0'; + // poststring(xip); + // post("ft1: %f, %d", x->x_jodel, sz); + // outlet_float(x->t_ob.ob_outlet, x->x_jodel + x->x_jodel); + outlet_symbol(x->t_ob.ob_outlet, gensym(xip)); + for (i = 0; i < g-2;++i) + outlet_symbol(x->t_ob.ob_outlet, gensym(xap)); + if (g > 1) + outlet_symbol(x->t_ob.ob_outlet, gensym(xip)); + x->x_jodel = g; +} + +static void ascwave_width(t_ascwave *x, t_floatarg g) +{ + if (g < 0) + x->x_julp = 0; + else + x->x_julp = g; + //post("ascwave: setting width: %f", x->x_julp); +} + + +static void ascwave_chr(t_ascwave *x, t_floatarg g) +{ + x->x_chr = g; + // post("ascwave: setting character: %f", x->x_chr); +} + + +void ascwave_free() { } + +void *ascwave_new() +{ + t_ascwave *x = (t_ascwave *)pd_new(ascwave_class); + x->x_chr = 46; + // outlet_new(&x->t_ob, &s_float); + outlet_new(&x->t_ob, &s_symbol); + inlet_new(&x->t_ob, &x->t_ob.ob_pd, gensym("float"), gensym("ft1")); + inlet_new(&x->t_ob, &x->t_ob.ob_pd, gensym("float"), gensym("ft2")); + inlet_new(&x->t_ob, &x->t_ob.ob_pd, gensym("float"), gensym("ft3")); + // post("ascwave_new"); + return (void *)x; +} + +void ascwave_setup() +{ + // post("ascwave_setup"); + ascwave_class = class_new(gensym("ascwave"), (t_newmethod)ascwave_new, 0, + sizeof(t_ascwave), 0, 0); + class_addmethod(ascwave_class, (t_method)ascwave_bang, gensym("bang"), 0); + class_addmethod(ascwave_class, (t_method)ascwave_fill, gensym("fill"), A_FLOAT, A_NULL); + class_addmethod(ascwave_class, (t_method) ascwave_open, gensym("open"), A_SYMBOL,A_NULL); + class_addmethod(ascwave_class, (t_method)ascwave_ft1, gensym("ft1"), A_FLOAT, 0); + class_addmethod(ascwave_class, (t_method)ascwave_width, gensym("ft2"), A_FLOAT, 0); + // set chr + class_addmethod(ascwave_class, (t_method)ascwave_chr, gensym("ft3"), A_FLOAT, 0); +} diff --git a/bangfilt.c b/bangfilt.c new file mode 100644 index 0000000..54b1e69 --- /dev/null +++ b/bangfilt.c @@ -0,0 +1,52 @@ +/* bangfilter: = % x plus sel 0 + * spaeter: % x plus sel y mit 2 arguments + */ +#include "m_pd.h" +#include + +static t_class *bfilt_class; + +typedef struct _bfilt +{ + t_object x_obj; + t_float x_f1; + t_float x_f2; +} t_bfilt; + +static void *bfilt_new(t_floatarg f) +{ + t_bfilt *x = (t_bfilt *)pd_new(bfilt_class); + outlet_new(&x->x_obj, &s_bang); + floatinlet_new(&x->x_obj, &x->x_f2); + x->x_f1 = 0; + x->x_f2 = f; + return (x); +} + +static void bfilt_bang(t_bfilt *x) +{ + int n2 = x->x_f2, result; + if (n2 < 0) n2 = -n2; + else if (!n2) n2 = 1; + result = ((int)(x->x_f1)) % n2; + if (result == 0) //result += n2; + { + outlet_bang(x->x_obj.ob_outlet); + } + //outlet_float(x->x_obj.ob_outlet, (t_float)result); +} + +static void bfilt_float(t_bfilt *x, t_float f) +{ + x->x_f1 = f; + bfilt_bang(x); +} + + +void bfilt_setup() +{ + bfilt_class = class_new(gensym("bfilt"), (t_newmethod)bfilt_new, 0, + sizeof(t_bfilt), 0, A_DEFFLOAT, 0); + class_addbang(bfilt_class, bfilt_bang); + class_addfloat(bfilt_class, (t_method)bfilt_float); +} diff --git a/bangfilt2.c b/bangfilt2.c new file mode 100644 index 0000000..9dd6c8c --- /dev/null +++ b/bangfilt2.c @@ -0,0 +1,53 @@ +/* bangfilter: = % x plus sel 0 + * spaeter: % x plus sel y mit 2 arguments + */ +#include "m_pd.h" +#include + +static t_class *bfilt2_class; + +typedef struct _bfilt2 +{ + t_object x_obj; + t_float x_f1; + t_float x_f2; +} t_bfilt2; + +static void *bfilt2_new(t_floatarg f) +{ + t_bfilt2 *x = (t_bfilt2 *)pd_new(bfilt2_class); + outlet_new(&x->x_obj, &s_bang); + floatinlet_new(&x->x_obj, &x->x_f2); + x->x_f1 = 0; + x->x_f2 = f; + return (x); +} + +static void bfilt2_bang(t_bfilt2 *x) +{ + int n2 = x->x_f2, result; + if (n2 < 0) n2 = -n2; + else if (!n2) n2 = 1; + x->x_f1++; + result = ((int)(x->x_f1)) % n2; + if (result == 0) //result += n2; + { + outlet_bang(x->x_obj.ob_outlet); + } + //outlet_float(x->x_obj.ob_outlet, (t_float)result); +} + +static void bfilt2_float(t_bfilt2 *x, t_float f) +{ + x->x_f1 = f; + bfilt2_bang(x); +} + + +void bfilt2_setup() +{ + bfilt2_class = class_new(gensym("bfilt2"), (t_newmethod)bfilt2_new, 0, + sizeof(t_bfilt2), 0, A_DEFFLOAT, 0); + class_addbang(bfilt2_class, bfilt2_bang); + class_addfloat(bfilt2_class, (t_method)bfilt2_float); +} diff --git a/binshift.c b/binshift.c new file mode 100644 index 0000000..aaa184d --- /dev/null +++ b/binshift.c @@ -0,0 +1,81 @@ +#include "m_pd.h" +#include + +static t_class *binshift_class; + +typedef struct _binshift +{ + t_object x_obj; + t_float x_f1; + t_float x_f2; + t_int x_t1; + t_int x_t2; +} t_binshift; + +/* ------------------ binop1: +, -, *, / ----------------------------- */ + +static void *binshift1_new(t_class *floatclass, t_floatarg f) +{ + t_binshift *x = (t_binshift *)pd_new(floatclass); + outlet_new(&x->x_obj, &s_float); + floatinlet_new(&x->x_obj, &x->x_f2); + x->x_f1 = 0; + x->x_f2 = f; + return (x); +} + + +/* --------------------- rightshift ------------------------------- */ + +static t_class *binshift1_rshift_class; + +static void *binshift1_rshift_new(t_floatarg f) +{ + return (binshift1_new(binshift1_rshift_class, f)); +} + +static void binshift1_rshift_bang(t_binshift *x) +{ + outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1) >> (int)(x->x_f2))); +} + +static void binshift1_rshift_float(t_binshift *x, t_float f) +{ + outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f) >> (int)(x->x_f2))); +} + +/* --------------------- leftshift ------------------------------- */ + +static t_class *binshift1_lshift_class; + +static void *binshift1_lshift_new(t_floatarg f) +{ + return (binshift1_new(binshift1_lshift_class, f)); +} + +static void binshift1_lshift_bang(t_binshift *x) +{ + outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1) << (int)(x->x_f2))); +} + +static void binshift1_lshift_float(t_binshift *x, t_float f) +{ + outlet_float(x->x_obj.ob_outlet, ((int)(x->x_f1 = f) << (int)(x->x_f2))); +} + +/* setup */ + +void binshift_setup(void) +{ + // post("binary shift"); + + binshift1_rshift_class = class_new(gensym(">>"), (t_newmethod)binshift1_rshift_new, 0, + sizeof(t_binshift), 0, A_DEFFLOAT, 0); + class_addbang(binshift1_rshift_class, binshift1_rshift_bang); + class_addfloat(binshift1_rshift_class, (t_method)binshift1_rshift_float); + + binshift1_lshift_class = class_new(gensym("<<"), (t_newmethod)binshift1_lshift_new, 0, + sizeof(t_binshift), 0, A_DEFFLOAT, 0); + class_addbang(binshift1_lshift_class, binshift1_lshift_bang); + class_addfloat(binshift1_lshift_class, (t_method)binshift1_lshift_float); +} diff --git a/counter.c b/counter.c new file mode 100644 index 0000000..436cb42 --- /dev/null +++ b/counter.c @@ -0,0 +1,226 @@ +/* + * Copyright (c) 1997-1999 Mark Danks. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. + */ + +#include "m_pd.h" + +/* -------------------------- counter ------------------------------ */ + +/* instance structure */ +static t_class *counter_class; + +typedef struct _counter +{ + t_object x_obj; /* obligatory object header */ + int c_current; /* current number */ + int c_high; /* highest number */ + int c_low; /* lowest number */ + int c_updown; /* 0 = going up, 1 = going down */ + int c_dir; /* counter dir. 1=up, 2=down, 3=up/down */ + t_outlet *t_out1; /* the outlet */ + t_outlet *t_out2; /* the outlet */ +} t_counter; + +void counter_bang(t_counter *x) +{ + int sendBang = 0; + switch(x->c_dir) + { + // count up + case 1: + x->c_current++; + if (x->c_current > x->c_high) + x->c_current = x->c_low; + else if (x->c_current < x->c_low) + x->c_current = x->c_low; + else if (x->c_current == x->c_high) + sendBang = 1; + break; + // count down + case 2: + x->c_current--; + if (x->c_current < x->c_low) + x->c_current = x->c_high; + else if (x->c_current > x->c_high) + x->c_current = x->c_high; + else if (x->c_current == x->c_low) + sendBang = 1; + break; + // count up and down + case 3: + // going up + if (x->c_updown == 0) + { + x->c_current++; + if (x->c_current > x->c_high) + { + x->c_current = x->c_high - 1; + x->c_updown = 1; + } + else if (x->c_current < x->c_low) + x->c_current = x->c_low; + else if (x->c_current == x->c_high) + sendBang = 1; + } + // going down + else if (x->c_updown == 1) + { + x->c_current--; + if (x->c_current < x->c_low) + { + x->c_current = x->c_low + 1; + x->c_updown = 0; + } + else if (x->c_current > x->c_high) + x->c_current = x->c_high; + else if (x->c_current == x->c_low) + sendBang = 1; + } + else + { + error("up/down wrong"); + return; + } + break; + default: + error("dir wrong"); + return; + } + outlet_float(x->t_out1, (float)x->c_current); + if (sendBang) + outlet_bang(x->t_out2); +} + +void counter_dir(t_counter *x, t_floatarg n) +{ + if (n == 1 || n == 2 || n == 3) x->c_dir = (int)n; + else error("bad dir"); +} + +void counter_high(t_counter *x, t_floatarg n) +{ + x->c_high = (int)n; +} + +void counter_low(t_counter *x, t_floatarg n) +{ + x->c_low = (int)n; +} + +void counter_reset(t_counter *x, t_symbol *s, int argc, t_atom *argv) +{ + if (!argc) + { + switch(x->c_dir) + { + case 1: + x->c_current = x->c_low; + break; + case 2: + x->c_current = x->c_high; + break; + case 3: + if (x->c_updown == 0) x->c_current = x->c_low; + else if (x->c_updown == 1) x->c_current = x->c_high; + break; + default: + return; + } + } + else + { + switch(argv[0].a_type) + { + case A_FLOAT : + x->c_current = (int)argv[0].a_w.w_float; + break; + default : + error ("counter: reset not float"); + break; + } + } + outlet_float(x->t_out1, (float)x->c_current); +} + +void counter_clear(t_counter *x, t_symbol *s, int argc, t_atom *argv) +{ + if (!argc) + { + switch(x->c_dir) + { + case 1: + x->c_current = x->c_low - 1; + break; + case 2: + x->c_current = x->c_high + 1; + break; + case 3: + if (x->c_updown == 0) x->c_current = x->c_low - 1; + else if (x->c_updown == 1) x->c_current = x->c_high + 1; + break; + default: + break; + } + } + else + { + switch(argv[0].a_type) + { + case A_FLOAT : + x->c_current = (int)argv[0].a_w.w_float - 1; + break; + default : + error ("counter: reset not float"); + break; + } + } +} + +void *counter_new(t_floatarg f, t_floatarg g, t_floatarg h) /* init vals in struc */ +{ + t_counter *x = (t_counter *)pd_new(counter_class); + x->t_out1 = outlet_new(&x->x_obj, 0); + x->t_out2 = outlet_new(&x->x_obj, 0); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl3")); + x->c_current = 0; + x->c_updown = 0; + if (h) + { + counter_low(x, f); + counter_high(x, g); + counter_dir(x, h); + } + else if (g) + { + x->c_dir = 1; + counter_low(x, f); + counter_high(x, g); + } + else if (f) + { + x->c_dir = x->c_low = 1; + counter_high(x, f); + } + else + { + x->c_dir = x->c_low = 1; + x->c_high = 10; + } + return (x); +} + +void counter_setup(void) +{ + counter_class = class_new(gensym("counter"), (t_newmethod)counter_new, 0, + sizeof(t_counter), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(counter_class, (t_method)counter_bang); + class_addmethod(counter_class, (t_method)counter_dir, gensym("fl1"), A_FLOAT, 0); + class_addmethod(counter_class, (t_method)counter_low, gensym("fl2"), A_FLOAT, 0); + class_addmethod(counter_class, (t_method)counter_high, gensym("fl3"), A_FLOAT, 0); + class_addmethod(counter_class, (t_method)counter_reset, gensym("reset"), A_GIMME, 0); + class_addmethod(counter_class, (t_method)counter_clear, gensym("clear"), A_GIMME, 0); +} diff --git a/cx.c b/cx.c new file mode 100644 index 0000000..f8020d6 --- /dev/null +++ b/cx.c @@ -0,0 +1,103 @@ + +#ifndef VERSION +#define VERSION "0.04" +#endif + +#ifndef __DATE__ +#define __DATE__ "without using a gnu compiler" +#endif + +#include + + +typedef struct _cxc +{ + t_object x_obj; +} t_cxc; + +static t_class* cxc_class; + +void binshift_setup(); +void ascwave_setup(); +void ascseq_setup(); +void ixprint_setup(); +//void mixer_setup(); +//void makesymbol_setup(); +void bfilt_setup(); +void bfilt2_setup(); +/* void sendOSC_setup(); */ +/* void dumpOSC_setup(); */ +/* void routeOSC_setup(); */ +//void testy_tilde_setup(); +//void garlic_tilde_setup(); +void counter_setup(); +void reson_setup(); +//void serialize_setup(); +void prepend_setup(); +void utime_setup(); +// RNG's +void random1_setup(); +void random_fl_setup(); +void random_icg_setup(); +void random_tw_setup(); +void dist_normal_setup(); + +void ENV_setup(); +void proc_setup(); + +void cxmean_setup(); +void cxavgdev_setup(); +void cxstddev_setup(); + +void mean_tilde_setup(); + +void delta_tilde_setup(); + +static void* cxc_new(t_symbol* s) { + t_cxc *x = (t_cxc *)pd_new(cxc_class); + return (x); +} + +void cxc_setup(void) +{ + cxc_class = class_new(gensym("cxc"), (t_newmethod)cxc_new, 0, + sizeof(t_cxc), 0,0); + ixprint_setup(); + binshift_setup(); + ascwave_setup(); + ascseq_setup(); + // mixer_setup(); + // makesymbol_setup(); + bfilt_setup(); + bfilt2_setup(); +/* sendOSC_setup(); */ +/* dumpOSC_setup(); */ +/* routeOSC_setup(); */ + counter_setup(); + reson_setup(); + //serialize_setup(); + prepend_setup(); + utime_setup(); + // RNG's + random1_setup(); + random_fl_setup(); + random_icg_setup(); + random_tw_setup(); + dist_normal_setup(); + + ENV_setup(); + proc_setup(); + + cxmean_setup(); + cxavgdev_setup(); + cxstddev_setup(); + + mean_tilde_setup(); + + delta_tilde_setup(); + + post("c : jdl@xdv.org ========================================"); + post(" x : ver: "VERSION" ============================================"); + post(" c: compiled: "__DATE__" =================================="); + post("\\"); +} diff --git a/gpl.txt b/gpl.txt new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/gpl.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/hex2dec.c b/hex2dec.c new file mode 100644 index 0000000..1176838 --- /dev/null +++ b/hex2dec.c @@ -0,0 +1,47 @@ +#include "m_pd.h" +#include + +#include +#include + +/* ----------------------- hex2dec --------------------- */ + +static t_class *hex2dec_class; + +typedef struct _hex2dec +{ + t_object x_obj; + t_symbol *x_format; +} t_hex2dec; + +static void *hex2dec_new(t_symbol *s) +{ + t_hex2dec *x = (t_hex2dec *)pd_new(hex2dec_class); + if (!s->s_name) s = gensym("file.%d"); + outlet_new(&x->x_obj, &s_symbol); + x->x_format = s; + return (x); +} + +static void hex2dec_float(t_hex2dec *x, t_floatarg f) +{ + char buf[MAXPDSTRING]; + sprintf(buf, x->x_format->s_name, (int)f); + outlet_symbol(x->x_obj.ob_outlet, gensym(buf)); +} + +static void hex2dec_symbol(t_hex2dec *x, t_symbol *s) +{ + char buf[MAXPDSTRING]; + sprintf(buf, x->x_format->s_name, s->s_name); + outlet_symbol(x->x_obj.ob_outlet, gensym(buf)); +} + +static void hex2dec_setup(void) +{ + hex2dec_class = class_new(gensym("hex2dec"), + (t_newmethod)hex2dec_new, 0, + sizeof(t_hex2dec), 0, A_DEFSYM, 0); + class_addfloat(hex2dec_class, hex2dec_float); + class_addsymbol(hex2dec_class, hex2dec_symbol); +} diff --git a/ixprint.c b/ixprint.c new file mode 100644 index 0000000..5de6160 --- /dev/null +++ b/ixprint.c @@ -0,0 +1,88 @@ +#include "m_pd.h" + +/* -------------------------- ixprint ------------------------------ + * print without "print: " ... + */ +static t_class *ixprint_class; + +typedef struct _ixprint +{ + t_object x_obj; + t_symbol *x_sym; +} t_ixprint; + +static void *ixprint_new(t_symbol *s) +{ + t_ixprint *x = (t_ixprint *)pd_new(ixprint_class); + if (*s->s_name) x->x_sym = s; + // change, plain print .. + else x->x_sym = gensym(""); + return (x); +} + +static void ixprint_bang(t_ixprint *x) +{ + post("bang", x->x_sym->s_name); +} + +static void ixprint_pointer(t_ixprint *x, t_gpointer *gp) +{ + post("(gpointer)", x->x_sym->s_name); +} + +static void ixprint_float(t_ixprint *x, t_float f) +{ + post("%g",f); +} + +static void ixprint_list(t_ixprint *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + char buf[80]; + if (argc && argv->a_type != A_SYMBOL) startpost("%s:", x->x_sym->s_name); + else startpost("%s", + (argc > 1 ? s_list.s_name : s_symbol.s_name)); + postatom(argc, argv); + endpost(); +} + +static void ixprint_anything(t_ixprint *x, t_symbol *s, int argc, t_atom *argv) +{ + int i; + char buf[80]; + startpost("%s", s->s_name); + postatom(argc, argv); + endpost(); +} + +/* -------------------------- logger ------------------------------ + * log text input into file , output linecount .. + */ + +/* static t_class *logger_class; + +typedef struct _logger +{ + t_object x_obj; + t_symbol x_fname; + t_float x_lc; +} t_logger; + +static void *logger_new(t_symbol *s) +{ + t_logger *x = (t_logger *)pd_new(logger_class); + x->x_fname = gensym("pd.log"); + return (x); +} +*/ + +void ixprint_setup(void) +{ + ixprint_class = class_new(gensym("ixprint"), (t_newmethod)ixprint_new, 0, + sizeof(t_ixprint), 0, A_DEFSYM, 0); + class_addbang(ixprint_class, ixprint_bang); + class_addfloat(ixprint_class, ixprint_float); + class_addpointer(ixprint_class, ixprint_pointer); + class_addlist(ixprint_class, ixprint_list); + class_addanything(ixprint_class, ixprint_anything); +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..1ecb81d --- /dev/null +++ b/makefile @@ -0,0 +1,44 @@ + +current: linux + +.SUFFIXES: .pd_linux +INSTALL_PREFIX = /usr +PD_DIR = $(INSTALL_PREFIX)/lib/pd + +VERSION = \"$(shell cat VERSION)\" +#LIBOSC = ../OSC/perl/libOSC/libOSC.a +LIBOSC = + +TARGETS = binshift ascwave ixprint bangfilt bangfilt2 \ + counter reson prepend microtime ascseq \ + randomix ENV proc mean sigdelta cx + +# mean +# serialize + +LINUXOBJECTS = $(TARGETS:%=%.o) + +LINCLUDE = -I. -I../pd-0.35-test24/src +# possible defines +# -DPRINTADDRS +DEBUG = -DDEBUG -ggdb +#DEBUG = +CFLAGS = -O2 -DPD -DVERSION=$(VERSION) $(DEBUG) -fPIC $(LINCLUDE) +LIBS = -lc -lm +linux: $(LINUXOBJECTS) + ld -export_dynamic -shared -o cxc.pd_linux *.o $(LIBS) ${LIBOSC} + strip --strip-unneeded cxc.pd_linux + +.c.pd_linux: + cc $(CFLAGS) -c $*.c ${LIBOSC} + +clean: + rm *.pd_linux *.o *~ + +install: + install -d $(PD_DIR)/doc/5.reference/cxc + install -m664 reference/*.pd $(PD_DIR)/doc/5.reference/cxc + install -m664 cxc.pd_linux $(PD_DIR)/externs +uninstall: + rm -rf $(PD_DIR)/doc/5.reference/cxc + rm -rf $(PD_DIR)/externs/cxc.pd_linux diff --git a/mean.c b/mean.c new file mode 100644 index 0000000..3781f3e --- /dev/null +++ b/mean.c @@ -0,0 +1,434 @@ +/* + jdl@xdv.org, 200203 + calculate mean of buffer + standard deviation + histogram + */ + +#include "m_imp.h" +//#include "m_pd.h" +#include +//#include + + +/* cx.mean: calculate the mean from a table */ +/* as defined by: add all samples together and divide by number of samples */ +t_class *cxmean_class; + +typedef struct _cxmean +{ + t_object x_obj; + t_symbol *x_arrayname; + t_float x_mean; + float *x_vec; + t_float f; + int x_nsampsintab; +} t_cxmean; + +void *cxmean_new(t_symbol *s) +{ + t_cxmean *x = (t_cxmean *)pd_new(cxmean_class); + x->x_arrayname = s; + x->x_mean = 0; + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void cxmean_set(t_cxmean *x, t_symbol *s) +{ + t_garray *a; + + x->x_arrayname = s; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + { + if (*s->s_name) pd_error(x, "mean~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; + } + else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) + { + error("%s: bad template for mean~", x->x_arrayname->s_name); + x->x_vec = 0; + } + else garray_usedindsp(a); +} + +void cxmean_bang(t_cxmean *x) +{ + outlet_float(x->x_obj.ob_outlet,x->x_mean); +} + +static void cxmean_mean(t_cxmean *x) +{ + // t_float *bl; + t_garray *a; + int cnt; + t_float *fp; + t_float xz = 0.; + + cnt = 0; + if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname,garray_class))) { + pd_error(x, "%s: no such table", x->x_arrayname->s_name); + } + garray_getfloatarray(a,&x->x_nsampsintab,&x->x_vec); + + fp = x->x_vec; + + while(cnt < x->x_nsampsintab) { + //post("cxc/mean.c: %f",*fp++); + xz += *fp++; + cnt++; + } +#ifdef DEBUG + post("cxc/mean.c: sampsum: %f",xz); +#endif + x->x_mean = xz / x->x_nsampsintab; + + outlet_float(x->x_obj.ob_outlet, x->x_mean); +} + +void cxmean_setup(void) +{ + cxmean_class = class_new(gensym("cx.mean"), + (t_newmethod)cxmean_new, + 0, + sizeof(t_cxmean), + CLASS_DEFAULT, + A_DEFSYM, 0); + class_addmethod(cxmean_class, (t_method)cxmean_set, + gensym("set"), A_DEFSYM, 0); + class_addmethod(cxmean_class, (t_method)cxmean_mean, + gensym("mean"), A_DEFSYM, 0); + class_addbang(cxmean_class, cxmean_bang); + class_sethelpsymbol(cxmean_class, gensym("cxc/statistics.pd")); +} + + +/* cx.avgdev: calculate the average deviation of an array from + mean as input and array. + takes mean as input, sum of abs values of sample-val - mean + divided by number of samples + */ + +t_class *cxavgdev_class; + +typedef struct _cxavgdev +{ + t_object x_obj; + t_symbol *x_arrayname; + t_float x_avgdev; + float *x_vec; + t_float f; + int x_nsampsintab; +} t_cxavgdev; + +void *cxavgdev_new(t_symbol *s) +{ + t_cxavgdev *x = (t_cxavgdev *)pd_new(cxavgdev_class); + x->x_arrayname = s; + x->x_avgdev = 0; + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void cxavgdev_set(t_cxavgdev *x, t_symbol *s) +{ + t_garray *a; + + x->x_arrayname = s; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + { + if (*s->s_name) pd_error(x, "mean~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; + } + else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) + { + error("%s: bad template for mean~", x->x_arrayname->s_name); + x->x_vec = 0; + } + else garray_usedindsp(a); +} + +void cxavgdev_bang(t_cxavgdev *x) +{ + outlet_float(x->x_obj.ob_outlet,x->x_avgdev); +} + +static void cxavgdev_float(t_cxavgdev *x, t_float f) +{ + // t_float *bl; + t_garray *a; + int cnt; + t_float *fp; + t_float xz = 0.; + t_float tz = 0.; + + cnt = 0; + if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname,garray_class))) { + pd_error(x, "%s: no such table", x->x_arrayname->s_name); + } + garray_getfloatarray(a,&x->x_nsampsintab,&x->x_vec); + + fp = x->x_vec; + + while(cnt < x->x_nsampsintab) { + tz = *fp++; + tz = fabs(tz - f); + xz += tz; +#ifdef DEBUG + //post("cxc/mean.c: sampdeviation: %f",tz); +#endif + cnt++; + } +#ifdef DEBUG + post("cxc/mean.c: avgsum: %f",xz); +#endif + x->x_avgdev = xz / x->x_nsampsintab; + + outlet_float(x->x_obj.ob_outlet, x->x_avgdev); +} + +void cxavgdev_setup(void) +{ + cxavgdev_class = class_new(gensym("cx.avgdev"), + (t_newmethod)cxavgdev_new, + 0, + sizeof(t_cxavgdev), + CLASS_DEFAULT, + A_DEFSYM, 0); + class_addmethod(cxavgdev_class, (t_method)cxavgdev_set, + gensym("set"), A_DEFSYM, 0); +/* class_addmethod(cxavgdev_class, (t_method)cxavgdev_mean, */ +/* gensym("mean"), A_DEFSYM, 0); */ + class_addfloat(cxavgdev_class, (t_method)cxavgdev_float); + class_addbang(cxavgdev_class, cxavgdev_bang); + class_sethelpsymbol(cxavgdev_class, gensym("cxc/statistics.pd")); +} + +/* cx.stddev: calculate the standard deviation of an array from + mean as input and array. + square root of sum of power of sample - mean divided by num of + samps - 1 + */ + +t_class *cxstddev_class; + +typedef struct _cxstddev +{ + t_object x_obj; + t_symbol *x_arrayname; + t_float x_stddev; + float *x_vec; + t_float f; + int x_nsampsintab; +} t_cxstddev; + +void *cxstddev_new(t_symbol *s) +{ + t_cxstddev *x = (t_cxstddev *)pd_new(cxstddev_class); + x->x_arrayname = s; + x->x_stddev = 0; + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void cxstddev_set(t_cxstddev *x, t_symbol *s) +{ + t_garray *a; + + x->x_arrayname = s; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + { + if (*s->s_name) pd_error(x, "mean~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; + } + else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) + { + error("%s: bad template for mean~", x->x_arrayname->s_name); + x->x_vec = 0; + } + else garray_usedindsp(a); +} + +void cxstddev_bang(t_cxstddev *x) +{ + outlet_float(x->x_obj.ob_outlet,x->x_stddev); +} + +static void cxstddev_float(t_cxstddev *x, t_float f) +{ + // t_float *bl; + t_garray *a; + int cnt; + t_float *fp; + t_float xz = 0.; + t_float tz = 0.; + + cnt = 0; + if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname,garray_class))) { + pd_error(x, "%s: no such table", x->x_arrayname->s_name); + } + garray_getfloatarray(a,&x->x_nsampsintab,&x->x_vec); + + fp = x->x_vec; + + while(cnt < x->x_nsampsintab) { + tz = *fp++; + tz = pow(tz - f,2); // power of 2 + xz += tz; +#ifdef DEBUG + //post("cxc/mean.c: sampdeviation: %f",tz); +#endif + cnt++; + } +#ifdef DEBUG + post("cxc/mean.c: avgsum: %f",xz); +#endif + x->x_stddev = sqrt(xz / (x->x_nsampsintab - 1)); + + outlet_float(x->x_obj.ob_outlet, x->x_stddev); +} + +void cxstddev_setup(void) +{ + cxstddev_class = class_new(gensym("cx.stddev"), + (t_newmethod)cxstddev_new, + 0, + sizeof(t_cxstddev), + CLASS_DEFAULT, + A_DEFSYM, 0); + class_addmethod(cxstddev_class, (t_method)cxstddev_set, + gensym("set"), A_DEFSYM, 0); +/* class_addmethod(cxstddev_class, (t_method)cxstddev_mean, */ +/* gensym("mean"), A_DEFSYM, 0); */ + class_addfloat(cxstddev_class, (t_method)cxstddev_float); + class_addbang(cxstddev_class, cxstddev_bang); + class_sethelpsymbol(cxstddev_class, gensym("cxc/statistics.pd")); +} + +/* ---------- mean~ ---------- */ +/* output the mean as a signal */ + +t_class *mean_tilde_class; + +typedef struct _mean_tilde +{ + t_object x_obj; + t_symbol *x_arrayname; + t_float x_mean; + float *x_vec; + t_float f; + int x_nsampsintab; +} t_mean_tilde; + +void *mean_tilde_new(t_symbol *s) +{ + t_mean_tilde *x = (t_mean_tilde *)pd_new(mean_tilde_class); + x->x_arrayname = s; + x->x_mean = 0; + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static t_int *mean_tilde_perform(t_int *w) +{ + t_mean_tilde *x = (t_mean_tilde *)(w[1]); + //t_float *out = (t_float *)(w[3]), + t_float *fp; + //// t_float *in = (t_float *)(w[2]); + //// *out = *in; + int n = (int)(w[2]); + t_float xz = 0.; + fp = x->x_vec; + while(n--) { + xz += abs(*fp++); + //post("cxc/mean.c: %d : %f : %f",n,xz,fp); + } + x->x_mean = (t_float)(xz / n); + //post("cxc/mean.c: %f",xz); + return (w+3); + //return 0; +} + +static void mean_tilde_set(t_mean_tilde *x, t_symbol *s) +{ + t_garray *a; + + x->x_arrayname = s; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + { + if (*s->s_name) pd_error(x, "mean~: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; + } + else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) + { + error("%s: bad template for mean~", x->x_arrayname->s_name); + x->x_vec = 0; + } + else garray_usedindsp(a); +} + +static void mean_tilde_dsp(t_mean_tilde *x, t_signal **sp) +{ + mean_tilde_set(x, x->x_arrayname); + //dsp_add(mean_tilde_perform, 2, x, sp[0]->s_vec, sp[0]->s_n); + //dsp_add(mean_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); + dsp_add(mean_tilde_perform, 2, x, sp[0]->s_n); +} + +void mean_tilde_bang(t_mean_tilde *x) +{ + outlet_float(x->x_obj.ob_outlet,x->x_mean); +} + +static void mean_tilde_mean(t_mean_tilde *x) +{ + // t_float *bl; + t_garray *a; + int cnt; + t_float *fp; + t_float xz = 0.; + + cnt = 0; + if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname,garray_class))) { + pd_error(x, "%s: no such table", x->x_arrayname->s_name); + } + garray_getfloatarray(a,&x->x_nsampsintab,&x->x_vec); + + fp = x->x_vec; + + while(cnt < x->x_nsampsintab) { + //post("cxc/mean.c: %f",*fp++); + xz += *fp++; + cnt++; + } +#ifdef DEBUG + post("cxc/mean.c: sampsum: %f",xz); +#endif + x->x_mean = xz / x->x_nsampsintab; + + outlet_float(x->x_obj.ob_outlet, x->x_mean); +} + +void mean_tilde_setup(void) +{ + //post("mean~ setup"); + mean_tilde_class = class_new(gensym("mean~"), + (t_newmethod)mean_tilde_new, + 0, + sizeof(t_mean_tilde), + CLASS_DEFAULT, + A_DEFSYM, 0); + //CLASS_MAINSIGNALIN(mean_tilde_class, t_mean_tilde, f); + class_addmethod(mean_tilde_class, nullfn, gensym("signal"), 0); + class_addmethod(mean_tilde_class, + (t_method)mean_tilde_dsp, + gensym("dsp"), 0); + class_addmethod(mean_tilde_class, (t_method)mean_tilde_set, + gensym("set"), A_DEFSYM, 0); + class_addmethod(mean_tilde_class, (t_method)mean_tilde_mean, + gensym("mean"), A_DEFSYM, 0); + class_addbang(mean_tilde_class, mean_tilde_bang); +} diff --git a/microtime.c b/microtime.c new file mode 100644 index 0000000..587ddef --- /dev/null +++ b/microtime.c @@ -0,0 +1,54 @@ +/* + (c) 2002:cxc@web.fm + microtime: seconds since epoch plus microsecs + */ + +#include +#include +#include + +/* ----------------------- utime --------------------- */ + +static t_class *utime_class; + +typedef struct _utime +{ + t_object x_obj; + t_outlet *x_outlet1; + t_outlet *x_outlet2; +} t_utime; + +static void *utime_new(t_symbol *s, int argc, t_atom *argv) { + t_utime *x = (t_utime *)pd_new(utime_class); + x->x_outlet1 = outlet_new(&x->x_obj, &s_float); + x->x_outlet2 = outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void utime_bang(t_utime *x) +{ + struct timeval myutime; + struct timezone mytz; + + gettimeofday(&myutime, &mytz); + outlet_float(x->x_outlet2, (t_float)myutime.tv_usec); + outlet_float(x->x_outlet1, (t_float)myutime.tv_sec); +} + +static void help_utime(t_utime *x) +{ + post("\n%c utime\t\t:: get the current system time", 70); + post("\noutputs are\t: seconds since epoch / remaining microseconds"); +} + +void utime_setup(void) +{ + utime_class = class_new(gensym("utime"), + (t_newmethod)utime_new, 0, + sizeof(t_utime), 0, A_GIMME, 0); + + class_addbang(utime_class, utime_bang); + + class_addmethod(utime_class, (t_method)help_utime, gensym("help"), 0); + class_sethelpsymbol(utime_class, gensym("cxc/utime.pd")); +} diff --git a/prepend.c b/prepend.c new file mode 100644 index 0000000..bc6313a --- /dev/null +++ b/prepend.c @@ -0,0 +1,121 @@ +#include +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* this is taken from ggee, where the file was hanging around but the object was not + funtional. i keep it here for reference since i dont wnat to fix it over and over ;) + but its not included in the makefile to avoid namespace clash with ggee.prepend + anyhow, i ll just rename it cxc.prepend +*/ + +/* ------------------------ prepend ----------------------------- */ + +static t_class *prepend_class; + + +typedef struct _prepend +{ + t_object x_obj; + t_symbol* x_s; +} t_prepend; + + +void prepend_anything(t_prepend *x,t_symbol* s,t_int argc,t_atom* argv) +{ + int i = argc; + t_symbol* cur; + t_atom a_out[256]; + int c_out = 0; + t_atom* a = a_out; + +#if 1 + // post("sym: %s",s->s_name); + SETSYMBOL(a,s); + a++; + c_out++; +#endif + + while (i--) { + switch( argv->a_type) { + case A_FLOAT: + // post("flo: %f",atom_getfloat(argv)); + SETFLOAT(a,atom_getfloat(argv)); + a++; + c_out++; + break; + case A_SYMBOL: + // post("sym: %s",atom_getsymbol(argv)->s_name); + SETSYMBOL(a,atom_getsymbol(argv)); + a++; + c_out++; + break; + default: + post("prepend.c: unknown type"); + } + argv++; + } + + outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out); + //post("done"); +} + +void prepend_list(t_prepend *x,t_symbol* s,t_int argc,t_atom* argv) +{ + int i = argc; + t_symbol* cur; + t_atom a_out[256]; + int c_out = 0; + t_atom* a = a_out; + + while (i--) { + switch( argv->a_type) { + case A_FLOAT: + // post("flo: %f",atom_getfloat(argv)); + SETFLOAT(a,atom_getfloat(argv)); + a++; + c_out++; + break; + case A_SYMBOL: + // post("sym: %s",atom_getsymbol(argv)->s_name); + SETSYMBOL(a,atom_getsymbol(argv)); + a++; + c_out++; + break; + default: + post("prepend.c: unknown type"); + } + argv++; + } + + outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out); + //post("done"); +} + +static void *prepend_new(t_symbol* s) +{ + t_prepend *x = (t_prepend *)pd_new(prepend_class); + outlet_new(&x->x_obj, &s_float); + if (s != &s_) + x->x_s = s; + else + x->x_s = gensym("cxc.prepend"); + return (x); +} + +static void prepend_set(t_prepend *x, t_symbol *s) +{ + x->x_s = s; +} + +void prepend_setup(void) +{ + prepend_class = class_new(gensym("cxc.prepend"), (t_newmethod)prepend_new, 0, + sizeof(t_prepend), 0,A_DEFSYM,NULL); + class_addlist(prepend_class, prepend_list); + class_addanything(prepend_class,prepend_anything); + class_addmethod(prepend_class, (t_method)prepend_set, gensym("set"), A_SYMBOL, 0); +} + + diff --git a/proc.c b/proc.c new file mode 100644 index 0000000..22cd23a --- /dev/null +++ b/proc.c @@ -0,0 +1,223 @@ +/* + cxc@web.fm, 200203 + interface to the linux proc filesystem + TODO: stat, number of users, network stats (tx,rx,etc) + */ + +#include "m_pd.h" +#include +#include +#include +//#include +// later for number of users +// #include + +#ifndef SSIZE_MAX +#define SSIZE_MAX 255 +#endif + +#ifndef RAND_MAX +#define RAND_MAX 2147483647 +#endif + +#ifndef MAXOUTAT +#define MAXOUTAT 50 +#endif + +t_class *proc_class; + +typedef struct proc +{ + t_object x_obj; + // t_float x_RM; + t_atom x_at[MAXOUTAT]; + int x_atc; +} t_proc; + +void proc_float(t_proc *x, t_floatarg f) +{ + post("cxc/proc.c: %f", f); +} + +void proc_cpuinfo(t_proc *x) +{ + char name[255]; // filename + char rest[255]; // string value + t_float restf; // float value + char bla[1]; + FILE* fp; // info file descriptor + // t_float val; + int ac; // atom count + t_atom* at = x->x_at; // out atom + int atc = x->x_atc; // out atom count + + //name = "/proc/cpuinfo"; + sprintf(name,"%s","/proc/cpuinfo"); + //val = 0; + restf = 0; + ac = 0; + + fp = fopen(name,"r"); + if (!fp) { + post("cxc/proc.c: unable to open %s",name); + return; + } + //*name = 0; + while(!feof(fp)) + { +/* fread(bla,1,1,fp); */ +/* post("cxc/proc.c: '%s'",bla); */ + //ac = fscanf(fp,"%s\t: %s",name,rest); + ac = fscanf(fp,"%s\t: %f",name,&restf); + // fscanf(fp,"%s\t%s %d",name,rest,&val); + if((!strcmp("MHz",name) || + !strcmp("processor",name) || + !strcmp("bogomips",name)) && + ac != -1) + { + if(!strcmp("MHz",name)) { + //val = (t_float)sprintf("%f",rest); + SETFLOAT(at+atc,restf); + atc++; + } else if (!strcmp("processor",name)) { + SETFLOAT(at+atc,restf); + atc++; + } else if (!strcmp("bogomips",name)) { + SETFLOAT(at+atc,restf); + atc++; + } +#ifdef DEBUG + post("cxc/proc.c: count %d, '%s' -> '%f'",ac,name,restf); +#endif + } + } + outlet_anything(x->x_obj.ob_outlet, gensym("cpuinfo"),atc,at); +} + +///////////////////////////////////////////////////////////////// +// more generic proc function: file to open is the message itself +void proc_proc(t_proc *x, t_symbol *s) +{ + char name[255]; // filename + char rest[255]; // string value + t_float restf; // float value + t_float restg; // another float, needing more etc + t_float resth; // another float, needing more etc + // unsmart, convert the whole line + // into an atom vector or something ... + int a,b,c; // few helper ints for scanf + char bla[1]; + FILE* fp; // info file descriptor + // t_float val; + int ac; // atom count + t_atom* at = x->x_at; // out atom + int atc = x->x_atc; // out atom count + + //post("cxc/proc.c: %s",s->s_name); + + //sprintf(name,"%s","/proc/cpuinfo"); + sprintf(name,"/proc/%s",s->s_name); + //val = 0; + restf = 0; + ac = 0; + + fp = fopen(name,"r"); + if (!fp) { + post("cxc/proc.c: unable to open %s",name); + return; + } + //*name = 0; + while(!feof(fp)) { + /* fread(bla,1,1,fp); */ + /* post("cxc/proc.c: '%s'",bla); */ + //ac = fscanf(fp,"%s\t: %s",name,rest); +// ac = fscanf(fp,"%s\t: %f",name,&restf); + // fscanf(fp,"%s\t%s %d",name,rest,&val); + + ////////////////////////////////////////////////// + // cpuinfo (rel. compl. parse) + if(!strcmp("cpuinfo",s->s_name)) { + ac = fscanf(fp,"%s\t: %f",name,&restf); + +#ifdef DEBUG + if((!strcmp("MHz",name) || + !strcmp("processor",name) || + !strcmp("bogomips",name)) && + ac != -1) { + post("cxc/proc.c: count %d, '%s' -> '%f'",ac,name,restf); + } +#endif + + if(!strcmp("MHz",name)) { + //val = (t_float)sprintf("%f",rest); + SETFLOAT(at+atc,restf); + atc++; + } else if (!strcmp("processor",name)) { + SETFLOAT(at+atc,restf); + atc++; + } else if (!strcmp("bogomips",name)) { + SETFLOAT(at+atc,restf); + atc++; + } + ////////////////////////////////////////////////// + // uptime (easy, just two floats ... + } else if (!strcmp("uptime",s->s_name)) { + ac = fscanf(fp,"%f %f",&restf,&restg); + SETFLOAT(at+atc,restf); atc++; + SETFLOAT(at+atc,restg); atc++; + // why break here? + break; + ////////////////////////////////////////////////// + // loadavg + } else if (!strcmp("loadavg",s->s_name)) { + ac = fscanf(fp,"%f %f %f %d/%d %d",&restf,&restg,&resth,&a,&b,&c); + SETFLOAT(at+atc,restf); atc++; + SETFLOAT(at+atc,restg); atc++; + SETFLOAT(at+atc,resth); atc++; + SETFLOAT(at+atc,(t_float)a); atc++; + SETFLOAT(at+atc,(t_float)b); atc++; + SETFLOAT(at+atc,(t_float)c); atc++; + // why break here? + break; + ////////////////////////////////////////////////// + // version (linux version) + } else if (!strcmp("version",s->s_name)) { + ac = fscanf(fp,"%s %s %d.%d.%d *",name,rest,&a,&b,&c); + SETFLOAT(at+atc,a); atc++; + SETFLOAT(at+atc,b); atc++; + SETFLOAT(at+atc,c); atc++; + // why break here? + break; +/* } else if (!strcmp("stat",s->s_name)) { */ +/* break; */ + } else { + post("cxc/proc.c: %s not yet implemented",s->s_name); + break; + } + } + fclose(fp); + outlet_anything(x->x_obj.ob_outlet, gensym(s->s_name),atc,at); +} + +void *proc_new(void) +{ + t_proc *x = (t_proc *)pd_new(proc_class); + x->x_atc = 0; + outlet_new(&x->x_obj, &s_anything); + return (void *)x; +} + +void proc_setup(void) +{ + // post("proc_setup"); + proc_class = class_new(gensym("proc"), (t_newmethod)proc_new, 0, + sizeof(t_proc), 0, 0); + class_addmethod(proc_class, (t_method)proc_cpuinfo, gensym("cpuinfo"), 0); + class_addmethod(proc_class, (t_method)proc_proc, gensym("proc"), A_SYMBOL); + //class_addmethod(proc_class, (t_method)proc_RAND_MAX, gensym("RAND_MAX"), 0); + //class_addmethod(proc_class, (t_method)proc_getenv, gensym("getenv"), A_SYMBOL); + //class_addmethod(proc_class, (t_method)proc_setenv, gensym("setenv"), A_SYMBOL, A_SYMBOL); + class_addfloat(proc_class, proc_float); + class_sethelpsymbol(proc_class, gensym("cxc/proc.pd")); +} + diff --git a/randomix.c b/randomix.c new file mode 100644 index 0000000..5a0f96b --- /dev/null +++ b/randomix.c @@ -0,0 +1,682 @@ +/* + (c) 2002:cxc@web.fm + randomix: various PRNG's + code taken from: http://remus.rutgers.edu/%7Erhoads/Code/code.html + let's check it out + */ + +#include +#include +#include + +#define SMALLEST_RANGE .0001 + +#ifndef RAND_MAX +#define RAND_MAX 2147483647 +#endif + +static unsigned random_icg_INVERSE_seed (); +static int makeseed(void); +static int rand_random1(int); +static int rand_random_fl(int); +//static void random_tw_rand_seed(t_class, int, int, int); + +static int makeseed(void) +{ + static unsigned int random1_nextseed = 1489853723; + random1_nextseed = random1_nextseed * 435898247 + 938284287; + return (random1_nextseed & 0x7fffffff); +} + +/* -------------------------- random1 ------------------------------ */ +/* linear congruential generator. Generator x[n+1] = a * x[n] mod m */ +static int rand_random1(seed) +{ + int state; + + //unsigned int a = 1588635695, m = 4294967291U, q = 2, r = 1117695901; + // unsigned int a = 1588635695, m = (RAND_MAX * 2), q = 2, r = 1117695901; + + /* static unsigned int a = 1223106847, m = 4294967291U, q = 3, r = 625646750;*/ + /* static unsigned int a = 279470273, m = 4294967291U, q = 15, r = 102913196;*/ + //static unsigned int a = 1583458089, m = 2147483647, q = 1, r = 564025558; + static unsigned int a = 784588716, m = 2147483647, q = 2, r = 578306215; + /* static unsigned int a = 16807, m = 2147483647, q = 127773, r = 2836; */ + /* static unsigned int a = 950706376, m = 2147483647, q = 2, r = 246070895; */ + + //state = (seed) ? seed : makeseed(); + state = seed; + state = a*(state % q) - r*(state / q); + return (state); +} + +static int rand_random_fl(seed) { + int q; + double state; + + /* The following parameters are recommended settings based on research + uncomment the one you want. */ + + double a = 1389796, m = RAND_MAX; + /* static double a = 950975, m = 2147483647; */ + /* static double a = 3467255, m = 21474836472; */ + /* static double a = 657618, m = 4294967291; */ + /* static double a = 93167, m = 4294967291; */ + /* static double a = 1345659, m = 4294967291; */ + + state = seed; + state *= a; + q = state / m; + state -= q*m; + return state; +} + +/* -------------------------- random1 ------------------------------ */ +/* linear congruential generator. Generator x[n+1] = a * x[n] mod m */ + +static t_class *random1_class; + +typedef struct _random1 +{ + t_object x_obj; + t_float x_f; // lower limit + t_float x_g; // upper limit + unsigned int x_state; // current seed +} t_random1; + +static void *random1_new(t_floatarg f, t_floatarg g) +{ + t_random1 *x = (t_random1 *)pd_new(random1_class); + x->x_f = (f) ? f : 0; + x->x_g = (g) ? g : RAND_MAX; + //post("cxc/randomix.c: lolim: %f - %f, uplim: %f - %f", x->x_f, f, x->x_g, g); + x->x_state = makeseed(); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +/* -------------------------- random_fl ------------------------------ */ +/* An improved (faster) implementation of the Linear Congruential Generator. Has parameters for 6 separate */ +/* linear congruence formulas. These formulas are different than those above because the previous formulas won't work */ +/* correctly in this implementation. Also, this method only works if your floating point mantissa has at least 53 bits. */ + +/* linear congruential generator. Generator x[n+1] = a * x[n] mod m */ +/* works if your floating pt. mantissa has at least 53 bits. + faster than other versions */ +static void random1_bang(t_random1 *x) +{ + int n = x->x_f; + double nval; + unsigned int m; + // this seems weird? + m = (RAND_MAX * 2); + // unsigned int a = 1588635695, m = 4294967291U, q = 2, r = 1117695901; + + // post("cxc/randomix.c: x_state: %d",x->x_state); + x->x_state = rand_random1(x->x_state); + nval = ((double)x->x_state / (double)m) * (double)(x->x_g - x->x_f) + (double)x->x_f; + // post("cxc/randomix.c: lolim: %f, uplim: %f", x->x_f, x->x_g); + // post("cxc/randomix.c: nval: %f",nval); + outlet_float(x->x_obj.ob_outlet, nval); +} + +void random1_low(t_random1 *x, t_floatarg f) +{ + if(f >= x->x_g) { + post("cxc/randomix.c: lower larger than upper, setting to upper - %f = %f", + SMALLEST_RANGE, + x->x_g - SMALLEST_RANGE); + x->x_f = x->x_g - SMALLEST_RANGE; + } else x->x_f = f; +} + +void random1_upp(t_random1 *x, t_floatarg f) +{ + if(f <= x->x_f) { + post("cxc/randomix.c: upper smaller than lower, setting to lower + %f = %f", + SMALLEST_RANGE, + x->x_f + SMALLEST_RANGE); + x->x_g = x->x_f + SMALLEST_RANGE; + } else x->x_g = f; +} + +static void random1_seed(t_random1 *x, float f, float glob) +{ + x->x_state = f; +} + +void random1_setup(void) +{ + random1_class = class_new(gensym("random1"), (t_newmethod)random1_new, 0, + sizeof(t_random1), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(random1_class, random1_bang); + class_addmethod(random1_class, (t_method)random1_low, gensym("fl1"), A_FLOAT, 0); + class_addmethod(random1_class, (t_method)random1_upp, gensym("fl2"), A_FLOAT, 0); + + class_addmethod(random1_class, (t_method)random1_seed, + gensym("seed"), A_FLOAT, 0); +} + + +/* -------------------------- random_fl ------------------------------ */ +/* An improved (faster) implementation of the Linear Congruential Generator. Has parameters for 6 separate */ +/* linear congruence formulas. These formulas are different than those above because the previous formulas won't work */ +/* correctly in this implementation. Also, this method only works if your floating point mantissa has at least 53 bits. */ + +/* linear congruential generator. Generator x[n+1] = a * x[n] mod m */ +/* works if your floating pt. mantissa has at least 53 bits. + faster than other versions */ + +static t_class *random_fl_class; + +typedef struct _random_fl +{ + t_object x_obj; + t_float x_f; // lower limit + t_float x_g; // upper limit + unsigned int x_state; // current seed +} t_random_fl; + +static void *random_fl_new(t_floatarg f, t_floatarg g) +{ + t_random_fl *x = (t_random_fl *)pd_new(random_fl_class); + x->x_f = (f) ? f : 0; + x->x_g = (g) ? g : RAND_MAX; + //post("cxc/randomix.c: lolim: %f - %f, uplim: %f - %f", x->x_f, f, x->x_g, g); + x->x_state = makeseed(); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +void random_fl_bang(t_random_fl *x) +{ + int n = x->x_f; + int q; + double nval; + double m; + + m = RAND_MAX; + x->x_state = rand_random_fl(x->x_state); + nval = ((x->x_state / m) * (double)(x->x_g - x->x_f) + (double)x->x_f); + outlet_float(x->x_obj.ob_outlet, nval); +} + +void random_fl_low(t_random_fl *x, t_floatarg f) +{ + if(f >= x->x_g) { + post("cxc/randomix.c: lower larger than upper, setting to upper - %f = %f", + SMALLEST_RANGE, + x->x_g - SMALLEST_RANGE); + x->x_f = x->x_g - SMALLEST_RANGE; + } else x->x_f = f; +} + +void random_fl_upp(t_random_fl *x, t_floatarg f) +{ + if(f <= x->x_f) { + post("cxc/randomix.c: upper smaller than lower, setting to lower + %f = %f", + SMALLEST_RANGE, + x->x_f + SMALLEST_RANGE); + x->x_g = x->x_f + SMALLEST_RANGE; + } else x->x_g = f; +} + +static void random_fl_seed(t_random_fl *x, float f, float glob) +{ + x->x_state = f; +} + +void random_fl_setup(void) +{ + random_fl_class = class_new(gensym("random_fl"), (t_newmethod)random_fl_new, 0, + sizeof(t_random_fl), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(random_fl_class, random_fl_bang); + class_addmethod(random_fl_class, (t_method)random_fl_low, gensym("fl1"), A_FLOAT, 0); + class_addmethod(random_fl_class, (t_method)random_fl_upp, gensym("fl2"), A_FLOAT, 0); + + class_addmethod(random_fl_class, (t_method)random_fl_seed, + gensym("seed"), A_FLOAT, 0); +} + + +/* -------------------------- random_icg ------------------------------ */ +/* Inverse Congruential generator. This generator is quite a bit slower than the other ones on this page. and it */ +/* fails some statistical tests. The main factor in its favor is that its properties tend to be the opposite of linear congruential */ +/* generators. I.e. this generator is very likely to be good for those applications where linear congruential generators are */ +/* bad. You can choose among several parameters. */ + +/* inversive congruential generator. */ + +static t_class *random_icg_class; + +typedef struct _random_icg +{ + t_object x_obj; + t_float x_f; // lower limit + t_float x_g; // upper limit + t_float x_p; // 1st shared parameter of iter function .. + unsigned int x_state; // current seed +} t_random_icg; + +static void *random_icg_new(t_floatarg f, t_floatarg g) +{ + t_random_icg *x = (t_random_icg *)pd_new(random_icg_class); + x->x_f = (f) ? f : 0; + x->x_g = (g) ? g : RAND_MAX; + x->x_p = 2147483053; + //post("cxc/randomix.c: lolim: %f - %f, uplim: %f - %f", x->x_f, f, x->x_g, g); + x->x_state = makeseed(); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void random_icg_bang(t_random_icg *x) +{ + int n = x->x_f; + int p = x->x_p; + static int a, b, q, r; + double nval; + + unsigned int inv; + inv = random_icg_INVERSE_seed(x); + // post("cxc/randomix.c: current inv: %d", inv); + + a = 22211, b = 11926380,q = 96685, r = 12518; + /* static int p = 2147483053, a = 858993221, b = 1,q = 2, r = 429496611;*/ + /* static int p = 2147483053, a = 579, b = 24456079, q = 3708951, r = 424;*/ + /* static int p = 2147483053, a = 11972, b = 62187060,q = 179375, r = 5553;*/ + /* static int p = 2147483053, a = 21714, b = 94901263,q = 98898, r = 11881;*/ + /* static int p = 2147483053, a = 4594, b = 44183289,q = 467453, r = 3971;*/ + /* static int p = 2147483647, a = 1288490188, b = 1, q = 1, r = 858993459;*/ + /* static int p = 2147483647, a = 9102, b = 36884165, q = 235935, r =3277;*/ + /* static int p = 2147483647, a = 14288, b = 758634, q = 150299, r = 11535;*/ + /* static int p = 2147483647, a = 21916, b = 71499791, q = 97987, r = 555;*/ + /* static int p = 2147483647, a = 28933, b = 59217914, q = 74222, r = 18521;*/ + /* static int p = 2147483647, a = 31152, b = 48897674, q = 68935, r = 20527;*/ + + x->x_state = a*(inv % q) - r*(inv / q) + b; + + if (x->x_state < 0) x->x_state += x->x_p; + else if (x->x_state >= x->x_state) x->x_state -= x->x_p; + + nval = (((x->x_state / x->x_p) - 1) * (double)(x->x_g - x->x_f) + (double)x->x_f); + + // hakc, why is it out of range? + if(nval < (double)x->x_f) { + random_icg_bang(x); + } else { + outlet_float(x->x_obj.ob_outlet, nval); + } +} + +/* Modular Inversion using the extended Euclidean alg. for GCD */ +/***************************************************************/ +static unsigned random_icg_INVERSE_seed (t_random_icg *x) +{ + unsigned int q,d; + + // int p = x->x_p; + + signed int u,v,inv,t; + + if (x->x_state <= 1) return(x->x_state); + + d = x->x_p; inv = 0; v = 1; u = x->x_state; + + do { + q = d / u; + t = d % u; + d = u; + u = t; + t = inv - q*v; + inv = v; + v = t; + } while (u != 0); + + if (inv < 0 ) inv += x->x_p; + +/* if (1 != d) */ +/* post ("inverse_iter: Can't invert !"); */ + + return(inv); +} + + +void random_icg_low(t_random_icg *x, t_floatarg f) +{ + if(f >= x->x_g) { + post("cxc/randomix.c: lower larger than upper, setting to upper - %f = %f", + SMALLEST_RANGE, + x->x_g - SMALLEST_RANGE); + x->x_f = x->x_g - SMALLEST_RANGE; + } else x->x_f = f; +} + +void random_icg_upp(t_random_icg *x, t_floatarg f) +{ + if(f <= x->x_f) { + post("cxc/randomix.c: upper smaller than lower, setting to lower + %f = %f", + SMALLEST_RANGE, + x->x_f + SMALLEST_RANGE); + x->x_g = x->x_f + SMALLEST_RANGE; + } else x->x_g = f; +} + +static void random_icg_seed(t_random_icg *x, float f, float glob) +{ + x->x_state = f; +} + +void random_icg_setup(void) +{ + random_icg_class = class_new(gensym("random_icg"), (t_newmethod)random_icg_new, 0, + sizeof(t_random_icg), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(random_icg_class, random_icg_bang); + class_addmethod(random_icg_class, (t_method)random_icg_low, gensym("fl1"), A_FLOAT, 0); + class_addmethod(random_icg_class, (t_method)random_icg_upp, gensym("fl2"), A_FLOAT, 0); + + class_addmethod(random_icg_class, (t_method)random_icg_seed, + gensym("seed"), A_FLOAT, 0); +} + + + +/* -------------------------- random_tw ------------------------------ */ +/* Combination of three tausworth generators. Has parameters for two different generators. Fast and excellent. */ + +/* Combination of 3 tausworth generators -- assumes 32-bit integers */ + +static t_class *random_tw_class; + +typedef struct _random_tw +{ + t_object x_obj; + t_float x_f; // lower limit + t_float x_g; // upper limit + + t_int x_s1; + t_int x_s2; + t_int x_s3; + + t_int x_mask1; + t_int x_mask2; + t_int x_mask3; + + t_int x_shft1; + t_int x_shft2; + t_int x_shft3; + t_int x_k1; + t_int x_k2; + t_int x_k3; + + t_int x_q1; + t_int x_q2; + t_int x_q3; + t_int x_p1; + t_int x_p2; + t_int x_p3; + + unsigned int x_state; // current seed +} t_random_tw; + +void random_tw_rand_seed (t_random_tw *x, unsigned int a, unsigned int b, unsigned int c) +{ + static unsigned int zf = 4294967295U; + + x->x_shft1 = x->x_k1 - x->x_p1; + x->x_shft2=x->x_k2-x->x_p2; + x->x_shft3=x->x_k3-x->x_p3; + x->x_mask1 = zf << (32-x->x_k1); + x->x_mask2 = zf << (32-x->x_k2); + x->x_mask3 = zf << (32-x->x_k3); + if (a > (1<x_shft1)) x->x_s1 = a; + if (b > (1<x_shft2)) x->x_s2 = b; + if (c > (1<x_shft3)) x->x_s3 = c; + // rand(); +} + +static void *random_tw_new(t_floatarg f, t_floatarg g) +{ + t_random_tw *x = (t_random_tw *)pd_new(random_tw_class); + + x->x_f = (f) ? f : 0; + x->x_g = (g) ? g : RAND_MAX; + //post("cxc/randomix.c: lolim: %f - %f, uplim: %f - %f", x->x_f, f, x->x_g, g); + x->x_state = makeseed(); + + x->x_s1=390451501; + x->x_s2=613566701; + x->x_s3=858993401; + + x->x_k1=31; + x->x_k2=29; + x->x_k3=28; + + x->x_q1=13; + x->x_q2=2; + x->x_q3=3; + x->x_p1=12; + x->x_p2=4; + x->x_p3=17; + +/* x->x_q1=3; */ +/* x->x_q2=2; */ +/* x->x_q3=13; */ +/* x->x_p1=20; */ +/* x->x_p2=16; */ +/* x->x_p3=7; */ + + random_tw_rand_seed(x, makeseed(),makeseed(),makeseed()); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + outlet_new(&x->x_obj, &s_float); + return (x); +} + + +static void random_tw_bang(t_random_tw *x) +{ + unsigned int b; + double nval; + static unsigned int zf = 4294967295U; + + b = ((x->x_s1 << x->x_q1)^x->x_s1) >> x->x_shft1; + x->x_s1 = ((x->x_s1 & x->x_mask1) << x->x_p1) ^ b; + b = ((x->x_s2 << x->x_q2) ^ x->x_s2) >> x->x_shft2; + x->x_s2 = ((x->x_s2 & x->x_mask2) << x->x_p2) ^ b; + b = ((x->x_s3 << x->x_q3) ^ x->x_s3) >> x->x_shft3; + x->x_s3 = ((x->x_s3 & x->x_mask3) << x->x_p3) ^ b; + nval = (((double)(x->x_s1 ^ x->x_s2 ^ x->x_s3) / (double)(zf) + 0.5) * (double)(x->x_g - x->x_f) + (double)x->x_f); + + //nval = ((x->x_state / (double)m) * (double)(x->x_g - x->x_f) + (double)x->x_f); + //post("cxc/randomix.c: current rand: %f", nval); + outlet_float(x->x_obj.ob_outlet, nval); +} + +void random_tw_low(t_random_tw *x, t_floatarg f) +{ + if(f >= x->x_g) { + post("cxc/randomix.c: lower larger than upper, setting to upper - %f = %f", + SMALLEST_RANGE, + x->x_g - SMALLEST_RANGE); + x->x_f = x->x_g - SMALLEST_RANGE; + } else x->x_f = f; +} + +void random_tw_upp(t_random_tw *x, t_floatarg f) +{ + if(f <= x->x_f) { + post("cxc/randomix.c: upper smaller than lower, setting to lower + %f = %f", + SMALLEST_RANGE, + x->x_f + SMALLEST_RANGE); + x->x_g = x->x_f + SMALLEST_RANGE; + } else x->x_g = f; +} + +static void random_tw_seed(t_random_tw *x, float f, float glob) +{ + //x->x_state = f; + // questionable .. dont quite get how this one's seeded .. + random_tw_rand_seed(x, f, (f*0.455777), f); +} + +static void random_tw_help(t_random_tw *x) +{ + post("RAND_MAX: %d",RAND_MAX); + post("range: %f - %f", x->x_f, x->x_g); +} + +void random_tw_setup(void) +{ + random_tw_class = class_new(gensym("random_tw"), (t_newmethod)random_tw_new, 0, + sizeof(t_random_tw), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(random_tw_class, random_tw_bang); + class_addmethod(random_tw_class, (t_method)random_tw_low, gensym("fl1"), A_FLOAT, 0); + class_addmethod(random_tw_class, (t_method)random_tw_upp, gensym("fl2"), A_FLOAT, 0); + + class_addmethod(random_tw_class, (t_method)random_tw_seed, + gensym("seed"), A_FLOAT, 0); + class_addmethod(random_tw_class, (t_method)random_tw_help, + gensym("help"), 0, 0); +} + + + + +/* -------------------------- dist_normal ------------------------------ */ +/* Generate a normal random variable with mean 0 and standard deviation + of 1. To adjust to some other distribution, multiply by the standard + deviation and add the mean. Box-Muller method + note: rand() is a function that returns a uniformly distributed random + number from 0 to RAND_MAX +*/ + +static t_class *dist_normal_class; + +typedef struct _dist_normal +{ + t_object x_obj; + t_float x_mn; // mean + t_float x_dv; // deviation + t_float x_u1; + t_float x_u2; + + t_float x_f; // lower limit + t_float x_g; // upper limit + unsigned int x_state; // current seed +} t_dist_normal; + +static void *dist_normal_new(t_floatarg mn, t_floatarg dv) +{ + t_dist_normal *x = (t_dist_normal *)pd_new(dist_normal_class); + x->x_mn = (mn) ? mn : 0; + x->x_dv = (dv) ? dv : 1; + x->x_u1 = 13; + x->x_u2 = 1000; + x->x_f = 0; + x->x_g = RAND_MAX; + //post("cxc/randomix.c: lolim: %f - %f, uplim: %f - %f", x->x_f, f, x->x_g, g); + x->x_state = makeseed(); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl1")); + // inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("fl2")); + //outlet_new(&x->x_obj, &s_float); + outlet_new(&x->x_obj, 0); + return (x); +} + +static double dist_normal_rand(t_dist_normal *x) +{ + int n = x->x_f; + double nval; + double m; + + m = (double)RAND_MAX * 2; + + // post("cxc/randomix.c: x_state: %d",x->x_state); + x->x_state = rand_random_fl(x->x_state); + //nval = ((double)x->x_state / m) * (double)(x->x_g - x->x_f) + (double)x->x_f; + nval = (double)x->x_state; + return (nval); +} + +static void dist_normal_doit(t_dist_normal *x) +{ + static double V2, fac; + static int phase = 0; + double S, Z, U1, U2, V1; + + if (phase) + Z = V2 * fac; + else + { + do { +/* U1 = (double)rand() / RAND_MAX; */ +/* U2 = (double)rand() / RAND_MAX; */ + U1 = (double)dist_normal_rand(x) / RAND_MAX; + U2 = (double)dist_normal_rand(x) / RAND_MAX; + + // post("cxc/randomix.c: test %f %f %f %f", x->x_u1, x->x_u2, U1, U2); + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while(S >= 1); + + fac = sqrt (-2 * log(S) / S); + Z = V1 * fac; + } + + phase = 1 - phase; + + //return Z; + outlet_float(x->x_obj.ob_outlet, Z); +} + +static void dist_normal_bang(t_dist_normal *x) +{ +/* post("cxc/randomix.c: dist_normal banged"); */ +/* post("cxc/randomix.c: RAND_MAX: %d",RAND_MAX); */ +/* post("cxc/randomix.c: test: %f %f", x->x_u1, x->x_u2); */ + dist_normal_doit(x); +} + +void dist_normal_low(t_dist_normal *x, t_floatarg mn) +{ + x->x_mn = mn; +} + +void dist_normal_upp(t_dist_normal *x, t_floatarg dv) +{ + x->x_dv = dv; +} + +void dist_normal_float(t_dist_normal *x, t_floatarg r) +{ + outlet_float(x->x_obj.ob_outlet, r); +} + +void dist_normal_list(t_dist_normal *x, t_symbol *s, int argc, t_atom *argv) +{ + outlet_list(x->x_obj.ob_outlet, s, argc, argv); +} + +void dist_normal_setup(void) +{ + dist_normal_class = class_new(gensym("dist_normal"), (t_newmethod)dist_normal_new, 0, + sizeof(t_dist_normal), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + class_addbang(dist_normal_class, dist_normal_bang); + class_addmethod(dist_normal_class, (t_method)dist_normal_low, gensym("fl1"), A_FLOAT, 0); + // class_addmethod(dist_normal_class, (t_method)dist_normal_upp, gensym("fl2"), A_FLOAT, 0); + class_addlist (dist_normal_class, dist_normal_list); + +/* class_addmethod(dist_normal_class, (t_method)dist_normal_seed, */ +/* gensym("seed"), A_FLOAT, 0); */ +} + + diff --git a/reference/ENV.pd b/reference/ENV.pd new file mode 100644 index 0000000..7582c67 --- /dev/null +++ b/reference/ENV.pd @@ -0,0 +1,34 @@ +#N canvas 370 240 625 314 10; +#X obj 147 203 ENV; +#X msg 147 163 RAND_MAX; +#X floatatom 226 253 10 0 0; +#X obj 147 277 print; +#X msg 214 164 getenv \$1; +#X symbolatom 215 130 10 0 0; +#X obj 295 130 symbol; +#X msg 311 105 HOSTNAME; +#X msg 310 80 USERNAME; +#X obj 147 228 route symbol; +#X msg 147 253 \$1; +#X msg 424 110 USERNAME bla; +#X obj 386 168 cxc.prepend setenv; +#X obj 395 202 print pre; +#X msg 425 135 HOSTNAME testi; +#X msg 312 45 RANDOM; +#X text 18 7 get and set environment variables etc ...; +#X msg 244 51 DATE; +#X connect 0 0 9 0; +#X connect 1 0 0 0; +#X connect 4 0 0 0; +#X connect 5 0 4 0; +#X connect 6 0 4 0; +#X connect 7 0 6 0; +#X connect 8 0 6 0; +#X connect 9 0 10 0; +#X connect 9 1 2 0; +#X connect 10 0 3 0; +#X connect 11 0 12 0; +#X connect 12 0 0 0; +#X connect 14 0 12 0; +#X connect 15 0 6 0; +#X connect 17 0 6 0; diff --git a/reference/ascseq.pd b/reference/ascseq.pd new file mode 100644 index 0000000..5038a84 --- /dev/null +++ b/reference/ascseq.pd @@ -0,0 +1,12 @@ +#N canvas 454 117 570 300 10; +#X obj 132 168 print ascseq; +#X msg 253 112 bang; +#X obj 223 70 random_fl -10000 10000; +#X obj 131 118 ascseq 100; +#X floatatom 268 137 5 0 0; +#X msg 83 34 "abcde 123 dsfjnsdf ewrte 3k4n5 3n hjb5465hj 6"; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 0 0; +#X connect 4 0 3 1; +#X connect 5 0 3 0; diff --git a/reference/ascwave.pd b/reference/ascwave.pd new file mode 100644 index 0000000..bb36502 --- /dev/null +++ b/reference/ascwave.pd @@ -0,0 +1,65 @@ +#N canvas 448 258 407 316 10; +#X msg 80 153 bang; +#X floatatom 169 176; +#X floatatom 214 58; +#X obj 151 13 loadbang; +#X obj 157 97 metro 100; +#X msg 157 196 1; +#X msg 157 58 1; +#X msg 186 58 0; +#X obj 145 221 ascwave; +#X msg 75 192 fill 1; +#X msg 74 211 fill 0; +#X obj 145 262 ixprint; +#X msg 145 241 \$1; +#N canvas 517 176 588 372 modulate 0; +#X obj 84 200 outlet; +#X obj 84 139 random 80; +#X msg 30 110 bang; +#X obj 84 75 * 50; +#X obj 84 93 metro 5000; +#X obj 29 52 loadbang; +#X msg 29 70 1; +#X obj 84 161 pack 1 5000; +#X obj 84 180 line; +#X obj 86 31 inlet start/stop; +#X obj 130 53 inlet time; +#X connect 1 0 7 0; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 3 0 7 1; +#X connect 4 0 1 0; +#X connect 5 0 6 0; +#X connect 6 0 4 0; +#X connect 7 0 8 0; +#X connect 8 0 0 0; +#X connect 9 0 4 0; +#X connect 10 0 3 0; +#X restore 169 154 page modulate; +#X floatatom 262 132; +#X obj 262 179 min 127; +#X obj 262 154 max 33; +#X obj 157 77 f; +#X obj 210 78 f; +#X text 200 178 <== here; +#X text 297 131 <== and here; +#X connect 0 0 8 0; +#X connect 1 0 8 2; +#X connect 2 0 18 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 8 1; +#X connect 6 0 17 0; +#X connect 7 0 17 0; +#X connect 8 0 12 0; +#X connect 9 0 8 0; +#X connect 10 0 8 0; +#X connect 12 0 11 0; +#X connect 13 0 8 2; +#X connect 14 0 16 0; +#X connect 15 0 8 3; +#X connect 16 0 15 0; +#X connect 17 0 4 0; +#X connect 17 0 13 0; +#X connect 18 0 4 1; +#X connect 18 0 13 1; diff --git a/reference/bfilt.pd b/reference/bfilt.pd new file mode 100644 index 0000000..4be9d45 --- /dev/null +++ b/reference/bfilt.pd @@ -0,0 +1,23 @@ +#N canvas 203 207 404 226 10; +#X floatatom 85 119; +#X obj 57 175 print; +#X floatatom 45 120; +#X obj 58 146 bfilt 5; +#X text 43 16 bfilt (at the moment) is: modulo something + select 0; +#X floatatom 167 120; +#X obj 139 176 print; +#X floatatom 127 121; +#X obj 140 147 bfilt2 5; +#X obj 145 87 metro 100; +#X msg 145 68 1; +#X text 42 29 bfilt2: real bangfilter: bangs on first inlet \, internal counter \, only outputs every arg2th bang ...; +#X msg 169 67 0; +#X connect 0 0 3 1; +#X connect 2 0 3 0; +#X connect 3 0 1 0; +#X connect 5 0 8 1; +#X connect 7 0 8 0; +#X connect 8 0 6 0; +#X connect 9 0 8 0; +#X connect 10 0 9 0; +#X connect 12 0 9 0; diff --git a/reference/cxc.prepend.pd b/reference/cxc.prepend.pd new file mode 100644 index 0000000..eaa57dc --- /dev/null +++ b/reference/cxc.prepend.pd @@ -0,0 +1,13 @@ +#N canvas 322 265 450 300 10; +#X obj 186 244 print; +#X msg 200 102 itsch ni san chi; +#X obj 186 187 cxc.prepend /bla; +#X obj 186 210 cxc.prepend send; +#X floatatom 155 79 5 0 0; +#X msg 214 138 qui qua 2 3.4555 "bla ha"; +#X text 25 11 prepend arbitrary length lists/anythings with stuff; +#X connect 1 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 0 0; +#X connect 4 0 2 0; +#X connect 5 0 2 0; diff --git a/reference/delta.pd b/reference/delta.pd new file mode 100644 index 0000000..7f0bf8b --- /dev/null +++ b/reference/delta.pd @@ -0,0 +1,63 @@ +#N canvas 9 51 986 579 10; +#X obj 139 177 delta~; +#X obj 80 44 noise~; +#X obj 83 268 print a; +#X obj 143 267 print b; +#X obj 329 312 dac~; +#X obj 226 47 osc~ 400; +#X graph graph1 0 -1 999 1 497 206 697 66; +#X array orig 1000 float 0; +#X pop; +#X graph graph2 0 -1 999 1 431 563 931 203; +#X array diff 1000 float 0; +#X pop; +#X obj 129 390 tabwrite~ diff; +#X msg 220 340 bang; +#X floatatom 225 24 5 0 0; +#X obj 139 468 table test; +#X msg 139 442 resize 2205; +#X obj 242 389 tabwrite~ test; +#X obj 243 415 tabwrite~ orig; +#X obj 403 515 print; +#X msg 350 441 bang; +#X obj 346 530 t b; +#X obj 332 552 spigot; +#X obj 375 528 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 +1; +#X obj 320 474 tabread~ test; +#X obj 201 532 phasor~ 10; +#X floatatom 201 510 5 0 0; +#X obj 201 556 *~ 2205; +#X obj 147 45 phasor~ 1; +#X obj 160 93 nop~; +#X obj 287 224 metro 100; +#X obj 287 198 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 +1; +#X floatatom 173 18 5 0 0; +#X obj 109 77 *~ 0.1; +#X floatatom 86 103 5 0 0; +#X text 308 36 if this sample is larger than last \, value is positive +\, else negative ...; +#X text 308 18 delta~: difference between this and last sample; +#X connect 0 0 4 1; +#X connect 0 0 8 0; +#X connect 1 0 29 0; +#X connect 9 0 8 0; +#X connect 9 0 13 0; +#X connect 9 0 14 0; +#X connect 10 0 5 0; +#X connect 12 0 11 0; +#X connect 17 0 18 0; +#X connect 19 0 18 1; +#X connect 21 0 23 0; +#X connect 22 0 21 0; +#X connect 23 0 20 0; +#X connect 24 0 25 0; +#X connect 25 0 0 0; +#X connect 25 0 13 0; +#X connect 25 0 14 0; +#X connect 26 0 9 0; +#X connect 27 0 26 0; +#X connect 28 0 24 0; +#X connect 29 0 25 0; +#X connect 30 0 29 1; diff --git a/reference/proc.pd b/reference/proc.pd new file mode 100644 index 0000000..65411ae --- /dev/null +++ b/reference/proc.pd @@ -0,0 +1,75 @@ +#N canvas 179 113 717 546 10; +#X obj 151 118 proc; +#X text 96 15 interface to the linux proc filesystem; +#X msg 88 80 cpuinfo; +#X obj 27 281 unpack f f f; +#X floatatom 25 304 5 0 0; +#X floatatom 67 305 5 0 0; +#X floatatom 109 304 5 0 0; +#X text 37 254 cpu-id \, cpu-mhz \, bogomips; +#X obj 151 147 print proc_raw; +#X msg 151 94 proc \$1; +#X obj 151 71 symbol; +#X msg 123 38 cpuinfo; +#X msg 183 38 uptime; +#X msg 351 38 stat; +#X msg 389 38 blubb; +#X obj 242 276 unpack f f; +#X text 241 255 uptime in s \, idle-time in s; +#X floatatom 241 301 5 0 0; +#X floatatom 302 305 5 0 0; +#X msg 237 38 loadavg; +#X msg 297 39 version; +#X obj 174 349 unpack f f f f f f; +#X floatatom 172 373 5 0 0; +#X floatatom 187 397 5 0 0; +#X floatatom 220 373 5 0 0; +#X floatatom 238 397 5 0 0; +#X floatatom 271 372 5 0 0; +#X floatatom 289 396 5 0 0; +#X text 315 345 apparently the loadavg format is something liek this +; +#X text 318 359 my manpage seems outdated ...; +#X text 330 379 1: number of jobs in the run queue (1'); +#X text 340 394 2: numofjobs in R qu (5'); +#X text 348 411 3: numofjobs in R qu (15'); +#X text 339 425 4: num of procs waiting for disk io?; +#X text 339 452 6: num of processes ever total; +#X text 339 438 5: num of processes now total; +#X obj 27 234 route cpuinfo uptime loadavg version stat; +#X obj 458 241 unpack f f f; +#X floatatom 458 267 5 0 0; +#X floatatom 484 293 5 0 0; +#X floatatom 516 266 5 0 0; +#X text 462 215 uname -r; +#X text 307 82 really useless stuff but maybe good for estimating number +of voices in self-generating patches; +#X connect 0 0 8 0; +#X connect 0 0 36 0; +#X connect 2 0 0 0; +#X connect 3 0 4 0; +#X connect 3 1 5 0; +#X connect 3 2 6 0; +#X connect 9 0 0 0; +#X connect 10 0 9 0; +#X connect 11 0 10 0; +#X connect 12 0 10 0; +#X connect 13 0 10 0; +#X connect 14 0 10 0; +#X connect 15 0 17 0; +#X connect 15 1 18 0; +#X connect 19 0 10 0; +#X connect 20 0 10 0; +#X connect 21 0 22 0; +#X connect 21 1 23 0; +#X connect 21 2 24 0; +#X connect 21 3 25 0; +#X connect 21 4 26 0; +#X connect 21 5 27 0; +#X connect 36 0 3 0; +#X connect 36 1 15 0; +#X connect 36 2 21 0; +#X connect 36 3 37 0; +#X connect 37 0 38 0; +#X connect 37 1 39 0; +#X connect 37 2 40 0; diff --git a/reference/randomix.pd b/reference/randomix.pd new file mode 100644 index 0000000..3f6823b --- /dev/null +++ b/reference/randomix.pd @@ -0,0 +1,181 @@ +#N canvas 33 162 966 505 10; +#X msg 197 150 bang; +#X floatatom 244 150 5 0 0; +#X floatatom 197 218 10 0 0; +#X floatatom 53 162 5 0 0; +#X msg 54 111 bang; +#X floatatom 289 152 5 0 0; +#X obj 53 135 random 100; +#X msg 427 151 bang; +#X floatatom 474 151 5 0 0; +#X floatatom 427 219 10 0 0; +#X floatatom 519 153 5 0 0; +#X obj 196 183 random1 0 1; +#X obj 426 184 random_fl 0 1; +#X msg 672 152 bang; +#X floatatom 719 152 5 0 0; +#X floatatom 672 220 10 0 0; +#X floatatom 764 154 5 0 0; +#X obj 671 185 random_icg 0 1; +#X msg 197 276 bang; +#X floatatom 244 276 5 0 0; +#X floatatom 197 344 10 0 0; +#X floatatom 289 278 5 0 0; +#X text 193 251 random_icg lowerlimit \, upperlimit; +#X msg 368 288 help; +#X text 253 10 the random number generatorse; +#X obj 539 406 dist_normal; +#X msg 540 356 bang; +#X obj 579 357 metro 100; +#X obj 579 337 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 +1; +#X obj 196 309 random_tw 0 1; +#X floatatom 637 334 5 0 0; +#N canvas 0 0 600 400 streamview 0; +#X graph graph2 0 -2 99 2 92 362 292 222; +#X array randstream 100 float 0; +#X pop; +#X obj 146 144 tabwrite randstream; +#X obj 200 63 count; +#X obj 200 88 % 100; +#X obj 156 28 t f b; +#X obj 49 15 inlet; +#X connect 2 0 3 0; +#X connect 3 0 1 1; +#X connect 4 0 1 0; +#X connect 4 1 2 0; +#X connect 5 0 4 0; +#X restore 570 433 pd streamview; +#N canvas 306 24 679 400 distview 0; +#X graph graph1 0 0 99 200 248 231 648 31; +#X array randview1 100 float 0; +#X pop; +#X obj 28 26 inlet; +#X obj 45 355 tabwrite randview1; +#X obj 136 201 * 100; +#X obj 136 225 int; +#X obj 136 153 + 2; +#X obj 45 280 tabread randview1; +#X obj 136 176 / 4; +#X obj 136 250 t f f; +#X obj 45 304 t f b; +#X obj 45 329 + 1; +#X obj 136 129 t f; +#X connect 1 0 11 0; +#X connect 3 0 4 0; +#X connect 4 0 8 0; +#X connect 5 0 7 0; +#X connect 6 0 9 0; +#X connect 7 0 3 0; +#X connect 8 0 6 0; +#X connect 8 1 2 1; +#X connect 9 0 10 0; +#X connect 10 0 2 0; +#X connect 11 0 5 0; +#X restore 550 458 pd distview; +#X obj 540 381 t b; +#X floatatom 477 430 5 0 0; +#N canvas 0 0 600 400 seedit 0; +#X msg 284 154 seed \$1; +#X obj 284 107 utime; +#X msg 304 74 bang; +#X obj 254 28 loadbang; +#X obj 284 130 * 1e+06; +#X obj 360 167 until; +#X msg 455 156 bang; +#X obj 359 194 random 2.14748e+08; +#X msg 359 267 seed \$1; +#X msg 385 294 seed \$1; +#X msg 412 318 seed \$1; +#X msg 439 267 seed \$1; +#X msg 466 293 seed \$1; +#X obj 254 50 t b b; +#X obj 195 155 print seed1; +#X obj 143 360 outlet; +#X obj 204 361 outlet; +#X obj 264 361 outlet; +#X obj 317 361 outlet; +#X obj 367 361 outlet; +#X text 35 9 seed one random obj \, which generates the seeds for all +the others.; +#X obj 359 218 serialize 6; +#X msg 360 140 6; +#X obj 359 242 unpack f f f f f f; +#X msg 485 317 seed \$1; +#X obj 420 359 outlet; +#X connect 0 0 7 0; +#X connect 1 1 4 0; +#X connect 2 0 1 0; +#X connect 3 0 13 0; +#X connect 4 0 0 0; +#X connect 4 0 14 0; +#X connect 5 0 7 0; +#X connect 6 0 7 0; +#X connect 7 0 21 0; +#X connect 8 0 15 0; +#X connect 9 0 16 0; +#X connect 10 0 17 0; +#X connect 11 0 18 0; +#X connect 12 0 19 0; +#X connect 13 0 22 0; +#X connect 13 1 1 0; +#X connect 21 0 23 0; +#X connect 22 0 5 0; +#X connect 23 0 8 0; +#X connect 23 1 9 0; +#X connect 23 2 10 0; +#X connect 23 3 11 0; +#X connect 23 4 12 0; +#X connect 23 5 24 0; +#X connect 24 0 25 0; +#X restore 258 33 pd seedit; +#X text 37 79 std pd random; +#X text 197 124 linear congruential generator; +#X text 197 77 creation arguments for the extra randoms are:; +#X text 205 92 \, defaults to 0 respectively +RAND_MAX; +#X text 545 17 see also:; +#X obj 545 40 utime; +#X text 428 129 another lcg method ..; +#X text 668 127 inverse linear congruential generator; +#X text 536 249 normal distribution mean 0 and dist 1; +#X text 536 264 right now it uses random1 for the actual rand values +; +#X text 537 278 but later on it should take one of the randoms as creation +argument \, so yu can specify which generator is being used.; +#X text 198 106 they all output floats); +#X text 540 311 also \, there is some burst at the upper and lower +limits; +#X connect 0 0 11 0; +#X connect 1 0 11 1; +#X connect 4 0 6 0; +#X connect 5 0 11 2; +#X connect 6 0 3 0; +#X connect 7 0 12 0; +#X connect 8 0 12 1; +#X connect 10 0 12 2; +#X connect 11 0 2 0; +#X connect 12 0 9 0; +#X connect 13 0 17 0; +#X connect 14 0 17 1; +#X connect 16 0 17 2; +#X connect 17 0 15 0; +#X connect 18 0 29 0; +#X connect 19 0 29 1; +#X connect 21 0 29 2; +#X connect 23 0 29 0; +#X connect 25 0 31 0; +#X connect 25 0 32 0; +#X connect 25 0 34 0; +#X connect 26 0 33 0; +#X connect 27 0 33 0; +#X connect 28 0 27 0; +#X connect 29 0 20 0; +#X connect 30 0 27 1; +#X connect 33 0 25 0; +#X connect 35 0 6 0; +#X connect 35 1 11 0; +#X connect 35 2 12 0; +#X connect 35 3 17 0; +#X connect 35 4 29 0; +#X connect 35 5 25 0; diff --git a/reference/serialize.pd b/reference/serialize.pd new file mode 100644 index 0000000..b9d8469 --- /dev/null +++ b/reference/serialize.pd @@ -0,0 +1,10 @@ +#N canvas 246 82 551 292 10; +#X obj 34 141 print; +#X floatatom 34 69 0 0 0; +#X text 30 195 (C) 2000 Guenter Geiger; +#X text 30 39 serialize ... turn a stream of floats into a list; +#X obj 33 107 serialize 4; +#X floatatom 105 82 5 0 0; +#X connect 1 0 4 0; +#X connect 4 0 0 0; +#X connect 5 0 4 1; diff --git a/reference/statistics.pd b/reference/statistics.pd new file mode 100644 index 0000000..24d7ca3 --- /dev/null +++ b/reference/statistics.pd @@ -0,0 +1,120 @@ +#N canvas 416 554 622 369 10; +#X obj 64 102 noise~; +#X obj 463 105 mean~ blir; +#X obj 21 262 table blir; +#N canvas 162 270 331 246 fillary 0; +#X obj 34 53 until; +#X obj 34 79 count; +#X msg 85 27 bang; +#X obj 34 105 - 1; +#X obj 34 130 t b f; +#X obj 34 166 random_fl -1 1; +#X obj 162 16 loadbang; +#X obj 192 64 utime; +#X obj 200 100 +; +#X msg 200 124 seed \$1; +#X obj 162 39 t b b b; +#X obj 232 13 inlet; +#X obj 120 65 t b b; +#X msg 34 27 1000; +#X msg 132 108 set \$1; +#X obj 280 13 inlet; +#X obj 178 165 random_icg -1 1; +#X obj 34 192 tabwrite blor; +#X connect 0 0 1 0; +#X connect 1 0 3 0; +#X connect 2 0 1 1; +#X connect 3 0 4 0; +#X connect 4 0 5 0; +#X connect 4 1 17 1; +#X connect 5 0 17 0; +#X connect 6 0 10 0; +#X connect 7 0 8 0; +#X connect 7 1 8 1; +#X connect 8 0 9 0; +#X connect 9 0 5 0; +#X connect 9 0 16 0; +#X connect 10 0 12 0; +#X connect 10 1 7 0; +#X connect 11 0 12 0; +#X connect 12 0 13 0; +#X connect 12 1 2 0; +#X connect 13 0 0 0; +#X connect 14 0 13 0; +#X connect 15 0 14 0; +#X connect 16 0 17 0; +#X restore 152 241 pd fillary; +#X obj 21 175 tabwrite~ blir; +#X msg 21 147 bang; +#X obj 356 102 samplerate~; +#X floatatom 356 126 5 0 0; +#X obj 356 80 loadbang; +#X floatatom 463 129 8 0 0; +#X obj 64 150 +~ 0.1; +#X floatatom 101 127 5 0 0; +#X msg 152 218 bang; +#X text 44 30 mean~ ; +#X floatatom 160 160 5 0 0; +#X obj 160 183 t f f; +#X text 206 163 set arraysize; +#X text 529 130 mean; +#X text 43 10 this is supposed to calculate the signal mean of an array. +; +#X msg 463 82 mean; +#X msg 503 82 ad; +#X msg 534 82 sd; +#X obj 462 35 mean 1 2 3; +#X floatatom 462 59 5 0 0; +#X msg 462 13 1 2 3.6677; +#X obj 316 251 cx.mean blir; +#X floatatom 271 305 8 0 0; +#X msg 316 228 mean; +#X msg 350 228 ad; +#X obj 446 251 histo; +#X obj 21 291 table blor; +#X obj 342 304 cx.avgdev blir; +#X floatatom 341 325 10 0 0; +#X floatatom 461 326 10 0 0; +#X obj 392 150 loadbang; +#X obj 460 304 cx.stddev blir; +#X obj 316 272 t f f f; +#X text 542 36 pd's mean; +#X text 544 115 dont need this; +#X msg 392 218 set \$1; +#X obj 392 194 symbol; +#X msg 392 173 blir; +#X msg 429 173 blor; +#X msg 20 214 \; blir resize \$1 \;; +#X msg 113 270 \; blor resize \$1 \;; +#X connect 0 0 10 0; +#X connect 1 0 9 0; +#X connect 5 0 4 0; +#X connect 6 0 7 0; +#X connect 8 0 6 0; +#X connect 10 0 4 0; +#X connect 11 0 10 1; +#X connect 12 0 3 0; +#X connect 14 0 15 0; +#X connect 15 0 43 0; +#X connect 15 0 44 0; +#X connect 15 1 3 1; +#X connect 19 0 1 0; +#X connect 20 0 1 0; +#X connect 21 0 1 0; +#X connect 22 0 23 0; +#X connect 24 0 22 0; +#X connect 25 0 36 0; +#X connect 27 0 25 0; +#X connect 28 0 25 0; +#X connect 31 0 32 0; +#X connect 34 0 42 0; +#X connect 35 0 33 0; +#X connect 36 0 26 0; +#X connect 36 1 31 0; +#X connect 36 2 35 0; +#X connect 39 0 25 0; +#X connect 39 0 31 0; +#X connect 39 0 35 0; +#X connect 40 0 39 0; +#X connect 41 0 40 0; +#X connect 42 0 40 0; diff --git a/reference/utime.pd b/reference/utime.pd new file mode 100644 index 0000000..aa5af83 --- /dev/null +++ b/reference/utime.pd @@ -0,0 +1,9 @@ +#N canvas 305 149 450 300 10; +#X obj 199 94 utime; +#X msg 192 55 bang; +#X floatatom 259 170 8 0 0; +#X floatatom 174 129 20 0 0; +#X text 25 8 output seconds since epoch and microsecond fraction; +#X connect 0 0 3 0; +#X connect 0 1 2 0; +#X connect 1 0 0 0; diff --git a/reson.c b/reson.c new file mode 100644 index 0000000..a7ba2b0 --- /dev/null +++ b/reson.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 1997-1999 Mark Danks. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. + */ + +/* Original code by Miller Puckette */ +/* a non-interpolating reson filter, not very carefully coded... */ +/* 11/29/94 modified to do interpolation - M. Danks */ + +#include "m_pd.h" + +#include + +#define BUFSIZE 4096 + +typedef struct resonctl +{ + float c_freq; + float c_samprate; + float c_feedback; + int c_delayinsamps; + float c_fraction; + int c_phase; + float *c_buf; +} t_resonctl; + +typedef struct sigreson +{ + t_object x_obj; /* header */ + t_resonctl *x_ctl; /* pointer to state */ + t_resonctl x_cspace; /* garage for state when not in a chain */ +} t_sigreson; + +/* the DSP routine -- called for every n samples of input */ +static t_int *cu_reson(t_int *w) +{ + t_float *in1 = (t_float *)(w[1]); + t_float *in2 = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + t_resonctl *x = (t_resonctl *)(w[4]); + int n = (int)(w[5]); + long i; + int writephase = x->c_phase; + for (i = 0; i < n; i++) + { + /* note two tricks: 1. input is read before output + * is written, because the routine might be called + * in-place; + * 2 - a seed of 1E-20 is thrown in to avoid floating + * underflow which slows the calculation down. + */ + int readphase, phase, delayinsamps; + float fraction, f, g, freq, freqtemp; + + float ftemp; + + freq = *in2++; + freqtemp = (freq < 1 ? 1 : freq); + + ftemp = x->c_samprate/freqtemp; + if (ftemp >= BUFSIZE-1) + ftemp = BUFSIZE - 1.f; + else if (ftemp < 1.0) + ftemp = 1.f; + delayinsamps = (int)ftemp; + fraction = ftemp - delayinsamps; + + readphase = writephase - delayinsamps; + phase = readphase & (BUFSIZE-1); + f = x->c_buf[phase] + fraction * + (x->c_buf[(phase-1)& (BUFSIZE-1)] - x->c_buf[phase]); + g = *in1++; + *out++ = x->c_buf[(writephase++) & (BUFSIZE-1)] = + g + x->c_feedback * f + 1E-20f; + } + x->c_phase = writephase & (BUFSIZE-1); + return (w+6); +} + +/* sets the reson frequency */ + +void sigreson_float(t_sigreson *x, t_floatarg f) +{ + float ftemp; + + x->x_ctl->c_freq = (f < 1 ? 1 : f); + + ftemp = x->x_ctl->c_samprate/x->x_ctl->c_freq; + if (ftemp >= BUFSIZE - 1) + ftemp = BUFSIZE - 1.f; + else if (ftemp < 1.0) + ftemp = 1.f; + x->x_ctl->c_delayinsamps = (int)ftemp; + x->x_ctl->c_fraction = ftemp - x->x_ctl->c_delayinsamps; +} + +/* routine which FTS calls to put you on the DSP chain or take you off. */ + +static void sigreson_dsp(t_sigreson *x, t_signal **sp) +{ + x->x_ctl->c_samprate = sp[0]->s_sr; + sigreson_float(x, x->x_ctl->c_freq); + dsp_add(cu_reson, 5, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, + x->x_ctl, sp[0]->s_n); +} + +static void sigreson_ft1(t_sigreson *x, t_floatarg f) /* sets feedback */ +{ + if (f > .99999) f = .99999f; + else if (f < -.99999) f = -.99999f; + x->x_ctl->c_feedback = (float)f; +} + +static void sigreson_ff(t_sigreson *x) /* cleanup on free */ +{ + free(x->x_ctl->c_buf); +} + +static t_class *sigreson_class; + +void *sigreson_new(t_floatarg f, t_floatarg g) +{ + t_sigreson *x = (t_sigreson *)pd_new(sigreson_class); + outlet_new(&x->x_obj, &s_signal); + + /* things in "cspace" are things you'll actually use at DSP time */ + x->x_cspace.c_phase = 0; + if (!(x->x_cspace.c_buf = (float *)malloc(BUFSIZE * sizeof(float)))) + { + error("buffer alloc failed"); + return (0); + } + x->x_cspace.c_samprate = 44100.f; /* just a plausible default */ + + /* control block is in the garage at startup */ + x->x_ctl = &x->x_cspace; + sigreson_float(x, (t_float)f); /* setup params */ + sigreson_ft1(x, g); + /* make a "float" inlet */ + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + return (x); +} + +void reson_setup() +{ + sigreson_class = class_new(gensym("reson~"), (t_newmethod)sigreson_new, + (t_method)sigreson_ff, sizeof(t_sigreson), 0, + A_DEFFLOAT, A_DEFFLOAT, 0); + class_addfloat(sigreson_class, (t_method)sigreson_float); + class_addmethod(sigreson_class, (t_method)sigreson_ft1, gensym("ft1"), A_FLOAT, 0); + class_addmethod(sigreson_class, (t_method)nullfn, &s_signal, A_NULL); + class_addmethod(sigreson_class, (t_method)sigreson_dsp, gensym("dsp"), A_NULL); +} + diff --git a/sigdelta.c b/sigdelta.c new file mode 100644 index 0000000..92ed69c --- /dev/null +++ b/sigdelta.c @@ -0,0 +1,56 @@ +#include "m_pd.h" +#include +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/* ------------------------ delta~ ----------------------------- */ + +/* tilde object to take difference value. */ + +static t_class *delta_class; + +typedef struct _delta +{ + t_object x_obj; + t_sample x_last; +} t_delta; + +static t_int *delta_perform(t_int *w) +{ + t_delta *x = (t_delta *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + int n = (int)(w[4]); + while (n--) + { + float f = *(in++); + // *out++ = (f > 0 ? f : -f); + *out++ = (f > x->x_last ? fabs(f - x->x_last) : -fabs(f - x->x_last)); + x->x_last = f; + } + return (w+5); +} + +static void delta_dsp(t_delta *x, t_signal **sp) +{ + dsp_add(delta_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +static void *delta_new(void) +{ + t_delta *x = (t_delta *)pd_new(delta_class); + x->x_last = 0.; + outlet_new(&x->x_obj, gensym("signal")); + return (x); +} + +void delta_tilde_setup(void) +{ + delta_class = class_new(gensym("delta~"), (t_newmethod)delta_new, 0, + sizeof(t_delta), 0, A_DEFFLOAT, 0); + class_addmethod(delta_class, nullfn, gensym("signal"), 0); + class_addmethod(delta_class, (t_method)delta_dsp, gensym("dsp"), 0); + class_sethelpsymbol(delta_class, gensym("cxc/delta.pd")); +} diff --git a/x_connective_pd034.diff b/x_connective_pd034.diff new file mode 100644 index 0000000..ff47812 --- /dev/null +++ b/x_connective_pd034.diff @@ -0,0 +1,22 @@ +187a188,192 +> static void send_set(t_send *x, t_symbol *s) +> { +> x->x_sym = s; +> } +> +235a241 +> class_addmethod(send_class, (t_method)send_set, gensym("set"), A_SYMBOL, 0); +246a253,259 +> static void receive_set(t_receive *x, t_symbol *s) +> { +> pd_unbind(&x->x_obj.ob_pd, x->x_sym); +> x->x_sym = s; +> pd_bind(&x->x_obj.ob_pd, s); +> } +> +294c307 +< (t_method)receive_free, sizeof(t_receive), CLASS_NOINLET, A_DEFSYM, 0); +--- +> (t_method)receive_free, sizeof(t_receive), 0, A_DEFSYM, 0); +301a315 +> class_addmethod(receive_class, (t_method)receive_set, gensym("set"), A_SYMBOL, 0); diff --git a/x_connective_pd035.diff b/x_connective_pd035.diff new file mode 100644 index 0000000..e99d56e --- /dev/null +++ b/x_connective_pd035.diff @@ -0,0 +1,14 @@ +246a247,253 +> static void receive_set(t_receive *x, t_symbol *s) +> { +> pd_unbind(&x->x_obj.ob_pd, x->x_sym); +> x->x_sym = s; +> pd_bind(&x->x_obj.ob_pd, s); +> } +> +294c301 +< (t_method)receive_free, sizeof(t_receive), CLASS_NOINLET, A_DEFSYM, 0); +--- +> (t_method)receive_free, sizeof(t_receive), 0, A_DEFSYM, 0); +301a309 +> class_addmethod(receive_class, (t_method)receive_set, gensym("set"), A_SYMBOL, 0); -- cgit v1.2.1