aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-14 21:59:09 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-14 21:59:09 +0000
commitc1419b43ea354fa04360450ae4f64612df065099 (patch)
tree8c38d7338e9df7e889a18dceeedb3509adbbf423
parent76be9508936fa53fe661d378ee2fc41cc9baebf3 (diff)
these pragmas are only used for MSVC, not MinGW or Cygwin, therefore changing the define from NT to _MSC_VER
svn path=/trunk/externals/ggee/; revision=3903
-rwxr-xr-xcontrol/concat.c118
-rwxr-xr-xcontrol/constant.c122
-rwxr-xr-xcontrol/inv.c154
-rwxr-xr-xcontrol/prepend.c152
-rwxr-xr-xcontrol/qread.c258
-rwxr-xr-xcontrol/rl.c162
-rwxr-xr-xcontrol/rtout.c82
-rwxr-xr-xcontrol/serial_bird.c530
-rwxr-xr-xcontrol/serial_ms.c240
-rwxr-xr-xcontrol/serial_mt.c154
-rwxr-xr-xcontrol/serialize.c116
-rwxr-xr-xcontrol/shell.c624
-rwxr-xr-xcontrol/sinh.c108
-rwxr-xr-xcontrol/sl.c148
-rwxr-xr-xcontrol/stripdir.c96
-rwxr-xr-xcontrol/unserialize.c114
-rwxr-xr-xcontrol/unwonk.c238
-rwxr-xr-xexperimental/fofsynth~.c708
-rwxr-xr-xexperimental/pvocfreq.c228
-rwxr-xr-xfilters/bandpass.c172
-rwxr-xr-xfilters/equalizer.c178
-rwxr-xr-xfilters/highpass.c174
-rwxr-xr-xfilters/highshelf.c180
-rwxr-xr-xfilters/hlshelf.c452
-rwxr-xr-xfilters/lowpass.c178
-rwxr-xr-xfilters/lowshelf.c182
-rwxr-xr-xfilters/moog~.c364
-rwxr-xr-xfilters/notch.c178
-rw-r--r--gui/button.c2
-rw-r--r--gui/image.c2
-rw-r--r--gui/sliderh.c2
-rwxr-xr-xgui/state.c2
-rwxr-xr-xgui/ticker.c2
-rwxr-xr-xgui/toddle.c2
-rwxr-xr-xother/messages.c80
-rwxr-xr-xother/vbap.c596
-rwxr-xr-xsignal/sfwrite~.c2
-rwxr-xr-xsignal/streamin~.c2
38 files changed, 3551 insertions, 3551 deletions
diff --git a/control/concat.c b/control/concat.c
index 2a8cc16..575f998 100755
--- a/control/concat.c
+++ b/control/concat.c
@@ -1,59 +1,59 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <string.h>
-
-/* ------------------------ concat ----------------------------- */
-
-#define MAX_ELEMENTS 256
-
-static t_class *concat_class;
-
-
-typedef struct _concat
-{
- t_object x_obj;
- t_symbol* x_sym;
-} t_concat;
-
-static char tsym[2048];
-
-void concat_float(t_concat *x,t_float f)
-{
- sprintf(tsym,"%g",f);
- strcat(tsym,x->x_sym->s_name);
-
- outlet_symbol(x->x_obj.ob_outlet,gensym(tsym));
-}
-
-void concat_symbol(t_concat *x,t_symbol* s)
-{
- strcpy(tsym,s->s_name);
- strcat(tsym,x->x_sym->s_name);
-
- outlet_symbol(x->x_obj.ob_outlet,gensym(tsym));
-}
-
-
-static void *concat_new(t_symbol* s)
-{
- t_concat *x = (t_concat *)pd_new(concat_class);
- outlet_new(&x->x_obj,&s_float);
- symbolinlet_new(&x->x_obj, &x->x_sym);
- x->x_sym = s;
- *tsym = 0;
- return (x);
-}
-
-
-
-void concat_setup(void)
-{
- concat_class = class_new(gensym("concat"), (t_newmethod)concat_new, 0,
- sizeof(t_concat),0, A_DEFSYM,0);
- class_addsymbol(concat_class,concat_symbol);
- class_addfloat(concat_class,concat_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <string.h>
+
+/* ------------------------ concat ----------------------------- */
+
+#define MAX_ELEMENTS 256
+
+static t_class *concat_class;
+
+
+typedef struct _concat
+{
+ t_object x_obj;
+ t_symbol* x_sym;
+} t_concat;
+
+static char tsym[2048];
+
+void concat_float(t_concat *x,t_float f)
+{
+ sprintf(tsym,"%g",f);
+ strcat(tsym,x->x_sym->s_name);
+
+ outlet_symbol(x->x_obj.ob_outlet,gensym(tsym));
+}
+
+void concat_symbol(t_concat *x,t_symbol* s)
+{
+ strcpy(tsym,s->s_name);
+ strcat(tsym,x->x_sym->s_name);
+
+ outlet_symbol(x->x_obj.ob_outlet,gensym(tsym));
+}
+
+
+static void *concat_new(t_symbol* s)
+{
+ t_concat *x = (t_concat *)pd_new(concat_class);
+ outlet_new(&x->x_obj,&s_float);
+ symbolinlet_new(&x->x_obj, &x->x_sym);
+ x->x_sym = s;
+ *tsym = 0;
+ return (x);
+}
+
+
+
+void concat_setup(void)
+{
+ concat_class = class_new(gensym("concat"), (t_newmethod)concat_new, 0,
+ sizeof(t_concat),0, A_DEFSYM,0);
+ class_addsymbol(concat_class,concat_symbol);
+ class_addfloat(concat_class,concat_float);
+}
+
+
diff --git a/control/constant.c b/control/constant.c
index 7e8ccfa..877326b 100755
--- a/control/constant.c
+++ b/control/constant.c
@@ -1,61 +1,61 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <math.h>
-#include <string.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ constant ----------------------------- */
-#ifndef M_PI
-#define M_PI 3.141593f
-#endif
-
-static t_class *constant_class;
-
-
-typedef struct _constant
-{
- t_object x_obj;
- t_float x_constant;
-} t_constant;
-
-
-void constant_bang(t_constant *x)
-{
- outlet_float(x->x_obj.ob_outlet, x->x_constant);
-}
-
-static void *constant_new(t_symbol* s)
-{
- t_constant *x = (t_constant *)pd_new(constant_class);
-
- if (s == &s_)
- x->x_constant = M_PI;
-
- if (!strcmp(s->s_name,"PI"))
- x->x_constant = M_PI;
-
- if (!strcmp(s->s_name,"TWOPI"))
- x->x_constant = 2*M_PI;
-
- if (!strcmp(s->s_name,"e"))
- x->x_constant = exp(1.0);
-
-
-
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-void constant_setup(void)
-{
- constant_class = class_new(gensym("constant"), (t_newmethod)constant_new, 0,
- sizeof(t_constant), 0,0);
- class_addbang(constant_class,constant_bang);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <math.h>
+#include <string.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ constant ----------------------------- */
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+static t_class *constant_class;
+
+
+typedef struct _constant
+{
+ t_object x_obj;
+ t_float x_constant;
+} t_constant;
+
+
+void constant_bang(t_constant *x)
+{
+ outlet_float(x->x_obj.ob_outlet, x->x_constant);
+}
+
+static void *constant_new(t_symbol* s)
+{
+ t_constant *x = (t_constant *)pd_new(constant_class);
+
+ if (s == &s_)
+ x->x_constant = M_PI;
+
+ if (!strcmp(s->s_name,"PI"))
+ x->x_constant = M_PI;
+
+ if (!strcmp(s->s_name,"TWOPI"))
+ x->x_constant = 2*M_PI;
+
+ if (!strcmp(s->s_name,"e"))
+ x->x_constant = exp(1.0);
+
+
+
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void constant_setup(void)
+{
+ constant_class = class_new(gensym("constant"), (t_newmethod)constant_new, 0,
+ sizeof(t_constant), 0,0);
+ class_addbang(constant_class,constant_bang);
+}
+
+
diff --git a/control/inv.c b/control/inv.c
index df6c2e2..0cff552 100755
--- a/control/inv.c
+++ b/control/inv.c
@@ -1,77 +1,77 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-#include <m_pd.h>
-
-
-typedef struct inv
-{
- t_object x_obj;
-} t_inv;
-
-static t_class *inv_class;
-
-static void *inv_new(void)
-{
- t_inv *x = (t_inv *)pd_new(inv_class);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-static t_int *inv_perform(t_int *w) /* not static; also used in d_fft.c */
-{
- float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
- t_int n = *(t_int *)(w+3);
- while (n--)
- {
- *out++ = 1/ *in++;
- }
- return (w + 4);
-}
-
-static void inv_dsp(t_inv *x, t_signal **sp)
-{
- dsp_add(inv_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void inv_tilde_setup(void)
-{
- inv_class = class_new(gensym("inv~"), (t_newmethod)inv_new, 0,
- sizeof(t_inv), 0, 0);
-
- class_addcreator(inv_new,gensym("1/x~"),0);
-
- class_addmethod(inv_class, nullfn, gensym("signal"), 0);
- class_addmethod(inv_class, (t_method)inv_dsp, gensym("dsp"), 0);
-}
-
-
-
-
-typedef struct scalarinv
-{
- t_object x_obj;
-} t_scalarinv;
-
-static t_class *scalarinv_class;
-
-static void *scalarinv_new(void)
-{
- t_scalarinv *x = (t_scalarinv *)pd_new(scalarinv_class);
- outlet_new(&x->x_obj, gensym("float"));
- return (x);
-}
-
-static void scalarinv_float(t_scalarinv *x,t_float val)
-{
- outlet_float(x->x_obj.ob_outlet,1.0f/val);
-
-}
-
-void inv_setup(void)
-{
- scalarinv_class = class_new(gensym("inv"), (t_newmethod)scalarinv_new, 0,
- sizeof(t_scalarinv), 0, 0);
- class_addcreator(scalarinv_new,gensym("1/x"),0);
-
- class_addfloat(scalarinv_class, (t_method)scalarinv_float);
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+#include <m_pd.h>
+
+
+typedef struct inv
+{
+ t_object x_obj;
+} t_inv;
+
+static t_class *inv_class;
+
+static void *inv_new(void)
+{
+ t_inv *x = (t_inv *)pd_new(inv_class);
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static t_int *inv_perform(t_int *w) /* not static; also used in d_fft.c */
+{
+ float *in = *(t_float **)(w+1), *out = *(t_float **)(w+2);
+ t_int n = *(t_int *)(w+3);
+ while (n--)
+ {
+ *out++ = 1/ *in++;
+ }
+ return (w + 4);
+}
+
+static void inv_dsp(t_inv *x, t_signal **sp)
+{
+ dsp_add(inv_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+void inv_tilde_setup(void)
+{
+ inv_class = class_new(gensym("inv~"), (t_newmethod)inv_new, 0,
+ sizeof(t_inv), 0, 0);
+
+ class_addcreator(inv_new,gensym("1/x~"),0);
+
+ class_addmethod(inv_class, nullfn, gensym("signal"), 0);
+ class_addmethod(inv_class, (t_method)inv_dsp, gensym("dsp"), 0);
+}
+
+
+
+
+typedef struct scalarinv
+{
+ t_object x_obj;
+} t_scalarinv;
+
+static t_class *scalarinv_class;
+
+static void *scalarinv_new(void)
+{
+ t_scalarinv *x = (t_scalarinv *)pd_new(scalarinv_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (x);
+}
+
+static void scalarinv_float(t_scalarinv *x,t_float val)
+{
+ outlet_float(x->x_obj.ob_outlet,1.0f/val);
+
+}
+
+void inv_setup(void)
+{
+ scalarinv_class = class_new(gensym("inv"), (t_newmethod)scalarinv_new, 0,
+ sizeof(t_scalarinv), 0, 0);
+ class_addcreator(scalarinv_new,gensym("1/x"),0);
+
+ class_addfloat(scalarinv_class, (t_method)scalarinv_float);
+}
diff --git a/control/prepend.c b/control/prepend.c
index 7b5bb0f..f0c6f15 100755
--- a/control/prepend.c
+++ b/control/prepend.c
@@ -1,76 +1,76 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ 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 (argv->a_type == A_SYMBOL) {
- SETSYMBOL(a,s);
- a++;
- c_out++;
- }
-
- while (i--) {
- switch( argv->a_type) {
- case A_FLOAT:
- SETFLOAT(a,atom_getfloat(argv));
- a++;
- c_out++;
- break;
- case A_SYMBOL:
- SETSYMBOL(a,atom_getsymbol(argv));
- a++;
- c_out++;
- break;
- default:
- post("unknown type");
- }
- argv++;
- }
- outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out);
-}
-
-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("prepend");
- error("prepend needs symbol argument");
- }
- return (x);
-}
-
-void prepend_setup(void)
-{
- prepend_class = class_new(gensym("prepend"), (t_newmethod)prepend_new, 0,
- sizeof(t_prepend), 0,A_DEFSYM,NULL);
- class_addanything(prepend_class,prepend_anything);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ 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 (argv->a_type == A_SYMBOL) {
+ SETSYMBOL(a,s);
+ a++;
+ c_out++;
+ }
+
+ while (i--) {
+ switch( argv->a_type) {
+ case A_FLOAT:
+ SETFLOAT(a,atom_getfloat(argv));
+ a++;
+ c_out++;
+ break;
+ case A_SYMBOL:
+ SETSYMBOL(a,atom_getsymbol(argv));
+ a++;
+ c_out++;
+ break;
+ default:
+ post("unknown type");
+ }
+ argv++;
+ }
+ outlet_anything(x->x_obj.ob_outlet,x->x_s,c_out,(t_atom*)&a_out);
+}
+
+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("prepend");
+ error("prepend needs symbol argument");
+ }
+ return (x);
+}
+
+void prepend_setup(void)
+{
+ prepend_class = class_new(gensym("prepend"), (t_newmethod)prepend_new, 0,
+ sizeof(t_prepend), 0,A_DEFSYM,NULL);
+ class_addanything(prepend_class,prepend_anything);
+}
+
+
diff --git a/control/qread.c b/control/qread.c
index f7c3897..28112df 100755
--- a/control/qread.c
+++ b/control/qread.c
@@ -1,129 +1,129 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-
-/* ------------------------ qread ----------------------------- */
-
-#include <stdio.h>
-
-static t_class *qread_class;
-
-
-#define MAXLINE 255
-
-typedef struct _qread
-{
- t_object x_obj;
- FILE* x_file;
- int x_size;
- t_clock* x_clock;
- t_glist * x_glist;
- int x_num;
- t_symbol* x_name;
-} t_qread;
-
-
-
-static void qread_open(t_qread *x,t_symbol *filename)
-{
- char fname[MAXPDSTRING];
-
- if (filename == &s_) {
- post("sfread: open without filename");
- return;
- }
-
- canvas_makefilename((void*)glist_getcanvas(x->x_glist), filename->s_name,
- fname, MAXPDSTRING);
-
-
- /* close the old file */
-
- if (x->x_file) fclose(x->x_file);
-
- if (!(x->x_file = fopen(fname,"r")))
- {
- error("can't open %s",fname);
- return;
- }
-
-
-}
-
-void qread_next(t_qread *x)
-{
- int i;
- float delay;
- char name[MAXLINE];
- t_atom at[20];
- int ac=0;
- t_floatarg ff;
-
- if (!x->x_file) return;
-
- fscanf(x->x_file,"%f",&delay);
- if (feof(x->x_file)) {
- clock_unset(x->x_clock);
- return;
- }
-
- fscanf(x->x_file,"%s",name);
-#ifdef DEBUG
- post("next: name = %s delay = %f",name,delay);
-#endif
-
- for (i=0;i<=x->x_num && !feof(x->x_file);i++) {
- fscanf(x->x_file,"%f",&ff);
- SETFLOAT(at+i,ff);
- }
- ac = i-1;
- fscanf(x->x_file,";");
-
-
- clock_delay(x->x_clock,delay);
-
- outlet_list(x->x_obj.ob_outlet, gensym(name), ac, at);
-}
-
-static void qread_bang(t_qread *x)
-{
- if (!x->x_file) return;
-
- fseek(x->x_file,0,SEEK_SET);
- clock_delay(x->x_clock,0);
-
-#ifdef DEBUG
- post("bang");
-#endif
-}
-
-static void qread_stop(t_qread *x)
-{
- clock_unset(x->x_clock);
-}
-
-static void *qread_new(t_floatarg n)
-{
- t_qread *x = (t_qread *)pd_new(qread_class);
- outlet_new(&x->x_obj, &s_float);
-
- x->x_name = gensym("qread");
- x->x_glist = (t_glist*) canvas_getcurrent();
- x->x_clock = clock_new(x, (t_method)qread_next);
- x->x_file = NULL;
- x->x_num = n;
- return (x);
-}
-
-void qread_setup(void)
-{
- qread_class = class_new(gensym("qread"), (t_newmethod)qread_new, 0,
- sizeof(t_qread), 0,A_DEFFLOAT,A_NULL);
- class_addbang(qread_class,qread_bang);
- class_addmethod(qread_class,(t_method)qread_next,gensym("next"),A_NULL);
- class_addmethod(qread_class,(t_method)qread_open,gensym("open"),A_SYMBOL,A_NULL);
- class_addmethod(qread_class,(t_method)qread_stop,gensym("stop"),A_NULL);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+
+/* ------------------------ qread ----------------------------- */
+
+#include <stdio.h>
+
+static t_class *qread_class;
+
+
+#define MAXLINE 255
+
+typedef struct _qread
+{
+ t_object x_obj;
+ FILE* x_file;
+ int x_size;
+ t_clock* x_clock;
+ t_glist * x_glist;
+ int x_num;
+ t_symbol* x_name;
+} t_qread;
+
+
+
+static void qread_open(t_qread *x,t_symbol *filename)
+{
+ char fname[MAXPDSTRING];
+
+ if (filename == &s_) {
+ post("sfread: open without filename");
+ return;
+ }
+
+ canvas_makefilename((void*)glist_getcanvas(x->x_glist), filename->s_name,
+ fname, MAXPDSTRING);
+
+
+ /* close the old file */
+
+ if (x->x_file) fclose(x->x_file);
+
+ if (!(x->x_file = fopen(fname,"r")))
+ {
+ error("can't open %s",fname);
+ return;
+ }
+
+
+}
+
+void qread_next(t_qread *x)
+{
+ int i;
+ float delay;
+ char name[MAXLINE];
+ t_atom at[20];
+ int ac=0;
+ t_floatarg ff;
+
+ if (!x->x_file) return;
+
+ fscanf(x->x_file,"%f",&delay);
+ if (feof(x->x_file)) {
+ clock_unset(x->x_clock);
+ return;
+ }
+
+ fscanf(x->x_file,"%s",name);
+#ifdef DEBUG
+ post("next: name = %s delay = %f",name,delay);
+#endif
+
+ for (i=0;i<=x->x_num && !feof(x->x_file);i++) {
+ fscanf(x->x_file,"%f",&ff);
+ SETFLOAT(at+i,ff);
+ }
+ ac = i-1;
+ fscanf(x->x_file,";");
+
+
+ clock_delay(x->x_clock,delay);
+
+ outlet_list(x->x_obj.ob_outlet, gensym(name), ac, at);
+}
+
+static void qread_bang(t_qread *x)
+{
+ if (!x->x_file) return;
+
+ fseek(x->x_file,0,SEEK_SET);
+ clock_delay(x->x_clock,0);
+
+#ifdef DEBUG
+ post("bang");
+#endif
+}
+
+static void qread_stop(t_qread *x)
+{
+ clock_unset(x->x_clock);
+}
+
+static void *qread_new(t_floatarg n)
+{
+ t_qread *x = (t_qread *)pd_new(qread_class);
+ outlet_new(&x->x_obj, &s_float);
+
+ x->x_name = gensym("qread");
+ x->x_glist = (t_glist*) canvas_getcurrent();
+ x->x_clock = clock_new(x, (t_method)qread_next);
+ x->x_file = NULL;
+ x->x_num = n;
+ return (x);
+}
+
+void qread_setup(void)
+{
+ qread_class = class_new(gensym("qread"), (t_newmethod)qread_new, 0,
+ sizeof(t_qread), 0,A_DEFFLOAT,A_NULL);
+ class_addbang(qread_class,qread_bang);
+ class_addmethod(qread_class,(t_method)qread_next,gensym("next"),A_NULL);
+ class_addmethod(qread_class,(t_method)qread_open,gensym("open"),A_SYMBOL,A_NULL);
+ class_addmethod(qread_class,(t_method)qread_stop,gensym("stop"),A_NULL);
+}
+
+
diff --git a/control/rl.c b/control/rl.c
index dba7f78..55bddaf 100755
--- a/control/rl.c
+++ b/control/rl.c
@@ -1,81 +1,81 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <stdio.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-
-/* -------------------- lreceive ------------------------------ */
-
-static t_class *lreceive_class;
-
-typedef struct _lreceive
-{
- t_object x_obj;
- t_symbol *x_sym;
-} t_lreceive;
-
-static void lreceive_bang(t_lreceive *x)
-{
- outlet_bang(x->x_obj.ob_outlet);
-}
-
-static void lreceive_float(t_lreceive *x, t_float f)
-{
- outlet_float(x->x_obj.ob_outlet, f);
-}
-
-static void lreceive_symbol(t_lreceive *x, t_symbol *s)
-{
- outlet_symbol(x->x_obj.ob_outlet, s);
-}
-
-static void lreceive_pointer(t_lreceive *x, t_gpointer *gp)
-{
- outlet_pointer(x->x_obj.ob_outlet, gp);
-}
-
-static void lreceive_list(t_lreceive *x, t_symbol *s, int argc, t_atom *argv)
-{
- outlet_list(x->x_obj.ob_outlet, s, argc, argv);
-}
-
-static void lreceive_anything(t_lreceive *x, t_symbol *s, int argc, t_atom *argv)
-{
- outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
-}
-
-static void *lreceive_new(t_symbol *s)
-{
- t_lreceive *x = (t_lreceive *)pd_new(lreceive_class);
- char mysym[MAXPDSTRING];
-
- sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent());
- x->x_sym = gensym(mysym);
- pd_bind(&x->x_obj.ob_pd, x->x_sym);
- outlet_new(&x->x_obj, 0);
- return (x);
-}
-
-static void lreceive_free(t_lreceive *x)
-{
- pd_unbind(&x->x_obj.ob_pd, x->x_sym);
-}
-
-void rl_setup(void)
-{
- lreceive_class = class_new(gensym("receivelocal"), (t_newmethod)lreceive_new,
- (t_method)lreceive_free, sizeof(t_lreceive), CLASS_NOINLET, A_SYMBOL, 0);
- class_addcreator((t_newmethod)lreceive_new, gensym("rl"), A_DEFSYM, 0);
- class_addbang(lreceive_class, lreceive_bang);
- class_addfloat(lreceive_class, (t_method)lreceive_float);
- class_addsymbol(lreceive_class, lreceive_symbol);
- class_addpointer(lreceive_class, lreceive_pointer);
- class_addlist(lreceive_class, lreceive_list);
- class_addanything(lreceive_class, lreceive_anything);
- post("Warning: receivelocal (rl) is deprecated, please use \"receive $0-var\" instead");
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <stdio.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+/* -------------------- lreceive ------------------------------ */
+
+static t_class *lreceive_class;
+
+typedef struct _lreceive
+{
+ t_object x_obj;
+ t_symbol *x_sym;
+} t_lreceive;
+
+static void lreceive_bang(t_lreceive *x)
+{
+ outlet_bang(x->x_obj.ob_outlet);
+}
+
+static void lreceive_float(t_lreceive *x, t_float f)
+{
+ outlet_float(x->x_obj.ob_outlet, f);
+}
+
+static void lreceive_symbol(t_lreceive *x, t_symbol *s)
+{
+ outlet_symbol(x->x_obj.ob_outlet, s);
+}
+
+static void lreceive_pointer(t_lreceive *x, t_gpointer *gp)
+{
+ outlet_pointer(x->x_obj.ob_outlet, gp);
+}
+
+static void lreceive_list(t_lreceive *x, t_symbol *s, int argc, t_atom *argv)
+{
+ outlet_list(x->x_obj.ob_outlet, s, argc, argv);
+}
+
+static void lreceive_anything(t_lreceive *x, t_symbol *s, int argc, t_atom *argv)
+{
+ outlet_anything(x->x_obj.ob_outlet, s, argc, argv);
+}
+
+static void *lreceive_new(t_symbol *s)
+{
+ t_lreceive *x = (t_lreceive *)pd_new(lreceive_class);
+ char mysym[MAXPDSTRING];
+
+ sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent());
+ x->x_sym = gensym(mysym);
+ pd_bind(&x->x_obj.ob_pd, x->x_sym);
+ outlet_new(&x->x_obj, 0);
+ return (x);
+}
+
+static void lreceive_free(t_lreceive *x)
+{
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+}
+
+void rl_setup(void)
+{
+ lreceive_class = class_new(gensym("receivelocal"), (t_newmethod)lreceive_new,
+ (t_method)lreceive_free, sizeof(t_lreceive), CLASS_NOINLET, A_SYMBOL, 0);
+ class_addcreator((t_newmethod)lreceive_new, gensym("rl"), A_DEFSYM, 0);
+ class_addbang(lreceive_class, lreceive_bang);
+ class_addfloat(lreceive_class, (t_method)lreceive_float);
+ class_addsymbol(lreceive_class, lreceive_symbol);
+ class_addpointer(lreceive_class, lreceive_pointer);
+ class_addlist(lreceive_class, lreceive_list);
+ class_addanything(lreceive_class, lreceive_anything);
+ post("Warning: receivelocal (rl) is deprecated, please use \"receive $0-var\" instead");
+}
diff --git a/control/rtout.c b/control/rtout.c
index 95df28c..bc211e2 100755
--- a/control/rtout.c
+++ b/control/rtout.c
@@ -1,41 +1,41 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-
-/* -------------------------- rtout -------------------------- */
-
-void sys_putmidimess(int portno, int a, int b, int c);
-
-static t_class *rtout_class;
-
-
-
-typedef struct _rtout
-{
- t_object x_obj;
- t_float x_rt;
- t_float x_channel;
-} t_rtout;
-
-static void *rtout_new(t_floatarg channel)
-{
- t_rtout *x = (t_rtout *)pd_new(rtout_class);
- if (channel <= 0) channel = 1;
- x->x_channel = channel;
- return (x);
-}
-
-static void rtout_float(t_rtout *x, t_float f)
-{
- int binchan = (int) x->x_channel - 1;
- sys_putmidimess((binchan>>4),(int) f,0,0);
-}
-
-void rtout_setup(void)
-{
- rtout_class = class_new(gensym("rtout"), (t_newmethod)rtout_new, 0,
- sizeof(t_rtout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addfloat(rtout_class, rtout_float);
-}
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+
+/* -------------------------- rtout -------------------------- */
+
+void sys_putmidimess(int portno, int a, int b, int c);
+
+static t_class *rtout_class;
+
+
+
+typedef struct _rtout
+{
+ t_object x_obj;
+ t_float x_rt;
+ t_float x_channel;
+} t_rtout;
+
+static void *rtout_new(t_floatarg channel)
+{
+ t_rtout *x = (t_rtout *)pd_new(rtout_class);
+ if (channel <= 0) channel = 1;
+ x->x_channel = channel;
+ return (x);
+}
+
+static void rtout_float(t_rtout *x, t_float f)
+{
+ int binchan = (int) x->x_channel - 1;
+ sys_putmidimess((binchan>>4),(int) f,0,0);
+}
+
+void rtout_setup(void)
+{
+ rtout_class = class_new(gensym("rtout"), (t_newmethod)rtout_new, 0,
+ sizeof(t_rtout), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addfloat(rtout_class, rtout_float);
+}
+
diff --git a/control/serial_bird.c b/control/serial_bird.c
index 410202a..6423dc7 100755
--- a/control/serial_bird.c
+++ b/control/serial_bird.c
@@ -1,265 +1,265 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <string.h>
-
-#define DEBUG(x)
-/*#define DEBUG(x) x*/
-
-static t_class *serial_bird_class;
-
-
-#define BIRD_DATA_START 0x80
-
-#define BIRDCMD_MODE_POS 86
-#define BIRD_BYTES_POS 6
-
-#define BIRDCMD_MODE_POSANG 89
-#define BIRD_BYTES_POSANG 12
-
-#define BIRDCMD_MODE_POSMAT 90
-#define BIRD_BYTES_POSMAT 24
-
-#define BIRDCMD_MODE_POSQUAT 93
-#define BIRD_BYTES_POSQUAT 14
-
-#define BIRDCMD_MODE_QUAT 92
-#define BIRD_BYTES_QUAT 8
-
-#define BIRDCMD_STREAM 64
-#define BIRDCMD_POINT 66
-
-#define BIRD_GETDATA(x,y) ((float)((short)(y<<9 | x<<2)))
-
-#define MAXBUFFER 32
-
-
-
-typedef struct _serial_bird
-{
- t_object x_obj;
- char x_c[MAXBUFFER];
- t_int x_dataformat;
- t_int x_maxcount;
- t_int x_count;
- t_float x_posx;
- t_float x_posy;
- t_float x_posz;
- t_outlet *x_out2;
-} t_serial_bird;
-
-
-static void serial_bird_reset( t_serial_bird* x)
-{
- x->x_posx=0;
- x->x_posy=0;
- x->x_count = 0;
- outlet_float(x->x_obj.ob_outlet, x->x_posx);
- outlet_float(x->x_out2, x->x_posy);
-}
-
-static void serial_bird_float( t_serial_bird* x,t_floatarg f)
-{
- unsigned char c = (unsigned char) f;
- t_atom at[BIRD_BYTES_POSMAT];
- t_int ac = 0;
-
- if (c&BIRD_DATA_START) {
- x->x_count=0;
- x->x_c[x->x_count] = c & 0x7f;
- }
- else
- x->x_c[x->x_count] = c;
-
- DEBUG(post("data %d in = %x, start = %d",x->x_count,c,c&BIRD_DATA_START);)
-
- if (x->x_count == x->x_maxcount-1) {
- switch (x->x_dataformat) {
- case BIRDCMD_MODE_POS:
- ac = 3;
- SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1]));
- SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3]));
- SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5]));
- break;
- case BIRDCMD_MODE_POSANG:
- ac = 6;
- SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1]));
- SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3]));
- SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5]));
- SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
- SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
- SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
- break;
- case BIRDCMD_MODE_POSMAT:
- ac = 12;
- SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
- SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
- SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
- SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
- SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
- SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
- SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13]));
- SETFLOAT(&at[7], BIRD_GETDATA(x->x_c[14],x->x_c[15]));
- SETFLOAT(&at[8], BIRD_GETDATA(x->x_c[16],x->x_c[17]));
- SETFLOAT(&at[9], BIRD_GETDATA(x->x_c[18],x->x_c[19]));
- SETFLOAT(&at[10], BIRD_GETDATA(x->x_c[20],x->x_c[21]));
- SETFLOAT(&at[11], BIRD_GETDATA(x->x_c[22],x->x_c[23]));
- break;
- case BIRDCMD_MODE_POSQUAT:
- ac = 7;
- SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
- SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
- SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
- SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
- SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
- SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
- SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13]));
- break;
- case BIRDCMD_MODE_QUAT:
- ac = 4;
- SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
- SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
- SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
- SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
- break;
- }
-
-/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/
- outlet_list(x->x_obj.ob_outlet,&s_list, ac, at);
- }
-
- x->x_count = (++x->x_count)%(x->x_maxcount);
-}
-
-static void serial_bird_poll( t_serial_bird* x)
-{
- post("poll");
- /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
- outlet_float(x->x_out2,(float)BIRDCMD_POINT);
-}
-
-static void serial_bird_mode( t_serial_bird* x,t_symbol* s)
-{
- post("mode");
- /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
-
-
- if (!strcmp(s->s_name,"position")) {
- x->x_dataformat = BIRDCMD_MODE_POS;
- x->x_maxcount = BIRD_BYTES_POS;
- }
-
- if (!strcmp(s->s_name,"positionangle")) {
- x->x_dataformat = BIRDCMD_MODE_POSANG;
- x->x_maxcount = BIRD_BYTES_POSANG;
- }
-
- if (!strcmp(s->s_name,"positionmatrix")) {
- x->x_dataformat = BIRDCMD_MODE_POSMAT;
- x->x_maxcount = BIRD_BYTES_POSMAT;
- }
-
- if (!strcmp(s->s_name,"positionquat")) {
- x->x_dataformat = BIRDCMD_MODE_POSQUAT;
- x->x_maxcount = BIRD_BYTES_POSQUAT;
- }
-
- if (!strcmp(s->s_name,"quaternion")) {
- x->x_dataformat = BIRDCMD_MODE_QUAT;
- x->x_maxcount = BIRD_BYTES_QUAT;
- }
-
- outlet_float(x->x_out2,(float)x->x_dataformat);
-}
-
-static void serial_bird_init( t_serial_bird* x)
-{
- t_atom cmd[8];
-
- SETFLOAT(cmd,14400.);
- outlet_anything(x->x_out2,gensym("speed"),1,cmd);
-
-
- SETFLOAT(cmd,0.);
- SETSYMBOL(cmd+1,gensym("CLOCAL"));
- SETSYMBOL(cmd+2,gensym("CREAD"));
- SETSYMBOL(cmd+3,gensym("CS8"));
- outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd);
-
- SETFLOAT(cmd,0.);
- SETSYMBOL(cmd+1,gensym("IXOFF"));
- outlet_anything(x->x_out2,gensym("setinput"),2,cmd);
-
- SETFLOAT(cmd,0.);
- outlet_anything(x->x_out2,gensym("setlocal"),1,cmd);
-
- SETFLOAT(cmd,0.);
- SETFLOAT(cmd+1,20.);
- outlet_anything(x->x_out2,gensym("vtime"),2,cmd);
-
-
- SETSYMBOL(cmd,gensym("RTS"));
- SETFLOAT(cmd+1,0.);
- outlet_anything(x->x_out2,gensym("setlines"),2,cmd);
-
- SETSYMBOL(cmd,gensym("DTR"));
- SETFLOAT(cmd+1,1.);
- outlet_anything(x->x_out2,gensym("setlines"),2,cmd);
-
-
- /* start the polling on the serial device immediately */
-
- outlet_anything(x->x_out2,gensym("start"),0,cmd);
-
-}
-
-static void serial_bird_start( t_serial_bird* x)
-{
- post("start");
- /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
- outlet_float(x->x_out2,(float)BIRDCMD_STREAM);
-}
-
-
-static void serial_bird_stop( t_serial_bird* x)
-{
- post("stop");
- outlet_float(x->x_out2,(float)BIRDCMD_POINT);
-}
-
-static void *serial_bird_new(t_symbol *s)
-{
- t_serial_bird *x = (t_serial_bird *)pd_new(serial_bird_class);
-
- x->x_count = 0;
- x->x_posx = 0;
- x->x_posy = 0;
- x->x_dataformat = BIRDCMD_MODE_POSANG;
- x->x_maxcount = BIRD_BYTES_POSANG;
-
-
- outlet_new(&x->x_obj, &s_float);
- x->x_out2 = outlet_new(&x->x_obj, &s_float);
-
- return x;
-}
-
-
-void serial_bird_setup(void)
-{
- serial_bird_class = class_new(gensym("serial_bird"), (t_newmethod)serial_bird_new,
- NULL,
- sizeof(t_serial_bird), 0,A_DEFSYM,0);
- class_addfloat(serial_bird_class,serial_bird_float);
- class_addmethod(serial_bird_class,(t_method) serial_bird_reset,gensym("reset"),0);
- class_addmethod(serial_bird_class,(t_method) serial_bird_init,gensym("init"),0);
-
-
- class_addmethod(serial_bird_class,(t_method) serial_bird_start,gensym("start"),0);
- class_addmethod(serial_bird_class,(t_method) serial_bird_stop,gensym("stop"),0);
- class_addmethod(serial_bird_class,(t_method) serial_bird_poll,gensym("poll"),0);
- class_addmethod(serial_bird_class,(t_method) serial_bird_mode,gensym("mode"),A_SYMBOL,NULL);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <string.h>
+
+#define DEBUG(x)
+/*#define DEBUG(x) x*/
+
+static t_class *serial_bird_class;
+
+
+#define BIRD_DATA_START 0x80
+
+#define BIRDCMD_MODE_POS 86
+#define BIRD_BYTES_POS 6
+
+#define BIRDCMD_MODE_POSANG 89
+#define BIRD_BYTES_POSANG 12
+
+#define BIRDCMD_MODE_POSMAT 90
+#define BIRD_BYTES_POSMAT 24
+
+#define BIRDCMD_MODE_POSQUAT 93
+#define BIRD_BYTES_POSQUAT 14
+
+#define BIRDCMD_MODE_QUAT 92
+#define BIRD_BYTES_QUAT 8
+
+#define BIRDCMD_STREAM 64
+#define BIRDCMD_POINT 66
+
+#define BIRD_GETDATA(x,y) ((float)((short)(y<<9 | x<<2)))
+
+#define MAXBUFFER 32
+
+
+
+typedef struct _serial_bird
+{
+ t_object x_obj;
+ char x_c[MAXBUFFER];
+ t_int x_dataformat;
+ t_int x_maxcount;
+ t_int x_count;
+ t_float x_posx;
+ t_float x_posy;
+ t_float x_posz;
+ t_outlet *x_out2;
+} t_serial_bird;
+
+
+static void serial_bird_reset( t_serial_bird* x)
+{
+ x->x_posx=0;
+ x->x_posy=0;
+ x->x_count = 0;
+ outlet_float(x->x_obj.ob_outlet, x->x_posx);
+ outlet_float(x->x_out2, x->x_posy);
+}
+
+static void serial_bird_float( t_serial_bird* x,t_floatarg f)
+{
+ unsigned char c = (unsigned char) f;
+ t_atom at[BIRD_BYTES_POSMAT];
+ t_int ac = 0;
+
+ if (c&BIRD_DATA_START) {
+ x->x_count=0;
+ x->x_c[x->x_count] = c & 0x7f;
+ }
+ else
+ x->x_c[x->x_count] = c;
+
+ DEBUG(post("data %d in = %x, start = %d",x->x_count,c,c&BIRD_DATA_START);)
+
+ if (x->x_count == x->x_maxcount-1) {
+ switch (x->x_dataformat) {
+ case BIRDCMD_MODE_POS:
+ ac = 3;
+ SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1]));
+ SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3]));
+ SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5]));
+ break;
+ case BIRDCMD_MODE_POSANG:
+ ac = 6;
+ SETFLOAT(&at[0], 0.25*BIRD_GETDATA(x->x_c[0],x->x_c[1]));
+ SETFLOAT(&at[1], 0.25*BIRD_GETDATA(x->x_c[2],x->x_c[3]));
+ SETFLOAT(&at[2], 0.25*BIRD_GETDATA(x->x_c[4],x->x_c[5]));
+ SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
+ SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
+ SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
+ break;
+ case BIRDCMD_MODE_POSMAT:
+ ac = 12;
+ SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
+ SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
+ SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
+ SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
+ SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
+ SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
+ SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13]));
+ SETFLOAT(&at[7], BIRD_GETDATA(x->x_c[14],x->x_c[15]));
+ SETFLOAT(&at[8], BIRD_GETDATA(x->x_c[16],x->x_c[17]));
+ SETFLOAT(&at[9], BIRD_GETDATA(x->x_c[18],x->x_c[19]));
+ SETFLOAT(&at[10], BIRD_GETDATA(x->x_c[20],x->x_c[21]));
+ SETFLOAT(&at[11], BIRD_GETDATA(x->x_c[22],x->x_c[23]));
+ break;
+ case BIRDCMD_MODE_POSQUAT:
+ ac = 7;
+ SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
+ SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
+ SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
+ SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
+ SETFLOAT(&at[4], BIRD_GETDATA(x->x_c[8],x->x_c[9]));
+ SETFLOAT(&at[5], BIRD_GETDATA(x->x_c[10],x->x_c[11]));
+ SETFLOAT(&at[6], BIRD_GETDATA(x->x_c[12],x->x_c[13]));
+ break;
+ case BIRDCMD_MODE_QUAT:
+ ac = 4;
+ SETFLOAT(&at[0], BIRD_GETDATA(x->x_c[0],x->x_c[1]));
+ SETFLOAT(&at[1], BIRD_GETDATA(x->x_c[2],x->x_c[3]));
+ SETFLOAT(&at[2], BIRD_GETDATA(x->x_c[4],x->x_c[5]));
+ SETFLOAT(&at[3], BIRD_GETDATA(x->x_c[6],x->x_c[7]));
+ break;
+ }
+
+/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/
+ outlet_list(x->x_obj.ob_outlet,&s_list, ac, at);
+ }
+
+ x->x_count = (++x->x_count)%(x->x_maxcount);
+}
+
+static void serial_bird_poll( t_serial_bird* x)
+{
+ post("poll");
+ /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
+ outlet_float(x->x_out2,(float)BIRDCMD_POINT);
+}
+
+static void serial_bird_mode( t_serial_bird* x,t_symbol* s)
+{
+ post("mode");
+ /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
+
+
+ if (!strcmp(s->s_name,"position")) {
+ x->x_dataformat = BIRDCMD_MODE_POS;
+ x->x_maxcount = BIRD_BYTES_POS;
+ }
+
+ if (!strcmp(s->s_name,"positionangle")) {
+ x->x_dataformat = BIRDCMD_MODE_POSANG;
+ x->x_maxcount = BIRD_BYTES_POSANG;
+ }
+
+ if (!strcmp(s->s_name,"positionmatrix")) {
+ x->x_dataformat = BIRDCMD_MODE_POSMAT;
+ x->x_maxcount = BIRD_BYTES_POSMAT;
+ }
+
+ if (!strcmp(s->s_name,"positionquat")) {
+ x->x_dataformat = BIRDCMD_MODE_POSQUAT;
+ x->x_maxcount = BIRD_BYTES_POSQUAT;
+ }
+
+ if (!strcmp(s->s_name,"quaternion")) {
+ x->x_dataformat = BIRDCMD_MODE_QUAT;
+ x->x_maxcount = BIRD_BYTES_QUAT;
+ }
+
+ outlet_float(x->x_out2,(float)x->x_dataformat);
+}
+
+static void serial_bird_init( t_serial_bird* x)
+{
+ t_atom cmd[8];
+
+ SETFLOAT(cmd,14400.);
+ outlet_anything(x->x_out2,gensym("speed"),1,cmd);
+
+
+ SETFLOAT(cmd,0.);
+ SETSYMBOL(cmd+1,gensym("CLOCAL"));
+ SETSYMBOL(cmd+2,gensym("CREAD"));
+ SETSYMBOL(cmd+3,gensym("CS8"));
+ outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd);
+
+ SETFLOAT(cmd,0.);
+ SETSYMBOL(cmd+1,gensym("IXOFF"));
+ outlet_anything(x->x_out2,gensym("setinput"),2,cmd);
+
+ SETFLOAT(cmd,0.);
+ outlet_anything(x->x_out2,gensym("setlocal"),1,cmd);
+
+ SETFLOAT(cmd,0.);
+ SETFLOAT(cmd+1,20.);
+ outlet_anything(x->x_out2,gensym("vtime"),2,cmd);
+
+
+ SETSYMBOL(cmd,gensym("RTS"));
+ SETFLOAT(cmd+1,0.);
+ outlet_anything(x->x_out2,gensym("setlines"),2,cmd);
+
+ SETSYMBOL(cmd,gensym("DTR"));
+ SETFLOAT(cmd+1,1.);
+ outlet_anything(x->x_out2,gensym("setlines"),2,cmd);
+
+
+ /* start the polling on the serial device immediately */
+
+ outlet_anything(x->x_out2,gensym("start"),0,cmd);
+
+}
+
+static void serial_bird_start( t_serial_bird* x)
+{
+ post("start");
+ /* outlet_float(x->x_out2,(float)x->x_dataformat);*/
+ outlet_float(x->x_out2,(float)BIRDCMD_STREAM);
+}
+
+
+static void serial_bird_stop( t_serial_bird* x)
+{
+ post("stop");
+ outlet_float(x->x_out2,(float)BIRDCMD_POINT);
+}
+
+static void *serial_bird_new(t_symbol *s)
+{
+ t_serial_bird *x = (t_serial_bird *)pd_new(serial_bird_class);
+
+ x->x_count = 0;
+ x->x_posx = 0;
+ x->x_posy = 0;
+ x->x_dataformat = BIRDCMD_MODE_POSANG;
+ x->x_maxcount = BIRD_BYTES_POSANG;
+
+
+ outlet_new(&x->x_obj, &s_float);
+ x->x_out2 = outlet_new(&x->x_obj, &s_float);
+
+ return x;
+}
+
+
+void serial_bird_setup(void)
+{
+ serial_bird_class = class_new(gensym("serial_bird"), (t_newmethod)serial_bird_new,
+ NULL,
+ sizeof(t_serial_bird), 0,A_DEFSYM,0);
+ class_addfloat(serial_bird_class,serial_bird_float);
+ class_addmethod(serial_bird_class,(t_method) serial_bird_reset,gensym("reset"),0);
+ class_addmethod(serial_bird_class,(t_method) serial_bird_init,gensym("init"),0);
+
+
+ class_addmethod(serial_bird_class,(t_method) serial_bird_start,gensym("start"),0);
+ class_addmethod(serial_bird_class,(t_method) serial_bird_stop,gensym("stop"),0);
+ class_addmethod(serial_bird_class,(t_method) serial_bird_poll,gensym("poll"),0);
+ class_addmethod(serial_bird_class,(t_method) serial_bird_mode,gensym("mode"),A_SYMBOL,NULL);
+}
+
+
diff --git a/control/serial_ms.c b/control/serial_ms.c
index 723b8bf..b012fdf 100755
--- a/control/serial_ms.c
+++ b/control/serial_ms.c
@@ -1,120 +1,120 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-
-
-static t_class *serial_ms_class;
-
-
-typedef struct _serial_ms
-{
- t_object x_obj;
- char x_c[4];
- t_int x_count;
- t_int x_posx;
- t_int x_posy;
- t_outlet *x_out2;
-} t_serial_ms;
-
-
-static void serial_ms_reset( t_serial_ms* x)
-{
- x->x_posx=0;
- x->x_posy=0;
- x->x_count = 0;
- outlet_float(x->x_obj.ob_outlet, x->x_posx);
- outlet_float(x->x_out2, x->x_posy);
-}
-
-static void serial_ms_init( t_serial_ms* x)
-{
- t_atom cmd[8];
-
- SETFLOAT(cmd,0.);
- SETSYMBOL(cmd+1,gensym("CLOCAL"));
- SETSYMBOL(cmd+2,gensym("CREAD"));
- SETSYMBOL(cmd+3,gensym("CS7"));
-/* SETSYMBOL(cmd+4,gensym("HUPCL")); */
- outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd);
-
- SETFLOAT(cmd,0.);
- SETSYMBOL(cmd+1,gensym("IGNBRK"));
- SETSYMBOL(cmd+2,gensym("IGNPAR"));
- outlet_anything(x->x_out2,gensym("setinput"),3,cmd);
-
- SETFLOAT(cmd,0.);
- SETFLOAT(cmd+1,1.);
- outlet_anything(x->x_out2,gensym("vtime"),2,cmd);
-
- SETFLOAT(cmd,1200.);
- outlet_anything(x->x_out2,gensym("speed"),1,cmd);
-
- SETSYMBOL(cmd,gensym("*n"));
- outlet_anything(x->x_out2,gensym("send"),1,cmd);
-
-
- SETSYMBOL(cmd,gensym("N"));
- outlet_anything(x->x_out2,gensym("send"),1,cmd);
-
-
-}
-
-
-
-static void serial_ms_float( t_serial_ms* x,t_floatarg f)
-{
- int dx,dy;
- t_atom at[2];
-
- x->x_c[x->x_count] = (char) f;
-
- x->x_count = (++x->x_count)%3;
-
- if (x->x_count==2) {
- dx= (signed char)(((x->x_c[0] & 0x03) << 6) |
- (x->x_c[1] & 0x3F));
- dy= (signed char)(((x->x_c[0] & 0x0C) << 4) |
- (x->x_c[2] & 0x3F));
- x->x_posx += dx;
- x->x_posy += dy;
-/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/
-
- SETFLOAT(at,x->x_posx);
- SETFLOAT(at+1,x->x_posy);
- outlet_list(x->x_obj.ob_outlet,&s_list, 2, at);
- }
-
-
-}
-
-
-static void *serial_ms_new(t_symbol *s)
-{
- t_serial_ms *x = (t_serial_ms *)pd_new(serial_ms_class);
-
- x->x_count = 0;
- x->x_posx = 0;
- x->x_posy = 0;
-
-
- outlet_new(&x->x_obj, &s_float);
- x->x_out2 = outlet_new(&x->x_obj, &s_float);
-
- return x;
-}
-
-
-void serial_ms_setup(void)
-{
- serial_ms_class = class_new(gensym("serial_ms"), (t_newmethod)serial_ms_new,
- NULL,
- sizeof(t_serial_ms), 0,A_DEFSYM,0);
- class_addfloat(serial_ms_class,serial_ms_float);
- class_addmethod(serial_ms_class,(t_method) serial_ms_reset,gensym("reset"),0);
- class_addmethod(serial_ms_class, (t_method)serial_ms_init, gensym("init"),0);
-
-
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+
+
+static t_class *serial_ms_class;
+
+
+typedef struct _serial_ms
+{
+ t_object x_obj;
+ char x_c[4];
+ t_int x_count;
+ t_int x_posx;
+ t_int x_posy;
+ t_outlet *x_out2;
+} t_serial_ms;
+
+
+static void serial_ms_reset( t_serial_ms* x)
+{
+ x->x_posx=0;
+ x->x_posy=0;
+ x->x_count = 0;
+ outlet_float(x->x_obj.ob_outlet, x->x_posx);
+ outlet_float(x->x_out2, x->x_posy);
+}
+
+static void serial_ms_init( t_serial_ms* x)
+{
+ t_atom cmd[8];
+
+ SETFLOAT(cmd,0.);
+ SETSYMBOL(cmd+1,gensym("CLOCAL"));
+ SETSYMBOL(cmd+2,gensym("CREAD"));
+ SETSYMBOL(cmd+3,gensym("CS7"));
+/* SETSYMBOL(cmd+4,gensym("HUPCL")); */
+ outlet_anything(x->x_out2,gensym("setcontrol"),4,cmd);
+
+ SETFLOAT(cmd,0.);
+ SETSYMBOL(cmd+1,gensym("IGNBRK"));
+ SETSYMBOL(cmd+2,gensym("IGNPAR"));
+ outlet_anything(x->x_out2,gensym("setinput"),3,cmd);
+
+ SETFLOAT(cmd,0.);
+ SETFLOAT(cmd+1,1.);
+ outlet_anything(x->x_out2,gensym("vtime"),2,cmd);
+
+ SETFLOAT(cmd,1200.);
+ outlet_anything(x->x_out2,gensym("speed"),1,cmd);
+
+ SETSYMBOL(cmd,gensym("*n"));
+ outlet_anything(x->x_out2,gensym("send"),1,cmd);
+
+
+ SETSYMBOL(cmd,gensym("N"));
+ outlet_anything(x->x_out2,gensym("send"),1,cmd);
+
+
+}
+
+
+
+static void serial_ms_float( t_serial_ms* x,t_floatarg f)
+{
+ int dx,dy;
+ t_atom at[2];
+
+ x->x_c[x->x_count] = (char) f;
+
+ x->x_count = (++x->x_count)%3;
+
+ if (x->x_count==2) {
+ dx= (signed char)(((x->x_c[0] & 0x03) << 6) |
+ (x->x_c[1] & 0x3F));
+ dy= (signed char)(((x->x_c[0] & 0x0C) << 4) |
+ (x->x_c[2] & 0x3F));
+ x->x_posx += dx;
+ x->x_posy += dy;
+/* post("posx %d, posy %d",x->x_posx,x->x_posy);*/
+
+ SETFLOAT(at,x->x_posx);
+ SETFLOAT(at+1,x->x_posy);
+ outlet_list(x->x_obj.ob_outlet,&s_list, 2, at);
+ }
+
+
+}
+
+
+static void *serial_ms_new(t_symbol *s)
+{
+ t_serial_ms *x = (t_serial_ms *)pd_new(serial_ms_class);
+
+ x->x_count = 0;
+ x->x_posx = 0;
+ x->x_posy = 0;
+
+
+ outlet_new(&x->x_obj, &s_float);
+ x->x_out2 = outlet_new(&x->x_obj, &s_float);
+
+ return x;
+}
+
+
+void serial_ms_setup(void)
+{
+ serial_ms_class = class_new(gensym("serial_ms"), (t_newmethod)serial_ms_new,
+ NULL,
+ sizeof(t_serial_ms), 0,A_DEFSYM,0);
+ class_addfloat(serial_ms_class,serial_ms_float);
+ class_addmethod(serial_ms_class,(t_method) serial_ms_reset,gensym("reset"),0);
+ class_addmethod(serial_ms_class, (t_method)serial_ms_init, gensym("init"),0);
+
+
+}
+
+
diff --git a/control/serial_mt.c b/control/serial_mt.c
index ed8a0ed..02a1aac 100755
--- a/control/serial_mt.c
+++ b/control/serial_mt.c
@@ -1,77 +1,77 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-
-
-static t_class *serial_mt_class;
-
-
-typedef struct _serial_mt
-{
- t_object x_obj;
- char x_c[4];
- t_int x_count;
- t_int x_posx;
- t_int x_posy;
- t_outlet *x_out2;
-} t_serial_mt;
-
-
-static void serial_mt_reset( t_serial_mt* x)
-{
- x->x_posx=0;
- x->x_posy=0;
- x->x_count = 0;
-}
-
-static void serial_mt_float( t_serial_mt* x,t_floatarg f)
-{
- int dx,dy;
-
- x->x_c[x->x_count] = (char) f;
-
- x->x_count = (++x->x_count)%3;
-
- if (x->x_count==2) {
- dx= (signed char)(((x->x_c[0] & 0x03) << 6) |
- (x->x_c[1] & 0x3F));
- dy= (signed char)(((x->x_c[0] & 0x0C) << 4) |
- (x->x_c[2] & 0x3F));
- x->x_posx += dx;
- x->x_posy += dy;
-/* post("posx %d, posy %d",x->x_posx,x->x_posy); */
- outlet_float(x->x_obj.ob_outlet, x->x_posx);
- outlet_float(x->x_out2, x->x_posy);
- }
-
-
-}
-
-
-static void *serial_mt_new(t_symbol *s)
-{
- t_serial_mt *x = (t_serial_mt *)pd_new(serial_mt_class);
-
- x->x_count = 0;
- x->x_posx = 0;
- x->x_posy = 0;
-
-
- outlet_new(&x->x_obj, &s_float);
- x->x_out2 = outlet_new(&x->x_obj, &s_float);
-
- return x;
-}
-
-
-void serial_mt_setup(void)
-{
- serial_mt_class = class_new(gensym("serial_mt"), (t_newmethod)serial_mt_new,
- NULL,
- sizeof(t_serial_mt), 0,A_DEFSYM,0);
- class_addfloat(serial_mt_class,serial_mt_float);
- class_addmethod(serial_mt_class,(t_method) serial_mt_reset,gensym("reset"),0);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+
+
+static t_class *serial_mt_class;
+
+
+typedef struct _serial_mt
+{
+ t_object x_obj;
+ char x_c[4];
+ t_int x_count;
+ t_int x_posx;
+ t_int x_posy;
+ t_outlet *x_out2;
+} t_serial_mt;
+
+
+static void serial_mt_reset( t_serial_mt* x)
+{
+ x->x_posx=0;
+ x->x_posy=0;
+ x->x_count = 0;
+}
+
+static void serial_mt_float( t_serial_mt* x,t_floatarg f)
+{
+ int dx,dy;
+
+ x->x_c[x->x_count] = (char) f;
+
+ x->x_count = (++x->x_count)%3;
+
+ if (x->x_count==2) {
+ dx= (signed char)(((x->x_c[0] & 0x03) << 6) |
+ (x->x_c[1] & 0x3F));
+ dy= (signed char)(((x->x_c[0] & 0x0C) << 4) |
+ (x->x_c[2] & 0x3F));
+ x->x_posx += dx;
+ x->x_posy += dy;
+/* post("posx %d, posy %d",x->x_posx,x->x_posy); */
+ outlet_float(x->x_obj.ob_outlet, x->x_posx);
+ outlet_float(x->x_out2, x->x_posy);
+ }
+
+
+}
+
+
+static void *serial_mt_new(t_symbol *s)
+{
+ t_serial_mt *x = (t_serial_mt *)pd_new(serial_mt_class);
+
+ x->x_count = 0;
+ x->x_posx = 0;
+ x->x_posy = 0;
+
+
+ outlet_new(&x->x_obj, &s_float);
+ x->x_out2 = outlet_new(&x->x_obj, &s_float);
+
+ return x;
+}
+
+
+void serial_mt_setup(void)
+{
+ serial_mt_class = class_new(gensym("serial_mt"), (t_newmethod)serial_mt_new,
+ NULL,
+ sizeof(t_serial_mt), 0,A_DEFSYM,0);
+ class_addfloat(serial_mt_class,serial_mt_float);
+ class_addmethod(serial_mt_class,(t_method) serial_mt_reset,gensym("reset"),0);
+}
+
+
diff --git a/control/serialize.c b/control/serialize.c
index d288ec4..961a32d 100755
--- a/control/serialize.c
+++ b/control/serialize.c
@@ -1,58 +1,58 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ serialize ----------------------------- */
-
-#define MAX_ELEMENTS 256
-
-static t_class *serialize_class;
-
-
-typedef struct _serialize
-{
- t_object x_obj;
- t_atom x_abuf[MAX_ELEMENTS];
- t_int x_count;
- t_float x_elements;
-} t_serialize;
-
-
-void serialize_float(t_serialize *x,t_floatarg f)
-{
- SETFLOAT(&x->x_abuf[x->x_count],f);
- x->x_count++;
-
- if (x->x_count == x->x_elements) {
- outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf);
- x->x_count = 0;
- }
-}
-
-
-static void *serialize_new(t_floatarg f)
-{
- t_serialize *x = (t_serialize *)pd_new(serialize_class);
- outlet_new(&x->x_obj,&s_float);
- x->x_elements = f;
- x->x_count=0;
- if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1;
- floatinlet_new(&x->x_obj, &x->x_elements);
- return (x);
-}
-
-
-
-void serialize_setup(void)
-{
- serialize_class = class_new(gensym("serialize"), (t_newmethod)serialize_new, 0,
- sizeof(t_serialize),0, A_DEFFLOAT,0);
- class_addfloat(serialize_class,serialize_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ serialize ----------------------------- */
+
+#define MAX_ELEMENTS 256
+
+static t_class *serialize_class;
+
+
+typedef struct _serialize
+{
+ t_object x_obj;
+ t_atom x_abuf[MAX_ELEMENTS];
+ t_int x_count;
+ t_float x_elements;
+} t_serialize;
+
+
+void serialize_float(t_serialize *x,t_floatarg f)
+{
+ SETFLOAT(&x->x_abuf[x->x_count],f);
+ x->x_count++;
+
+ if (x->x_count == x->x_elements) {
+ outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf);
+ x->x_count = 0;
+ }
+}
+
+
+static void *serialize_new(t_floatarg f)
+{
+ t_serialize *x = (t_serialize *)pd_new(serialize_class);
+ outlet_new(&x->x_obj,&s_float);
+ x->x_elements = f;
+ x->x_count=0;
+ if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1;
+ floatinlet_new(&x->x_obj, &x->x_elements);
+ return (x);
+}
+
+
+
+void serialize_setup(void)
+{
+ serialize_class = class_new(gensym("serialize"), (t_newmethod)serialize_new, 0,
+ sizeof(t_serialize),0, A_DEFFLOAT,0);
+ class_addfloat(serialize_class,serialize_float);
+}
+
+
diff --git a/control/shell.c b/control/shell.c
index 78e6e03..ad989be 100755
--- a/control/shell.c
+++ b/control/shell.c
@@ -1,312 +1,312 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <sched.h>
-
-void sys_rmpollfn(int fd);
-void sys_addpollfn(int fd, void* fn, void *ptr);
-
-/* ------------------------ shell ----------------------------- */
-
-#define INBUFSIZE 1024
-
-static t_class *shell_class;
-
-
-static void drop_priority(void)
-{
-#ifdef _POSIX_PRIORITY_SCHEDULING
- struct sched_param par;
- int p1 ,p2, p3;
- par.sched_priority = 0;
- sched_setscheduler(0,SCHED_OTHER,&par);
-#endif
-}
-
-
-typedef struct _shell
-{
- t_object x_obj;
- int x_echo;
- char *sr_inbuf;
- int sr_inhead;
- int sr_intail;
- void* x_binbuf;
- int fdpipe[2];
- int fdinpipe[2];
- int pid;
- int x_del;
- t_outlet* x_done;
- t_clock* x_clock;
-} t_shell;
-
-static int shell_pid;
-
-
-void shell_cleanup(t_shell* x)
-{
- sys_rmpollfn(x->fdpipe[0]);
-
- if (x->fdpipe[0]>0) close(x->fdpipe[0]);
- if (x->fdpipe[1]>0) close(x->fdpipe[1]);
- if (x->fdinpipe[0]>0) close(x->fdinpipe[0]);
- if (x->fdinpipe[1]>0) close(x->fdinpipe[1]);
-
- x->fdpipe[0] = -1;
- x->fdpipe[1] = -1;
- x->fdinpipe[0] = -1;
- x->fdinpipe[1] = -1;
- clock_unset(x->x_clock);
-}
-
-void shell_check(t_shell* x)
-{
- int ret;
- int status;
- ret = waitpid(x->pid,&status,WNOHANG);
- if (ret == x->pid) {
- shell_cleanup(x);
- if (WIFEXITED(status)) {
- outlet_float(x->x_done,WEXITSTATUS(status));
- }
- else outlet_float(x->x_done,0);
- }
- else {
- if (x->x_del < 100) x->x_del+=2; /* increment poll times */
- clock_delay(x->x_clock,x->x_del);
- }
-}
-
-
-void shell_bang(t_shell *x)
-{
- post("bang");
-}
-
-/* snippet from pd's code */
-static void shell_doit(void *z, t_binbuf *b)
-{
- t_shell *x = (t_shell *)z;
- int msg, natom = binbuf_getnatom(b);
- t_atom *at = binbuf_getvec(b);
-
- for (msg = 0; msg < natom;)
- {
- int emsg;
- for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA
- && at[emsg].a_type != A_SEMI; emsg++)
- ;
- if (emsg > msg)
- {
- int i;
- for (i = msg; i < emsg; i++)
- if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM)
- {
- pd_error(x, "netreceive: got dollar sign in message");
- goto nodice;
- }
- if (at[msg].a_type == A_FLOAT)
- {
- if (emsg > msg + 1)
- outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg);
- else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float);
- }
- else if (at[msg].a_type == A_SYMBOL)
- outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol,
- emsg-msg-1, at + msg + 1);
- }
- nodice:
- msg = emsg + 1;
- }
-}
-
-
-void shell_read(t_shell *x, int fd)
-{
- char buf[INBUFSIZE];
- t_binbuf* bbuf = binbuf_new();
- int i;
- int readto =
- (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
- int ret;
-
- ret = read(fd, buf,INBUFSIZE-1);
- buf[ret] = '\0';
-
- for (i=0;i<ret;i++)
- if (buf[i] == '\n') buf[i] = ';';
- if (ret < 0)
- {
- error("shell: pipe read error");
- sys_rmpollfn(fd);
- x->fdpipe[0] = -1;
- close(fd);
- return;
- }
- else if (ret == 0)
- {
- post("EOF on socket %d\n", fd);
- sys_rmpollfn(fd);
- x->fdpipe[0] = -1;
- close(fd);
- return;
- }
- else
- {
- int natom;
- t_atom *at;
- binbuf_text(bbuf, buf, strlen(buf));
-
- natom = binbuf_getnatom(bbuf);
- at = binbuf_getvec(bbuf);
- shell_doit(x,bbuf);
- }
- binbuf_free(bbuf);
-}
-
-
-static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at)
-{
- int i;
- char tmp[MAXPDSTRING];
- int size = 0;
-
- if (x->fdinpipe[0] == -1) return; /* nothing to send to */
-
- for (i=0;i<ac;i++) {
- atom_string(at,tmp+size,MAXPDSTRING - size);
- at++;
- size=strlen(tmp);
- tmp[size++] = ' ';
- }
- tmp[size-1] = '\0';
- post("sending %s",tmp);
- write(x->fdinpipe[0],tmp,strlen(tmp));
-}
-
-static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at)
-{
- int i;
- char* argv[20];
- t_symbol* sym;
-
- if (!strcmp(s->s_name,"send")) {
- post("send");
- shell_send(x,s,ac,at);
- return;
- }
-
- argv[0] = s->s_name;
-
- if (x->fdpipe[0] != -1) {
- post("shell: old process still running");
- kill(x->pid,SIGKILL);
- shell_cleanup(x);
- }
-
-
- if (pipe(x->fdpipe) < 0) {
- error("unable to create pipe");
- return;
- }
-
- if (pipe(x->fdinpipe) < 0) {
- error("unable to create input pipe");
- return;
- }
-
-
- sys_addpollfn(x->fdpipe[0],shell_read,x);
-
- if (!(x->pid = fork())) {
- int status;
- char* cmd = getbytes(1024);
- char* tcmd = getbytes(1024);
- strcpy(cmd,s->s_name);
-
-#if 0
- for (i=1;i<=ac;i++) {
- argv[i] = getbytes(255);
- atom_string(at,argv[i],255);
-/* post("argument %s",argv[i]); */
- at++;
- }
- argv[i] = 0;
-#endif
- for (i=1;i<=ac;i++) {
- atom_string(at,tcmd,255);
- strcat(cmd," ");
- strcat(cmd,tcmd);
- at++;
- }
-
-
- /* reassign stdout */
- dup2(x->fdpipe[1],1);
- dup2(x->fdinpipe[1],0);
-
- /* drop privileges */
- drop_priority();
- seteuid(getuid()); /* lose setuid priveliges */
-
- post("executing %s",cmd);
- system(cmd);
-// execvp(s->s_name,argv);
- exit(0);
- }
- x->x_del = 4;
- clock_delay(x->x_clock,x->x_del);
-
- if (x->x_echo)
- outlet_anything(x->x_obj.ob_outlet, s, ac, at);
-}
-
-
-
-void shell_free(t_shell* x)
-{
- binbuf_free(x->x_binbuf);
-}
-
-static void *shell_new(void)
-{
- t_shell *x = (t_shell *)pd_new(shell_class);
-
- x->x_echo = 0;
- x->fdpipe[0] = -1;
- x->fdpipe[1] = -1;
- x->fdinpipe[0] = -1;
- x->fdinpipe[1] = -1;
-
- x->sr_inhead = x->sr_intail = 0;
- if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");;
-
- x->x_binbuf = binbuf_new();
-
- outlet_new(&x->x_obj, &s_list);
- x->x_done = outlet_new(&x->x_obj, &s_bang);
- x->x_clock = clock_new(x, (t_method) shell_check);
- return (x);
-}
-
-void shell_setup(void)
-{
- shell_class = class_new(gensym("shell"), (t_newmethod)shell_new,
- (t_method)shell_free,sizeof(t_shell), 0,0);
- class_addbang(shell_class,shell_bang);
- class_addanything(shell_class, shell_anything);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+#include <sched.h>
+
+void sys_rmpollfn(int fd);
+void sys_addpollfn(int fd, void* fn, void *ptr);
+
+/* ------------------------ shell ----------------------------- */
+
+#define INBUFSIZE 1024
+
+static t_class *shell_class;
+
+
+static void drop_priority(void)
+{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ struct sched_param par;
+ int p1 ,p2, p3;
+ par.sched_priority = 0;
+ sched_setscheduler(0,SCHED_OTHER,&par);
+#endif
+}
+
+
+typedef struct _shell
+{
+ t_object x_obj;
+ int x_echo;
+ char *sr_inbuf;
+ int sr_inhead;
+ int sr_intail;
+ void* x_binbuf;
+ int fdpipe[2];
+ int fdinpipe[2];
+ int pid;
+ int x_del;
+ t_outlet* x_done;
+ t_clock* x_clock;
+} t_shell;
+
+static int shell_pid;
+
+
+void shell_cleanup(t_shell* x)
+{
+ sys_rmpollfn(x->fdpipe[0]);
+
+ if (x->fdpipe[0]>0) close(x->fdpipe[0]);
+ if (x->fdpipe[1]>0) close(x->fdpipe[1]);
+ if (x->fdinpipe[0]>0) close(x->fdinpipe[0]);
+ if (x->fdinpipe[1]>0) close(x->fdinpipe[1]);
+
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+ clock_unset(x->x_clock);
+}
+
+void shell_check(t_shell* x)
+{
+ int ret;
+ int status;
+ ret = waitpid(x->pid,&status,WNOHANG);
+ if (ret == x->pid) {
+ shell_cleanup(x);
+ if (WIFEXITED(status)) {
+ outlet_float(x->x_done,WEXITSTATUS(status));
+ }
+ else outlet_float(x->x_done,0);
+ }
+ else {
+ if (x->x_del < 100) x->x_del+=2; /* increment poll times */
+ clock_delay(x->x_clock,x->x_del);
+ }
+}
+
+
+void shell_bang(t_shell *x)
+{
+ post("bang");
+}
+
+/* snippet from pd's code */
+static void shell_doit(void *z, t_binbuf *b)
+{
+ t_shell *x = (t_shell *)z;
+ int msg, natom = binbuf_getnatom(b);
+ t_atom *at = binbuf_getvec(b);
+
+ for (msg = 0; msg < natom;)
+ {
+ int emsg;
+ for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA
+ && at[emsg].a_type != A_SEMI; emsg++)
+ ;
+ if (emsg > msg)
+ {
+ int i;
+ for (i = msg; i < emsg; i++)
+ if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM)
+ {
+ pd_error(x, "netreceive: got dollar sign in message");
+ goto nodice;
+ }
+ if (at[msg].a_type == A_FLOAT)
+ {
+ if (emsg > msg + 1)
+ outlet_list(x->x_obj.ob_outlet, 0, emsg-msg, at + msg);
+ else outlet_float(x->x_obj.ob_outlet, at[msg].a_w.w_float);
+ }
+ else if (at[msg].a_type == A_SYMBOL)
+ outlet_anything(x->x_obj.ob_outlet, at[msg].a_w.w_symbol,
+ emsg-msg-1, at + msg + 1);
+ }
+ nodice:
+ msg = emsg + 1;
+ }
+}
+
+
+void shell_read(t_shell *x, int fd)
+{
+ char buf[INBUFSIZE];
+ t_binbuf* bbuf = binbuf_new();
+ int i;
+ int readto =
+ (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
+ int ret;
+
+ ret = read(fd, buf,INBUFSIZE-1);
+ buf[ret] = '\0';
+
+ for (i=0;i<ret;i++)
+ if (buf[i] == '\n') buf[i] = ';';
+ if (ret < 0)
+ {
+ error("shell: pipe read error");
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else if (ret == 0)
+ {
+ post("EOF on socket %d\n", fd);
+ sys_rmpollfn(fd);
+ x->fdpipe[0] = -1;
+ close(fd);
+ return;
+ }
+ else
+ {
+ int natom;
+ t_atom *at;
+ binbuf_text(bbuf, buf, strlen(buf));
+
+ natom = binbuf_getnatom(bbuf);
+ at = binbuf_getvec(bbuf);
+ shell_doit(x,bbuf);
+ }
+ binbuf_free(bbuf);
+}
+
+
+static void shell_send(t_shell *x, t_symbol *s,int ac, t_atom *at)
+{
+ int i;
+ char tmp[MAXPDSTRING];
+ int size = 0;
+
+ if (x->fdinpipe[0] == -1) return; /* nothing to send to */
+
+ for (i=0;i<ac;i++) {
+ atom_string(at,tmp+size,MAXPDSTRING - size);
+ at++;
+ size=strlen(tmp);
+ tmp[size++] = ' ';
+ }
+ tmp[size-1] = '\0';
+ post("sending %s",tmp);
+ write(x->fdinpipe[0],tmp,strlen(tmp));
+}
+
+static void shell_anything(t_shell *x, t_symbol *s, int ac, t_atom *at)
+{
+ int i;
+ char* argv[20];
+ t_symbol* sym;
+
+ if (!strcmp(s->s_name,"send")) {
+ post("send");
+ shell_send(x,s,ac,at);
+ return;
+ }
+
+ argv[0] = s->s_name;
+
+ if (x->fdpipe[0] != -1) {
+ post("shell: old process still running");
+ kill(x->pid,SIGKILL);
+ shell_cleanup(x);
+ }
+
+
+ if (pipe(x->fdpipe) < 0) {
+ error("unable to create pipe");
+ return;
+ }
+
+ if (pipe(x->fdinpipe) < 0) {
+ error("unable to create input pipe");
+ return;
+ }
+
+
+ sys_addpollfn(x->fdpipe[0],shell_read,x);
+
+ if (!(x->pid = fork())) {
+ int status;
+ char* cmd = getbytes(1024);
+ char* tcmd = getbytes(1024);
+ strcpy(cmd,s->s_name);
+
+#if 0
+ for (i=1;i<=ac;i++) {
+ argv[i] = getbytes(255);
+ atom_string(at,argv[i],255);
+/* post("argument %s",argv[i]); */
+ at++;
+ }
+ argv[i] = 0;
+#endif
+ for (i=1;i<=ac;i++) {
+ atom_string(at,tcmd,255);
+ strcat(cmd," ");
+ strcat(cmd,tcmd);
+ at++;
+ }
+
+
+ /* reassign stdout */
+ dup2(x->fdpipe[1],1);
+ dup2(x->fdinpipe[1],0);
+
+ /* drop privileges */
+ drop_priority();
+ seteuid(getuid()); /* lose setuid priveliges */
+
+ post("executing %s",cmd);
+ system(cmd);
+// execvp(s->s_name,argv);
+ exit(0);
+ }
+ x->x_del = 4;
+ clock_delay(x->x_clock,x->x_del);
+
+ if (x->x_echo)
+ outlet_anything(x->x_obj.ob_outlet, s, ac, at);
+}
+
+
+
+void shell_free(t_shell* x)
+{
+ binbuf_free(x->x_binbuf);
+}
+
+static void *shell_new(void)
+{
+ t_shell *x = (t_shell *)pd_new(shell_class);
+
+ x->x_echo = 0;
+ x->fdpipe[0] = -1;
+ x->fdpipe[1] = -1;
+ x->fdinpipe[0] = -1;
+ x->fdinpipe[1] = -1;
+
+ x->sr_inhead = x->sr_intail = 0;
+ if (!(x->sr_inbuf = (char*) malloc(INBUFSIZE))) bug("t_shell");;
+
+ x->x_binbuf = binbuf_new();
+
+ outlet_new(&x->x_obj, &s_list);
+ x->x_done = outlet_new(&x->x_obj, &s_bang);
+ x->x_clock = clock_new(x, (t_method) shell_check);
+ return (x);
+}
+
+void shell_setup(void)
+{
+ shell_class = class_new(gensym("shell"), (t_newmethod)shell_new,
+ (t_method)shell_free,sizeof(t_shell), 0,0);
+ class_addbang(shell_class,shell_bang);
+ class_addanything(shell_class, shell_anything);
+}
+
+
diff --git a/control/sinh.c b/control/sinh.c
index 609ef3f..915ee5f 100755
--- a/control/sinh.c
+++ b/control/sinh.c
@@ -1,54 +1,54 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-#include <math.h>
-
-
-
-/* ------------------------ sinh ----------------------------- */
-
-static t_class *sinh_class;
-
-
-typedef struct _sinh
-{
- t_object x_obj;
-} t_sinh;
-
-
-void sinh_bang(t_sinh *x)
-{
- post("bang");
-}
-
-
-void sinh_float(t_sinh *x,t_floatarg f)
-{
-
- outlet_float(x->x_obj.ob_outlet,sinh(f));
-}
-
-
-static void *sinh_new()
-{
- t_sinh *x = (t_sinh *)pd_new(sinh_class);
-
- outlet_new(&x->x_obj,&s_float);
- return (x);
-}
-
-void sinh_setup(void)
-{
- sinh_class = class_new(gensym("sinh"), (t_newmethod)sinh_new, 0,
- sizeof(t_sinh), 0,0);
- class_addbang(sinh_class,sinh_bang);
- class_addfloat(sinh_class,sinh_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+#include <math.h>
+
+
+
+/* ------------------------ sinh ----------------------------- */
+
+static t_class *sinh_class;
+
+
+typedef struct _sinh
+{
+ t_object x_obj;
+} t_sinh;
+
+
+void sinh_bang(t_sinh *x)
+{
+ post("bang");
+}
+
+
+void sinh_float(t_sinh *x,t_floatarg f)
+{
+
+ outlet_float(x->x_obj.ob_outlet,sinh(f));
+}
+
+
+static void *sinh_new()
+{
+ t_sinh *x = (t_sinh *)pd_new(sinh_class);
+
+ outlet_new(&x->x_obj,&s_float);
+ return (x);
+}
+
+void sinh_setup(void)
+{
+ sinh_class = class_new(gensym("sinh"), (t_newmethod)sinh_new, 0,
+ sizeof(t_sinh), 0,0);
+ class_addbang(sinh_class,sinh_bang);
+ class_addfloat(sinh_class,sinh_float);
+}
+
+
diff --git a/control/sl.c b/control/sl.c
index d2284e0..8629947 100755
--- a/control/sl.c
+++ b/control/sl.c
@@ -1,74 +1,74 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <stdio.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-
-/* -------------------- lsend ------------------------------ */
-
-static t_class *lsend_class;
-
-typedef struct _lsend
-{
- t_object x_obj;
- t_symbol *x_sym;
-} t_lsend;
-
-static void lsend_bang(t_lsend *x)
-{
- if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing);
-}
-
-static void lsend_float(t_lsend *x, t_float f)
-{
- if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f);
-}
-
-static void lsend_symbol(t_lsend *x, t_symbol *s)
-{
- if (x->x_sym->s_thing) pd_symbol(x->x_sym->s_thing, s);
-}
-
-static void lsend_pointer(t_lsend *x, t_gpointer *gp)
-{
- if (x->x_sym->s_thing) pd_pointer(x->x_sym->s_thing, gp);
-}
-
-static void lsend_list(t_lsend *x, t_symbol *s, int argc, t_atom *argv)
-{
- if (x->x_sym->s_thing) pd_list(x->x_sym->s_thing, s, argc, argv);
-}
-
-static void lsend_anything(t_lsend *x, t_symbol *s, int argc, t_atom *argv)
-{
- if (x->x_sym->s_thing) typedmess(x->x_sym->s_thing, s, argc, argv);
-}
-
-static void *lsend_new(t_symbol *s)
-{
- t_lsend *x = (t_lsend *)pd_new(lsend_class);
- char mysym[MAXPDSTRING];
-
- sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent());
- x->x_sym = gensym(mysym);
- return (x);
-}
-
-void sl_setup(void)
-{
- lsend_class = class_new(gensym("sendlocal"), (t_newmethod)lsend_new, 0,
- sizeof(t_lsend), 0, A_DEFSYM, 0);
- class_addcreator((t_newmethod)lsend_new, gensym("sl"), A_DEFSYM, 0);
- class_addbang(lsend_class, lsend_bang);
- class_addfloat(lsend_class, lsend_float);
- class_addsymbol(lsend_class, lsend_symbol);
- class_addpointer(lsend_class, lsend_pointer);
- class_addlist(lsend_class, lsend_list);
- class_addanything(lsend_class, lsend_anything);
- post("Warning: sendlocal (sl) is deprecated, please use \"send $0-var\" instead");
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <stdio.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+/* -------------------- lsend ------------------------------ */
+
+static t_class *lsend_class;
+
+typedef struct _lsend
+{
+ t_object x_obj;
+ t_symbol *x_sym;
+} t_lsend;
+
+static void lsend_bang(t_lsend *x)
+{
+ if (x->x_sym->s_thing) pd_bang(x->x_sym->s_thing);
+}
+
+static void lsend_float(t_lsend *x, t_float f)
+{
+ if (x->x_sym->s_thing) pd_float(x->x_sym->s_thing, f);
+}
+
+static void lsend_symbol(t_lsend *x, t_symbol *s)
+{
+ if (x->x_sym->s_thing) pd_symbol(x->x_sym->s_thing, s);
+}
+
+static void lsend_pointer(t_lsend *x, t_gpointer *gp)
+{
+ if (x->x_sym->s_thing) pd_pointer(x->x_sym->s_thing, gp);
+}
+
+static void lsend_list(t_lsend *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if (x->x_sym->s_thing) pd_list(x->x_sym->s_thing, s, argc, argv);
+}
+
+static void lsend_anything(t_lsend *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if (x->x_sym->s_thing) typedmess(x->x_sym->s_thing, s, argc, argv);
+}
+
+static void *lsend_new(t_symbol *s)
+{
+ t_lsend *x = (t_lsend *)pd_new(lsend_class);
+ char mysym[MAXPDSTRING];
+
+ sprintf(mysym,"%s%p",s->s_name,canvas_getcurrent());
+ x->x_sym = gensym(mysym);
+ return (x);
+}
+
+void sl_setup(void)
+{
+ lsend_class = class_new(gensym("sendlocal"), (t_newmethod)lsend_new, 0,
+ sizeof(t_lsend), 0, A_DEFSYM, 0);
+ class_addcreator((t_newmethod)lsend_new, gensym("sl"), A_DEFSYM, 0);
+ class_addbang(lsend_class, lsend_bang);
+ class_addfloat(lsend_class, lsend_float);
+ class_addsymbol(lsend_class, lsend_symbol);
+ class_addpointer(lsend_class, lsend_pointer);
+ class_addlist(lsend_class, lsend_list);
+ class_addanything(lsend_class, lsend_anything);
+ post("Warning: sendlocal (sl) is deprecated, please use \"send $0-var\" instead");
+}
diff --git a/control/stripdir.c b/control/stripdir.c
index 10ba19b..9202f19 100755
--- a/control/stripdir.c
+++ b/control/stripdir.c
@@ -1,48 +1,48 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <string.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ stripdir ----------------------------- */
-
-static t_class *stripdir_class;
-
-
-typedef struct _stripdir
-{
- t_object x_obj;
-} t_stripdir;
-
-
-void stripdir_symbol(t_stripdir *x,t_symbol* s)
-{
- int len = strlen(s->s_name);
-
- while (len--)
- if (*(s->s_name + len) == '/') {
- outlet_symbol(x->x_obj.ob_outlet,gensym(s->s_name + len + 1));
- break;
- }
-
-}
-
-static void *stripdir_new()
-{
- t_stripdir *x = (t_stripdir *)pd_new(stripdir_class);
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-void stripdir_setup(void)
-{
- stripdir_class = class_new(gensym("stripdir"), (t_newmethod)stripdir_new, 0,
- sizeof(t_stripdir), 0,0);
- class_addsymbol(stripdir_class,stripdir_symbol);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <string.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ stripdir ----------------------------- */
+
+static t_class *stripdir_class;
+
+
+typedef struct _stripdir
+{
+ t_object x_obj;
+} t_stripdir;
+
+
+void stripdir_symbol(t_stripdir *x,t_symbol* s)
+{
+ int len = strlen(s->s_name);
+
+ while (len--)
+ if (*(s->s_name + len) == '/') {
+ outlet_symbol(x->x_obj.ob_outlet,gensym(s->s_name + len + 1));
+ break;
+ }
+
+}
+
+static void *stripdir_new()
+{
+ t_stripdir *x = (t_stripdir *)pd_new(stripdir_class);
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void stripdir_setup(void)
+{
+ stripdir_class = class_new(gensym("stripdir"), (t_newmethod)stripdir_new, 0,
+ sizeof(t_stripdir), 0,0);
+ class_addsymbol(stripdir_class,stripdir_symbol);
+}
+
+
diff --git a/control/unserialize.c b/control/unserialize.c
index 6133ead..a061a25 100755
--- a/control/unserialize.c
+++ b/control/unserialize.c
@@ -1,57 +1,57 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ unserialize ----------------------------- */
-
-#define MAX_ELEMENTS 256
-
-static t_class *unserialize_class;
-
-
-typedef struct _unserialize
-{
- t_object x_obj;
- t_atom x_abuf[MAX_ELEMENTS];
- t_int x_count;
- t_int x_elements;
-} t_unserialize;
-
-
-void unserialize_float(t_unserialize *x,t_floatarg f)
-{
- SETFLOAT(&x->x_abuf[x->x_count],f);
- x->x_count++;
-
- if (x->x_count == x->x_elements) {
- outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf);
- x->x_count = 0;
- }
-}
-
-
-static void *unserialize_new(t_floatarg f)
-{
- t_unserialize *x = (t_unserialize *)pd_new(unserialize_class);
- outlet_new(&x->x_obj,&s_float);
- x->x_elements = f;
- x->x_count=0;
- if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1;
- return (x);
-}
-
-
-
-void unserialize_setup(void)
-{
- unserialize_class = class_new(gensym("unserialize"), (t_newmethod)unserialize_new,
- 0,sizeof(t_unserialize),0, A_DEFFLOAT,0);
- class_addfloat(unserialize_class,unserialize_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ unserialize ----------------------------- */
+
+#define MAX_ELEMENTS 256
+
+static t_class *unserialize_class;
+
+
+typedef struct _unserialize
+{
+ t_object x_obj;
+ t_atom x_abuf[MAX_ELEMENTS];
+ t_int x_count;
+ t_int x_elements;
+} t_unserialize;
+
+
+void unserialize_float(t_unserialize *x,t_floatarg f)
+{
+ SETFLOAT(&x->x_abuf[x->x_count],f);
+ x->x_count++;
+
+ if (x->x_count == x->x_elements) {
+ outlet_list(x->x_obj.ob_outlet,0,x->x_count,x->x_abuf);
+ x->x_count = 0;
+ }
+}
+
+
+static void *unserialize_new(t_floatarg f)
+{
+ t_unserialize *x = (t_unserialize *)pd_new(unserialize_class);
+ outlet_new(&x->x_obj,&s_float);
+ x->x_elements = f;
+ x->x_count=0;
+ if ((f <= 0) || (f > MAX_ELEMENTS)) x->x_elements = 1;
+ return (x);
+}
+
+
+
+void unserialize_setup(void)
+{
+ unserialize_class = class_new(gensym("unserialize"), (t_newmethod)unserialize_new,
+ 0,sizeof(t_unserialize),0, A_DEFFLOAT,0);
+ class_addfloat(unserialize_class,unserialize_float);
+}
+
+
diff --git a/control/unwonk.c b/control/unwonk.c
index e44ef10..2c1fa9e 100755
--- a/control/unwonk.c
+++ b/control/unwonk.c
@@ -1,119 +1,119 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-
-
-/* -------------------------- unwonk ------------------------------ */
-
-static t_class *unwonk_class;
-
-typedef struct unwonkout
-{
- t_atomtype u_type;
- t_outlet *u_outlet;
-} t_unwonkout;
-
-typedef struct _unwonk
-{
- t_object x_obj;
- t_int x_n;
- t_unwonkout *x_vec;
-} t_unwonk;
-
-static void *unwonk_new(t_symbol *s, int argc, t_atom *argv)
-{
- t_unwonk *x = (t_unwonk *)pd_new(unwonk_class);
- t_atom defarg[2], *ap;
- t_unwonkout *u;
- int i;
- if (!argc)
- {
- argv = defarg;
- argc = 2;
- SETFLOAT(&defarg[0], 0);
- SETFLOAT(&defarg[1], 0);
- }
-
- x->x_n = argc + 1;
- x->x_vec = (t_unwonkout *)getbytes(x->x_n * sizeof(*x->x_vec));
-
- for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++)
- {
- t_atomtype type = ap->a_type;
- if (type == A_SYMBOL)
- {
- char c = *ap->a_w.w_symbol->s_name;
- if (c == 's')
- {
- u->u_type = A_SYMBOL;
- u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
- }
- else if (c == 'p')
- {
- u->u_type = A_POINTER;
- u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
- }
- else
- {
- if (c != 'f') error("unwonk: %s: bad type",
- ap->a_w.w_symbol->s_name);
- u->u_type = A_FLOAT;
- u->u_outlet = outlet_new(&x->x_obj, &s_float);
- }
- }
- else
- {
- u->u_type = A_FLOAT;
- u->u_outlet = outlet_new(&x->x_obj, &s_float);
- }
- }
-
- u->u_type = A_GIMME;
- u->u_outlet = outlet_new(&x->x_obj, &s_list);
-
- return (x);
-}
-
-static void unwonk_list(t_unwonk *x, t_symbol *s, int argc, t_atom *argv)
-{
- t_atom *ap;
- t_unwonkout *u;
- int i;
- int margc = argc;
-
-
- if (argc > x->x_n - 1) margc = x->x_n - 1;
-
- if (argc - margc > 0) {
- ap = argv + margc;
- u = x->x_vec + margc;
- outlet_list(u->u_outlet,0,argc - margc, ap);
- }
-
- for (i = margc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;)
- {
- t_atomtype type = u->u_type;
- if (type != ap->a_type)
- error("unwonk: type mismatch");
- else if (type == A_FLOAT)
- outlet_float(u->u_outlet, ap->a_w.w_float);
- else if (type == A_SYMBOL)
- outlet_symbol(u->u_outlet, ap->a_w.w_symbol);
- else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer);
- }
-
-
-}
-
-static void unwonk_free(t_unwonk *x)
-{
- freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
-}
-
-void unwonk_setup(void)
-{
- unwonk_class = class_new(gensym("unwonk"), (t_newmethod)unwonk_new,
- (t_method)unwonk_free, sizeof(t_unwonk), 0, A_GIMME, 0);
- class_addlist(unwonk_class, unwonk_list);
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+
+
+/* -------------------------- unwonk ------------------------------ */
+
+static t_class *unwonk_class;
+
+typedef struct unwonkout
+{
+ t_atomtype u_type;
+ t_outlet *u_outlet;
+} t_unwonkout;
+
+typedef struct _unwonk
+{
+ t_object x_obj;
+ t_int x_n;
+ t_unwonkout *x_vec;
+} t_unwonk;
+
+static void *unwonk_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_unwonk *x = (t_unwonk *)pd_new(unwonk_class);
+ t_atom defarg[2], *ap;
+ t_unwonkout *u;
+ int i;
+ if (!argc)
+ {
+ argv = defarg;
+ argc = 2;
+ SETFLOAT(&defarg[0], 0);
+ SETFLOAT(&defarg[1], 0);
+ }
+
+ x->x_n = argc + 1;
+ x->x_vec = (t_unwonkout *)getbytes(x->x_n * sizeof(*x->x_vec));
+
+ for (i = 0, ap = argv, u = x->x_vec; i < argc; u++, ap++, i++)
+ {
+ t_atomtype type = ap->a_type;
+ if (type == A_SYMBOL)
+ {
+ char c = *ap->a_w.w_symbol->s_name;
+ if (c == 's')
+ {
+ u->u_type = A_SYMBOL;
+ u->u_outlet = outlet_new(&x->x_obj, &s_symbol);
+ }
+ else if (c == 'p')
+ {
+ u->u_type = A_POINTER;
+ u->u_outlet = outlet_new(&x->x_obj, &s_pointer);
+ }
+ else
+ {
+ if (c != 'f') error("unwonk: %s: bad type",
+ ap->a_w.w_symbol->s_name);
+ u->u_type = A_FLOAT;
+ u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ }
+ }
+ else
+ {
+ u->u_type = A_FLOAT;
+ u->u_outlet = outlet_new(&x->x_obj, &s_float);
+ }
+ }
+
+ u->u_type = A_GIMME;
+ u->u_outlet = outlet_new(&x->x_obj, &s_list);
+
+ return (x);
+}
+
+static void unwonk_list(t_unwonk *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_atom *ap;
+ t_unwonkout *u;
+ int i;
+ int margc = argc;
+
+
+ if (argc > x->x_n - 1) margc = x->x_n - 1;
+
+ if (argc - margc > 0) {
+ ap = argv + margc;
+ u = x->x_vec + margc;
+ outlet_list(u->u_outlet,0,argc - margc, ap);
+ }
+
+ for (i = margc, u = x->x_vec + i, ap = argv + i; u--, ap--, i--;)
+ {
+ t_atomtype type = u->u_type;
+ if (type != ap->a_type)
+ error("unwonk: type mismatch");
+ else if (type == A_FLOAT)
+ outlet_float(u->u_outlet, ap->a_w.w_float);
+ else if (type == A_SYMBOL)
+ outlet_symbol(u->u_outlet, ap->a_w.w_symbol);
+ else outlet_pointer(u->u_outlet, ap->a_w.w_gpointer);
+ }
+
+
+}
+
+static void unwonk_free(t_unwonk *x)
+{
+ freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
+}
+
+void unwonk_setup(void)
+{
+ unwonk_class = class_new(gensym("unwonk"), (t_newmethod)unwonk_new,
+ (t_method)unwonk_free, sizeof(t_unwonk), 0, A_GIMME, 0);
+ class_addlist(unwonk_class, unwonk_list);
+}
diff --git a/experimental/fofsynth~.c b/experimental/fofsynth~.c
index 53df270..5a9de5b 100755
--- a/experimental/fofsynth~.c
+++ b/experimental/fofsynth~.c
@@ -1,354 +1,354 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <math.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ fofsynth~ ----------------------------- */
-
-#ifndef NT
-void garray_usedindsp(t_garray *x);
-#endif
-
-#define DEBUG(a,b) if (x->debug) post(a,b);
-
-#define MAXGRAINS 1000
-#define PD_PI 3.14159
-
-static float* cos_table;
-static float* halfcos_table;
-static float* exp_table;
-
-static void cos_maketable(void)
-{
- int i;
- float *fp, phase, phsinc = (2. * PD_PI) / COSTABSIZE;
-
- if (cos_table) return;
- cos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
-
- for (i = COSTABSIZE + 1, fp = cos_table, phase = 0; i--;
- fp++, phase += phsinc)
- *fp = cos(phase);
-
-}
-
-static void halfcos_maketable(void)
-{
- int i;
- float *fp, phase, phsinc = (PD_PI) / COSTABSIZE;
-
- if (halfcos_table) return;
- halfcos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
-
- for (i = COSTABSIZE + 1, fp = halfcos_table, phase = PD_PI; i--;
- fp++, phase += phsinc)
- *fp = 0.5*(cos(phase) + 1.0);
-}
-
-
-static void exp_maketable(void)
-{
- int i;
- float *fp, phase, phsinc = (2 * PD_PI) / COSTABSIZE;
-
- if (exp_table) return;
- exp_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
-
- for (i = COSTABSIZE + 1, fp = exp_table, phase = 0; i--;
- fp++, phase += phsinc)
- *fp = exp(-phase);
-}
-
-
-static t_class *fofsynth_class;
-
-typedef struct _grain
-{
- struct _grain *next;
- t_float formph; /* 0 ... 1 */
- t_float formphinc;
- t_float envph;
- int falling;
-} t_grain;
-
-
-typedef struct _fofsynth
-{
- t_object x_obj;
-
- /* it is possible to use 2 array, prob change this one
- int the future */
-
- t_symbol* x_arrayname;
-
- /* template */
-
- int x_npoints;
- t_float *x_vec;
-
- /* fof */
- int debug;
-
- int maxgrains;
- int numgrains;
-
- float* x_envelope;
-
- /* the queue of grains */
-
- t_grain* grainbase;
- t_grain* grainstart;
- t_grain* grainend;
-
-
- t_float fundph; /* 0 to 1; if 1 -> add a new grain */
-
- t_float fundfreq; /* input parameter 1 */
- t_float formfreq; /* input paramter 2 */
- t_float risedur; /* input parameter 3 ( in % of total duration )*/
- t_float falldur; /* input parameter 5 ( in % of total duration */
-
- /* other */
- int neednewgrain;
-} t_fofsynth;
-
-
-
-
-/* build a cyclic list */
-static t_grain* grain_makecyclic(t_grain* base,int num)
-{
- t_grain* cur = base;
- while (--num) {
- cur->next = cur+1;
- cur++;
- }
- cur->next = base;
- return base;
-}
-
-
-
-
-
-static t_int *fofsynth_perform(t_int *w)
-{
- t_fofsynth* x = (t_fofsynth*) (w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
-
- float totaldur = (x->risedur+ x->falldur)*0.01/ *in;
-
- float srate = 44100.0; /*((t_signal*)w[2])->s_sr;*/
- float israte = 1.0/srate;
-
- float fundphase = x->fundph;
- float numperiods = totaldur*x->formfreq;
- float formphinc = (x->formfreq/srate);
-
- float risinc;
- float fallinc;
-
- t_grain* cur;
-
- risinc = (x->risedur == 0) ? 1.0 : 1.0/ (srate*totaldur*0.01*x->risedur);
- fallinc = (x->falldur == 0.0) ? 1.0 :1.0/ (srate*totaldur*0.01*x->falldur);
-
- DEBUG(" fundph %3.2f",x->fundph);
- DEBUG(" fundfreq %3.2f",x->fundfreq);
- DEBUG(" formfreq %3.2f",x->formfreq);
- DEBUG(" risedur %3.2f %",x->risedur);
- DEBUG(" falldur %3.2f %",x->falldur);
- DEBUG(" totaldur %3.2f s",totaldur);
- DEBUG(" risinc %0.6f",risinc);
- DEBUG(" fallinc %0.6f",fallinc);
- DEBUG(" formant increase %3.2f",formphinc);
- DEBUG(" numgrains %d",x->numgrains);
-
- while (n--)
- {
- fundphase+=*++in*israte;
- *out = 0.0;
-
- if (x->neednewgrain) { /* new grain, they are deleted separetely */
- t_grain* newgrain = x->grainend;
-/* DEBUG("new grain created",0); */
- if (newgrain->next == x->grainstart) {
- post("fof: grain overflow");
- x->neednewgrain = 0;
- }
- else {
- x->numgrains++;
- x->grainend = newgrain->next;
- newgrain->formphinc = formphinc;
- newgrain->falling = 0;
- newgrain->formph = newgrain->envph = 0.0;
- x->neednewgrain = 0;
- }
- }
-
- cur = x->grainstart;
- while (cur != x->grainend) {
- float formphase = cur->formph;
- float envelope;
-
- float tph = (formphase - (float)((int) formphase));
- float val = *(x->x_vec + (int) (tph * x->x_npoints));
-
- /* Apply the envelope */
-
- if (!cur->falling && (cur->envph <= 1.0)) {
- envelope = *(halfcos_table + (int) (cur->envph * COSTABSIZE));
- cur->envph+=risinc;
- val *= envelope;
- }
- else if (!cur->falling)
- {
- cur->falling = 1;
- cur->envph = 0;
- }
-
-
- if (cur->falling) {
- envelope = *(exp_table + (int) (cur->envph * COSTABSIZE));
- cur->envph+=fallinc;
- val *= envelope;
- }
-
- /* end of envelope code */
-
-
- formphase+=cur->formphinc;
- cur->formph = formphase;
-
- if (formphase >= numperiods) { /* dead */
- DEBUG("grain died",0);
- x->grainstart = cur->next;
- x->numgrains--;/* not needed */
- }
-
- cur = cur->next;
- *out += val;
- }
-
-
- if (fundphase > 1.0) {
- fundphase -= 1.0;
- x->neednewgrain=1;
- }
- out++;
- }
-
- x->fundph=fundphase;
- x->debug = 0;
-
-
- return (w+5);
-}
-
-void fofsynth_usearray(t_symbol* s,int* points,t_float** vec)
-{
- t_garray *a;
- if (!(a = (t_garray *)pd_findbyclass(s, garray_class)))
- error("%s: no such array", s->s_name);
- else if (!garray_getfloatarray(a,points,vec))
- error("%s: bad template for fof~", s->s_name);
- else
- garray_usedindsp(a);
-}
-
-static void fofsynth_dsp(t_fofsynth *x, t_signal **sp)
-{
-
- if (x->x_arrayname)
- fofsynth_usearray(x->x_arrayname,&x->x_npoints, &x->x_vec);
- else {
- x->x_npoints=COSTABSIZE;
- x->x_vec = cos_table;
- }
-
- dsp_add(fofsynth_perform, 4, x,
- sp[0]->s_vec,sp[1]->s_vec, sp[0]->s_n);
-}
-
-
-static void fofsynth_free(t_fofsynth *x)
-{
- freebytes(x->grainbase,sizeof(t_grain)*x->maxgrains);
-}
-
-
-static void fofsynth_debug(t_fofsynth* x)
-{
- x->debug = 1;
-}
-
-
-static void fofsynth_float(t_fofsynth* x,t_float f)
-{
- x->fundfreq = f > 0.0 ? f : -f;
-}
-
-
-static void *fofsynth_new(t_symbol* s,t_float a,t_float b,t_float c,t_float d)
-{
- int maxgrains = MAXGRAINS;
- t_fofsynth *x = (t_fofsynth *)pd_new(fofsynth_class);
-
- x->debug = 0;
- x->x_arrayname = s;
-
- if (s == &s_)
- x->x_arrayname = NULL;
-
- /* setup the grain queue */
-
- x->grainbase = getbytes(sizeof(t_grain)*maxgrains);
- x->maxgrains = maxgrains;
- grain_makecyclic(x->grainbase,maxgrains);
- x->grainstart = x->grainbase;
- x->grainend = x->grainbase;
- x->numgrains = 0;
-
- /* some of them could be signals too */
-
- floatinlet_new(&x->x_obj, &x->formfreq);
- floatinlet_new(&x->x_obj, &x->risedur);
- floatinlet_new(&x->x_obj, &x->falldur);
-
- x->fundph = 0.0;
- x->fundfreq = 200.0;
- x->formfreq = 600.0;
- x->risedur = 5.0;
- x->falldur = 140.0;
-
- if (a) x->fundfreq = a;
- if (b) x->formfreq = b;
- if (c) x->risedur = c;
- if (d) x->falldur = d;
-
- outlet_new(&x->x_obj, &s_signal);
- return (x);
-}
-
-void fofsynth_tilde_setup(void)
-{
- cos_table = NULL;
- halfcos_table = NULL;
- fofsynth_class = class_new(gensym("fof~"), (t_newmethod) fofsynth_new,(t_method) fofsynth_free,
- sizeof(t_fofsynth), 0,A_DEFSYM, A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addcreator((t_newmethod)fofsynth_new,gensym("fofsynth~"),A_DEFSYM, A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addmethod(fofsynth_class, nullfn, gensym("signal"), 0);
- class_addmethod(fofsynth_class, (t_method) fofsynth_dsp, gensym("dsp"), 0);
- class_addfloat(fofsynth_class, (t_method) fofsynth_float);
- class_addmethod(fofsynth_class,(t_method) fofsynth_debug, gensym("debug"),0);
- cos_maketable();
- halfcos_maketable();
- exp_maketable();
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <math.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ fofsynth~ ----------------------------- */
+
+#ifndef NT
+void garray_usedindsp(t_garray *x);
+#endif
+
+#define DEBUG(a,b) if (x->debug) post(a,b);
+
+#define MAXGRAINS 1000
+#define PD_PI 3.14159
+
+static float* cos_table;
+static float* halfcos_table;
+static float* exp_table;
+
+static void cos_maketable(void)
+{
+ int i;
+ float *fp, phase, phsinc = (2. * PD_PI) / COSTABSIZE;
+
+ if (cos_table) return;
+ cos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
+
+ for (i = COSTABSIZE + 1, fp = cos_table, phase = 0; i--;
+ fp++, phase += phsinc)
+ *fp = cos(phase);
+
+}
+
+static void halfcos_maketable(void)
+{
+ int i;
+ float *fp, phase, phsinc = (PD_PI) / COSTABSIZE;
+
+ if (halfcos_table) return;
+ halfcos_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
+
+ for (i = COSTABSIZE + 1, fp = halfcos_table, phase = PD_PI; i--;
+ fp++, phase += phsinc)
+ *fp = 0.5*(cos(phase) + 1.0);
+}
+
+
+static void exp_maketable(void)
+{
+ int i;
+ float *fp, phase, phsinc = (2 * PD_PI) / COSTABSIZE;
+
+ if (exp_table) return;
+ exp_table = (float *)getbytes(sizeof(float) * (COSTABSIZE+1));
+
+ for (i = COSTABSIZE + 1, fp = exp_table, phase = 0; i--;
+ fp++, phase += phsinc)
+ *fp = exp(-phase);
+}
+
+
+static t_class *fofsynth_class;
+
+typedef struct _grain
+{
+ struct _grain *next;
+ t_float formph; /* 0 ... 1 */
+ t_float formphinc;
+ t_float envph;
+ int falling;
+} t_grain;
+
+
+typedef struct _fofsynth
+{
+ t_object x_obj;
+
+ /* it is possible to use 2 array, prob change this one
+ int the future */
+
+ t_symbol* x_arrayname;
+
+ /* template */
+
+ int x_npoints;
+ t_float *x_vec;
+
+ /* fof */
+ int debug;
+
+ int maxgrains;
+ int numgrains;
+
+ float* x_envelope;
+
+ /* the queue of grains */
+
+ t_grain* grainbase;
+ t_grain* grainstart;
+ t_grain* grainend;
+
+
+ t_float fundph; /* 0 to 1; if 1 -> add a new grain */
+
+ t_float fundfreq; /* input parameter 1 */
+ t_float formfreq; /* input paramter 2 */
+ t_float risedur; /* input parameter 3 ( in % of total duration )*/
+ t_float falldur; /* input parameter 5 ( in % of total duration */
+
+ /* other */
+ int neednewgrain;
+} t_fofsynth;
+
+
+
+
+/* build a cyclic list */
+static t_grain* grain_makecyclic(t_grain* base,int num)
+{
+ t_grain* cur = base;
+ while (--num) {
+ cur->next = cur+1;
+ cur++;
+ }
+ cur->next = base;
+ return base;
+}
+
+
+
+
+
+static t_int *fofsynth_perform(t_int *w)
+{
+ t_fofsynth* x = (t_fofsynth*) (w[1]);
+ t_float *in = (t_float *)(w[2]);
+ t_float *out = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+
+ float totaldur = (x->risedur+ x->falldur)*0.01/ *in;
+
+ float srate = 44100.0; /*((t_signal*)w[2])->s_sr;*/
+ float israte = 1.0/srate;
+
+ float fundphase = x->fundph;
+ float numperiods = totaldur*x->formfreq;
+ float formphinc = (x->formfreq/srate);
+
+ float risinc;
+ float fallinc;
+
+ t_grain* cur;
+
+ risinc = (x->risedur == 0) ? 1.0 : 1.0/ (srate*totaldur*0.01*x->risedur);
+ fallinc = (x->falldur == 0.0) ? 1.0 :1.0/ (srate*totaldur*0.01*x->falldur);
+
+ DEBUG(" fundph %3.2f",x->fundph);
+ DEBUG(" fundfreq %3.2f",x->fundfreq);
+ DEBUG(" formfreq %3.2f",x->formfreq);
+ DEBUG(" risedur %3.2f %",x->risedur);
+ DEBUG(" falldur %3.2f %",x->falldur);
+ DEBUG(" totaldur %3.2f s",totaldur);
+ DEBUG(" risinc %0.6f",risinc);
+ DEBUG(" fallinc %0.6f",fallinc);
+ DEBUG(" formant increase %3.2f",formphinc);
+ DEBUG(" numgrains %d",x->numgrains);
+
+ while (n--)
+ {
+ fundphase+=*++in*israte;
+ *out = 0.0;
+
+ if (x->neednewgrain) { /* new grain, they are deleted separetely */
+ t_grain* newgrain = x->grainend;
+/* DEBUG("new grain created",0); */
+ if (newgrain->next == x->grainstart) {
+ post("fof: grain overflow");
+ x->neednewgrain = 0;
+ }
+ else {
+ x->numgrains++;
+ x->grainend = newgrain->next;
+ newgrain->formphinc = formphinc;
+ newgrain->falling = 0;
+ newgrain->formph = newgrain->envph = 0.0;
+ x->neednewgrain = 0;
+ }
+ }
+
+ cur = x->grainstart;
+ while (cur != x->grainend) {
+ float formphase = cur->formph;
+ float envelope;
+
+ float tph = (formphase - (float)((int) formphase));
+ float val = *(x->x_vec + (int) (tph * x->x_npoints));
+
+ /* Apply the envelope */
+
+ if (!cur->falling && (cur->envph <= 1.0)) {
+ envelope = *(halfcos_table + (int) (cur->envph * COSTABSIZE));
+ cur->envph+=risinc;
+ val *= envelope;
+ }
+ else if (!cur->falling)
+ {
+ cur->falling = 1;
+ cur->envph = 0;
+ }
+
+
+ if (cur->falling) {
+ envelope = *(exp_table + (int) (cur->envph * COSTABSIZE));
+ cur->envph+=fallinc;
+ val *= envelope;
+ }
+
+ /* end of envelope code */
+
+
+ formphase+=cur->formphinc;
+ cur->formph = formphase;
+
+ if (formphase >= numperiods) { /* dead */
+ DEBUG("grain died",0);
+ x->grainstart = cur->next;
+ x->numgrains--;/* not needed */
+ }
+
+ cur = cur->next;
+ *out += val;
+ }
+
+
+ if (fundphase > 1.0) {
+ fundphase -= 1.0;
+ x->neednewgrain=1;
+ }
+ out++;
+ }
+
+ x->fundph=fundphase;
+ x->debug = 0;
+
+
+ return (w+5);
+}
+
+void fofsynth_usearray(t_symbol* s,int* points,t_float** vec)
+{
+ t_garray *a;
+ if (!(a = (t_garray *)pd_findbyclass(s, garray_class)))
+ error("%s: no such array", s->s_name);
+ else if (!garray_getfloatarray(a,points,vec))
+ error("%s: bad template for fof~", s->s_name);
+ else
+ garray_usedindsp(a);
+}
+
+static void fofsynth_dsp(t_fofsynth *x, t_signal **sp)
+{
+
+ if (x->x_arrayname)
+ fofsynth_usearray(x->x_arrayname,&x->x_npoints, &x->x_vec);
+ else {
+ x->x_npoints=COSTABSIZE;
+ x->x_vec = cos_table;
+ }
+
+ dsp_add(fofsynth_perform, 4, x,
+ sp[0]->s_vec,sp[1]->s_vec, sp[0]->s_n);
+}
+
+
+static void fofsynth_free(t_fofsynth *x)
+{
+ freebytes(x->grainbase,sizeof(t_grain)*x->maxgrains);
+}
+
+
+static void fofsynth_debug(t_fofsynth* x)
+{
+ x->debug = 1;
+}
+
+
+static void fofsynth_float(t_fofsynth* x,t_float f)
+{
+ x->fundfreq = f > 0.0 ? f : -f;
+}
+
+
+static void *fofsynth_new(t_symbol* s,t_float a,t_float b,t_float c,t_float d)
+{
+ int maxgrains = MAXGRAINS;
+ t_fofsynth *x = (t_fofsynth *)pd_new(fofsynth_class);
+
+ x->debug = 0;
+ x->x_arrayname = s;
+
+ if (s == &s_)
+ x->x_arrayname = NULL;
+
+ /* setup the grain queue */
+
+ x->grainbase = getbytes(sizeof(t_grain)*maxgrains);
+ x->maxgrains = maxgrains;
+ grain_makecyclic(x->grainbase,maxgrains);
+ x->grainstart = x->grainbase;
+ x->grainend = x->grainbase;
+ x->numgrains = 0;
+
+ /* some of them could be signals too */
+
+ floatinlet_new(&x->x_obj, &x->formfreq);
+ floatinlet_new(&x->x_obj, &x->risedur);
+ floatinlet_new(&x->x_obj, &x->falldur);
+
+ x->fundph = 0.0;
+ x->fundfreq = 200.0;
+ x->formfreq = 600.0;
+ x->risedur = 5.0;
+ x->falldur = 140.0;
+
+ if (a) x->fundfreq = a;
+ if (b) x->formfreq = b;
+ if (c) x->risedur = c;
+ if (d) x->falldur = d;
+
+ outlet_new(&x->x_obj, &s_signal);
+ return (x);
+}
+
+void fofsynth_tilde_setup(void)
+{
+ cos_table = NULL;
+ halfcos_table = NULL;
+ fofsynth_class = class_new(gensym("fof~"), (t_newmethod) fofsynth_new,(t_method) fofsynth_free,
+ sizeof(t_fofsynth), 0,A_DEFSYM, A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addcreator((t_newmethod)fofsynth_new,gensym("fofsynth~"),A_DEFSYM, A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addmethod(fofsynth_class, nullfn, gensym("signal"), 0);
+ class_addmethod(fofsynth_class, (t_method) fofsynth_dsp, gensym("dsp"), 0);
+ class_addfloat(fofsynth_class, (t_method) fofsynth_float);
+ class_addmethod(fofsynth_class,(t_method) fofsynth_debug, gensym("debug"),0);
+ cos_maketable();
+ halfcos_maketable();
+ exp_maketable();
+}
diff --git a/experimental/pvocfreq.c b/experimental/pvocfreq.c
index 4eb30ca..67ed01c 100755
--- a/experimental/pvocfreq.c
+++ b/experimental/pvocfreq.c
@@ -1,114 +1,114 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ shuffle ----------------------------- */
-
-static t_class *shuffle_class;
-
-
-typedef struct _shuffle
-{
- t_object x_obj;
- t_float x;
-} t_shuffle;
-
-
-void shuffle_float(t_shuffle *x, t_floatarg f)
-{
- post("float %f",f);
- x->x = f;
-}
-
-
-
-static t_int *shuffle_perform(t_int *w)
-{
- t_shuffle* x = (t_shuffle*)(w[1]);
- t_float* in1 = (t_float*) w[2];
- t_float* in2 = (t_float*) w[3];
- t_float* out = (t_float*) w[4];
- int n = w[5];
-
- if (x->x <= 0) {
- while (n--) {
- *out++ = *in1++;
- }
- return w+6;
- }
-
- if (x->x < 0.5) {
- t_int index = 1/x->x;
- while (n--) {
- if (n%index){
- *out++ = *in1++;
- in2++;
- }
- else {
- *out++ = *in2++;
- in1++;
- }
- }
- return w+6;
- }
-
- if (x->x > 1.0) {
- while (n--) {
- *out++ = *in2++;
- }
- return w+6;
- }
-
- if (x->x >= 0.5) {
- t_int index = 1/(1.0- x->x);
- while (n--) {
- if (n%index) {
- *out++ = *in2++;
- in1++;
- }
- else {
- *out++ = *in1++;
- in2++;
- }
- }
- }
-
- return w+6;
-}
-
-
-static void shuffle_dsp(t_shuffle *x, t_signal **sp)
-{
- dsp_add(shuffle_perform, 5, x, sp[0]->s_vec,
- sp[1]->s_vec,sp[2]->s_vec, sp[0]->s_n);
-
-}
-
-static void *shuffle_new()
-{
- t_shuffle *x = (t_shuffle *)pd_new(shuffle_class);
-
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
-
-
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-void shuffle_setup(void)
-{
- shuffle_class = class_new(gensym("shuffle~"), (t_newmethod)shuffle_new, 0,
- sizeof(t_shuffle), 0,0);
-
- class_addmethod(shuffle_class, nullfn, gensym("signal"), 0);
- class_addmethod(shuffle_class, (t_method) shuffle_dsp, gensym("dsp"), 0);
-
- class_addfloat(shuffle_class,shuffle_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ shuffle ----------------------------- */
+
+static t_class *shuffle_class;
+
+
+typedef struct _shuffle
+{
+ t_object x_obj;
+ t_float x;
+} t_shuffle;
+
+
+void shuffle_float(t_shuffle *x, t_floatarg f)
+{
+ post("float %f",f);
+ x->x = f;
+}
+
+
+
+static t_int *shuffle_perform(t_int *w)
+{
+ t_shuffle* x = (t_shuffle*)(w[1]);
+ t_float* in1 = (t_float*) w[2];
+ t_float* in2 = (t_float*) w[3];
+ t_float* out = (t_float*) w[4];
+ int n = w[5];
+
+ if (x->x <= 0) {
+ while (n--) {
+ *out++ = *in1++;
+ }
+ return w+6;
+ }
+
+ if (x->x < 0.5) {
+ t_int index = 1/x->x;
+ while (n--) {
+ if (n%index){
+ *out++ = *in1++;
+ in2++;
+ }
+ else {
+ *out++ = *in2++;
+ in1++;
+ }
+ }
+ return w+6;
+ }
+
+ if (x->x > 1.0) {
+ while (n--) {
+ *out++ = *in2++;
+ }
+ return w+6;
+ }
+
+ if (x->x >= 0.5) {
+ t_int index = 1/(1.0- x->x);
+ while (n--) {
+ if (n%index) {
+ *out++ = *in2++;
+ in1++;
+ }
+ else {
+ *out++ = *in1++;
+ in2++;
+ }
+ }
+ }
+
+ return w+6;
+}
+
+
+static void shuffle_dsp(t_shuffle *x, t_signal **sp)
+{
+ dsp_add(shuffle_perform, 5, x, sp[0]->s_vec,
+ sp[1]->s_vec,sp[2]->s_vec, sp[0]->s_n);
+
+}
+
+static void *shuffle_new()
+{
+ t_shuffle *x = (t_shuffle *)pd_new(shuffle_class);
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+
+
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+void shuffle_setup(void)
+{
+ shuffle_class = class_new(gensym("shuffle~"), (t_newmethod)shuffle_new, 0,
+ sizeof(t_shuffle), 0,0);
+
+ class_addmethod(shuffle_class, nullfn, gensym("signal"), 0);
+ class_addmethod(shuffle_class, (t_method) shuffle_dsp, gensym("dsp"), 0);
+
+ class_addfloat(shuffle_class,shuffle_float);
+}
+
+
diff --git a/filters/bandpass.c b/filters/bandpass.c
index c4c2e13..90431ee 100755
--- a/filters/bandpass.c
+++ b/filters/bandpass.c
@@ -1,86 +1,86 @@
-
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-/* ------------------- bandpass ----------------------------*/
-
-static t_class *bandpass_class;
-
-void bandpass_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float alpha = e_alpha(x->x_bw* 0.01,omega);
- t_float b1 = 0.;
- t_float b0 = alpha;
- t_float b2 = -alpha;
- t_float a0 = 1 + alpha;
- t_float a1 = -2.*cos(omega);
- t_float a2 = 1 - alpha;
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("bandpass: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void bandpass_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- bandpass_bang(x);
-}
-
-
-static void *bandpass_new(t_floatarg f,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
-/* floatinlet_new(&x->x_obj, &x->x_gain); */
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- return (x);
-}
-
-
-void bandpass_setup(void)
-{
- bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(bandpass_class,bandpass_bang);
- class_addfloat(bandpass_class,bandpass_float);
-}
-
-
-
+
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+/* ------------------- bandpass ----------------------------*/
+
+static t_class *bandpass_class;
+
+void bandpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = 0.;
+ t_float b0 = alpha;
+ t_float b2 = -alpha;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("bandpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void bandpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ bandpass_bang(x);
+}
+
+
+static void *bandpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void bandpass_setup(void)
+{
+ bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(bandpass_class,bandpass_bang);
+ class_addfloat(bandpass_class,bandpass_float);
+}
+
+
+
diff --git a/filters/equalizer.c b/filters/equalizer.c
index ea1ebec..6765df4 100755
--- a/filters/equalizer.c
+++ b/filters/equalizer.c
@@ -1,89 +1,89 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-
-/* ------------------- equ ----------------------------*/
-static t_class *equ_class;
-
-void equ_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float alpha = e_alpha(x->x_bw*0.01,omega);
- t_float b0 = 1 + alpha*e_A(x->x_gain);
- t_float b1 = -2.*cos(omega);
- t_float b2 = 1 - alpha*e_A(x->x_gain);
- t_float a0 = 1 + alpha/e_A(x->x_gain);
- t_float a1 = -2.*cos(omega);
- t_float a2 = 1 - alpha/e_A(x->x_gain);
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("equ: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void equ_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- equ_bang(x);
-}
-
-
-static void *equ_new(t_floatarg f,t_floatarg g,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(equ_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
- floatinlet_new(&x->x_obj, &x->x_gain);
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- if (g != 0.) x->x_gain = g;
- return (x);
-}
-
-
-void equalizer_setup(void)
-{
- equ_class = class_new(gensym("equalizer"), (t_newmethod)equ_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(equ_class,equ_bang);
- class_addfloat(equ_class,equ_float);
-}
-
-
-
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- equ ----------------------------*/
+static t_class *equ_class;
+
+void equ_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b0 = 1 + alpha*e_A(x->x_gain);
+ t_float b1 = -2.*cos(omega);
+ t_float b2 = 1 - alpha*e_A(x->x_gain);
+ t_float a0 = 1 + alpha/e_A(x->x_gain);
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha/e_A(x->x_gain);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("equ: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void equ_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ equ_bang(x);
+}
+
+
+static void *equ_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(equ_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void equalizer_setup(void)
+{
+ equ_class = class_new(gensym("equalizer"), (t_newmethod)equ_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(equ_class,equ_bang);
+ class_addfloat(equ_class,equ_float);
+}
+
+
+
+
+
diff --git a/filters/highpass.c b/filters/highpass.c
index e7e0443..901c742 100755
--- a/filters/highpass.c
+++ b/filters/highpass.c
@@ -1,87 +1,87 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-/* ------------------- highpass ----------------------------*/
-
-static t_class *highpass_class;
-
-void highpass_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float alpha = e_alpha(x->x_bw* 0.01,omega);
- t_float b1 = -(1 + cos(omega));
- t_float b0 = -b1/2.;
- t_float b2 = b0;
- t_float a0 = 1 + alpha;
- t_float a1 = -2.*cos(omega);
- t_float a2 = 1 - alpha;
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("highpass: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void highpass_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- highpass_bang(x);
-}
-
-
-static void *highpass_new(t_floatarg f,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
-/* floatinlet_new(&x->x_obj, &x->x_gain); */
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- return (x);
-}
-
-
-void highpass_setup(void)
-{
- highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(highpass_class,highpass_bang);
- class_addfloat(highpass_class,highpass_float);
-}
-
-
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highpass ----------------------------*/
+
+static t_class *highpass_class;
+
+void highpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -(1 + cos(omega));
+ t_float b0 = -b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highpass_bang(x);
+}
+
+
+static void *highpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void highpass_setup(void)
+{
+ highpass_class = class_new(gensym("highpass"), (t_newmethod)highpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highpass_class,highpass_bang);
+ class_addfloat(highpass_class,highpass_float);
+}
+
+
+
+
diff --git a/filters/highshelf.c b/filters/highshelf.c
index ee6006c..5af6132 100755
--- a/filters/highshelf.c
+++ b/filters/highshelf.c
@@ -1,90 +1,90 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-/* ------------------- highshelf ----------------------------*/
-
-static t_class *highshelf_class;
-
-void highshelf_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float A = e_A(x->x_gain);
- t_float cs = cos(omega);
- t_float sn = sin(omega);
- t_float beta = e_beta(A,x->x_bw* 0.01);
-
- t_float b0 = A*((A+1) + (A-1)*cs + beta*sn);
- t_float b1 =-2.*A*((A-1) + (A+1)*cs);
- t_float b2 = A*((A+1) + (A-1)*cs - beta*sn);
- t_float a0 = ((A+1) - (A-1)*cs + beta*sn);
- t_float a1 = 2.*((A-1) - (A+1)*cs);
- t_float a2 = ((A+1) - (A-1)*cs - beta*sn);
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("highshelf: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void highshelf_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- highshelf_bang(x);
-}
-
-
-static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
- floatinlet_new(&x->x_obj, &x->x_gain);
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- if (g != 0.) x->x_gain = g;
- return (x);
-}
-
-
-void highshelf_setup(void)
-{
- highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(highshelf_class,highshelf_bang);
- class_addfloat(highshelf_class,highshelf_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+/* ------------------- highshelf ----------------------------*/
+
+static t_class *highshelf_class;
+
+void highshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw* 0.01);
+
+ t_float b0 = A*((A+1) + (A-1)*cs + beta*sn);
+ t_float b1 =-2.*A*((A-1) + (A+1)*cs);
+ t_float b2 = A*((A+1) + (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) - (A-1)*cs + beta*sn);
+ t_float a1 = 2.*((A-1) - (A+1)*cs);
+ t_float a2 = ((A+1) - (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw);*/
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("highshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void highshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ highshelf_bang(x);
+}
+
+
+static void *highshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(highshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void highshelf_setup(void)
+{
+ highshelf_class = class_new(gensym("highshelf"), (t_newmethod)highshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(highshelf_class,highshelf_bang);
+ class_addfloat(highshelf_class,highshelf_float);
+}
+
+
diff --git a/filters/hlshelf.c b/filters/hlshelf.c
index a2189d7..7cf99c5 100755
--- a/filters/hlshelf.c
+++ b/filters/hlshelf.c
@@ -1,226 +1,226 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#include <math.h>
-
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ hlshelf ----------------------------- */
-
-
-#ifndef M_PI
-#define M_PI 3.141593f
-#endif
-
-#define SRATE 44100.0
-#define MAX_GAIN 120.0f
-
-static t_class *hlshelf_class;
-
-
-typedef struct _hlshelf
-{
- t_object x_obj;
- float s_rate;
- float s_gain0;
- float s_gain1;
- float s_gain2;
- float s_ltransfq;
- float s_htransfq;
- float s_lradians;
- float s_hradians;
-} t_hlshelf;
-
-
-int hlshelf_check_stability(t_float fb1,
- t_float fb2,
- t_float ff1,
- t_float ff2,
- t_float ff3)
-{
- float discriminant = fb1 * fb1 + 4 * fb2;
-
- if (discriminant < 0) /* imaginary roots -- resonant filter */
- {
- /* they're conjugates so we just check that the product
- is less than one */
- if (fb2 >= -1.0f) goto stable;
- }
- else /* real roots */
- {
- /* check that the parabola 1 - fb1 x - fb2 x^2 has a
- vertex between -1 and 1, and that it's nonnegative
- at both ends, which implies both roots are in [1-,1]. */
- if (fb1 <= 2.0f && fb1 >= -2.0f &&
- 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
- goto stable;
- }
- return 0;
-stable:
- return 1;
-}
-
-
-void hlshelf_check(t_hlshelf *x)
-{
-
- if(x->s_gain0 - x->s_gain1 > MAX_GAIN) {
- x->s_gain0 = x->s_gain1 + MAX_GAIN;
- post("setting gain0 to %f",x->s_gain0);
- }
-
-
- if(x->s_gain1 > MAX_GAIN) {
- x->s_gain1 = MAX_GAIN;
- post("setting gain1 to %f",x->s_gain1);
- }
-
- if(x->s_gain2 - x->s_gain1 > MAX_GAIN) {
- x->s_gain2 = x->s_gain1 + MAX_GAIN;
- post("setting gain2 to %f",x->s_gain2);
- }
-
- /* constrain: 0 <= x->s_ltransfq < x->s_htransfq. */
- x->s_ltransfq = (x->s_ltransfq < x->s_htransfq) ? x->s_ltransfq : x->s_htransfq - 0.5f;
-
- if (x->s_ltransfq < 0) x->s_ltransfq = 0.0f;
-
- x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
- x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
-
-}
-
-
-void hlshelf_bang(t_hlshelf *x)
-{
- t_atom at[6];
- float c0, c1, c2, d0, d1, d2; /* output coefs */
- float a1, a2, b1, b2, g1, g2; /* temp coefs */
- double xf;
-
- hlshelf_check(x);
-
- /* low shelf */
- xf = 0.5 * 0.115129255 * (double)(x->s_gain0 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
- if(xf < -200.) /* exp(x) -> 0 */
- {
- a1 = 1.0f;
- b1 = -1.0f;
- g1 = 0.0f;
- }
- else
- {
- double t = tan(x->s_lradians);
- double e = exp(xf);
- double r = t / e;
- double kr = t * e;
-
- a1 = (r - 1) / (r + 1);
- b1 = (kr - 1) / (kr + 1);
- g1 = (kr + 1) / (r + 1);
- }
-
- /* high shelf */
- xf = 0.5 * 0.115129255 * (double)(x->s_gain2 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
- if(xf < -200.) /* exp(x) -> 0 */
- {
- a2 = -1.0f;
- b2 = 1.0f;
- g2 = 0.0f;
- }
- else
- {
- double t = tan(x->s_hradians);
- double e = exp(xf);
- double r = t / e;
- double kr = t * e;
-
- a2 = (1 - r) / (1 + r);
- b2 = (1 - kr) / (1 + kr);
- g2 = (1 + kr) / (1 + r);
- }
-
- /* form product */
- c0 = g1 * g2 * (float)(exp((double)(x->s_gain1) * 0.05f * 2.302585093f)); ;
- c1 = a1 + a2;
- c2 = a1 * a2;
- d0 = 1.0f;
- d1 = b1 + b2;
- d2 = b1 * b2;
-
- if (!hlshelf_check_stability(-c1/d0,-c2/d0,d0/d0,d1/d0,d2/d0)) {
- post("hlshelf: filter unstable -> resetting");
- c0=1.;c1=0.;c2=0.;
- d0=1.;d1=0.;d2=0.;
- }
-
- SETFLOAT(at,-c1/d0);
- SETFLOAT(at+1,-c2/d0);
- SETFLOAT(at+2,d0/d0);
- SETFLOAT(at+3,d1/d0);
- SETFLOAT(at+4,d2/d0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-void hlshelf_float(t_hlshelf *x,t_floatarg f)
-{
- x->s_gain0 = f;
- hlshelf_bang(x);
-}
-
-
-static void *hlshelf_new(t_symbol* s,t_int argc, t_atom* at)
-{
- t_hlshelf *x = (t_hlshelf *)pd_new(hlshelf_class);
- t_float k0 = atom_getfloat(at);
- t_float k1 = atom_getfloat(at+1);
- t_float k2 = atom_getfloat(at+2);
- t_float f1 = atom_getfloat(at+3);
- t_float f2 = atom_getfloat(at+4);
-
-
- f1 = atom_getfloat(at);
- f2 = atom_getfloat(at);
-
- if ((f1 == 0.0f && f2 == 0.0f) || f1 > f2){ /* all gains = 0db */
- f1 = 150.0f;
- f2 = 5000.0f;
- }
-
- if (f1 < 0) f1 = 0.0f;
- if (f2 > SRATE) f2 = .5f*SRATE;
-
- x->s_rate = SRATE; /* srate default */
- x->s_gain0 = k0;
- x->s_gain1 = k1;
- x->s_gain2 = k2;
-
- x->s_ltransfq = 0.0f;
- x->s_htransfq = SRATE/2;
-
- x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
- x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
-
- floatinlet_new(&x->x_obj, &x->s_gain1);
- floatinlet_new(&x->x_obj, &x->s_gain2);
- floatinlet_new(&x->x_obj, &x->s_ltransfq);
- floatinlet_new(&x->x_obj, &x->s_htransfq);
- outlet_new(&x->x_obj, &s_list);
-
- return (x);
-}
-
-void hlshelf_setup(void)
-{
- hlshelf_class = class_new(gensym("hlshelf"), (t_newmethod)hlshelf_new, 0,
- sizeof(t_hlshelf), 0, A_GIMME, 0);
- class_addbang(hlshelf_class,hlshelf_bang);
- class_addfloat(hlshelf_class,hlshelf_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#include <math.h>
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ hlshelf ----------------------------- */
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+#define SRATE 44100.0
+#define MAX_GAIN 120.0f
+
+static t_class *hlshelf_class;
+
+
+typedef struct _hlshelf
+{
+ t_object x_obj;
+ float s_rate;
+ float s_gain0;
+ float s_gain1;
+ float s_gain2;
+ float s_ltransfq;
+ float s_htransfq;
+ float s_lradians;
+ float s_hradians;
+} t_hlshelf;
+
+
+int hlshelf_check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+void hlshelf_check(t_hlshelf *x)
+{
+
+ if(x->s_gain0 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain0 = x->s_gain1 + MAX_GAIN;
+ post("setting gain0 to %f",x->s_gain0);
+ }
+
+
+ if(x->s_gain1 > MAX_GAIN) {
+ x->s_gain1 = MAX_GAIN;
+ post("setting gain1 to %f",x->s_gain1);
+ }
+
+ if(x->s_gain2 - x->s_gain1 > MAX_GAIN) {
+ x->s_gain2 = x->s_gain1 + MAX_GAIN;
+ post("setting gain2 to %f",x->s_gain2);
+ }
+
+ /* constrain: 0 <= x->s_ltransfq < x->s_htransfq. */
+ x->s_ltransfq = (x->s_ltransfq < x->s_htransfq) ? x->s_ltransfq : x->s_htransfq - 0.5f;
+
+ if (x->s_ltransfq < 0) x->s_ltransfq = 0.0f;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+}
+
+
+void hlshelf_bang(t_hlshelf *x)
+{
+ t_atom at[6];
+ float c0, c1, c2, d0, d1, d2; /* output coefs */
+ float a1, a2, b1, b2, g1, g2; /* temp coefs */
+ double xf;
+
+ hlshelf_check(x);
+
+ /* low shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain0 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a1 = 1.0f;
+ b1 = -1.0f;
+ g1 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_lradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a1 = (r - 1) / (r + 1);
+ b1 = (kr - 1) / (kr + 1);
+ g1 = (kr + 1) / (r + 1);
+ }
+
+ /* high shelf */
+ xf = 0.5 * 0.115129255 * (double)(x->s_gain2 - x->s_gain1); /* ln(10) / 20 = 0.115129255 */
+ if(xf < -200.) /* exp(x) -> 0 */
+ {
+ a2 = -1.0f;
+ b2 = 1.0f;
+ g2 = 0.0f;
+ }
+ else
+ {
+ double t = tan(x->s_hradians);
+ double e = exp(xf);
+ double r = t / e;
+ double kr = t * e;
+
+ a2 = (1 - r) / (1 + r);
+ b2 = (1 - kr) / (1 + kr);
+ g2 = (1 + kr) / (1 + r);
+ }
+
+ /* form product */
+ c0 = g1 * g2 * (float)(exp((double)(x->s_gain1) * 0.05f * 2.302585093f)); ;
+ c1 = a1 + a2;
+ c2 = a1 * a2;
+ d0 = 1.0f;
+ d1 = b1 + b2;
+ d2 = b1 * b2;
+
+ if (!hlshelf_check_stability(-c1/d0,-c2/d0,d0/d0,d1/d0,d2/d0)) {
+ post("hlshelf: filter unstable -> resetting");
+ c0=1.;c1=0.;c2=0.;
+ d0=1.;d1=0.;d2=0.;
+ }
+
+ SETFLOAT(at,-c1/d0);
+ SETFLOAT(at+1,-c2/d0);
+ SETFLOAT(at+2,d0/d0);
+ SETFLOAT(at+3,d1/d0);
+ SETFLOAT(at+4,d2/d0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+void hlshelf_float(t_hlshelf *x,t_floatarg f)
+{
+ x->s_gain0 = f;
+ hlshelf_bang(x);
+}
+
+
+static void *hlshelf_new(t_symbol* s,t_int argc, t_atom* at)
+{
+ t_hlshelf *x = (t_hlshelf *)pd_new(hlshelf_class);
+ t_float k0 = atom_getfloat(at);
+ t_float k1 = atom_getfloat(at+1);
+ t_float k2 = atom_getfloat(at+2);
+ t_float f1 = atom_getfloat(at+3);
+ t_float f2 = atom_getfloat(at+4);
+
+
+ f1 = atom_getfloat(at);
+ f2 = atom_getfloat(at);
+
+ if ((f1 == 0.0f && f2 == 0.0f) || f1 > f2){ /* all gains = 0db */
+ f1 = 150.0f;
+ f2 = 5000.0f;
+ }
+
+ if (f1 < 0) f1 = 0.0f;
+ if (f2 > SRATE) f2 = .5f*SRATE;
+
+ x->s_rate = SRATE; /* srate default */
+ x->s_gain0 = k0;
+ x->s_gain1 = k1;
+ x->s_gain2 = k2;
+
+ x->s_ltransfq = 0.0f;
+ x->s_htransfq = SRATE/2;
+
+ x->s_lradians = M_PI * x->s_ltransfq / x->s_rate;
+ x->s_hradians= M_PI * (0.5f - (x->s_htransfq / x->s_rate));
+
+ floatinlet_new(&x->x_obj, &x->s_gain1);
+ floatinlet_new(&x->x_obj, &x->s_gain2);
+ floatinlet_new(&x->x_obj, &x->s_ltransfq);
+ floatinlet_new(&x->x_obj, &x->s_htransfq);
+ outlet_new(&x->x_obj, &s_list);
+
+ return (x);
+}
+
+void hlshelf_setup(void)
+{
+ hlshelf_class = class_new(gensym("hlshelf"), (t_newmethod)hlshelf_new, 0,
+ sizeof(t_hlshelf), 0, A_GIMME, 0);
+ class_addbang(hlshelf_class,hlshelf_bang);
+ class_addfloat(hlshelf_class,hlshelf_float);
+}
+
+
diff --git a/filters/lowpass.c b/filters/lowpass.c
index 4e1b2b9..7155044 100755
--- a/filters/lowpass.c
+++ b/filters/lowpass.c
@@ -1,89 +1,89 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-
-/* ------------------- lowpass ----------------------------*/
-
-static t_class *lowpass_class;
-
-void lowpass_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float alpha = e_alpha(x->x_bw*0.01,omega);
- t_float b1 = 1 - cos(omega);
- t_float b0 = b1/2.;
- t_float b2 = b0;
- t_float a0 = 1 + alpha;
- t_float a1 = -2.*cos(omega);
- t_float a2 = 1 - alpha;
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("lowpass: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void lowpass_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- lowpass_bang(x);
-}
-
-
-static void *lowpass_new(t_floatarg f,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(lowpass_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
-/* floatinlet_new(&x->x_obj, &x->x_gain); */
- floatinlet_new(&x->x_obj, &x->x_bw);
-
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- return (x);
-}
-
-
-void lowpass_setup(void)
-{
- lowpass_class = class_new(gensym("lowpass"), (t_newmethod)lowpass_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(lowpass_class,lowpass_bang);
- class_addfloat(lowpass_class,lowpass_float);
-}
-
-
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowpass ----------------------------*/
+
+static t_class *lowpass_class;
+
+void lowpass_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw*0.01,omega);
+ t_float b1 = 1 - cos(omega);
+ t_float b0 = b1/2.;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowpass: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowpass_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowpass_bang(x);
+}
+
+
+static void *lowpass_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowpass_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void lowpass_setup(void)
+{
+ lowpass_class = class_new(gensym("lowpass"), (t_newmethod)lowpass_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowpass_class,lowpass_bang);
+ class_addfloat(lowpass_class,lowpass_float);
+}
+
+
+
+
diff --git a/filters/lowshelf.c b/filters/lowshelf.c
index dd925dc..946de89 100755
--- a/filters/lowshelf.c
+++ b/filters/lowshelf.c
@@ -1,91 +1,91 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-
-/* ------------------- lowshelf ----------------------------*/
-
-static t_class *lowshelf_class;
-
-void lowshelf_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float A = e_A(x->x_gain);
- t_float cs = cos(omega);
- t_float sn = sin(omega);
- t_float beta = e_beta(A,x->x_bw*0.01);
-
- t_float b0 = A*((A+1) - (A-1)*cs + beta*sn);
- t_float b1 = 2.*A*((A-1) - (A+1)*cs);
- t_float b2 = A*((A+1) - (A-1)*cs - beta*sn);
- t_float a0 = ((A+1) + (A-1)*cs + beta*sn);
- t_float a1 = -2.*((A-1) + (A+1)*cs);
- t_float a2 = ((A+1) + (A-1)*cs - beta*sn);
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("lowshelf: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void lowshelf_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- lowshelf_bang(x);
-}
-
-
-static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
- floatinlet_new(&x->x_obj, &x->x_gain);
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- if (g != 0.) x->x_gain = g;
- return (x);
-}
-
-
-void lowshelf_setup(void)
-{
- lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(lowshelf_class,lowshelf_bang);
- class_addfloat(lowshelf_class,lowshelf_float);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- lowshelf ----------------------------*/
+
+static t_class *lowshelf_class;
+
+void lowshelf_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float A = e_A(x->x_gain);
+ t_float cs = cos(omega);
+ t_float sn = sin(omega);
+ t_float beta = e_beta(A,x->x_bw*0.01);
+
+ t_float b0 = A*((A+1) - (A-1)*cs + beta*sn);
+ t_float b1 = 2.*A*((A-1) - (A+1)*cs);
+ t_float b2 = A*((A+1) - (A-1)*cs - beta*sn);
+ t_float a0 = ((A+1) + (A-1)*cs + beta*sn);
+ t_float a1 = -2.*((A-1) + (A+1)*cs);
+ t_float a2 = ((A+1) + (A-1)*cs - beta*sn);
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("lowshelf: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void lowshelf_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ lowshelf_bang(x);
+}
+
+
+static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+ floatinlet_new(&x->x_obj, &x->x_gain);
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ if (g != 0.) x->x_gain = g;
+ return (x);
+}
+
+
+void lowshelf_setup(void)
+{
+ lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(lowshelf_class,lowshelf_bang);
+ class_addfloat(lowshelf_class,lowshelf_float);
+}
+
+
diff --git a/filters/moog~.c b/filters/moog~.c
index 8f4dbea..12f8cf2 100755
--- a/filters/moog~.c
+++ b/filters/moog~.c
@@ -1,182 +1,182 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include "math.h"
-#include <m_pd.h>
-
-/* ----------------------------- moog ----------------------------- */
-static t_class *moog_class;
-
-
-typedef struct _moog
-{
- t_object x_obj;
- t_pd in2;
- t_float x_1,x_2,x_3,x_4;
- t_float y_1,y_2,y_3,y_4;
-} t_moog;
-
-static void moog_reset(t_moog *x)
-{
- x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0.0;
- x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0.0;
-
-}
-
-
-
-static void *moog_new(t_symbol *s, int argc, t_atom *argv)
-{
- if (argc > 1) post("moog~: extra arguments ignored");
- {
- t_moog *x = (t_moog *)pd_new(moog_class);
- outlet_new(&x->x_obj, &s_signal);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
- moog_reset(x);
- return (x);
- }
-
-
-}
-
-
-
-static t_float calc_k(t_float f,t_float k) {
- if (k>4.) k =4.;
- if (k < 0.) k = 0.;
- if (f <= 3800) return k;
- k = k - 0.5*((f-3800)/4300);
- return k;
-}
-
-t_int *moog_perform(t_int *w)
-{
- t_moog* x = (t_moog*) (w[1]);
- t_float *in1 = (t_float *)(w[2]);
- t_float *p = (t_float *)(w[3]);
- t_float *k = (t_float *)(w[4]);
-
- t_float *out = (t_float *)(w[5]);
- int n = (int)(w[6]);
- float in;
- float pt,pt1;
-
- float x1 = x->x_1;
- float x2 = x->x_2;
- float x3 = x->x_3;
- float x4 = x->x_4;
- float ys1 = x->y_1;
- float ys2 = x->y_2;
- float ys3 = x->y_3;
- float ys4 = x->y_4;
-
-
- while (n--) {
- if (*p > 8140) *p = 8140.;
- *k = calc_k(*p,*k);
- pt =*p;
- pt1=(pt+1)*0.76923077;
- in = *in1++ - *k*ys4;
- ys1 = (pt1)*in + 0.3*x1 - pt*ys1;
- x1 = in;
- ys2 = (pt1)*ys1 + 0.3*x2 - pt*ys2;
- x2 = ys1;
- ys3 = (pt1)*ys2 + 0.3 *x3 - pt*ys3;
- x3 = ys2;
- ys4 = (pt1)*ys3 + 0.3*x4 - pt*ys4;
- x4 = ys3;
- *out++ = ys4;
- }
-
-
- x->y_1 = ys1;
- x->y_2 = ys2;
- x->y_3 = ys3;
- x->y_4 = ys4;
- x->x_1 = x1;
- x->x_2 = x2;
- x->x_3 = x3;
- x->x_4 = x4;
-
- return (w+7);
-}
-
-
-#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
-
-t_int *moog_perf8(t_int *w)
-{
- t_moog* x = (t_moog*) (w[1]);
- t_float *in1 = (t_float *)(w[2]);
- t_float *p = (t_float *)(w[3]);
- t_float *k = (t_float *)(w[4]);
- t_float *out = (t_float *)(w[5]);
- int n = (int)(w[6]);
-
- t_float x1 = x->x_1;
- t_float x2 = x->x_2;
- t_float x3 = x->x_3;
- t_float x4 = x->x_4;
- t_float ys1 = x->y_1;
- t_float ys2 = x->y_2;
- t_float ys3 = x->y_3;
- t_float ys4 = x->y_4;
- t_float temp,temp2;
- t_float pt,pt1;
- t_float in;
-
- while (n--) {
- if (*p > 8140.) *p = 8140.;
- *k = calc_k(*p,*k);
-
- pt =*p* 0.01*0.0140845 - 0.9999999f;
- pt1=(pt+1.0)*0.76923077;
- in = *in1++ - *k*ys4;
- ys1 = pt1*(in + 0.3*x1) - pt*ys1;
- x1 = in;
- ys2 = pt1*(ys1 + 0.3*x2) - pt*ys2;
- x2 = ys1;
- ys3 = pt1*(ys2 + 0.3*x3) - pt*ys3;
- x3 = ys2;
- ys4 = pt1*(ys3 + 0.3*x4) - pt*ys4;
- x4 = ys3;
- *out++ = ys4;
-
- p++;k++;
- }
-
- x->y_1 = ys1;
- x->y_2 = ys2;
- x->y_3 = ys3;
- x->y_4 = ys4;
- x->x_1 = x1;
- x->x_2 = x2;
- x->x_3 = x3;
- x->x_4 = x4;
-
- return (w+7);
-}
-
-void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
-{
- if (n&7)
- dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
- else
- dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
-}
-
-static void moog_dsp(t_moog *x, t_signal **sp)
-{
- dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
-}
-
-
-void moog_tilde_setup(void)
-{
- moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
- sizeof(t_moog), 0, A_GIMME, 0);
- class_addmethod(moog_class, nullfn, gensym("signal"), 0);
- class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
- class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
-}
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include "math.h"
+#include <m_pd.h>
+
+/* ----------------------------- moog ----------------------------- */
+static t_class *moog_class;
+
+
+typedef struct _moog
+{
+ t_object x_obj;
+ t_pd in2;
+ t_float x_1,x_2,x_3,x_4;
+ t_float y_1,y_2,y_3,y_4;
+} t_moog;
+
+static void moog_reset(t_moog *x)
+{
+ x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0.0;
+ x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0.0;
+
+}
+
+
+
+static void *moog_new(t_symbol *s, int argc, t_atom *argv)
+{
+ if (argc > 1) post("moog~: extra arguments ignored");
+ {
+ t_moog *x = (t_moog *)pd_new(moog_class);
+ outlet_new(&x->x_obj, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
+ moog_reset(x);
+ return (x);
+ }
+
+
+}
+
+
+
+static t_float calc_k(t_float f,t_float k) {
+ if (k>4.) k =4.;
+ if (k < 0.) k = 0.;
+ if (f <= 3800) return k;
+ k = k - 0.5*((f-3800)/4300);
+ return k;
+}
+
+t_int *moog_perform(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_float *in1 = (t_float *)(w[2]);
+ t_float *p = (t_float *)(w[3]);
+ t_float *k = (t_float *)(w[4]);
+
+ t_float *out = (t_float *)(w[5]);
+ int n = (int)(w[6]);
+ float in;
+ float pt,pt1;
+
+ float x1 = x->x_1;
+ float x2 = x->x_2;
+ float x3 = x->x_3;
+ float x4 = x->x_4;
+ float ys1 = x->y_1;
+ float ys2 = x->y_2;
+ float ys3 = x->y_3;
+ float ys4 = x->y_4;
+
+
+ while (n--) {
+ if (*p > 8140) *p = 8140.;
+ *k = calc_k(*p,*k);
+ pt =*p;
+ pt1=(pt+1)*0.76923077;
+ in = *in1++ - *k*ys4;
+ ys1 = (pt1)*in + 0.3*x1 - pt*ys1;
+ x1 = in;
+ ys2 = (pt1)*ys1 + 0.3*x2 - pt*ys2;
+ x2 = ys1;
+ ys3 = (pt1)*ys2 + 0.3 *x3 - pt*ys3;
+ x3 = ys2;
+ ys4 = (pt1)*ys3 + 0.3*x4 - pt*ys4;
+ x4 = ys3;
+ *out++ = ys4;
+ }
+
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+
+#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
+
+t_int *moog_perf8(t_int *w)
+{
+ t_moog* x = (t_moog*) (w[1]);
+ t_float *in1 = (t_float *)(w[2]);
+ t_float *p = (t_float *)(w[3]);
+ t_float *k = (t_float *)(w[4]);
+ t_float *out = (t_float *)(w[5]);
+ int n = (int)(w[6]);
+
+ t_float x1 = x->x_1;
+ t_float x2 = x->x_2;
+ t_float x3 = x->x_3;
+ t_float x4 = x->x_4;
+ t_float ys1 = x->y_1;
+ t_float ys2 = x->y_2;
+ t_float ys3 = x->y_3;
+ t_float ys4 = x->y_4;
+ t_float temp,temp2;
+ t_float pt,pt1;
+ t_float in;
+
+ while (n--) {
+ if (*p > 8140.) *p = 8140.;
+ *k = calc_k(*p,*k);
+
+ pt =*p* 0.01*0.0140845 - 0.9999999f;
+ pt1=(pt+1.0)*0.76923077;
+ in = *in1++ - *k*ys4;
+ ys1 = pt1*(in + 0.3*x1) - pt*ys1;
+ x1 = in;
+ ys2 = pt1*(ys1 + 0.3*x2) - pt*ys2;
+ x2 = ys1;
+ ys3 = pt1*(ys2 + 0.3*x3) - pt*ys3;
+ x3 = ys2;
+ ys4 = pt1*(ys3 + 0.3*x4) - pt*ys4;
+ x4 = ys3;
+ *out++ = ys4;
+
+ p++;k++;
+ }
+
+ x->y_1 = ys1;
+ x->y_2 = ys2;
+ x->y_3 = ys3;
+ x->y_4 = ys4;
+ x->x_1 = x1;
+ x->x_2 = x2;
+ x->x_3 = x3;
+ x->x_4 = x4;
+
+ return (w+7);
+}
+
+void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
+{
+ if (n&7)
+ dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
+ else
+ dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
+}
+
+static void moog_dsp(t_moog *x, t_signal **sp)
+{
+ dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
+}
+
+
+void moog_tilde_setup(void)
+{
+ moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
+ sizeof(t_moog), 0, A_GIMME, 0);
+ class_addmethod(moog_class, nullfn, gensym("signal"), 0);
+ class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
+ class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
+}
diff --git a/filters/notch.c b/filters/notch.c
index ab11a7a..c0741e2 100755
--- a/filters/notch.c
+++ b/filters/notch.c
@@ -1,89 +1,89 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-
- These filter coefficients computations are taken from
- http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
-
- written by Robert Bristow-Johnson
-
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-#include <math.h>
-#include "filters.h"
-
-
-
-/* ------------------- notch ----------------------------*/
-
-static t_class *notch_class;
-
-void notch_bang(t_rbjfilter *x)
-{
- t_atom at[5];
- t_float omega = e_omega(x->x_freq,x->x_rate);
- t_float alpha = e_alpha(x->x_bw* 0.01,omega);
- t_float b1 = -2.*cos(omega);
- t_float b0 = 1;
- t_float b2 = b0;
- t_float a0 = 1 + alpha;
- t_float a1 = -2.*cos(omega);
- t_float a2 = 1 - alpha;
-
-/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
-
- if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
- post("notch: filter unstable -> resetting");
- a0=1.;a1=0.;a2=0.;
- b0=1.;b1=0.;b2=0.;
- }
-
- SETFLOAT(at,-a1/a0);
- SETFLOAT(at+1,-a2/a0);
- SETFLOAT(at+2,b0/a0);
- SETFLOAT(at+3,b1/a0);
- SETFLOAT(at+4,b2/a0);
-
- outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
-}
-
-
-void notch_float(t_rbjfilter *x,t_floatarg f)
-{
- x->x_freq = f;
- notch_bang(x);
-}
-
-
-static void *notch_new(t_floatarg f,t_floatarg bw)
-{
- t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class);
-
- x->x_rate = 44100.0;
- outlet_new(&x->x_obj,&s_float);
-/* floatinlet_new(&x->x_obj, &x->x_gain); */
- floatinlet_new(&x->x_obj, &x->x_bw);
- if (f > 0.) x->x_freq = f;
- if (bw > 0.) x->x_bw = bw;
- return (x);
-}
-
-
-void notch_setup(void)
-{
- notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0,
- sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
- class_addbang(notch_class,notch_bang);
- class_addfloat(notch_class,notch_float);
-}
-
-
-
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+#include <math.h>
+#include "filters.h"
+
+
+
+/* ------------------- notch ----------------------------*/
+
+static t_class *notch_class;
+
+void notch_bang(t_rbjfilter *x)
+{
+ t_atom at[5];
+ t_float omega = e_omega(x->x_freq,x->x_rate);
+ t_float alpha = e_alpha(x->x_bw* 0.01,omega);
+ t_float b1 = -2.*cos(omega);
+ t_float b0 = 1;
+ t_float b2 = b0;
+ t_float a0 = 1 + alpha;
+ t_float a1 = -2.*cos(omega);
+ t_float a2 = 1 - alpha;
+
+/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
+
+ if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
+ post("notch: filter unstable -> resetting");
+ a0=1.;a1=0.;a2=0.;
+ b0=1.;b1=0.;b2=0.;
+ }
+
+ SETFLOAT(at,-a1/a0);
+ SETFLOAT(at+1,-a2/a0);
+ SETFLOAT(at+2,b0/a0);
+ SETFLOAT(at+3,b1/a0);
+ SETFLOAT(at+4,b2/a0);
+
+ outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
+}
+
+
+void notch_float(t_rbjfilter *x,t_floatarg f)
+{
+ x->x_freq = f;
+ notch_bang(x);
+}
+
+
+static void *notch_new(t_floatarg f,t_floatarg bw)
+{
+ t_rbjfilter *x = (t_rbjfilter *)pd_new(notch_class);
+
+ x->x_rate = 44100.0;
+ outlet_new(&x->x_obj,&s_float);
+/* floatinlet_new(&x->x_obj, &x->x_gain); */
+ floatinlet_new(&x->x_obj, &x->x_bw);
+ if (f > 0.) x->x_freq = f;
+ if (bw > 0.) x->x_bw = bw;
+ return (x);
+}
+
+
+void notch_setup(void)
+{
+ notch_class = class_new(gensym("notch"), (t_newmethod)notch_new, 0,
+ sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addbang(notch_class,notch_bang);
+ class_addfloat(notch_class,notch_float);
+}
+
+
+
+
+
diff --git a/gui/button.c b/gui/button.c
index 49bfb6d..7eaa7b9 100644
--- a/gui/button.c
+++ b/gui/button.c
@@ -5,7 +5,7 @@
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/gui/image.c b/gui/image.c
index d3134d6..f04f755 100644
--- a/gui/image.c
+++ b/gui/image.c
@@ -1,7 +1,7 @@
#include <m_pd.h>
#include "g_canvas.h"
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/gui/sliderh.c b/gui/sliderh.c
index d89b6de..c6c3128 100644
--- a/gui/sliderh.c
+++ b/gui/sliderh.c
@@ -2,7 +2,7 @@
#include "g_canvas.h"
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/gui/state.c b/gui/state.c
index c2e26f0..f078612 100755
--- a/gui/state.c
+++ b/gui/state.c
@@ -4,7 +4,7 @@
#include <m_pd.h>
#include <stdio.h>
#include <string.h>
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/gui/ticker.c b/gui/ticker.c
index 214ff53..6af0ee1 100755
--- a/gui/ticker.c
+++ b/gui/ticker.c
@@ -1,7 +1,7 @@
#include <m_pd.h>
#include "g_canvas.h"
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/gui/toddle.c b/gui/toddle.c
index 04a8f41..684283f 100755
--- a/gui/toddle.c
+++ b/gui/toddle.c
@@ -4,7 +4,7 @@
#include <m_pd.h>
#include "g_canvas.h"
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/other/messages.c b/other/messages.c
index f25f49e..023a226 100755
--- a/other/messages.c
+++ b/other/messages.c
@@ -1,40 +1,40 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-/* ------------------------ messages ----------------------------- */
-
-static t_class *messages_class;
-
-
-typedef struct _messages
-{
- t_object x_obj;
-} t_messages;
-
-
-void messages_bang(t_messages *x)
-{
- post("bang");
-}
-
-static void *messages_new()
-{
- t_messages *x = (t_messages *)pd_new(messages_class);
- outlet_new(&x->x_obj, &s_float);
- return (x);
-}
-
-void messages_setup(void)
-{
- messages_class = class_new(gensym("messages"), (t_newmethod)messages_new, 0,
- sizeof(t_messages), 0,0);
- class_addbang(messages_class,messages_bang);
-}
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+/* ------------------------ messages ----------------------------- */
+
+static t_class *messages_class;
+
+
+typedef struct _messages
+{
+ t_object x_obj;
+} t_messages;
+
+
+void messages_bang(t_messages *x)
+{
+ post("bang");
+}
+
+static void *messages_new()
+{
+ t_messages *x = (t_messages *)pd_new(messages_class);
+ outlet_new(&x->x_obj, &s_float);
+ return (x);
+}
+
+void messages_setup(void)
+{
+ messages_class = class_new(gensym("messages"), (t_newmethod)messages_new, 0,
+ sizeof(t_messages), 0,0);
+ class_addbang(messages_class,messages_bang);
+}
+
+
diff --git a/other/vbap.c b/other/vbap.c
index db36993..ea91e1e 100755
--- a/other/vbap.c
+++ b/other/vbap.c
@@ -1,298 +1,298 @@
-/* (C) Guenter Geiger <geiger@epy.co.at> */
-
-
-/*
-(C) Guenter Geiger
-
-
-based on code by:
-(c) Ville Pulkki 2.2.1999
-Helsinki University of Technology
-Laboratory of Acoustics and Audio Signal Processing
-*/
-
-#include <m_pd.h>
-#ifdef NT
-#pragma warning( disable : 4244 )
-#pragma warning( disable : 4305 )
-#endif
-
-
-#include <math.h>
-#include <stdio.h>
-#include <malloc.h>
-#include <string.h> /* strtok */
-
-#define MAX_TRIPLET_AMOUNT 64
-
-/* this is related to the number of ls ..
-
- and shoud be 3**(MAX_LS_AMOUNT / 4)
-
-*/
-
-#define MAX_LS_AMOUNT 16
-#define MAX_DIM_SQUARE 9
-
-
-/* ------------------------ vbap ----------------------------- */
-
-static t_class *vbap_class;
-
-
-typedef struct _vbap
-{
- t_object x_ob;
- t_outlet* x_out2;
- t_outlet* x_out3;
- t_float lsm[MAX_TRIPLET_AMOUNT][MAX_LS_AMOUNT+1]; /* loudspeaker triplet matrices */
- int lstripl[MAX_TRIPLET_AMOUNT][3]; /* loudspeaker triplet ldspeaker numbers */
- int lasttrip[3];
- int triplet_amount;
- int dimension;
- int opened;
-} t_vbap;
-
-
-
-
-t_float *angle_to_cart(t_float azi, t_float ele);
-void vbap(t_vbap* x,t_float g[3], int ls[3], t_float azi, t_float ele) ;
-int read_ls_conf(t_vbap* x,FILE *fp );
-
-
-void vbap_list(t_vbap *x,t_symbol* s,t_int argc,t_atom* argv)
-{
- t_float azi,ele;
- t_float g[3];
- int ls[3];
- t_atom a[2];
-
- if (argc != 2)
- post("vbap: list message <azimuth> <elevation> required %d",argc);
- else {
- int i;
- azi = atom_getfloat(argv++);
- ele = atom_getfloat(argv++);
-
- vbap(x,g,ls,azi,ele);
-
- for (i=0;i<x->dimension;i++) {
- if (x->lasttrip[i] != ls[i]) {
- SETFLOAT(a,(t_float)x->lasttrip[i]);
- SETFLOAT(a+1,0.0f);
- outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a);
- x->lasttrip[i] = ls[i];
- }
- }
-
- for (i=0;i<x->dimension;i++) {
- SETFLOAT(a,(t_float)ls[i]);
- SETFLOAT(a+1,g[i]);
- outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a);
-
- }
- }
-
-}
-
-
-void vbap_bang(t_vbap *x)
-{
- post("vbap: bang");
-}
-
-
-
-static void *vbap_new(t_symbol* s)
-{
- FILE *fp;
- t_vbap *x = (t_vbap *)pd_new(vbap_class);
- char fname[MAXPDSTRING];
-
- if (s == &s_) {
- post("vbap: Using default loudspeaker setup");
- s = gensym("ls_setup");
- }
-
- /* opening the loudspeaker matrix file*/
-
- canvas_makefilename(canvas_getcurrent(),s->s_name,
- fname,MAXPDSTRING);
-
- if((fp=fopen(fname,"r"))==NULL){
- post("vbap: Could not open loudspeaker data file %s\n",fname);
- x->opened = 0;
- }
- else {
- if (!read_ls_conf(x,fp))
- return NULL;
- x->opened = 1;
- fclose(fp);
- }
-
- x->lasttrip[0] = 0;
- x->lasttrip[1] = 1;
- x->lasttrip[2] = 2;
-
- outlet_new(&x->x_ob, &s_list);
-
- return (x);
-}
-
-void vbap_setup(void)
-{
- vbap_class = class_new(gensym("vbap"), (t_newmethod)vbap_new, 0,
- sizeof(t_vbap), 0,A_DEFSYM,0);
-/* class_addbang(vbap_class,vbap_bang);*/
- class_addlist(vbap_class,vbap_list);
-}
-
-
-
-
-t_float *angle_to_cart(t_float azi, t_float ele)
-{
- t_float *res;
- t_float atorad = (2 * 3.1415927 / 360) ;
- res = (t_float *) malloc(3*sizeof(t_float));
- res[0] = (float) (cos((t_float) (azi * atorad)) * cos((t_float) (ele * atorad)));
- res[1] = (float) (sin((t_float) (azi * atorad)) * cos((t_float) (ele * atorad)));
- res[2] = (float) (sin((t_float) (ele * atorad)));
- return res;
-}
-
-
-void vbap(t_vbap* x,t_float g[3], int ls[3], float azi, float ele)
-{
- /* calculates gain factors using loudspeaker setup and given direction */
- t_float *cartdir;
- t_float power;
- int i,j,k;
- t_float small_g;
- t_float big_sm_g, gtmp[3];
- int winner_triplet;
-
- cartdir=angle_to_cart(azi,ele);
- big_sm_g = -100000.0;
- for(i=0;i<x->triplet_amount;i++){
- small_g = 10000000.0;
- for(j=0;j<x->dimension;j++){
- gtmp[j]=0.0;
- for(k=0;k<x->dimension;k++)
- gtmp[j]+=cartdir[k]*x->lsm[i][k+j*x->dimension];
- if(gtmp[j] < small_g)
- small_g = gtmp[j];
- }
- if(small_g > big_sm_g){
- big_sm_g = small_g;
- winner_triplet=i;
- g[0]=gtmp[0]; g[1]=gtmp[1];
- ls[0]=x->lstripl[i][0]; ls[1]=x->lstripl[i][1];
- if(x->dimension==3){
- g[2]=gtmp[2];
- ls[2]=x->lstripl[i][2];
- } else {
- g[2]=0.0;
- ls[2]=0;
- }
- }
- }
-
- /* this should probably be optimized somehow */
-
- power=sqrt(g[0]*g[0] + g[1]*g[1] + g[2]*g[2]);
- /* power=g[0]+g[1];*/
-
- g[0] /= power;
- g[1] /= power;
- g[2] /= power;
-
-
- free(cartdir);
-}
-
-int read_ls_conf(t_vbap* x,FILE *fp ){
- /* reads from specified file the loudspeaker triplet setup */
- int amount,i,j,a,b,d=0;
- char *toke;
- char c[1000];
- t_float mx[MAX_DIM_SQUARE];
- fgets(c,1000,fp);
- toke = (char *) strtok(c, " ");
- toke = (char *) strtok(NULL, " ");
- toke = (char *) strtok(NULL, " ");
- if((toke = (char *) strtok(NULL, " "))==NULL){
- fprintf(stderr,"Wrong ls matrix file?\n");
- return 0;
- }
- sscanf(toke, "%d",&amount);
- toke = (char *) strtok(NULL, " ");
- toke = (char *) strtok(NULL, " ");
- if((toke = (char *) strtok(NULL, " "))==NULL){
- fprintf(stderr,"Wrong ls matrix file?\n");
- return 0;
- }
- sscanf(toke, "%d",&x->dimension);
-
- x->triplet_amount = amount;
-
- for(i=0;i<amount;i++){
- fgets(c,1000,fp);
- toke = (char *) strtok(c, " ");
- if(strncmp(toke,"Trip",4)!=0 && x->dimension==3){
- fprintf(stderr,"Something wrong in ls matrix file\n");
- return 0;
- }
- if(strncmp(toke,"Pair",4)!=0 && x->dimension==2){
- fprintf(stderr,"Something wrong in ls matrix file\n");
- return 0;
- }
- toke = (char *) strtok(NULL, " ");
- toke = (char *) strtok(NULL, " "); toke = (char *) strtok(NULL, " ");
- sscanf(toke, "%d",&a);
- x->lstripl[i][0]=a;
- toke = (char *) strtok(NULL, " ");
- sscanf(toke, "%d",&b);
- x->lstripl[i][1]=b;
- if (x->dimension==3){
- toke = (char *) strtok(NULL, " ");
- sscanf(toke, "%d",&d);
- x->lstripl[i][2]=d;
- }
-
-
- toke = (char *) strtok(NULL, " ");
- for(j=0;j<(x->dimension*x->dimension);j++){
- toke = (char *) strtok(NULL, " ");
- sscanf(toke, "%f",&(mx[j]));
- x->lsm[i][j]=mx[j];
- }
-
- }
- return 1;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+/* (C) Guenter Geiger <geiger@epy.co.at> */
+
+
+/*
+(C) Guenter Geiger
+
+
+based on code by:
+(c) Ville Pulkki 2.2.1999
+Helsinki University of Technology
+Laboratory of Acoustics and Audio Signal Processing
+*/
+
+#include <m_pd.h>
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include <math.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <string.h> /* strtok */
+
+#define MAX_TRIPLET_AMOUNT 64
+
+/* this is related to the number of ls ..
+
+ and shoud be 3**(MAX_LS_AMOUNT / 4)
+
+*/
+
+#define MAX_LS_AMOUNT 16
+#define MAX_DIM_SQUARE 9
+
+
+/* ------------------------ vbap ----------------------------- */
+
+static t_class *vbap_class;
+
+
+typedef struct _vbap
+{
+ t_object x_ob;
+ t_outlet* x_out2;
+ t_outlet* x_out3;
+ t_float lsm[MAX_TRIPLET_AMOUNT][MAX_LS_AMOUNT+1]; /* loudspeaker triplet matrices */
+ int lstripl[MAX_TRIPLET_AMOUNT][3]; /* loudspeaker triplet ldspeaker numbers */
+ int lasttrip[3];
+ int triplet_amount;
+ int dimension;
+ int opened;
+} t_vbap;
+
+
+
+
+t_float *angle_to_cart(t_float azi, t_float ele);
+void vbap(t_vbap* x,t_float g[3], int ls[3], t_float azi, t_float ele) ;
+int read_ls_conf(t_vbap* x,FILE *fp );
+
+
+void vbap_list(t_vbap *x,t_symbol* s,t_int argc,t_atom* argv)
+{
+ t_float azi,ele;
+ t_float g[3];
+ int ls[3];
+ t_atom a[2];
+
+ if (argc != 2)
+ post("vbap: list message <azimuth> <elevation> required %d",argc);
+ else {
+ int i;
+ azi = atom_getfloat(argv++);
+ ele = atom_getfloat(argv++);
+
+ vbap(x,g,ls,azi,ele);
+
+ for (i=0;i<x->dimension;i++) {
+ if (x->lasttrip[i] != ls[i]) {
+ SETFLOAT(a,(t_float)x->lasttrip[i]);
+ SETFLOAT(a+1,0.0f);
+ outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a);
+ x->lasttrip[i] = ls[i];
+ }
+ }
+
+ for (i=0;i<x->dimension;i++) {
+ SETFLOAT(a,(t_float)ls[i]);
+ SETFLOAT(a+1,g[i]);
+ outlet_list(x->x_ob.ob_outlet, &s_list,2 ,(t_atom*)&a);
+
+ }
+ }
+
+}
+
+
+void vbap_bang(t_vbap *x)
+{
+ post("vbap: bang");
+}
+
+
+
+static void *vbap_new(t_symbol* s)
+{
+ FILE *fp;
+ t_vbap *x = (t_vbap *)pd_new(vbap_class);
+ char fname[MAXPDSTRING];
+
+ if (s == &s_) {
+ post("vbap: Using default loudspeaker setup");
+ s = gensym("ls_setup");
+ }
+
+ /* opening the loudspeaker matrix file*/
+
+ canvas_makefilename(canvas_getcurrent(),s->s_name,
+ fname,MAXPDSTRING);
+
+ if((fp=fopen(fname,"r"))==NULL){
+ post("vbap: Could not open loudspeaker data file %s\n",fname);
+ x->opened = 0;
+ }
+ else {
+ if (!read_ls_conf(x,fp))
+ return NULL;
+ x->opened = 1;
+ fclose(fp);
+ }
+
+ x->lasttrip[0] = 0;
+ x->lasttrip[1] = 1;
+ x->lasttrip[2] = 2;
+
+ outlet_new(&x->x_ob, &s_list);
+
+ return (x);
+}
+
+void vbap_setup(void)
+{
+ vbap_class = class_new(gensym("vbap"), (t_newmethod)vbap_new, 0,
+ sizeof(t_vbap), 0,A_DEFSYM,0);
+/* class_addbang(vbap_class,vbap_bang);*/
+ class_addlist(vbap_class,vbap_list);
+}
+
+
+
+
+t_float *angle_to_cart(t_float azi, t_float ele)
+{
+ t_float *res;
+ t_float atorad = (2 * 3.1415927 / 360) ;
+ res = (t_float *) malloc(3*sizeof(t_float));
+ res[0] = (float) (cos((t_float) (azi * atorad)) * cos((t_float) (ele * atorad)));
+ res[1] = (float) (sin((t_float) (azi * atorad)) * cos((t_float) (ele * atorad)));
+ res[2] = (float) (sin((t_float) (ele * atorad)));
+ return res;
+}
+
+
+void vbap(t_vbap* x,t_float g[3], int ls[3], float azi, float ele)
+{
+ /* calculates gain factors using loudspeaker setup and given direction */
+ t_float *cartdir;
+ t_float power;
+ int i,j,k;
+ t_float small_g;
+ t_float big_sm_g, gtmp[3];
+ int winner_triplet;
+
+ cartdir=angle_to_cart(azi,ele);
+ big_sm_g = -100000.0;
+ for(i=0;i<x->triplet_amount;i++){
+ small_g = 10000000.0;
+ for(j=0;j<x->dimension;j++){
+ gtmp[j]=0.0;
+ for(k=0;k<x->dimension;k++)
+ gtmp[j]+=cartdir[k]*x->lsm[i][k+j*x->dimension];
+ if(gtmp[j] < small_g)
+ small_g = gtmp[j];
+ }
+ if(small_g > big_sm_g){
+ big_sm_g = small_g;
+ winner_triplet=i;
+ g[0]=gtmp[0]; g[1]=gtmp[1];
+ ls[0]=x->lstripl[i][0]; ls[1]=x->lstripl[i][1];
+ if(x->dimension==3){
+ g[2]=gtmp[2];
+ ls[2]=x->lstripl[i][2];
+ } else {
+ g[2]=0.0;
+ ls[2]=0;
+ }
+ }
+ }
+
+ /* this should probably be optimized somehow */
+
+ power=sqrt(g[0]*g[0] + g[1]*g[1] + g[2]*g[2]);
+ /* power=g[0]+g[1];*/
+
+ g[0] /= power;
+ g[1] /= power;
+ g[2] /= power;
+
+
+ free(cartdir);
+}
+
+int read_ls_conf(t_vbap* x,FILE *fp ){
+ /* reads from specified file the loudspeaker triplet setup */
+ int amount,i,j,a,b,d=0;
+ char *toke;
+ char c[1000];
+ t_float mx[MAX_DIM_SQUARE];
+ fgets(c,1000,fp);
+ toke = (char *) strtok(c, " ");
+ toke = (char *) strtok(NULL, " ");
+ toke = (char *) strtok(NULL, " ");
+ if((toke = (char *) strtok(NULL, " "))==NULL){
+ fprintf(stderr,"Wrong ls matrix file?\n");
+ return 0;
+ }
+ sscanf(toke, "%d",&amount);
+ toke = (char *) strtok(NULL, " ");
+ toke = (char *) strtok(NULL, " ");
+ if((toke = (char *) strtok(NULL, " "))==NULL){
+ fprintf(stderr,"Wrong ls matrix file?\n");
+ return 0;
+ }
+ sscanf(toke, "%d",&x->dimension);
+
+ x->triplet_amount = amount;
+
+ for(i=0;i<amount;i++){
+ fgets(c,1000,fp);
+ toke = (char *) strtok(c, " ");
+ if(strncmp(toke,"Trip",4)!=0 && x->dimension==3){
+ fprintf(stderr,"Something wrong in ls matrix file\n");
+ return 0;
+ }
+ if(strncmp(toke,"Pair",4)!=0 && x->dimension==2){
+ fprintf(stderr,"Something wrong in ls matrix file\n");
+ return 0;
+ }
+ toke = (char *) strtok(NULL, " ");
+ toke = (char *) strtok(NULL, " "); toke = (char *) strtok(NULL, " ");
+ sscanf(toke, "%d",&a);
+ x->lstripl[i][0]=a;
+ toke = (char *) strtok(NULL, " ");
+ sscanf(toke, "%d",&b);
+ x->lstripl[i][1]=b;
+ if (x->dimension==3){
+ toke = (char *) strtok(NULL, " ");
+ sscanf(toke, "%d",&d);
+ x->lstripl[i][2]=d;
+ }
+
+
+ toke = (char *) strtok(NULL, " ");
+ for(j=0;j<(x->dimension*x->dimension);j++){
+ toke = (char *) strtok(NULL, " ");
+ sscanf(toke, "%f",&(mx[j]));
+ x->lsm[i][j]=mx[j];
+ }
+
+ }
+ return 1;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/signal/sfwrite~.c b/signal/sfwrite~.c
index e254137..1b5ed05 100755
--- a/signal/sfwrite~.c
+++ b/signal/sfwrite~.c
@@ -2,7 +2,7 @@
#include <m_pd.h>
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
diff --git a/signal/streamin~.c b/signal/streamin~.c
index 1d81c2a..dd12f25 100755
--- a/signal/streamin~.c
+++ b/signal/streamin~.c
@@ -23,7 +23,7 @@
-#ifdef NT
+#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif