aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2007-06-01 09:15:09 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2007-06-01 09:15:09 +0000
commit843409ecc7baf287962cbe34e967380302f35509 (patch)
tree42bde9b459007104cb83b137e8c1c22319393f70
parent7119bfd22c7a53c254b3532649f0342efc6625e3 (diff)
new filelayout (one c-file per object)
svn path=/trunk/externals/iem16/; revision=7739
-rw-r--r--src/del16read~.c97
-rw-r--r--src/del16write~.c93
-rw-r--r--src/iem16.c35
-rw-r--r--src/iem16.h53
-rw-r--r--src/iem16_array.c173
-rw-r--r--src/iem16_array_tilde.c514
-rwxr-xr-xsrc/iem16_delay.c303
-rw-r--r--src/iem16_delay.h51
-rw-r--r--src/iem16_table.h49
-rw-r--r--src/tab16play~.c112
-rw-r--r--src/tab16read.c54
-rw-r--r--src/tab16read4.c70
-rw-r--r--src/tab16read4~.c105
-rw-r--r--src/tab16read~.c93
-rw-r--r--src/tab16receive~.c68
-rw-r--r--src/tab16send~.c83
-rw-r--r--src/tab16write.c58
-rw-r--r--src/tab16write~.c92
-rw-r--r--src/table16.c (renamed from src/iem16_table.c)0
-rw-r--r--src/vd16~.c97
20 files changed, 1152 insertions, 1048 deletions
diff --git a/src/del16read~.c b/src/del16read~.c
new file mode 100644
index 0000000..ed6d3ff
--- /dev/null
+++ b/src/del16read~.c
@@ -0,0 +1,97 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_delay.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* del16read~, del16write~, vd16~ */
+
+#include "iem16_delay.h"
+
+/* ----------------------------- del16read~ ----------------------------- */
+static t_class *sigdel16read_class;
+
+typedef struct _sigdel16read{
+ t_object x_obj;
+ t_symbol *x_sym;
+ t_float x_deltime; /* delay in msec */
+ int x_delsamps; /* delay in samples */
+ t_float x_sr; /* samples per msec */
+ t_float x_n; /* vector size */
+ int x_zerodel; /* 0 or vecsize depending on read/write order */
+} t_sigdel16read;
+
+static void sigdel16read_16bit(t_sigdel16read *x, t_float f);
+
+static void *sigdel16read_new(t_symbol *s, t_floatarg f){
+ t_sigdel16read *x = (t_sigdel16read *)pd_new(sigdel16read_class);
+ x->x_sym = s;
+ x->x_sr = 1;
+ x->x_n = 1;
+ x->x_zerodel = 0;
+ sigdel16read_16bit(x, f);
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static void sigdel16read_16bit(t_sigdel16read *x, t_float f){
+ t_sigdel16write *delwriter =
+ (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
+ x->x_deltime = f;
+ if (delwriter) {
+ x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime)
+ + x->x_n - x->x_zerodel;
+ if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n;
+ else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS)
+ x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS;
+ }
+}
+
+static t_int *sigdel16read_perform(t_int *w){
+ t_float *out = (t_float *)(w[1]);
+ t_del16writectl *c = (t_del16writectl *)(w[2]);
+ int delsamps = *(int *)(w[3]);
+ int n = (int)(w[4]);
+ int phase = c->c_phase - delsamps, nsamps = c->c_n;
+ t_iem16_16bit *vp = c->c_vec, *bp, *ep = vp + (c->c_n + XTRASAMPS);
+
+ if (phase < 0) phase += nsamps;
+ bp = vp + phase;
+ while (n--) {
+ *out++ = *bp++*IEM16_SCALE_DOWN;
+ if (bp == ep) bp -= nsamps;
+ }
+ return (w+5);
+}
+
+static void sigdel16read_dsp(t_sigdel16read *x, t_signal **sp){
+ t_sigdel16write *delwriter =
+ (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
+ x->x_sr = sp[0]->s_sr * 0.001;
+ x->x_n = sp[0]->s_n;
+ if (delwriter) {
+ sigdel16write_checkvecsize(delwriter, sp[0]->s_n);
+ x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
+ 0 : delwriter->x_vecsize);
+ sigdel16read_16bit(x, x->x_deltime);
+ dsp_add(sigdel16read_perform, 4,
+ sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n);
+ }
+ else if (*x->x_sym->s_name)
+ error("delread~: %s: no such delwrite~",x->x_sym->s_name);
+}
+
+static void sigdel16read_setup(void){
+ sigdel16read_class = class_new(gensym("del16read~"),
+ (t_newmethod)sigdel16read_new, 0,
+ sizeof(t_sigdel16read), 0, A_DEFSYM, A_DEFFLOAT, 0);
+ class_addmethod(sigdel16read_class, (t_method)sigdel16read_dsp,
+ gensym("dsp"), 0);
+ class_addfloat(sigdel16read_class, (t_method)sigdel16read_16bit);
+}
+
+// G.Holzmann: for PD-extended build system
+void del16read_tilde_setup(void)
+{
+ sigdel16read_setup();
+}
diff --git a/src/del16write~.c b/src/del16write~.c
new file mode 100644
index 0000000..d0ea389
--- /dev/null
+++ b/src/del16write~.c
@@ -0,0 +1,93 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_delay.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* del16read~, del16write~, vd16~ */
+
+#include "iem16_delay.h"
+
+
+
+/* ----------------------------- del16write~ ----------------------------- */
+
+/* routine to check that all del16writes/del16reads/vds have same vecsize */
+void sigdel16write_checkvecsize(t_sigdel16write *x, int vecsize){
+ if (x->x_rsortno != ugen_getsortno()) {
+ x->x_vecsize = vecsize;
+ x->x_rsortno = ugen_getsortno();
+ }
+ else if (vecsize != x->x_vecsize)
+ pd_error(x, "del16read/del16write/vd vector size mismatch");
+}
+
+static void *sigdel16write_new(t_symbol *s, t_floatarg msec){
+ int nsamps;
+ t_sigdel16write *x = (t_sigdel16write *)pd_new(sigdel16write_class);
+ if (!*s->s_name) s = gensym("del16write~");
+ pd_bind(&x->x_obj.ob_pd, s);
+ x->x_sym = s;
+ nsamps = msec * sys_getsr() * (float)(0.001f);
+ if (nsamps < 1) nsamps = 1;
+ nsamps += ((- nsamps) & (SAMPBLK - 1));
+ nsamps += DEFDELVS;
+ x->x_cspace.c_n = nsamps;
+ x->x_cspace.c_vec =
+ (t_iem16_16bit *)getbytes((nsamps + XTRASAMPS) * sizeof(t_iem16_16bit));
+ x->x_cspace.c_phase = XTRASAMPS;
+ x->x_sortno = 0;
+ x->x_vecsize = 0;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sigdel16write_perform(t_int *w){
+ t_float *in = (t_float *)(w[1]);
+ t_del16writectl *c = (t_del16writectl *)(w[2]);
+ int n = (int)(w[3]);
+ int phase = c->c_phase, nsamps = c->c_n;
+ t_iem16_16bit *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS);
+ phase += n;
+ while (n--) {
+ *bp++ = (*in++*IEM16_SCALE_UP);
+ if (bp == ep) {
+ vp[0] = ep[-4];
+ vp[1] = ep[-3];
+ vp[2] = ep[-2];
+ vp[3] = ep[-1];
+ bp = vp + XTRASAMPS;
+ phase -= nsamps;
+ }
+ }
+ c->c_phase = phase;
+ return (w+4);
+}
+
+static void sigdel16write_dsp(t_sigdel16write *x, t_signal **sp){
+ dsp_add(sigdel16write_perform, 3, sp[0]->s_vec, &x->x_cspace, sp[0]->s_n);
+ x->x_sortno = ugen_getsortno();
+ sigdel16write_checkvecsize(x, sp[0]->s_n);
+}
+
+static void sigdel16write_free(t_sigdel16write *x){
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+ freebytes(x->x_cspace.c_vec,
+ (x->x_cspace.c_n + XTRASAMPS) * sizeof(t_iem16_16bit));
+}
+
+static void sigdel16write_setup(void){
+ sigdel16write_class = class_new(gensym("del16write~"),
+ (t_newmethod)sigdel16write_new, (t_method)sigdel16write_free,
+ sizeof(t_sigdel16write), 0, A_DEFSYM, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(sigdel16write_class, t_sigdel16write, x_f);
+ class_addmethod(sigdel16write_class, (t_method)sigdel16write_dsp,
+ gensym("dsp"), 0);
+}
+
+// G.Holzmann: for PD-extended build system
+void del16write_tilde_setup(void)
+{
+ sigdel16write_setup();
+}
+
diff --git a/src/iem16.c b/src/iem16.c
index 518acf9..747e8c0 100644
--- a/src/iem16.c
+++ b/src/iem16.c
@@ -22,10 +22,19 @@ static void *iem16_new(void){
}
/* include some externals */
-void iem16_table_setup();
-void iem16_array_setup();
-void iem16_array_tilde_setup();
-void iem16_delay_setup();
+void del16read_tilde_setup();
+void del16write_tilde_setup();
+void tab16play_tilde_setup();
+void tab16read4_setup();
+void tab16read4_tilde_setup();
+void tab16read_setup();
+void tab16read_tilde_setup();
+void tab16receive_tilde_setup();
+void tab16send_tilde_setup();
+void tab16write_setup();
+void tab16write_tilde_setup();
+void table16_setup();
+void vd16_tilde_setup();
void iem16_setup(void) {
static unsigned int setupcount=0;
@@ -34,11 +43,21 @@ void iem16_setup(void) {
return;
}
setupcount++;
- iem16_table_setup();
- iem16_array_setup();
- iem16_array_tilde_setup();
- iem16_delay_setup();
+ del16read_tilde_setup();
+ del16write_tilde_setup();
+ tab16play_tilde_setup();
+ tab16read4_setup();
+ tab16read4_tilde_setup();
+ tab16read_setup();
+ tab16read_tilde_setup();
+ tab16receive_tilde_setup();
+ tab16send_tilde_setup();
+ tab16write_setup();
+ tab16write_tilde_setup();
+ table16_setup();
+ vd16_tilde_setup();
+
/* ************************************** */
post("iem16:\t16bit-objects for low memory usage");
post("iem16:\t(l) forum::für::umläute\t\tIOhannes m zmölnig");
diff --git a/src/iem16.h b/src/iem16.h
index f9649cd..87e758d 100644
--- a/src/iem16.h
+++ b/src/iem16.h
@@ -37,6 +37,57 @@ typedef short t_iem16_16bit;
#define IEM16_SCALE_UP (32767)
#define IEM16_SCALE_DOWN (1./32767)
-#define VERSION "0.1"
+#define VERSION "0.2"
+
+#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
+
+ /* machine-dependent definitions. These ifdefs really
+ should have been by CPU type and not by operating system! */
+#ifdef __irix__
+ /* big-endian. Most significant byte is at low address in memory */
+# define HIOFFSET 0 /* word offset to find MSB */
+# define LOWOFFSET 1 /* word offset to find LSB */
+# define int32 long /* a data type that has 32 bits */
+#elif defined __WIN32__
+ /* little-endian; most significant byte is at highest address */
+# define HIOFFSET 1
+# define LOWOFFSET 0
+# define int32 long
+#elif defined __FreeBSD__
+# include <machine/endian.h>
+# if BYTE_ORDER == LITTLE_ENDIAN
+# define HIOFFSET 1
+# define LOWOFFSET 0
+# else
+# define HIOFFSET 0 /* word offset to find MSB */
+# define LOWOFFSET 1 /* word offset to find LSB */
+# endif /* BYTE_ORDER */
+# include <sys/types.h>
+# define int32 int32_t
+#elif defined __linux__
+# include <endian.h>
+# if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
+# error No byte order defined
+# endif
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define HIOFFSET 1
+# define LOWOFFSET 0
+# else
+# define HIOFFSET 0 /* word offset to find MSB */
+# define LOWOFFSET 1 /* word offset to find LSB */
+# endif /* __BYTE_ORDER */
+# include <sys/types.h>
+# define int32 int32_t
+#elif defined __APPLE__
+# ifdef __BIG_ENDIAN__
+# define HIOFFSET 0 /* word offset to find MSB */
+# define LOWOFFSET 1 /* word offset to find LSB */
+# else
+# define HIOFFSET 1
+# define LOWOFFSET 0
+# endif
+# define int32 int /* a data type that has 32 bits */
+#endif /* system */
+
#endif
diff --git a/src/iem16_array.c b/src/iem16_array.c
deleted file mode 100644
index 55d3d81..0000000
--- a/src/iem16_array.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
- * based on d_array.c from pd:
- * Copyright (c) 1997-1999 Miller Puckette and others.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* tab16read, tab16read4, tab16write */
-
-#include "iem16_table.h"
-
-/* ---------- tab16read: control, non-interpolating ------------------------ */
-
-static t_class *tab16read_class;
-
-typedef struct _tab16read{
- t_object x_obj;
- t_symbol *x_arrayname;
-} t_tab16read;
-
-static void tab16read_float(t_tab16read *x, t_float f){
- t_table16 *a;
- int npoints;
- t_iem16_16bit *vec;
-
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
- error("%s: no such array", x->x_arrayname->s_name);
- else if (!table16_getarray16(a, &npoints, &vec))
- error("%s: bad template for tab16read", x->x_arrayname->s_name);
- else {
- int n = f;
- if (n < 0) n = 0;
- else if (n >= npoints) n = npoints - 1;
- outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0));
- }
-}
-
-static void tab16read_set(t_tab16read *x, t_symbol *s){
- x->x_arrayname = s;
-}
-
-static void *tab16read_new(t_symbol *s){
- t_tab16read *x = (t_tab16read *)pd_new(tab16read_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, gensym("float"));
- return (x);
-}
-
-void tab16read_setup(void){
- tab16read_class = class_new(gensym("tab16read"), (t_newmethod)tab16read_new,
- 0, sizeof(t_tab16read), 0, A_DEFSYM, 0);
- class_addfloat(tab16read_class, (t_method)tab16read_float);
- class_addmethod(tab16read_class, (t_method)tab16read_set, gensym("set"),
- A_SYMBOL, 0);
-}
-
-/* ---------- tab16read4: control, non-interpolating ------------------------ */
-
-static t_class *tab16read4_class;
-
-typedef struct _tab16read4{
- t_object x_obj;
- t_symbol *x_arrayname;
-} t_tab16read4;
-
-static void tab16read4_float(t_tab16read4 *x, t_float f){
- t_table16 *a;
- int npoints;
- t_iem16_16bit *vec;
-
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
- error("%s: no such array", x->x_arrayname->s_name);
- else if (!table16_getarray16(a, &npoints, &vec))
- error("%s: bad template for tab16read4", x->x_arrayname->s_name);
- else if (npoints < 4)
- outlet_float(x->x_obj.ob_outlet, 0);
- else if (f <= 1)
- outlet_float(x->x_obj.ob_outlet, vec[1]);
- else if (f >= npoints - 2)
- outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]);
- else {
- int n = f;
- float a, b, c, d, cminusb, frac;
- t_iem16_16bit *fp;
- if (n >= npoints - 2) n = npoints - 3;
- fp = vec + n;
- frac = f - n;
- a = fp[-1];
- b = fp[0];
- c = fp[1];
- d = fp[2];
- cminusb = c-b;
- outlet_float(x->x_obj.ob_outlet, b + frac * (
- cminusb - 0.5f * (frac-1.) * (
- (a - d + 3.0f * cminusb) * frac + (b - a - cminusb))));
- }
-}
-
-static void tab16read4_set(t_tab16read4 *x, t_symbol *s){
- x->x_arrayname = s;
-}
-
-static void *tab16read4_new(t_symbol *s){
- t_tab16read4 *x = (t_tab16read4 *)pd_new(tab16read4_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, gensym("float"));
- return (x);
-}
-
-void tab16read4_setup(void){
- tab16read4_class = class_new(gensym("tab16read4"), (t_newmethod)tab16read4_new,
- 0, sizeof(t_tab16read4), 0, A_DEFSYM, 0);
- class_addfloat(tab16read4_class, (t_method)tab16read4_float);
- class_addmethod(tab16read4_class, (t_method)tab16read4_set, gensym("set"),
- A_SYMBOL, 0);
-}
-
-/* ------------------ tab16write: control ------------------------ */
-
-static t_class *tab16write_class;
-
-typedef struct _tab16write {
- t_object x_obj;
- t_symbol *x_arrayname;
- float x_ft1;
- int x_set;
-} t_tab16write;
-
-static void tab16write_float(t_tab16write *x, t_float f) {
- int vecsize;
- t_table16 *a;
- t_iem16_16bit *vec;
-
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
- error("%s: no such array", x->x_arrayname->s_name);
- else if (!table16_getarray16(a, &vecsize, &vec))
- error("%s: bad template for tab16write", x->x_arrayname->s_name);
- else {
- int n = x->x_ft1;
- if (n < 0) n = 0;
- else if (n >= vecsize) n = vecsize-1;
- vec[n] = f;
- }
-}
-
-static void tab16write_set(t_tab16write *x, t_symbol *s){
- x->x_arrayname = s;
-}
-
-static void tab16write_free(t_tab16write *x){}
-
-static void *tab16write_new(t_symbol *s){
- t_tab16write *x = (t_tab16write *)pd_new(tab16write_class);
- x->x_ft1 = 0;
- x->x_arrayname = s;
- floatinlet_new(&x->x_obj, &x->x_ft1);
- return (x);
-}
-
-void tab16write_setup(void){
- tab16write_class = class_new(gensym("tab16write"), (t_newmethod)tab16write_new,
- (t_method)tab16write_free, sizeof(t_tab16write), 0, A_DEFSYM, 0);
- class_addfloat(tab16write_class, (t_method)tab16write_float);
- class_addmethod(tab16write_class, (t_method)tab16write_set, gensym("set"), A_SYMBOL, 0);
-}
-
-/* ------------------------ global setup routine ------------------------- */
-
-void iem16_array_setup(void){
- tab16read_setup();
- tab16read4_setup();
- tab16write_setup();
-}
-
diff --git a/src/iem16_array_tilde.c b/src/iem16_array_tilde.c
deleted file mode 100644
index 8e3dc8f..0000000
--- a/src/iem16_array_tilde.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
- * based on d_array.c from pd:
- * Copyright (c) 1997-1999 Miller Puckette and others.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
-
-#include "iem16_table.h"
-
-/* ------------------------- tab16write~ -------------------------- */
-
-static t_class *tab16write_tilde_class;
-
-typedef struct _tab16write_tilde {
- t_object x_obj;
- int x_phase;
- int x_nsampsintab;
- short *x_vec;
- t_symbol *x_arrayname;
- float x_f;
-} t_tab16write_tilde;
-
-static void *tab16write_tilde_new(t_symbol *s) {
- t_tab16write_tilde *x = (t_tab16write_tilde *)pd_new(tab16write_tilde_class);
- x->x_phase = 0x7fffffff;
- x->x_arrayname = s;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tab16write_tilde_perform(t_int *w) {
- t_tab16write_tilde *x = (t_tab16write_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
- if (!x->x_vec) goto bad;
-
- if (endphase > phase) {
- int nxfer = endphase - phase;
- t_iem16_16bit *fp = x->x_vec + phase;
- if (nxfer > n) nxfer = n;
- phase += nxfer;
- while (nxfer--)*fp++ = *in++*IEM16_SCALE_UP;
- x->x_phase = phase;
- }
- bad:
- return (w+4);
-}
-
-void tab16write_tilde_set(t_tab16write_tilde *x, t_symbol *s){
- t_table16 *a;
-
- x->x_arrayname = s;
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*s->s_name) pd_error(x, "tab16write~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!table16_getarray16(a, &x->x_nsampsintab, &x->x_vec)) {
- error("%s: bad template for tab16write~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else table16_usedindsp(a);
-}
-
-static void tab16write_tilde_dsp(t_tab16write_tilde *x, t_signal **sp){
- tab16write_tilde_set(x, x->x_arrayname);
- dsp_add(tab16write_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
-}
-
-static void tab16write_tilde_bang(t_tab16write_tilde *x){
- x->x_phase = 0;
-}
-
-static void tab16write_tilde_stop(t_tab16write_tilde *x){}
-
-static void tab16write_tilde_free(t_tab16write_tilde *x){}
-
-void tab16write_tilde_setup(void){
- tab16write_tilde_class = class_new(gensym("tab16write~"),
- (t_newmethod)tab16write_tilde_new, (t_method)tab16write_tilde_free,
- sizeof(t_tab16write_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tab16write_tilde_class, t_tab16write_tilde, x_f);
- class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_set,
- gensym("set"), A_SYMBOL, 0);
- class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_stop,
- gensym("stop"), 0);
- class_addbang(tab16write_tilde_class, tab16write_tilde_bang);
-}
-
-/* ------------ tab16play~ - non-transposing sample playback --------------- */
-
-static t_class *tab16play_tilde_class;
-
-typedef struct _tab16play_tilde{
- t_object x_obj;
- t_outlet *x_bangout;
- int x_phase;
- int x_nsampsintab;
- int x_limit;
- t_iem16_16bit *x_vec;
- t_symbol *x_arrayname;
-} t_tab16play_tilde;
-
-static void *tab16play_tilde_new(t_symbol *s){
- t_tab16play_tilde *x = (t_tab16play_tilde *)pd_new(tab16play_tilde_class);
- x->x_phase = 0x7fffffff;
- x->x_limit = 0;
- x->x_arrayname = s;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_bangout = outlet_new(&x->x_obj, gensym("bang"));
- return (x);
-}
-
-static t_int *tab16play_tilde_perform(t_int *w){
- t_tab16play_tilde *x = (t_tab16play_tilde *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_iem16_16bit *fp;
- int n = (int)(w[3]), phase = x->x_phase,
- endphase = (x->x_nsampsintab < x->x_limit ?
- x->x_nsampsintab : x->x_limit), nxfer, n3;
- if (!x->x_vec || phase >= endphase) goto zero;
-
- nxfer = endphase - phase;
- fp = x->x_vec + phase;
- if (nxfer > n)
- nxfer = n;
- n3 = n - nxfer;
- phase += nxfer;
- while (nxfer--) *out++ = *fp++*IEM16_SCALE_DOWN;
- if (phase >= endphase) {
- x->x_phase = 0x7fffffff;
- while (n3--) *out++ = 0;
- }
- else x->x_phase = phase;
-
- return (w+4);
- zero:
- while (n--) *out++ = 0;
- return (w+4);
-}
-
-void tab16play_tilde_set(t_tab16play_tilde *x, t_symbol *s){
- t_table16 *a;
-
- x->x_arrayname = s;
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*s->s_name) pd_error(x, "tab16play~: %s: no such array",
- x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!table16_getarray16(a, &x->x_nsampsintab, &x->x_vec)) {
- error("%s: bad template for tab16play~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else table16_usedindsp(a);
-}
-
-static void tab16play_tilde_dsp(t_tab16play_tilde *x, t_signal **sp){
- tab16play_tilde_set(x, x->x_arrayname);
- dsp_add(tab16play_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
-}
-
-static void tab16play_tilde_list(t_tab16play_tilde *x, t_symbol *s,
- int argc, t_atom *argv){
- long start = atom_getfloatarg(0, argc, argv);
- long length = atom_getfloatarg(1, argc, argv);
- if (start < 0) start = 0;
- if (length <= 0)x->x_limit = 0x7fffffff;
- else x->x_limit = start + length;
- x->x_phase = start;
-}
-
-static void tab16play_tilde_stop(t_tab16play_tilde *x){
- x->x_phase = 0x7fffffff;
-}
-
-static void tab16play_tilde_free(t_tab16play_tilde *x){}
-
-void tab16play_tilde_setup(void){
- tab16play_tilde_class = class_new(gensym("tab16play~"),
- (t_newmethod)tab16play_tilde_new, (t_method)tab16play_tilde_free,
- sizeof(t_tab16play_tilde), 0, A_DEFSYM, 0);
- class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_stop,
- gensym("stop"), 0);
- class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_set,
- gensym("set"), A_DEFSYM, 0);
- class_addlist(tab16play_tilde_class, tab16play_tilde_list);
-}
-
-/* ------------------------ tab16send~ ------------------------- */
-
-static t_class *tab16send_class;
-
-typedef struct _tab16send{
- t_object x_obj;
- t_iem16_16bit *x_vec;
- int x_graphperiod;
- int x_graphcount;
- t_symbol *x_arrayname;
- float x_f;
-} t_tab16send;
-
-static void *tab16send_new(t_symbol *s){
- t_tab16send *x = (t_tab16send *)pd_new(tab16send_class);
- x->x_graphcount = 0;
- x->x_arrayname = s;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tab16send_perform(t_int *w){
- t_tab16send *x = (t_tab16send *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- int n = w[3];
- t_iem16_16bit *dest = x->x_vec;
- int i = x->x_graphcount;
- if (!x->x_vec) goto bad;
-
- while (n--) *dest = *in++*IEM16_SCALE_UP;
- if (!i--)i = x->x_graphperiod;
- x->x_graphcount = i;
- bad:
- return (w+4);
-}
-
-static void tab16send_dsp(t_tab16send *x, t_signal **sp){
- int vecsize;
- t_table16 *a;
-
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*x->x_arrayname->s_name)
- error("tab16send~: %s: no such array", x->x_arrayname->s_name);
- }
- else if (!table16_getarray16(a, &vecsize, &x->x_vec))
- error("%s: bad template for tab16send~", x->x_arrayname->s_name);
- else {
- int n = sp[0]->s_n;
- int ticksper = sp[0]->s_sr/n;
- if (ticksper < 1) ticksper = 1;
- x->x_graphperiod = ticksper;
- if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
- if (n < vecsize) vecsize = n;
- table16_usedindsp(a);
- dsp_add(tab16send_perform, 3, x, sp[0]->s_vec, vecsize);
- }
-}
-
-static void tab16send_free(t_tab16send *x){}
-
-static void tab16send_setup(void){
- tab16send_class = class_new(gensym("tab16send~"), (t_newmethod)tab16send_new,
- (t_method)tab16send_free, sizeof(t_tab16send), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tab16send_class, t_tab16send, x_f);
- class_addmethod(tab16send_class, (t_method)tab16send_dsp, gensym("dsp"), 0);
-}
-
-// G.Holzmann: for PD-extended build system
-void tab16send_tilde_setup(void)
-{
- tab16send_setup();
-}
-
-/* ------------------------ tab16receive~ ------------------------- */
-
-static t_class *tab16receive_class;
-
-typedef struct _tab16receive{
- t_object x_obj;
- t_iem16_16bit *x_vec;
- t_symbol *x_arrayname;
-} t_tab16receive;
-
-static t_int *tab16receive_perform(t_int *w){
- t_tab16receive *x = (t_tab16receive *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- int n = w[3];
- t_iem16_16bit *from = x->x_vec;
- if (from) while (n--) *out++ = *from++*IEM16_SCALE_DOWN;
- else while (n--) *out++ = 0;
- return (w+4);
-}
-
-static void tab16receive_dsp(t_tab16receive *x, t_signal **sp){
- t_table16 *a;
- int vecsize;
-
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*x->x_arrayname->s_name)
- error("tab16send~: %s: no such array", x->x_arrayname->s_name);
- }
- else if (!table16_getarray16(a, &vecsize, &x->x_vec))
- error("%s: bad template for tab16receive~", x->x_arrayname->s_name);
- else {
- int n = sp[0]->s_n;
- if (n < vecsize) vecsize = n;
- table16_usedindsp(a);
- dsp_add(tab16receive_perform, 3, x, sp[0]->s_vec, vecsize);
- }
-}
-
-static void *tab16receive_new(t_symbol *s){
- t_tab16receive *x = (t_tab16receive *)pd_new(tab16receive_class);
- x->x_arrayname = s;
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-static void tab16receive_setup(void){
- tab16receive_class = class_new(gensym("tab16receive~"),
- (t_newmethod)tab16receive_new, 0,
- sizeof(t_tab16receive), 0, A_DEFSYM, 0);
- class_addmethod(tab16receive_class, (t_method)tab16receive_dsp,
- gensym("dsp"), 0);
-}
-
-// G.Holzmann: for PD-extended build system
-void tab16receive_tilde_setup(void)
-{
- tab16receive_setup();
-}
-
-/******************** tab16read~ ***********************/
-
-static t_class *tab16read_tilde_class;
-
-typedef struct _tab16read_tilde{
- t_object x_obj;
- int x_npoints;
- t_iem16_16bit *x_vec;
- t_symbol *x_arrayname;
- float x_f;
-} t_tab16read_tilde;
-
-static void *tab16read_tilde_new(t_symbol *s){
- t_tab16read_tilde *x = (t_tab16read_tilde *)pd_new(tab16read_tilde_class);
- x->x_arrayname = s;
- x->x_vec = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tab16read_tilde_perform(t_int *w){
- t_tab16read_tilde *x = (t_tab16read_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int maxindex;
- t_iem16_16bit *buf = x->x_vec;
- int i;
-
- maxindex = x->x_npoints - 1;
- if (!buf) goto zero;
-
- for (i = 0; i < n; i++) {
- int index = *in++;
- if (index < 0) index = 0;
- else if (index > maxindex) index = maxindex;
- *out++ = buf[index]*IEM16_SCALE_DOWN;
- }
- return (w+5);
- zero:
- while (n--) *out++ = 0;
-
- return (w+5);
-}
-
-void tab16read_tilde_set(t_tab16read_tilde *x, t_symbol *s){
- t_table16 *a;
-
- x->x_arrayname = s;
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*s->s_name)
- error("tab16read~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!table16_getarray16(a, &x->x_npoints, &x->x_vec)) {
- error("%s: bad template for tab16read~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else table16_usedindsp(a);
-}
-
-static void tab16read_tilde_dsp(t_tab16read_tilde *x, t_signal **sp){
- tab16read_tilde_set(x, x->x_arrayname);
-
- dsp_add(tab16read_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-
-}
-
-static void tab16read_tilde_free(t_tab16read_tilde *x){}
-
-void tab16read_tilde_setup(void){
- tab16read_tilde_class = class_new(gensym("tab16read~"),
- (t_newmethod)tab16read_tilde_new, (t_method)tab16read_tilde_free,
- sizeof(t_tab16read_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tab16read_tilde_class, t_tab16read_tilde, x_f);
- class_addmethod(tab16read_tilde_class, (t_method)tab16read_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tab16read_tilde_class, (t_method)tab16read_tilde_set,
- gensym("set"), A_SYMBOL, 0);
-}
-
-/******************** tab16read4~ ***********************/
-
-static t_class *tab16read4_tilde_class;
-
-typedef struct _tab16read4_tilde{
- t_object x_obj;
- int x_npoints;
- t_iem16_16bit *x_vec;
- t_symbol *x_arrayname;
- float x_f;
-} t_tab16read4_tilde;
-
-static void *tab16read4_tilde_new(t_symbol *s){
- t_tab16read4_tilde *x = (t_tab16read4_tilde *)pd_new(tab16read4_tilde_class);
- x->x_arrayname = s;
- x->x_vec = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *tab16read4_tilde_perform(t_int *w){
- t_tab16read4_tilde *x = (t_tab16read4_tilde *)(w[1]);
- t_float *in = (t_float *)(w[2]);
- t_float *out = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int maxindex;
- t_iem16_16bit *buf = x->x_vec;
- t_iem16_16bit *fp;
- int i;
-
- maxindex = x->x_npoints - 3;
-
- if (!buf) goto zero;
-
- for (i = 0; i < n; i++) {
- float findex = *in++;
- int index = findex;
- float frac, a, b, c, d, cminusb;
- if (index < 1) index = 1, frac = 0;
- else if (index > maxindex) index = maxindex, frac = 1;
- else frac = findex - index;
- fp = buf + index;
- a = fp[-1]*IEM16_SCALE_DOWN;
- b = fp[0]*IEM16_SCALE_DOWN;
- c = fp[1]*IEM16_SCALE_DOWN;
- d = fp[2]*IEM16_SCALE_DOWN;
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.5f * (frac-1.) * (
- (a - d + 3.0f * cminusb) * frac + (b - a - cminusb)
- )
- );
- }
- return (w+5);
- zero:
- while (n--) *out++ = 0;
-
- return (w+5);
-}
-
-void tab16read4_tilde_set(t_tab16read4_tilde *x, t_symbol *s){
- t_table16 *a;
-
- x->x_arrayname = s;
- if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
- if (*s->s_name)
- error("tab16read4~: %s: no such array", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else if (!table16_getarray16(a, &x->x_npoints, &x->x_vec)) {
- error("%s: bad template for tab16read4~", x->x_arrayname->s_name);
- x->x_vec = 0;
- }
- else table16_usedindsp(a);
-}
-
-static void tab16read4_tilde_dsp(t_tab16read4_tilde *x, t_signal **sp){
- tab16read4_tilde_set(x, x->x_arrayname);
-
- dsp_add(tab16read4_tilde_perform, 4, x,
- sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
-}
-
-void tab16read4_tilde_setup(void){
- tab16read4_tilde_class = class_new(gensym("tab16read4~"),
- (t_newmethod)tab16read4_tilde_new, 0,
- sizeof(t_tab16read4_tilde), 0, A_DEFSYM, 0);
- CLASS_MAINSIGNALIN(tab16read4_tilde_class, t_tab16read4_tilde, x_f);
- class_addmethod(tab16read4_tilde_class, (t_method)tab16read4_tilde_dsp,
- gensym("dsp"), 0);
- class_addmethod(tab16read4_tilde_class, (t_method)tab16read4_tilde_set,
- gensym("set"), A_SYMBOL, 0);
-}
-/* ------------------------ global setup routine ------------------------- */
-
-void iem16_array_tilde_setup(void){
- tab16write_tilde_setup();
- tab16play_tilde_setup();
- tab16read_tilde_setup();
- tab16read4_tilde_setup();
- tab16send_setup();
- tab16receive_setup();
-}
-
diff --git a/src/iem16_delay.c b/src/iem16_delay.c
deleted file mode 100755
index 8d29ba0..0000000
--- a/src/iem16_delay.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
- * based on d_delay.c from pd:
- * Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
-/* del16read~, del16write~, vd16~ */
-
-#include "iem16_table.h"
-
-#if defined __WIN32 || defined __WIN32__
-static int ugen_getsortno(void){return 0;}
-#else
-extern int ugen_getsortno(void);
-#endif
-
-#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
-
-/* ----------------------------- del16write~ ----------------------------- */
-static t_class *sigdel16write_class;
-
-typedef struct del16writectl{
- int c_n;
- t_iem16_16bit *c_vec;
- int c_phase;
-} t_del16writectl;
-
-typedef struct _sigdel16write{
- t_object x_obj;
- t_symbol *x_sym;
- t_del16writectl x_cspace;
- int x_sortno; /* DSP sort number at which this was last put on chain */
- int x_rsortno; /* DSP sort # for first del16read or write in chain */
- int x_vecsize; /* vector size for del16read~ to use */
- float x_f;
-} t_sigdel16write;
-
-#define XTRASAMPS 4
-#define SAMPBLK 4
-
-/* routine to check that all del16writes/del16reads/vds have same vecsize */
-static void sigdel16write_checkvecsize(t_sigdel16write *x, int vecsize){
- if (x->x_rsortno != ugen_getsortno()) {
- x->x_vecsize = vecsize;
- x->x_rsortno = ugen_getsortno();
- }
- else if (vecsize != x->x_vecsize)
- pd_error(x, "del16read/del16write/vd vector size mismatch");
-}
-
-static void *sigdel16write_new(t_symbol *s, t_floatarg msec){
- int nsamps;
- t_sigdel16write *x = (t_sigdel16write *)pd_new(sigdel16write_class);
- if (!*s->s_name) s = gensym("del16write~");
- pd_bind(&x->x_obj.ob_pd, s);
- x->x_sym = s;
- nsamps = msec * sys_getsr() * (float)(0.001f);
- if (nsamps < 1) nsamps = 1;
- nsamps += ((- nsamps) & (SAMPBLK - 1));
- nsamps += DEFDELVS;
- x->x_cspace.c_n = nsamps;
- x->x_cspace.c_vec =
- (t_iem16_16bit *)getbytes((nsamps + XTRASAMPS) * sizeof(t_iem16_16bit));
- x->x_cspace.c_phase = XTRASAMPS;
- x->x_sortno = 0;
- x->x_vecsize = 0;
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sigdel16write_perform(t_int *w){
- t_float *in = (t_float *)(w[1]);
- t_del16writectl *c = (t_del16writectl *)(w[2]);
- int n = (int)(w[3]);
- int phase = c->c_phase, nsamps = c->c_n;
- t_iem16_16bit *vp = c->c_vec, *bp = vp + phase, *ep = vp + (c->c_n + XTRASAMPS);
- phase += n;
- while (n--) {
- *bp++ = (*in++*IEM16_SCALE_UP);
- if (bp == ep) {
- vp[0] = ep[-4];
- vp[1] = ep[-3];
- vp[2] = ep[-2];
- vp[3] = ep[-1];
- bp = vp + XTRASAMPS;
- phase -= nsamps;
- }
- }
- c->c_phase = phase;
- return (w+4);
-}
-
-static void sigdel16write_dsp(t_sigdel16write *x, t_signal **sp){
- dsp_add(sigdel16write_perform, 3, sp[0]->s_vec, &x->x_cspace, sp[0]->s_n);
- x->x_sortno = ugen_getsortno();
- sigdel16write_checkvecsize(x, sp[0]->s_n);
-}
-
-static void sigdel16write_free(t_sigdel16write *x){
- pd_unbind(&x->x_obj.ob_pd, x->x_sym);
- freebytes(x->x_cspace.c_vec,
- (x->x_cspace.c_n + XTRASAMPS) * sizeof(t_iem16_16bit));
-}
-
-static void sigdel16write_setup(void){
- sigdel16write_class = class_new(gensym("del16write~"),
- (t_newmethod)sigdel16write_new, (t_method)sigdel16write_free,
- sizeof(t_sigdel16write), 0, A_DEFSYM, A_DEFFLOAT, 0);
- CLASS_MAINSIGNALIN(sigdel16write_class, t_sigdel16write, x_f);
- class_addmethod(sigdel16write_class, (t_method)sigdel16write_dsp,
- gensym("dsp"), 0);
-}
-
-// G.Holzmann: for PD-extended build system
-void del16write_tilde_setup(void)
-{
- sigdel16write_setup();
-}
-
-/* ----------------------------- del16read~ ----------------------------- */
-static t_class *sigdel16read_class;
-
-typedef struct _sigdel16read{
- t_object x_obj;
- t_symbol *x_sym;
- t_float x_deltime; /* delay in msec */
- int x_delsamps; /* delay in samples */
- t_float x_sr; /* samples per msec */
- t_float x_n; /* vector size */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
-} t_sigdel16read;
-
-static void sigdel16read_16bit(t_sigdel16read *x, t_float f);
-
-static void *sigdel16read_new(t_symbol *s, t_floatarg f){
- t_sigdel16read *x = (t_sigdel16read *)pd_new(sigdel16read_class);
- x->x_sym = s;
- x->x_sr = 1;
- x->x_n = 1;
- x->x_zerodel = 0;
- sigdel16read_16bit(x, f);
- outlet_new(&x->x_obj, gensym("signal"));
- return (x);
-}
-
-static void sigdel16read_16bit(t_sigdel16read *x, t_float f){
- t_sigdel16write *delwriter =
- (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
- x->x_deltime = f;
- if (delwriter) {
- x->x_delsamps = (int)(0.5 + x->x_sr * x->x_deltime)
- + x->x_n - x->x_zerodel;
- if (x->x_delsamps < x->x_n) x->x_delsamps = x->x_n;
- else if (x->x_delsamps > delwriter->x_cspace.c_n - DEFDELVS)
- x->x_delsamps = delwriter->x_cspace.c_n - DEFDELVS;
- }
-}
-
-static t_int *sigdel16read_perform(t_int *w){
- t_float *out = (t_float *)(w[1]);
- t_del16writectl *c = (t_del16writectl *)(w[2]);
- int delsamps = *(int *)(w[3]);
- int n = (int)(w[4]);
- int phase = c->c_phase - delsamps, nsamps = c->c_n;
- t_iem16_16bit *vp = c->c_vec, *bp, *ep = vp + (c->c_n + XTRASAMPS);
-
- if (phase < 0) phase += nsamps;
- bp = vp + phase;
- while (n--) {
- *out++ = *bp++*IEM16_SCALE_DOWN;
- if (bp == ep) bp -= nsamps;
- }
- return (w+5);
-}
-
-static void sigdel16read_dsp(t_sigdel16read *x, t_signal **sp){
- t_sigdel16write *delwriter =
- (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
- x->x_sr = sp[0]->s_sr * 0.001;
- x->x_n = sp[0]->s_n;
- if (delwriter) {
- sigdel16write_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- sigdel16read_16bit(x, x->x_deltime);
- dsp_add(sigdel16read_perform, 4,
- sp[0]->s_vec, &delwriter->x_cspace, &x->x_delsamps, sp[0]->s_n);
- }
- else if (*x->x_sym->s_name)
- error("delread~: %s: no such delwrite~",x->x_sym->s_name);
-}
-
-static void sigdel16read_setup(void){
- sigdel16read_class = class_new(gensym("del16read~"),
- (t_newmethod)sigdel16read_new, 0,
- sizeof(t_sigdel16read), 0, A_DEFSYM, A_DEFFLOAT, 0);
- class_addmethod(sigdel16read_class, (t_method)sigdel16read_dsp,
- gensym("dsp"), 0);
- class_addfloat(sigdel16read_class, (t_method)sigdel16read_16bit);
-}
-
-// G.Holzmann: for PD-extended build system
-void del16read_tilde_setup(void)
-{
- sigdel16read_setup();
-}
-
-/* ----------------------------- vd~ ----------------------------- */
-static t_class *sig16vd_class;
-
-typedef struct _sig16vd{
- t_object x_obj;
- t_symbol *x_sym;
- t_float x_sr; /* samples per msec */
- int x_zerodel; /* 0 or vecsize depending on read/write order */
- float x_f;
-} t_sig16vd;
-
-static void *sig16vd_new(t_symbol *s){
- t_sig16vd *x = (t_sig16vd *)pd_new(sig16vd_class);
- if (!*s->s_name) s = gensym("vd~");
- x->x_sym = s;
- x->x_sr = 1;
- x->x_zerodel = 0;
- outlet_new(&x->x_obj, gensym("signal"));
- x->x_f = 0;
- return (x);
-}
-
-static t_int *sig16vd_perform(t_int *w){
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_del16writectl *ctl = (t_del16writectl *)(w[3]);
- t_sig16vd *x = (t_sig16vd *)(w[4]);
- int n = (int)(w[5]);
-
- int nsamps = ctl->c_n;
- float limit = nsamps - n - 1;
- float fn = n-4;
- t_iem16_16bit *vp = ctl->c_vec, *bp, *wp = vp + ctl->c_phase;
- float zerodel = x->x_zerodel;
- while (n--) {
- float delsamps = x->x_sr * *in++ - zerodel, frac;
- int idelsamps;
- float a, b, c, d, cminusb;
- if (delsamps < 1.00001f) delsamps = 1.00001f;
- if (delsamps > limit) delsamps = limit;
- delsamps += fn;
- fn = fn - 1.0f;
- idelsamps = delsamps;
- frac = delsamps - (float)idelsamps;
- bp = wp - (idelsamps + 3);
- if (bp < vp + 4) bp += nsamps;
- d = bp[-3]*IEM16_SCALE_DOWN;
- c = bp[-2]*IEM16_SCALE_DOWN;
- b = bp[-1]*IEM16_SCALE_DOWN;
- a = bp[00]*IEM16_SCALE_DOWN;
- cminusb = c-b;
- *out++ = b + frac * (
- cminusb - 0.5f * (frac-1.) * (
- (a - d + 3.0f * cminusb) * frac + (b - a - cminusb)
- )
- );
- }
- return (w+6);
-}
-
-static void sig16vd_dsp(t_sig16vd *x, t_signal **sp){
- t_sigdel16write *delwriter =
- (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
- x->x_sr = sp[0]->s_sr * 0.001;
- if (delwriter) {
- sigdel16write_checkvecsize(delwriter, sp[0]->s_n);
- x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
- 0 : delwriter->x_vecsize);
- dsp_add(sig16vd_perform, 5,
- sp[0]->s_vec, sp[1]->s_vec,
- &delwriter->x_cspace, x, sp[0]->s_n);
- }
- else error("vd~: %s: no such delwrite~",x->x_sym->s_name);
-}
-
-static void sig16vd_setup(void){
- sig16vd_class = class_new(gensym("vd16~"), (t_newmethod)sig16vd_new, 0,
- sizeof(t_sig16vd), 0, A_DEFSYM, 0);
- class_addmethod(sig16vd_class, (t_method)sig16vd_dsp, gensym("dsp"), 0);
- CLASS_MAINSIGNALIN(sig16vd_class, t_sig16vd, x_f);
-}
-
-// G.Holzmann: for PD-extended build system
-void vd16_tilde_setup(void)
-{
- sig16vd_setup();
-}
-
-/* ----------------------- global setup routine ---------------- */
-
-void iem16_delay_setup(void){
- sigdel16write_setup();
- sigdel16read_setup();
- sig16vd_setup();
-}
-
diff --git a/src/iem16_delay.h b/src/iem16_delay.h
new file mode 100644
index 0000000..f3db27b
--- /dev/null
+++ b/src/iem16_delay.h
@@ -0,0 +1,51 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#ifndef INCLUDE_IEM16_DELAY_H__
+#define INCLUDE_IEM16_DELAY_H__
+
+/* sampling */
+
+#include "iem16.h"
+#include <string.h>
+
+
+#if defined __WIN32 || defined __WIN32__
+static int ugen_getsortno(void){return 0;}
+#else
+extern int ugen_getsortno(void);
+#endif
+
+
+t_class *sigdel16write_class;
+
+typedef struct del16writectl{
+ int c_n;
+ t_iem16_16bit *c_vec;
+ int c_phase;
+} t_del16writectl;
+
+typedef struct _sigdel16write{
+ t_object x_obj;
+ t_symbol *x_sym;
+ t_del16writectl x_cspace;
+ int x_sortno; /* DSP sort number at which this was last put on chain */
+ int x_rsortno; /* DSP sort # for first del16read or write in chain */
+ int x_vecsize; /* vector size for del16read~ to use */
+ float x_f;
+} t_sigdel16write;
+
+
+void sigdel16write_checkvecsize(t_sigdel16write *x, int vecsize);
+
+
+# define XTRASAMPS 4
+# define SAMPBLK 4
+
+
+#define DEFDELVS 64 /* LATER get this from canvas at DSP time */
+
+#endif
diff --git a/src/iem16_table.h b/src/iem16_table.h
index 7f285da..506fd8a 100644
--- a/src/iem16_table.h
+++ b/src/iem16_table.h
@@ -31,55 +31,6 @@ EXTERN int table16_getarray16(t_table16*x, int*size,t_iem16_16bit**vec);
EXTERN void table16_usedindsp(t_table16*x);
-#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
-
- /* machine-dependent definitions. These ifdefs really
- should have been by CPU type and not by operating system! */
-#ifdef __irix__
- /* big-endian. Most significant byte is at low address in memory */
-# define HIOFFSET 0 /* word offset to find MSB */
-# define LOWOFFSET 1 /* word offset to find LSB */
-# define int32 long /* a data type that has 32 bits */
-#elif defined __WIN32__
- /* little-endian; most significant byte is at highest address */
-# define HIOFFSET 1
-# define LOWOFFSET 0
-# define int32 long
-#elif defined __FreeBSD__
-# include <machine/endian.h>
-# if BYTE_ORDER == LITTLE_ENDIAN
-# define HIOFFSET 1
-# define LOWOFFSET 0
-# else
-# define HIOFFSET 0 /* word offset to find MSB */
-# define LOWOFFSET 1 /* word offset to find LSB */
-# endif /* BYTE_ORDER */
-# include <sys/types.h>
-# define int32 int32_t
-#elif defined __linux__
-# include <endian.h>
-# if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
-# error No byte order defined
-# endif
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-# define HIOFFSET 1
-# define LOWOFFSET 0
-# else
-# define HIOFFSET 0 /* word offset to find MSB */
-# define LOWOFFSET 1 /* word offset to find LSB */
-# endif /* __BYTE_ORDER */
-# include <sys/types.h>
-# define int32 int32_t
-#elif defined __APPLE__
-# ifdef __BIG_ENDIAN__
-# define HIOFFSET 0 /* word offset to find MSB */
-# define LOWOFFSET 1 /* word offset to find LSB */
-# else
-# define HIOFFSET 1
-# define LOWOFFSET 0
-# endif
-# define int32 int /* a data type that has 32 bits */
-#endif /* system */
union tabfudge
{
diff --git a/src/tab16play~.c b/src/tab16play~.c
new file mode 100644
index 0000000..23be427
--- /dev/null
+++ b/src/tab16play~.c
@@ -0,0 +1,112 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+
+/* ------------ tab16play~ - non-transposing sample playback --------------- */
+
+static t_class *tab16play_tilde_class;
+
+typedef struct _tab16play_tilde{
+ t_object x_obj;
+ t_outlet *x_bangout;
+ int x_phase;
+ int x_nsampsintab;
+ int x_limit;
+ t_iem16_16bit *x_vec;
+ t_symbol *x_arrayname;
+} t_tab16play_tilde;
+
+static void *tab16play_tilde_new(t_symbol *s){
+ t_tab16play_tilde *x = (t_tab16play_tilde *)pd_new(tab16play_tilde_class);
+ x->x_phase = 0x7fffffff;
+ x->x_limit = 0;
+ x->x_arrayname = s;
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_bangout = outlet_new(&x->x_obj, gensym("bang"));
+ return (x);
+}
+
+static t_int *tab16play_tilde_perform(t_int *w){
+ t_tab16play_tilde *x = (t_tab16play_tilde *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_iem16_16bit *fp;
+ int n = (int)(w[3]), phase = x->x_phase,
+ endphase = (x->x_nsampsintab < x->x_limit ?
+ x->x_nsampsintab : x->x_limit), nxfer, n3;
+ if (!x->x_vec || phase >= endphase) goto zero;
+
+ nxfer = endphase - phase;
+ fp = x->x_vec + phase;
+ if (nxfer > n)
+ nxfer = n;
+ n3 = n - nxfer;
+ phase += nxfer;
+ while (nxfer--) *out++ = *fp++*IEM16_SCALE_DOWN;
+ if (phase >= endphase) {
+ x->x_phase = 0x7fffffff;
+ while (n3--) *out++ = 0;
+ }
+ else x->x_phase = phase;
+
+ return (w+4);
+ zero:
+ while (n--) *out++ = 0;
+ return (w+4);
+}
+
+void tab16play_tilde_set(t_tab16play_tilde *x, t_symbol *s){
+ t_table16 *a;
+
+ x->x_arrayname = s;
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*s->s_name) pd_error(x, "tab16play~: %s: no such array",
+ x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else if (!table16_getarray16(a, &x->x_nsampsintab, &x->x_vec)) {
+ error("%s: bad template for tab16play~", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else table16_usedindsp(a);
+}
+
+static void tab16play_tilde_dsp(t_tab16play_tilde *x, t_signal **sp){
+ tab16play_tilde_set(x, x->x_arrayname);
+ dsp_add(tab16play_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+static void tab16play_tilde_list(t_tab16play_tilde *x, t_symbol *s,
+ int argc, t_atom *argv){
+ long start = atom_getfloatarg(0, argc, argv);
+ long length = atom_getfloatarg(1, argc, argv);
+ if (start < 0) start = 0;
+ if (length <= 0)x->x_limit = 0x7fffffff;
+ else x->x_limit = start + length;
+ x->x_phase = start;
+}
+
+static void tab16play_tilde_stop(t_tab16play_tilde *x){
+ x->x_phase = 0x7fffffff;
+}
+
+static void tab16play_tilde_free(t_tab16play_tilde *x){}
+
+void tab16play_tilde_setup(void){
+ tab16play_tilde_class = class_new(gensym("tab16play~"),
+ (t_newmethod)tab16play_tilde_new, (t_method)tab16play_tilde_free,
+ sizeof(t_tab16play_tilde), 0, A_DEFSYM, 0);
+ class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_dsp,
+ gensym("dsp"), 0);
+ class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_stop,
+ gensym("stop"), 0);
+ class_addmethod(tab16play_tilde_class, (t_method)tab16play_tilde_set,
+ gensym("set"), A_DEFSYM, 0);
+ class_addlist(tab16play_tilde_class, tab16play_tilde_list);
+}
diff --git a/src/tab16read.c b/src/tab16read.c
new file mode 100644
index 0000000..17b6c5c
--- /dev/null
+++ b/src/tab16read.c
@@ -0,0 +1,54 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16read, tab16read4, tab16write */
+
+#include "iem16_table.h"
+
+/* ---------- tab16read: control, non-interpolating ------------------------ */
+
+static t_class *tab16read_class;
+
+typedef struct _tab16read{
+ t_object x_obj;
+ t_symbol *x_arrayname;
+} t_tab16read;
+
+static void tab16read_float(t_tab16read *x, t_float f){
+ t_table16 *a;
+ int npoints;
+ t_iem16_16bit *vec;
+
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
+ error("%s: no such array", x->x_arrayname->s_name);
+ else if (!table16_getarray16(a, &npoints, &vec))
+ error("%s: bad template for tab16read", x->x_arrayname->s_name);
+ else {
+ int n = f;
+ if (n < 0) n = 0;
+ else if (n >= npoints) n = npoints - 1;
+ outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0));
+ }
+}
+
+static void tab16read_set(t_tab16read *x, t_symbol *s){
+ x->x_arrayname = s;
+}
+
+static void *tab16read_new(t_symbol *s){
+ t_tab16read *x = (t_tab16read *)pd_new(tab16read_class);
+ x->x_arrayname = s;
+ outlet_new(&x->x_obj, gensym("float"));
+ return (x);
+}
+
+void tab16read_setup(void){
+ tab16read_class = class_new(gensym("tab16read"), (t_newmethod)tab16read_new,
+ 0, sizeof(t_tab16read), 0, A_DEFSYM, 0);
+ class_addfloat(tab16read_class, (t_method)tab16read_float);
+ class_addmethod(tab16read_class, (t_method)tab16read_set, gensym("set"),
+ A_SYMBOL, 0);
+}
diff --git a/src/tab16read4.c b/src/tab16read4.c
new file mode 100644
index 0000000..0d37979
--- /dev/null
+++ b/src/tab16read4.c
@@ -0,0 +1,70 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16read, tab16read4, tab16write */
+
+#include "iem16_table.h"
+
+/* ---------- tab16read4: control, non-interpolating ------------------------ */
+
+static t_class *tab16read4_class;
+
+typedef struct _tab16read4{
+ t_object x_obj;
+ t_symbol *x_arrayname;
+} t_tab16read4;
+
+static void tab16read4_float(t_tab16read4 *x, t_float f){
+ t_table16 *a;
+ int npoints;
+ t_iem16_16bit *vec;
+
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
+ error("%s: no such array", x->x_arrayname->s_name);
+ else if (!table16_getarray16(a, &npoints, &vec))
+ error("%s: bad template for tab16read4", x->x_arrayname->s_name);
+ else if (npoints < 4)
+ outlet_float(x->x_obj.ob_outlet, 0);
+ else if (f <= 1)
+ outlet_float(x->x_obj.ob_outlet, vec[1]);
+ else if (f >= npoints - 2)
+ outlet_float(x->x_obj.ob_outlet, vec[npoints - 2]);
+ else {
+ int n = f;
+ float a, b, c, d, cminusb, frac;
+ t_iem16_16bit *fp;
+ if (n >= npoints - 2) n = npoints - 3;
+ fp = vec + n;
+ frac = f - n;
+ a = fp[-1];
+ b = fp[0];
+ c = fp[1];
+ d = fp[2];
+ cminusb = c-b;
+ outlet_float(x->x_obj.ob_outlet, b + frac * (
+ cminusb - 0.5f * (frac-1.) * (
+ (a - d + 3.0f * cminusb) * frac + (b - a - cminusb))));
+ }
+}
+
+static void tab16read4_set(t_tab16read4 *x, t_symbol *s){
+ x->x_arrayname = s;
+}
+
+static void *tab16read4_new(t_symbol *s){
+ t_tab16read4 *x = (t_tab16read4 *)pd_new(tab16read4_class);
+ x->x_arrayname = s;
+ outlet_new(&x->x_obj, gensym("float"));
+ return (x);
+}
+
+void tab16read4_setup(void){
+ tab16read4_class = class_new(gensym("tab16read4"), (t_newmethod)tab16read4_new,
+ 0, sizeof(t_tab16read4), 0, A_DEFSYM, 0);
+ class_addfloat(tab16read4_class, (t_method)tab16read4_float);
+ class_addmethod(tab16read4_class, (t_method)tab16read4_set, gensym("set"),
+ A_SYMBOL, 0);
+}
diff --git a/src/tab16read4~.c b/src/tab16read4~.c
new file mode 100644
index 0000000..5a9b9f8
--- /dev/null
+++ b/src/tab16read4~.c
@@ -0,0 +1,105 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+
+/******************** tab16read4~ ***********************/
+
+static t_class *tab16read4_tilde_class;
+
+typedef struct _tab16read4_tilde{
+ t_object x_obj;
+ int x_npoints;
+ t_iem16_16bit *x_vec;
+ t_symbol *x_arrayname;
+ float x_f;
+} t_tab16read4_tilde;
+
+static void *tab16read4_tilde_new(t_symbol *s){
+ t_tab16read4_tilde *x = (t_tab16read4_tilde *)pd_new(tab16read4_tilde_class);
+ x->x_arrayname = s;
+ x->x_vec = 0;
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *tab16read4_tilde_perform(t_int *w){
+ t_tab16read4_tilde *x = (t_tab16read4_tilde *)(w[1]);
+ t_float *in = (t_float *)(w[2]);
+ t_float *out = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+ int maxindex;
+ t_iem16_16bit *buf = x->x_vec;
+ t_iem16_16bit *fp;
+ int i;
+
+ maxindex = x->x_npoints - 3;
+
+ if (!buf) goto zero;
+
+ for (i = 0; i < n; i++) {
+ float findex = *in++;
+ int index = findex;
+ float frac, a, b, c, d, cminusb;
+ if (index < 1) index = 1, frac = 0;
+ else if (index > maxindex) index = maxindex, frac = 1;
+ else frac = findex - index;
+ fp = buf + index;
+ a = fp[-1]*IEM16_SCALE_DOWN;
+ b = fp[0]*IEM16_SCALE_DOWN;
+ c = fp[1]*IEM16_SCALE_DOWN;
+ d = fp[2]*IEM16_SCALE_DOWN;
+ cminusb = c-b;
+ *out++ = b + frac * (
+ cminusb - 0.5f * (frac-1.) * (
+ (a - d + 3.0f * cminusb) * frac + (b - a - cminusb)
+ )
+ );
+ }
+ return (w+5);
+ zero:
+ while (n--) *out++ = 0;
+
+ return (w+5);
+}
+
+void tab16read4_tilde_set(t_tab16read4_tilde *x, t_symbol *s){
+ t_table16 *a;
+
+ x->x_arrayname = s;
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*s->s_name)
+ error("tab16read4~: %s: no such array", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else if (!table16_getarray16(a, &x->x_npoints, &x->x_vec)) {
+ error("%s: bad template for tab16read4~", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else table16_usedindsp(a);
+}
+
+static void tab16read4_tilde_dsp(t_tab16read4_tilde *x, t_signal **sp){
+ tab16read4_tilde_set(x, x->x_arrayname);
+
+ dsp_add(tab16read4_tilde_perform, 4, x,
+ sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+void tab16read4_tilde_setup(void){
+ tab16read4_tilde_class = class_new(gensym("tab16read4~"),
+ (t_newmethod)tab16read4_tilde_new, 0,
+ sizeof(t_tab16read4_tilde), 0, A_DEFSYM, 0);
+ CLASS_MAINSIGNALIN(tab16read4_tilde_class, t_tab16read4_tilde, x_f);
+ class_addmethod(tab16read4_tilde_class, (t_method)tab16read4_tilde_dsp,
+ gensym("dsp"), 0);
+ class_addmethod(tab16read4_tilde_class, (t_method)tab16read4_tilde_set,
+ gensym("set"), A_SYMBOL, 0);
+}
diff --git a/src/tab16read~.c b/src/tab16read~.c
new file mode 100644
index 0000000..ff3d343
--- /dev/null
+++ b/src/tab16read~.c
@@ -0,0 +1,93 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+
+/******************** tab16read~ ***********************/
+
+static t_class *tab16read_tilde_class;
+
+typedef struct _tab16read_tilde{
+ t_object x_obj;
+ int x_npoints;
+ t_iem16_16bit *x_vec;
+ t_symbol *x_arrayname;
+ float x_f;
+} t_tab16read_tilde;
+
+static void *tab16read_tilde_new(t_symbol *s){
+ t_tab16read_tilde *x = (t_tab16read_tilde *)pd_new(tab16read_tilde_class);
+ x->x_arrayname = s;
+ x->x_vec = 0;
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *tab16read_tilde_perform(t_int *w){
+ t_tab16read_tilde *x = (t_tab16read_tilde *)(w[1]);
+ t_float *in = (t_float *)(w[2]);
+ t_float *out = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+ int maxindex;
+ t_iem16_16bit *buf = x->x_vec;
+ int i;
+
+ maxindex = x->x_npoints - 1;
+ if (!buf) goto zero;
+
+ for (i = 0; i < n; i++) {
+ int index = *in++;
+ if (index < 0) index = 0;
+ else if (index > maxindex) index = maxindex;
+ *out++ = buf[index]*IEM16_SCALE_DOWN;
+ }
+ return (w+5);
+ zero:
+ while (n--) *out++ = 0;
+
+ return (w+5);
+}
+
+void tab16read_tilde_set(t_tab16read_tilde *x, t_symbol *s){
+ t_table16 *a;
+
+ x->x_arrayname = s;
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*s->s_name)
+ error("tab16read~: %s: no such array", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else if (!table16_getarray16(a, &x->x_npoints, &x->x_vec)) {
+ error("%s: bad template for tab16read~", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else table16_usedindsp(a);
+}
+
+static void tab16read_tilde_dsp(t_tab16read_tilde *x, t_signal **sp){
+ tab16read_tilde_set(x, x->x_arrayname);
+
+ dsp_add(tab16read_tilde_perform, 4, x,
+ sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+
+}
+
+static void tab16read_tilde_free(t_tab16read_tilde *x){}
+
+void tab16read_tilde_setup(void){
+ tab16read_tilde_class = class_new(gensym("tab16read~"),
+ (t_newmethod)tab16read_tilde_new, (t_method)tab16read_tilde_free,
+ sizeof(t_tab16read_tilde), 0, A_DEFSYM, 0);
+ CLASS_MAINSIGNALIN(tab16read_tilde_class, t_tab16read_tilde, x_f);
+ class_addmethod(tab16read_tilde_class, (t_method)tab16read_tilde_dsp,
+ gensym("dsp"), 0);
+ class_addmethod(tab16read_tilde_class, (t_method)tab16read_tilde_set,
+ gensym("set"), A_SYMBOL, 0);
+}
diff --git a/src/tab16receive~.c b/src/tab16receive~.c
new file mode 100644
index 0000000..f946dce
--- /dev/null
+++ b/src/tab16receive~.c
@@ -0,0 +1,68 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+/* ------------------------ tab16receive~ ------------------------- */
+
+static t_class *tab16receive_class;
+
+typedef struct _tab16receive{
+ t_object x_obj;
+ t_iem16_16bit *x_vec;
+ t_symbol *x_arrayname;
+} t_tab16receive;
+
+static t_int *tab16receive_perform(t_int *w){
+ t_tab16receive *x = (t_tab16receive *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = w[3];
+ t_iem16_16bit *from = x->x_vec;
+ if (from) while (n--) *out++ = *from++*IEM16_SCALE_DOWN;
+ else while (n--) *out++ = 0;
+ return (w+4);
+}
+
+static void tab16receive_dsp(t_tab16receive *x, t_signal **sp){
+ t_table16 *a;
+ int vecsize;
+
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*x->x_arrayname->s_name)
+ error("tab16send~: %s: no such array", x->x_arrayname->s_name);
+ }
+ else if (!table16_getarray16(a, &vecsize, &x->x_vec))
+ error("%s: bad template for tab16receive~", x->x_arrayname->s_name);
+ else {
+ int n = sp[0]->s_n;
+ if (n < vecsize) vecsize = n;
+ table16_usedindsp(a);
+ dsp_add(tab16receive_perform, 3, x, sp[0]->s_vec, vecsize);
+ }
+}
+
+static void *tab16receive_new(t_symbol *s){
+ t_tab16receive *x = (t_tab16receive *)pd_new(tab16receive_class);
+ x->x_arrayname = s;
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static void tab16receive_setup(void){
+ tab16receive_class = class_new(gensym("tab16receive~"),
+ (t_newmethod)tab16receive_new, 0,
+ sizeof(t_tab16receive), 0, A_DEFSYM, 0);
+ class_addmethod(tab16receive_class, (t_method)tab16receive_dsp,
+ gensym("dsp"), 0);
+}
+
+// G.Holzmann: for PD-extended build system
+void tab16receive_tilde_setup(void)
+{
+ tab16receive_setup();
+}
diff --git a/src/tab16send~.c b/src/tab16send~.c
new file mode 100644
index 0000000..c5ff3af
--- /dev/null
+++ b/src/tab16send~.c
@@ -0,0 +1,83 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+
+/* ------------------------ tab16send~ ------------------------- */
+
+static t_class *tab16send_class;
+
+typedef struct _tab16send{
+ t_object x_obj;
+ t_iem16_16bit *x_vec;
+ int x_graphperiod;
+ int x_graphcount;
+ t_symbol *x_arrayname;
+ float x_f;
+} t_tab16send;
+
+static void *tab16send_new(t_symbol *s){
+ t_tab16send *x = (t_tab16send *)pd_new(tab16send_class);
+ x->x_graphcount = 0;
+ x->x_arrayname = s;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *tab16send_perform(t_int *w){
+ t_tab16send *x = (t_tab16send *)(w[1]);
+ t_float *in = (t_float *)(w[2]);
+ int n = w[3];
+ t_iem16_16bit *dest = x->x_vec;
+ int i = x->x_graphcount;
+ if (!x->x_vec) goto bad;
+
+ while (n--) *dest = *in++*IEM16_SCALE_UP;
+ if (!i--)i = x->x_graphperiod;
+ x->x_graphcount = i;
+ bad:
+ return (w+4);
+}
+
+static void tab16send_dsp(t_tab16send *x, t_signal **sp){
+ int vecsize;
+ t_table16 *a;
+
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*x->x_arrayname->s_name)
+ error("tab16send~: %s: no such array", x->x_arrayname->s_name);
+ }
+ else if (!table16_getarray16(a, &vecsize, &x->x_vec))
+ error("%s: bad template for tab16send~", x->x_arrayname->s_name);
+ else {
+ int n = sp[0]->s_n;
+ int ticksper = sp[0]->s_sr/n;
+ if (ticksper < 1) ticksper = 1;
+ x->x_graphperiod = ticksper;
+ if (x->x_graphcount > ticksper) x->x_graphcount = ticksper;
+ if (n < vecsize) vecsize = n;
+ table16_usedindsp(a);
+ dsp_add(tab16send_perform, 3, x, sp[0]->s_vec, vecsize);
+ }
+}
+
+static void tab16send_free(t_tab16send *x){}
+
+static void tab16send_setup(void){
+ tab16send_class = class_new(gensym("tab16send~"), (t_newmethod)tab16send_new,
+ (t_method)tab16send_free, sizeof(t_tab16send), 0, A_DEFSYM, 0);
+ CLASS_MAINSIGNALIN(tab16send_class, t_tab16send, x_f);
+ class_addmethod(tab16send_class, (t_method)tab16send_dsp, gensym("dsp"), 0);
+}
+
+// G.Holzmann: for PD-extended build system
+void tab16send_tilde_setup(void)
+{
+ tab16send_setup();
+}
diff --git a/src/tab16write.c b/src/tab16write.c
new file mode 100644
index 0000000..2c0e6ef
--- /dev/null
+++ b/src/tab16write.c
@@ -0,0 +1,58 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16read, tab16read4, tab16write */
+
+#include "iem16_table.h"
+
+/* ------------------ tab16write: control ------------------------ */
+
+static t_class *tab16write_class;
+
+typedef struct _tab16write {
+ t_object x_obj;
+ t_symbol *x_arrayname;
+ float x_ft1;
+ int x_set;
+} t_tab16write;
+
+static void tab16write_float(t_tab16write *x, t_float f) {
+ int vecsize;
+ t_table16 *a;
+ t_iem16_16bit *vec;
+
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class)))
+ error("%s: no such array", x->x_arrayname->s_name);
+ else if (!table16_getarray16(a, &vecsize, &vec))
+ error("%s: bad template for tab16write", x->x_arrayname->s_name);
+ else {
+ int n = x->x_ft1;
+ if (n < 0) n = 0;
+ else if (n >= vecsize) n = vecsize-1;
+ vec[n] = f;
+ }
+}
+
+static void tab16write_set(t_tab16write *x, t_symbol *s){
+ x->x_arrayname = s;
+}
+
+static void tab16write_free(t_tab16write *x){}
+
+static void *tab16write_new(t_symbol *s){
+ t_tab16write *x = (t_tab16write *)pd_new(tab16write_class);
+ x->x_ft1 = 0;
+ x->x_arrayname = s;
+ floatinlet_new(&x->x_obj, &x->x_ft1);
+ return (x);
+}
+
+void tab16write_setup(void){
+ tab16write_class = class_new(gensym("tab16write"), (t_newmethod)tab16write_new,
+ (t_method)tab16write_free, sizeof(t_tab16write), 0, A_DEFSYM, 0);
+ class_addfloat(tab16write_class, (t_method)tab16write_float);
+ class_addmethod(tab16write_class, (t_method)tab16write_set, gensym("set"), A_SYMBOL, 0);
+}
diff --git a/src/tab16write~.c b/src/tab16write~.c
new file mode 100644
index 0000000..2a41f2f
--- /dev/null
+++ b/src/tab16write~.c
@@ -0,0 +1,92 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_array.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* tab16write~, tab16play~, tab16read~, tab16read4~, tab16send~, tab16receive~ */
+
+#include "iem16_table.h"
+
+/* ------------------------- tab16write~ -------------------------- */
+
+static t_class *tab16write_tilde_class;
+
+typedef struct _tab16write_tilde {
+ t_object x_obj;
+ int x_phase;
+ int x_nsampsintab;
+ short *x_vec;
+ t_symbol *x_arrayname;
+ float x_f;
+} t_tab16write_tilde;
+
+static void *tab16write_tilde_new(t_symbol *s) {
+ t_tab16write_tilde *x = (t_tab16write_tilde *)pd_new(tab16write_tilde_class);
+ x->x_phase = 0x7fffffff;
+ x->x_arrayname = s;
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *tab16write_tilde_perform(t_int *w) {
+ t_tab16write_tilde *x = (t_tab16write_tilde *)(w[1]);
+ t_float *in = (t_float *)(w[2]);
+ int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
+ if (!x->x_vec) goto bad;
+
+ if (endphase > phase) {
+ int nxfer = endphase - phase;
+ t_iem16_16bit *fp = x->x_vec + phase;
+ if (nxfer > n) nxfer = n;
+ phase += nxfer;
+ while (nxfer--)*fp++ = *in++*IEM16_SCALE_UP;
+ x->x_phase = phase;
+ }
+ bad:
+ return (w+4);
+}
+
+void tab16write_tilde_set(t_tab16write_tilde *x, t_symbol *s){
+ t_table16 *a;
+
+ x->x_arrayname = s;
+ if (!(a = (t_table16 *)pd_findbyclass(x->x_arrayname, table16_class))) {
+ if (*s->s_name) pd_error(x, "tab16write~: %s: no such array",
+ x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else if (!table16_getarray16(a, &x->x_nsampsintab, &x->x_vec)) {
+ error("%s: bad template for tab16write~", x->x_arrayname->s_name);
+ x->x_vec = 0;
+ }
+ else table16_usedindsp(a);
+}
+
+static void tab16write_tilde_dsp(t_tab16write_tilde *x, t_signal **sp){
+ tab16write_tilde_set(x, x->x_arrayname);
+ dsp_add(tab16write_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+static void tab16write_tilde_bang(t_tab16write_tilde *x){
+ x->x_phase = 0;
+}
+
+static void tab16write_tilde_stop(t_tab16write_tilde *x){}
+
+static void tab16write_tilde_free(t_tab16write_tilde *x){}
+
+void tab16write_tilde_setup(void){
+ tab16write_tilde_class = class_new(gensym("tab16write~"),
+ (t_newmethod)tab16write_tilde_new, (t_method)tab16write_tilde_free,
+ sizeof(t_tab16write_tilde), 0, A_DEFSYM, 0);
+ CLASS_MAINSIGNALIN(tab16write_tilde_class, t_tab16write_tilde, x_f);
+ class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_dsp,
+ gensym("dsp"), 0);
+ class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_set,
+ gensym("set"), A_SYMBOL, 0);
+ class_addmethod(tab16write_tilde_class, (t_method)tab16write_tilde_stop,
+ gensym("stop"), 0);
+ class_addbang(tab16write_tilde_class, tab16write_tilde_bang);
+}
+
diff --git a/src/iem16_table.c b/src/table16.c
index fd9d585..fd9d585 100644
--- a/src/iem16_table.c
+++ b/src/table16.c
diff --git a/src/vd16~.c b/src/vd16~.c
new file mode 100644
index 0000000..c212349
--- /dev/null
+++ b/src/vd16~.c
@@ -0,0 +1,97 @@
+/* copyleft (c) 2003 forum::für::umläute -- IOhannes m zmölnig @ IEM
+ * based on d_delay.c from pd:
+ * Copyright (c) 1997-1999 Miller Puckette.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+/* del16read~, del16write~, vd16~ */
+
+#include "iem16_delay.h"
+
+/* ----------------------------- vd~ ----------------------------- */
+static t_class *sig16vd_class;
+
+typedef struct _sig16vd{
+ t_object x_obj;
+ t_symbol *x_sym;
+ t_float x_sr; /* samples per msec */
+ int x_zerodel; /* 0 or vecsize depending on read/write order */
+ float x_f;
+} t_sig16vd;
+
+static void *sig16vd_new(t_symbol *s){
+ t_sig16vd *x = (t_sig16vd *)pd_new(sig16vd_class);
+ if (!*s->s_name) s = gensym("vd~");
+ x->x_sym = s;
+ x->x_sr = 1;
+ x->x_zerodel = 0;
+ outlet_new(&x->x_obj, gensym("signal"));
+ x->x_f = 0;
+ return (x);
+}
+
+static t_int *sig16vd_perform(t_int *w){
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_del16writectl *ctl = (t_del16writectl *)(w[3]);
+ t_sig16vd *x = (t_sig16vd *)(w[4]);
+ int n = (int)(w[5]);
+
+ int nsamps = ctl->c_n;
+ float limit = nsamps - n - 1;
+ float fn = n-4;
+ t_iem16_16bit *vp = ctl->c_vec, *bp, *wp = vp + ctl->c_phase;
+ float zerodel = x->x_zerodel;
+ while (n--) {
+ float delsamps = x->x_sr * *in++ - zerodel, frac;
+ int idelsamps;
+ float a, b, c, d, cminusb;
+ if (delsamps < 1.00001f) delsamps = 1.00001f;
+ if (delsamps > limit) delsamps = limit;
+ delsamps += fn;
+ fn = fn - 1.0f;
+ idelsamps = delsamps;
+ frac = delsamps - (float)idelsamps;
+ bp = wp - (idelsamps + 3);
+ if (bp < vp + 4) bp += nsamps;
+ d = bp[-3]*IEM16_SCALE_DOWN;
+ c = bp[-2]*IEM16_SCALE_DOWN;
+ b = bp[-1]*IEM16_SCALE_DOWN;
+ a = bp[00]*IEM16_SCALE_DOWN;
+ cminusb = c-b;
+ *out++ = b + frac * (
+ cminusb - 0.5f * (frac-1.) * (
+ (a - d + 3.0f * cminusb) * frac + (b - a - cminusb)
+ )
+ );
+ }
+ return (w+6);
+}
+
+static void sig16vd_dsp(t_sig16vd *x, t_signal **sp){
+ t_sigdel16write *delwriter =
+ (t_sigdel16write *)pd_findbyclass(x->x_sym, sigdel16write_class);
+ x->x_sr = sp[0]->s_sr * 0.001;
+ if (delwriter) {
+ sigdel16write_checkvecsize(delwriter, sp[0]->s_n);
+ x->x_zerodel = (delwriter->x_sortno == ugen_getsortno() ?
+ 0 : delwriter->x_vecsize);
+ dsp_add(sig16vd_perform, 5,
+ sp[0]->s_vec, sp[1]->s_vec,
+ &delwriter->x_cspace, x, sp[0]->s_n);
+ }
+ else error("vd~: %s: no such delwrite~",x->x_sym->s_name);
+}
+
+static void sig16vd_setup(void){
+ sig16vd_class = class_new(gensym("vd16~"), (t_newmethod)sig16vd_new, 0,
+ sizeof(t_sig16vd), 0, A_DEFSYM, 0);
+ class_addmethod(sig16vd_class, (t_method)sig16vd_dsp, gensym("dsp"), 0);
+ CLASS_MAINSIGNALIN(sig16vd_class, t_sig16vd, x_f);
+}
+
+// G.Holzmann: for PD-extended build system
+void vd16_tilde_setup(void)
+{
+ sig16vd_setup();
+}