aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/block_delay~.c124
-rw-r--r--src/iem_delay.c34
-rw-r--r--src/iem_delay.dsp85
-rw-r--r--src/iem_delay.dsw29
-rw-r--r--src/iem_delay.h11
-rw-r--r--src/iemlib.h108
-rw-r--r--src/makefile49
-rw-r--r--src/makefile_linux49
-rw-r--r--src/makefile_win41
-rw-r--r--src/n_delay1p_line~.c428
-rw-r--r--src/n_delay2p_line~.c462
-rw-r--r--src/nz~.c250
12 files changed, 1670 insertions, 0 deletions
diff --git a/src/block_delay~.c b/src/block_delay~.c
new file mode 100644
index 0000000..d80f96b
--- /dev/null
+++ b/src/block_delay~.c
@@ -0,0 +1,124 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include "iem_delay.h"
+
+/* -------------------------- block_delay~ ------------------------------ */
+static t_class *block_delay_tilde_class;
+
+typedef struct _block_delay_tilde
+{
+ t_object x_obj;
+ t_float *x_begmem;
+ int x_blocksize;
+ t_float x_msi;
+} t_block_delay_tilde;
+
+static t_int *block_delay_tilde_perform(t_int *w)
+{
+ t_float *in = (float *)(w[1]);
+ t_float *out = (float *)(w[2]);
+ t_block_delay_tilde *x = (t_block_delay_tilde *)(w[3]);
+ int i, n = (t_int)(w[4]);
+ t_float *rw_vec, f;
+
+ rw_vec = x->x_begmem;
+ for(i=0; i<n; i++)
+ {
+ f = in[i];
+ out[i] = rw_vec[i];
+ rw_vec[i] = f;
+ }
+ return(w+5);
+}
+
+static t_int *block_delay_tilde_perf8(t_int *w)
+{
+ t_float *in = (float *)(w[1]);
+ t_float *out = (float *)(w[2]);
+ t_block_delay_tilde *x = (t_block_delay_tilde *)(w[3]);
+ int i, n = (t_int)(w[4]);
+ t_float *rw_vec, f[8];
+
+ rw_vec = x->x_begmem;
+ while(n)
+ {
+ f[0] = in[0];
+ f[1] = in[1];
+ f[2] = in[2];
+ f[3] = in[3];
+ f[4] = in[4];
+ f[5] = in[5];
+ f[6] = in[6];
+ f[7] = in[7];
+
+ out[0] = rw_vec[0];
+ out[1] = rw_vec[1];
+ out[2] = rw_vec[2];
+ out[3] = rw_vec[3];
+ out[4] = rw_vec[4];
+ out[5] = rw_vec[5];
+ out[6] = rw_vec[6];
+ out[7] = rw_vec[7];
+
+ rw_vec[0] = f[0];
+ rw_vec[1] = f[1];
+ rw_vec[2] = f[2];
+ rw_vec[3] = f[3];
+ rw_vec[4] = f[4];
+ rw_vec[5] = f[5];
+ rw_vec[6] = f[6];
+ rw_vec[7] = f[7];
+
+ rw_vec += 8;
+ in += 8;
+ out += 8;
+ n -= 8;
+ }
+ return(w+5);
+}
+
+static void block_delay_tilde_dsp(t_block_delay_tilde *x, t_signal **sp)
+{
+ int n = sp[0]->s_n;
+
+ if(!x->x_blocksize)/*first time*/
+ x->x_begmem = (t_float *)getbytes(n * sizeof(t_float));
+ else if(x->x_blocksize != n)
+ x->x_begmem = (t_float *)resizebytes(x->x_begmem, x->x_blocksize*sizeof(t_float), n*sizeof(t_float));
+ x->x_blocksize = n;
+ if(n&7)
+ dsp_add(block_delay_tilde_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
+ else
+ dsp_add(block_delay_tilde_perf8, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
+}
+
+static void *block_delay_tilde_new(void)
+{
+ t_block_delay_tilde *x = (t_block_delay_tilde *)pd_new(block_delay_tilde_class);
+
+ x->x_blocksize = 0;
+ x->x_begmem = (t_float *)0;
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_msi = 0.0f;
+ return (x);
+}
+
+static void block_delay_tilde_free(t_block_delay_tilde *x)
+{
+ if(x->x_begmem)
+ freebytes(x->x_begmem, x->x_blocksize * sizeof(t_float));
+}
+
+void block_delay_tilde_setup(void)
+{
+ block_delay_tilde_class = class_new(gensym("block_delay~"), (t_newmethod)block_delay_tilde_new, (t_method)block_delay_tilde_free,
+ sizeof(t_block_delay_tilde), 0, 0);
+ CLASS_MAINSIGNALIN(block_delay_tilde_class, t_block_delay_tilde, x_msi);
+ class_addmethod(block_delay_tilde_class, (t_method)block_delay_tilde_dsp, gensym("dsp"), 0);
+ class_sethelpsymbol(block_delay_tilde_class, gensym("iemhelp2/help-block_delay~"));
+}
diff --git a/src/iem_delay.c b/src/iem_delay.c
new file mode 100644
index 0000000..1ba3607
--- /dev/null
+++ b/src/iem_delay.c
@@ -0,0 +1,34 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+#include "m_pd.h"
+#include "iemlib.h"
+
+static t_class *iem_delay_class;
+
+static void *iem_delay_new(void)
+{
+ t_object *x = (t_object *)pd_new(iem_delay_class);
+
+ return (x);
+}
+
+void n_delay1p_line_tilde_setup(void);
+void n_delay2p_line_tilde_setup(void);
+void nz_tilde_setup(void);
+void block_delay_tilde_setup(void);
+
+/* ------------------------ setup routine ------------------------- */
+
+void iem_delay_setup(void)
+{
+ n_delay1p_line_tilde_setup();
+ n_delay2p_line_tilde_setup();
+ nz_tilde_setup();
+ block_delay_tilde_setup();
+
+ post("iem_delay (R-1.16) library loaded! (c) Thomas Musil 05.2005");
+ post(" musil%ciem.at iem KUG Graz Austria", '@');
+}
diff --git a/src/iem_delay.dsp b/src/iem_delay.dsp
new file mode 100644
index 0000000..df7588d
--- /dev/null
+++ b/src/iem_delay.dsp
@@ -0,0 +1,85 @@
+# Microsoft Developer Studio Project File - Name="iem_delay" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) External Target" 0x0106
+
+CFG=iem_delay - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "iem_delay.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "iem_delay.mak" CFG="iem_delay - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "iem_delay - Win32 Release" (basierend auf "Win32 (x86) External Target")
+!MESSAGE "iem_delay - Win32 Debug" (basierend auf "Win32 (x86) External Target")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+
+!IF "$(CFG)" == "iem_delay - Win32 Release"
+
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Cmd_Line "NMAKE /f makefile_win"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "makefile_win.exe"
+# PROP BASE Bsc_Name "makefile_win.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Cmd_Line "NMAKE /f makefile_win"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "iem_delay.exe"
+# PROP Bsc_Name "iem_delay.bsc"
+# PROP Target_Dir ""
+
+!ELSEIF "$(CFG)" == "iem_delay - Win32 Debug"
+
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Cmd_Line "NMAKE /f makefile_win"
+# PROP BASE Rebuild_Opt "/a"
+# PROP BASE Target_File "makefile_win.exe"
+# PROP BASE Bsc_Name "makefile_win.bsc"
+# PROP BASE Target_Dir ""
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Cmd_Line "NMAKE /f makefile_win"
+# PROP Rebuild_Opt "/a"
+# PROP Target_File "iem_delay.exe"
+# PROP Bsc_Name "iem_delay.bsc"
+# PROP Target_Dir ""
+
+!ENDIF
+
+# Begin Target
+
+# Name "iem_delay - Win32 Release"
+# Name "iem_delay - Win32 Debug"
+
+!IF "$(CFG)" == "iem_delay - Win32 Release"
+
+!ELSEIF "$(CFG)" == "iem_delay - Win32 Debug"
+
+!ENDIF
+
+# Begin Source File
+
+SOURCE=.\makefile_win
+# End Source File
+# End Target
+# End Project
diff --git a/src/iem_delay.dsw b/src/iem_delay.dsw
new file mode 100644
index 0000000..e8060b1
--- /dev/null
+++ b/src/iem_delay.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "iem_delay"=.\iem_delay.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/src/iem_delay.h b/src/iem_delay.h
new file mode 100644
index 0000000..dea664b
--- /dev/null
+++ b/src/iem_delay.h
@@ -0,0 +1,11 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+#ifndef __IEMDELAY_H__
+#define __IEMDELAY_H__
+
+#define DELLINE_DEF_VEC_SIZE 64
+
+#endif
diff --git a/src/iemlib.h b/src/iemlib.h
new file mode 100644
index 0000000..6be2de0
--- /dev/null
+++ b/src/iemlib.h
@@ -0,0 +1,108 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iemlib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
+
+#ifndef __IEMLIB_H__
+#define __IEMLIB_H__
+
+
+#define IS_A_POINTER(atom,index) ((atom+index)->a_type == A_POINTER)
+#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
+#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
+#define IS_A_DOLLAR(atom,index) ((atom+index)->a_type == A_DOLLAR)
+#define IS_A_DOLLSYM(atom,index) ((atom+index)->a_type == A_DOLLSYM)
+#define IS_A_SEMI(atom,index) ((atom+index)->a_type == A_SEMI)
+#define IS_A_COMMA(atom,index) ((atom+index)->a_type == A_COMMA)
+
+
+#ifdef NT
+int sys_noloadbang;
+//t_symbol *iemgui_key_sym=0;
+#include <io.h>
+#else
+extern int sys_noloadbang;
+//extern t_symbol *iemgui_key_sym;
+#include <unistd.h>
+#endif
+
+#define DEFDELVS 64
+#define XTRASAMPS 4
+#define SAMPBLK 4
+
+
+#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 */
+#else
+#ifdef MSW
+/* little-endian; most significant byte is at highest address */
+#define HIOFFSET 1
+#define LOWOFFSET 0
+#define int32 long
+#else
+#ifdef __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
+#endif
+#ifdef __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
+
+#else
+#ifdef __APPLE__
+#define HIOFFSET 0 /* word offset to find MSB */
+#define LOWOFFSET 1 /* word offset to find LSB */
+#define int32 int /* a data type that has 32 bits */
+
+#endif /* __APPLE__ */
+#endif /* __linux__ */
+#endif /* MSW */
+#endif /* SGI */
+
+union tabfudge
+{
+ double tf_d;
+ int32 tf_i[2];
+};
+
+#ifdef __i386__
+#define IEM_DENORMAL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
+(((*(unsigned int*)&(f))&0x60000000)==0x60000000))
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+#else
+
+#define IEM_DENORMAL(f) 0
+
+#endif
+
+#endif
diff --git a/src/makefile b/src/makefile
new file mode 100644
index 0000000..d551c0c
--- /dev/null
+++ b/src/makefile
@@ -0,0 +1,49 @@
+current: all
+
+.SUFFIXES: .pd_linux
+
+INCLUDE = -I. -I/usr/local/src/pd/src
+
+LDFLAGS = -export-dynamic -shared
+LIB = -ldl -lm
+
+#select either the DBG and OPT compiler flags below:
+
+CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
+ -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing \
+ -DDL_OPEN -fPIC
+
+SYSTEM = $(shell uname -m)
+
+# the sources
+
+SRC = n_delay1p_line~.c \
+ n_delay2p_line~.c \
+ nz~.c \
+ block_delay~.c \
+ iem_delay.c
+
+TARGET = iem_delay.pd_linux
+
+
+OBJ = $(SRC:.c=.o)
+
+#
+# ------------------ targets ------------------------------------
+#
+
+clean:
+ rm $(TARGET)
+ rm *.o
+
+all: $(OBJ)
+ @echo :: $(OBJ)
+ $(LD) $(LDFLAGS) -o $(TARGET) *.o $(LIB)
+ strip --strip-unneeded $(TARGET)
+
+$(OBJ) : %.o : %.c
+ $(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
+
+
+
+
diff --git a/src/makefile_linux b/src/makefile_linux
new file mode 100644
index 0000000..d551c0c
--- /dev/null
+++ b/src/makefile_linux
@@ -0,0 +1,49 @@
+current: all
+
+.SUFFIXES: .pd_linux
+
+INCLUDE = -I. -I/usr/local/src/pd/src
+
+LDFLAGS = -export-dynamic -shared
+LIB = -ldl -lm
+
+#select either the DBG and OPT compiler flags below:
+
+CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
+ -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing \
+ -DDL_OPEN -fPIC
+
+SYSTEM = $(shell uname -m)
+
+# the sources
+
+SRC = n_delay1p_line~.c \
+ n_delay2p_line~.c \
+ nz~.c \
+ block_delay~.c \
+ iem_delay.c
+
+TARGET = iem_delay.pd_linux
+
+
+OBJ = $(SRC:.c=.o)
+
+#
+# ------------------ targets ------------------------------------
+#
+
+clean:
+ rm $(TARGET)
+ rm *.o
+
+all: $(OBJ)
+ @echo :: $(OBJ)
+ $(LD) $(LDFLAGS) -o $(TARGET) *.o $(LIB)
+ strip --strip-unneeded $(TARGET)
+
+$(OBJ) : %.o : %.c
+ $(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
+
+
+
+
diff --git a/src/makefile_win b/src/makefile_win
new file mode 100644
index 0000000..2d84b91
--- /dev/null
+++ b/src/makefile_win
@@ -0,0 +1,41 @@
+
+all: iem_delay.dll
+
+VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98"
+
+PD_INST_PATH = "C:\Programme\pd-0.39-2"
+
+PD_WIN_INCLUDE_PATH = /I. /I$(PD_INST_PATH)\src /I$(VIS_CPP_PATH)\include
+
+PD_WIN_C_FLAGS = /nologo /W3 /WX /DMSW /DNT /DPD /DWIN32 /DWINDOWS /Ox -DPA_LITTLE_ENDIAN
+
+PD_WIN_L_FLAGS = /nologo
+
+PD_WIN_LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel /NODEFAULTLIB:uuid \
+ $(VIS_CPP_PATH)\lib\libc.lib \
+ $(VIS_CPP_PATH)\lib\oldnames.lib \
+ $(VIS_CPP_PATH)\lib\kernel32.lib \
+ $(VIS_CPP_PATH)\lib\wsock32.lib \
+ $(VIS_CPP_PATH)\lib\winmm.lib \
+ $(PD_INST_PATH)\bin\pthreadVC.lib \
+ $(PD_INST_PATH)\bin\pd.lib
+
+
+SRC = n_delay1p_line~.c \
+ n_delay2p_line~.c \
+ nz~.c \
+ block_delay~.c \
+ iem_delay.c
+
+
+OBJ = $(SRC:.c=.obj)
+
+.c.obj:
+ cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c
+
+iem_delay.dll: $(OBJ)
+ link $(PD_WIN_L_FLAGS) /dll /export:iem_delay_setup \
+ /out:iem_delay.dll $(OBJ) $(PD_WIN_LIB)
+
+clean:
+ del *.obj
diff --git a/src/n_delay1p_line~.c b/src/n_delay1p_line~.c
new file mode 100644
index 0000000..f65d149
--- /dev/null
+++ b/src/n_delay1p_line~.c
@@ -0,0 +1,428 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include "iem_delay.h"
+
+/* -------------------------- n_delay1p_line_tilde~ ------------------------------ */
+static t_class *n_delay1p_line_tilde_class;
+
+typedef struct _n_delay1p_line_tilde
+{
+ t_object x_obj;
+ int x_mallocsize;
+ t_float x_max_delay_ms;
+ t_float *x_begmem0;
+ t_float *x_begmem1;
+ int x_writeindex;
+ int x_n_delays;
+ int *x_del_samp256_end;
+ int *x_del_samp256_cur;
+ int *x_inc256;
+ int *x_biginc256;
+ int x_blocksize;
+ t_float x_sr;
+ t_float x_ms2tick;
+ t_float x_ms2samples256;
+ t_float x_interpol_ms;
+ int x_interpol_ticks;
+ int x_ticksleft;
+ int x_old;
+ int x_retarget;
+ t_float **x_io;
+ t_float x_msi;
+} t_n_delay1p_line_tilde;
+
+static void n_delay1p_line_tilde_list(t_n_delay1p_line_tilde *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if(argc == x->x_n_delays)
+ {
+ int i;
+ t_float delay, max=x->x_max_delay_ms;
+
+ if(x->x_interpol_ms <= 0.0f)
+ x->x_ticksleft = x->x_retarget = 0;
+ else
+ x->x_retarget = 1;
+ for(i=0; i<argc; i++)
+ {
+ delay = atom_getfloat(argv++);
+ if(delay < 0.0f)
+ delay = 0.0f;
+ if(delay > max)
+ delay = max;
+ if(x->x_interpol_ms <= 0.0f)
+ x->x_del_samp256_end[i] = x->x_del_samp256_cur[i] = (int)(x->x_ms2samples256 * delay + 0.5f) + 127;
+ else
+ x->x_del_samp256_end[i] = (int)(x->x_ms2samples256 * delay + 0.5f) + 127;
+ }
+ }
+}
+
+static void n_delay1p_line_tilde_time(t_n_delay1p_line_tilde *x, t_floatarg interpol_ms)
+{
+ if(interpol_ms < 0.0f)
+ interpol_ms = 0.0f;
+ x->x_interpol_ms = interpol_ms;
+ x->x_interpol_ticks = (int)(x->x_ms2tick * interpol_ms);
+}
+
+static void n_delay1p_line_tilde_stop(t_n_delay1p_line_tilde *x)
+{
+ int i, n=x->x_n_delays;
+
+ for(i=0; i<n; i++)
+ x->x_del_samp256_end[i] = x->x_del_samp256_cur[i];
+ x->x_ticksleft = x->x_retarget = 0;
+}
+
+static t_int *n_delay1p_line_tilde_perform(t_int *w)
+{
+ t_n_delay1p_line_tilde *x = (t_n_delay1p_line_tilde *)(w[1]);
+ int hn=(int)(w[2]);
+ int nout=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int writeindex = x->x_writeindex;
+ int i, j, n;
+ int malloc_samples = x->x_mallocsize;
+ t_float *begvec0 = x->x_begmem0;
+ t_float *begvec1 = x->x_begmem1;
+ t_float *writevec;
+ t_float *readvec;
+ int del256, inc256;
+
+ writevec = begvec0 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n--)
+ {
+ *writevec++ = *in++;
+ }
+ writevec = begvec1 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n--)
+ {
+ *writevec++ = *in++;
+ }
+
+ if(x->x_retarget)
+ {
+ int nticks = x->x_interpol_ticks;
+
+ if(!nticks)
+ nticks = 1;
+ x->x_ticksleft = nticks;
+ for(j=0; j<nout; j++)
+ {
+ x->x_biginc256[j] = (x->x_del_samp256_end[j] - x->x_del_samp256_cur[j]) / nticks;
+ x->x_inc256[j] = x->x_biginc256[j] / x->x_blocksize;
+ }
+ x->x_retarget = 0;
+ }
+
+ if(x->x_ticksleft)
+ {
+ for(j=0; j<nout; j++)
+ {
+ inc256 = x->x_inc256[j];
+ del256 = x->x_del_samp256_cur[j];
+ out = x->x_io[j+1];
+ for(i=0; i<hn; i++)
+ {
+ readvec = begvec1 + writeindex - (del256 >> 8) + i;
+ *out++ = *readvec;
+ del256 += inc256;
+ }
+ x->x_del_samp256_cur[j] += x->x_biginc256[j];
+ }
+ x->x_ticksleft--;
+ }
+ else
+ {
+ for(j=0; j<nout; j++)
+ {
+ del256 = x->x_del_samp256_cur[j] = x->x_del_samp256_end[j];
+ readvec = begvec1 + writeindex - (del256 >> 8);
+ out = x->x_io[j+1];
+ n = hn;
+ while(n--)
+ {
+ *out++ = *readvec++;
+ }
+ }
+ }
+ writeindex += hn;
+ if(writeindex >= malloc_samples)
+ {
+ writeindex -= malloc_samples;
+ }
+ x->x_writeindex = writeindex;
+ return(w+3);
+}
+
+static t_int *n_delay1p_line_tilde_perf8(t_int *w)
+{
+ t_n_delay1p_line_tilde *x = (t_n_delay1p_line_tilde *)(w[1]);
+ int hn=(int)(w[2]);
+ int nout=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int writeindex = x->x_writeindex;
+ int i, j, k, n;
+ int malloc_samples = x->x_mallocsize;
+ t_float *begvec0 = x->x_begmem0;
+ t_float *begvec1 = x->x_begmem1;
+ t_float *writevec;
+ t_float *readvec;
+ int del256, inc256;
+
+// post("writevec = %d",writeindex);
+ writevec = begvec0 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n)
+ {
+ writevec[0] = in[0];
+ writevec[1] = in[1];
+ writevec[2] = in[2];
+ writevec[3] = in[3];
+ writevec[4] = in[4];
+ writevec[5] = in[5];
+ writevec[6] = in[6];
+ writevec[7] = in[7];
+
+ writevec += 8;
+ n -= 8;
+ in += 8;
+ }
+ writevec = begvec1 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n)
+ {
+ writevec[0] = in[0];
+ writevec[1] = in[1];
+ writevec[2] = in[2];
+ writevec[3] = in[3];
+ writevec[4] = in[4];
+ writevec[5] = in[5];
+ writevec[6] = in[6];
+ writevec[7] = in[7];
+
+ writevec += 8;
+ n -= 8;
+ in += 8;
+ }
+
+ if(x->x_retarget)
+ {
+ int nticks = x->x_interpol_ticks;
+
+ if(!nticks)
+ nticks = 1;
+ x->x_ticksleft = nticks;
+ for(j=0; j<nout; j++)
+ {
+ x->x_biginc256[j] = (x->x_del_samp256_end[j] - x->x_del_samp256_cur[j]) / nticks;
+ x->x_inc256[j] = x->x_biginc256[j] / x->x_blocksize;
+ }
+ x->x_retarget = 0;
+ }
+
+ if(x->x_ticksleft)
+ {
+ for(j=0; j<nout; j++)
+ {
+ inc256 = x->x_inc256[j];
+ del256 = x->x_del_samp256_cur[j];
+ out = x->x_io[j+1];
+ readvec = begvec1 + writeindex;
+ for(i=0; i<hn; i+=8)
+ {
+ k = del256 >> 8;
+ out[0] = readvec[0-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[1] = readvec[1-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[2] = readvec[2-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[3] = readvec[3-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[4] = readvec[4-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[5] = readvec[5-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[6] = readvec[6-k];
+ del256 += inc256;
+
+ k = del256 >> 8;
+ out[7] = readvec[7-k];
+ del256 += inc256;
+
+ out += 8;
+ readvec += 8;
+ }
+ x->x_del_samp256_cur[j] += x->x_biginc256[j];
+ }
+ x->x_ticksleft--;
+ }
+ else
+ {
+ for(j=0; j<nout; j++)
+ {
+ del256 = x->x_del_samp256_cur[j] = x->x_del_samp256_end[j];
+ readvec = begvec1 + writeindex - (del256 >> 8);
+ out = x->x_io[j+1];
+ n = hn;
+ while(n)
+ {
+ out[0] = readvec[0];
+ out[1] = readvec[1];
+ out[2] = readvec[2];
+ out[3] = readvec[3];
+ out[4] = readvec[4];
+ out[5] = readvec[5];
+ out[6] = readvec[6];
+ out[7] = readvec[7];
+ out += 8;
+ readvec += 8;
+ n -= 8;
+ }
+ }
+ }
+
+ writeindex += hn;
+ if(writeindex >= malloc_samples)
+ {
+ writeindex -= malloc_samples;
+ }
+ x->x_writeindex = writeindex;
+
+ return(w+3);
+}
+
+static void n_delay1p_line_tilde_dsp(t_n_delay1p_line_tilde *x, t_signal **sp)
+{
+ int n = sp[0]->s_n;
+ int i, nd = x->x_n_delays + 1;
+
+ if(!x->x_blocksize)/*first time*/
+ {
+ int nsamps = x->x_max_delay_ms * (t_float)sp[0]->s_sr * 0.001f;
+
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (n - 1));
+ nsamps += n;
+ x->x_mallocsize = nsamps;
+ x->x_begmem0 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ x->x_writeindex = n;
+ }
+ else if((x->x_blocksize != n) || ((t_float)sp[0]->s_sr != x->x_sr))
+ {
+ int nsamps = x->x_max_delay_ms * (t_float)sp[0]->s_sr * 0.001f;
+
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (n - 1));
+ nsamps += n;
+
+ x->x_begmem0 = (t_float *)resizebytes(x->x_begmem0, 2*x->x_mallocsize*sizeof(t_float), 2*nsamps*sizeof(t_float));
+ x->x_mallocsize = nsamps;
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ if(x->x_writeindex >= nsamps)
+ x->x_writeindex -= nsamps;
+ }
+ x->x_blocksize = n;
+ x->x_ms2tick = 0.001f * (t_float)sp[0]->s_sr / (t_float)n;
+ x->x_ms2samples256 = 0.256f * (t_float)sp[0]->s_sr;
+ x->x_interpol_ticks = (int)(x->x_ms2tick * x->x_interpol_ms);
+ for(i=0; i<nd; i++)
+ x->x_io[i] = sp[i]->s_vec;
+ if(n&7)
+ dsp_add(n_delay1p_line_tilde_perform, 2, x, n);
+ else
+ dsp_add(n_delay1p_line_tilde_perf8, 2, x, n);
+}
+
+static void *n_delay1p_line_tilde_new(t_floatarg fout, t_floatarg delay_ms, t_floatarg interpol_ms)
+{
+ t_n_delay1p_line_tilde *x = (t_n_delay1p_line_tilde *)pd_new(n_delay1p_line_tilde_class);
+ int i, n_out = (int)fout;
+ int nsamps = delay_ms * sys_getsr() * 0.001f;
+
+ if(n_out < 1)
+ n_out = 1;
+ x->x_n_delays = n_out;
+ x->x_max_delay_ms = delay_ms;
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (DELLINE_DEF_VEC_SIZE - 1));
+ nsamps += DELLINE_DEF_VEC_SIZE;
+ x->x_mallocsize = nsamps;
+ x->x_begmem0 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ x->x_writeindex = DELLINE_DEF_VEC_SIZE;
+ x->x_blocksize = 0;
+ x->x_sr = 0.0f;
+ if(interpol_ms < 0.0f)
+ interpol_ms = 0.0f;
+ x->x_interpol_ms = interpol_ms;
+ x->x_io = (t_float **)getbytes((x->x_n_delays + 1) * sizeof(t_float *));
+ for(i=0; i<n_out; i++)
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_del_samp256_end = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_del_samp256_cur = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_inc256 = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_biginc256 = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_ticksleft = x->x_retarget = 0;
+ for(i=0; i<n_out; i++)
+ {
+ x->x_del_samp256_cur[i] = x->x_del_samp256_end[i] = 0;
+ x->x_inc256[i] = x->x_biginc256[i] = 0;
+ }
+ x->x_interpol_ticks = 0;
+ x->x_msi = 0.0f;
+ return (x);
+}
+
+static void n_delay1p_line_tilde_free(t_n_delay1p_line_tilde *x)
+{
+ freebytes(x->x_del_samp256_end, x->x_n_delays * sizeof(int));
+ freebytes(x->x_del_samp256_cur, x->x_n_delays * sizeof(int));
+ freebytes(x->x_inc256, x->x_n_delays * sizeof(int));
+ freebytes(x->x_biginc256, x->x_n_delays * sizeof(int));
+ freebytes(x->x_io, (x->x_n_delays + 1) * sizeof(t_float *));
+ freebytes(x->x_begmem0, 2 * x->x_mallocsize * sizeof(t_float));
+}
+
+void n_delay1p_line_tilde_setup(void)
+{
+ n_delay1p_line_tilde_class = class_new(gensym("n_delay1p_line~"), (t_newmethod)n_delay1p_line_tilde_new, (t_method)n_delay1p_line_tilde_free,
+ sizeof(t_n_delay1p_line_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(n_delay1p_line_tilde_class, t_n_delay1p_line_tilde, x_msi);
+ class_addlist(n_delay1p_line_tilde_class, (t_method)n_delay1p_line_tilde_list);
+ class_addmethod(n_delay1p_line_tilde_class, (t_method)n_delay1p_line_tilde_dsp, gensym("dsp"), 0);
+ class_addmethod(n_delay1p_line_tilde_class, (t_method)n_delay1p_line_tilde_stop, gensym("stop"), 0);
+ class_addmethod(n_delay1p_line_tilde_class, (t_method)n_delay1p_line_tilde_time, gensym("time"), A_FLOAT, 0);
+ class_sethelpsymbol(n_delay1p_line_tilde_class, gensym("iemhelp2/help-n_delay1p_line~"));
+}
diff --git a/src/n_delay2p_line~.c b/src/n_delay2p_line~.c
new file mode 100644
index 0000000..f747b65
--- /dev/null
+++ b/src/n_delay2p_line~.c
@@ -0,0 +1,462 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include "iem_delay.h"
+
+/* -------------------------- n_delay2p_line_tilde~ ------------------------------ */
+static t_class *n_delay2p_line_tilde_class;
+
+t_float n_delay2p_line_tilde_256f[258];
+
+typedef struct _n_delay2p_line_tilde
+{
+ t_object x_obj;
+ int x_mallocsize;
+ t_float x_max_delay_ms;
+ t_float *x_begmem0;
+ t_float *x_begmem1;
+ int x_writeindex;
+ int x_n_delays;
+ int *x_del_samp256_end;
+ int *x_del_samp256_cur;
+ int *x_inc256;
+ int *x_biginc256;
+ int x_blocksize;
+ t_float x_sr;
+ t_float x_ms2tick;
+ t_float x_ms2samples256;
+ t_float x_interpol_ms;
+ int x_interpol_ticks;
+ int x_ticksleft;
+ int x_old;
+ int x_retarget;
+ t_float **x_io;
+ t_float x_msi;
+} t_n_delay2p_line_tilde;
+
+static void n_delay2p_line_tilde_init_f(t_n_delay2p_line_tilde *x)
+{
+ if(n_delay2p_line_tilde_256f[257] == 0.0f)
+ {
+ int i;
+
+ for(i=0; i<257; i++)
+ {
+ n_delay2p_line_tilde_256f[i] = (t_float)i / 256.0f;
+ }
+ n_delay2p_line_tilde_256f[257] = 1.0f;
+ }
+}
+
+static void n_delay2p_line_tilde_list(t_n_delay2p_line_tilde *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if(argc == x->x_n_delays)
+ {
+ int i;
+ t_float delay, max=x->x_max_delay_ms;
+
+ if(x->x_interpol_ms <= 0.0f)
+ x->x_ticksleft = x->x_retarget = 0;
+ else
+ x->x_retarget = 1;
+ for(i=0; i<argc; i++)
+ {
+ delay = atom_getfloat(argv++);
+ if(delay < 0.0f)
+ delay = 0.0f;
+ if(delay > max)
+ delay = max;
+ if(x->x_interpol_ms <= 0.0f)
+ x->x_del_samp256_end[i] = x->x_del_samp256_cur[i] = (int)(x->x_ms2samples256 * delay + 0.5f) + 127;
+ else
+ x->x_del_samp256_end[i] = (int)(x->x_ms2samples256 * delay + 0.5f) + 127;
+ }
+ }
+}
+
+static void n_delay2p_line_tilde_time(t_n_delay2p_line_tilde *x, t_floatarg interpol_ms)
+{
+ if(interpol_ms < 0.0f)
+ interpol_ms = 0.0f;
+ x->x_interpol_ms = interpol_ms;
+ x->x_interpol_ticks = (int)(x->x_ms2tick * interpol_ms);
+}
+
+static void n_delay2p_line_tilde_stop(t_n_delay2p_line_tilde *x)
+{
+ int i, n=x->x_n_delays;
+
+ for(i=0; i<n; i++)
+ x->x_del_samp256_end[i] = x->x_del_samp256_cur[i];
+ x->x_ticksleft = x->x_retarget = 0;
+}
+
+static t_int *n_delay2p_line_tilde_perform(t_int *w)
+{
+ t_n_delay2p_line_tilde *x = (t_n_delay2p_line_tilde *)(w[1]);
+ int hn=(int)(w[2]);
+ int nout=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int writeindex = x->x_writeindex;
+ int i, j, n, fractindex;
+ int malloc_samples = x->x_mallocsize;
+ t_float *begvec0 = x->x_begmem0;
+ t_float *begvec1 = x->x_begmem1;
+ t_float *writevec;
+ t_float *readvec;
+ t_float fract;
+ int del256, inc256;
+
+ writevec = begvec0 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n--)
+ {
+ *writevec++ = *in++;
+ }
+ writevec = begvec1 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n--)
+ {
+ *writevec++ = *in++;
+ }
+
+ if(x->x_retarget)
+ {
+ int nticks = x->x_interpol_ticks;
+
+ if(!nticks)
+ nticks = 1;
+ x->x_ticksleft = nticks;
+ for(j=0; j<nout; j++)
+ {
+ x->x_biginc256[j] = (x->x_del_samp256_end[j] - x->x_del_samp256_cur[j]) / nticks;
+ x->x_inc256[j] = x->x_biginc256[j] / x->x_blocksize;
+ }
+ x->x_retarget = 0;
+ }
+
+ if(x->x_ticksleft)
+ {
+ for(j=0; j<nout; j++)
+ {
+ inc256 = x->x_inc256[j];
+ del256 = x->x_del_samp256_cur[j];
+ out = x->x_io[j+1];
+ for(i=0; i<hn; i++)
+ {
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ readvec = begvec1 + writeindex - (del256 >> 8) + i;
+ *out++ = readvec[0] - (readvec[0] - readvec[-1])*fract;
+ del256 += inc256;
+ }
+ x->x_del_samp256_cur[j] += x->x_biginc256[j];
+ }
+ x->x_ticksleft--;
+ }
+ else
+ {
+ for(j=0; j<nout; j++)
+ {
+ del256 = x->x_del_samp256_cur[j] = x->x_del_samp256_end[j];
+ readvec = begvec1 + writeindex - (del256 >> 8);
+ out = x->x_io[j+1];
+ n = hn;
+ while(n--)
+ {
+ *out++ = *readvec++;
+ }
+ }
+ }
+ writeindex += hn;
+ if(writeindex >= malloc_samples)
+ {
+ writeindex -= malloc_samples;
+ }
+ x->x_writeindex = writeindex;
+ return(w+3);
+}
+
+static t_int *n_delay2p_line_tilde_perf8(t_int *w)
+{
+ t_n_delay2p_line_tilde *x = (t_n_delay2p_line_tilde *)(w[1]);
+ int hn=(int)(w[2]);
+ int nout=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int writeindex = x->x_writeindex;
+ int i, j, k, n, fractindex;
+ int malloc_samples = x->x_mallocsize;
+ t_float *begvec0 = x->x_begmem0;
+ t_float *begvec1 = x->x_begmem1;
+ t_float *writevec;
+ t_float *readvec;
+ t_float fract;
+ int del256, inc256;
+
+// post("writevec = %d",writeindex);
+ writevec = begvec0 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n)
+ {
+ writevec[0] = in[0];
+ writevec[1] = in[1];
+ writevec[2] = in[2];
+ writevec[3] = in[3];
+ writevec[4] = in[4];
+ writevec[5] = in[5];
+ writevec[6] = in[6];
+ writevec[7] = in[7];
+
+ writevec += 8;
+ n -= 8;
+ in += 8;
+ }
+ writevec = begvec1 + writeindex;
+ in=x->x_io[0];
+ n = hn;
+ while(n)
+ {
+ writevec[0] = in[0];
+ writevec[1] = in[1];
+ writevec[2] = in[2];
+ writevec[3] = in[3];
+ writevec[4] = in[4];
+ writevec[5] = in[5];
+ writevec[6] = in[6];
+ writevec[7] = in[7];
+
+ writevec += 8;
+ n -= 8;
+ in += 8;
+ }
+
+ if(x->x_retarget)
+ {
+ int nticks = x->x_interpol_ticks;
+
+ if(!nticks)
+ nticks = 1;
+ x->x_ticksleft = nticks;
+ for(j=0; j<nout; j++)
+ {
+ x->x_biginc256[j] = (x->x_del_samp256_end[j] - x->x_del_samp256_cur[j]) / nticks;
+ x->x_inc256[j] = x->x_biginc256[j] / x->x_blocksize;
+ }
+ x->x_retarget = 0;
+ }
+
+ if(x->x_ticksleft)
+ {
+ for(j=0; j<nout; j++)
+ {
+ inc256 = x->x_inc256[j];
+ del256 = x->x_del_samp256_cur[j];
+ out = x->x_io[j+1];
+ readvec = begvec1 + writeindex;
+ for(i=0; i<hn; i+=8)
+ {
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[0] = readvec[0-k] - (readvec[0-k] - readvec[-1-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[1] = readvec[1-k] - (readvec[1-k] - readvec[0-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[2] = readvec[2-k] - (readvec[2-k] - readvec[1-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[3] = readvec[3-k] - (readvec[3-k] - readvec[2-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[4] = readvec[4-k] - (readvec[4-k] - readvec[3-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[5] = readvec[5-k] - (readvec[5-k] - readvec[4-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[6] = readvec[6-k] - (readvec[6-k] - readvec[5-k])*fract;
+ del256 += inc256;
+
+ fractindex = del256 & 0xff;
+ fract = n_delay2p_line_tilde_256f[fractindex];
+ k = del256 >> 8;
+ out[7] = readvec[7-k] - (readvec[7-k] - readvec[6-k])*fract;
+ del256 += inc256;
+
+ out += 8;
+ readvec += 8;
+ }
+ x->x_del_samp256_cur[j] += x->x_biginc256[j];
+ }
+ x->x_ticksleft--;
+ }
+ else
+ {
+ for(j=0; j<nout; j++)
+ {
+ del256 = x->x_del_samp256_cur[j] = x->x_del_samp256_end[j];
+ readvec = begvec1 + writeindex - (del256 >> 8);
+ out = x->x_io[j+1];
+ n = hn;
+ while(n)
+ {
+ out[0] = readvec[0];
+ out[1] = readvec[1];
+ out[2] = readvec[2];
+ out[3] = readvec[3];
+ out[4] = readvec[4];
+ out[5] = readvec[5];
+ out[6] = readvec[6];
+ out[7] = readvec[7];
+ out += 8;
+ readvec += 8;
+ n -= 8;
+ }
+ }
+ }
+ writeindex += hn;
+ if(writeindex >= malloc_samples)
+ {
+ writeindex -= malloc_samples;
+ }
+ x->x_writeindex = writeindex;
+ return(w+3);
+}
+
+static void n_delay2p_line_tilde_dsp(t_n_delay2p_line_tilde *x, t_signal **sp)
+{
+ int n = sp[0]->s_n;
+ int i, nd = x->x_n_delays + 1;
+
+ if(!x->x_blocksize)/*first time*/
+ {
+ int nsamps = x->x_max_delay_ms * (t_float)sp[0]->s_sr * 0.001f;
+
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (n - 1));
+ nsamps += n;
+ x->x_mallocsize = nsamps;
+ x->x_begmem0 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ x->x_writeindex = n;
+ }
+ else if((x->x_blocksize != n) || ((t_float)sp[0]->s_sr != x->x_sr))
+ {
+ int nsamps = x->x_max_delay_ms * (t_float)sp[0]->s_sr * 0.001f;
+
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (n - 1));
+ nsamps += n;
+ x->x_begmem0 = (t_float *)resizebytes(x->x_begmem0, 2*x->x_mallocsize*sizeof(t_float), 2*nsamps*sizeof(t_float));
+ x->x_mallocsize = nsamps;
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ if(x->x_writeindex >= nsamps)
+ x->x_writeindex -= nsamps;
+ }
+ x->x_blocksize = n;
+ x->x_ms2tick = 0.001f * (t_float)sp[0]->s_sr / (t_float)n;
+ x->x_ms2samples256 = 0.256f * (t_float)sp[0]->s_sr;
+ x->x_interpol_ticks = (int)(x->x_ms2tick * x->x_interpol_ms);
+ for(i=0; i<nd; i++)
+ x->x_io[i] = sp[i]->s_vec;
+ if(n&7)
+ dsp_add(n_delay2p_line_tilde_perform, 2, x, n);
+ else
+ dsp_add(n_delay2p_line_tilde_perf8, 2, x, n);
+}
+
+static void *n_delay2p_line_tilde_new(t_floatarg fout, t_floatarg delay_ms, t_floatarg interpol_ms)
+{
+ t_n_delay2p_line_tilde *x = (t_n_delay2p_line_tilde *)pd_new(n_delay2p_line_tilde_class);
+ int i, n_out = (int)fout;
+ int nsamps = delay_ms * sys_getsr() * 0.001f;
+
+ if(n_out < 1)
+ n_out = 1;
+ x->x_n_delays = n_out;
+ x->x_max_delay_ms = delay_ms;
+ if(nsamps < 1)
+ nsamps = 1;
+ nsamps += ((- nsamps) & (DELLINE_DEF_VEC_SIZE - 1));
+ nsamps += DELLINE_DEF_VEC_SIZE;
+ x->x_mallocsize = nsamps;
+ x->x_begmem0 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem1 = x->x_begmem0 + x->x_mallocsize;
+ x->x_writeindex = DELLINE_DEF_VEC_SIZE;
+ x->x_blocksize = 0;
+ x->x_sr = 0.0f;
+ if(interpol_ms < 0.0f)
+ interpol_ms = 0.0f;
+ x->x_interpol_ms = interpol_ms;
+ x->x_io = (t_float **)getbytes((x->x_n_delays + 1) * sizeof(t_float *));
+ for(i=0; i<n_out; i++)
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_del_samp256_end = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_del_samp256_cur = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_inc256 = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_biginc256 = (int *)getbytes(x->x_n_delays * sizeof(int));
+ x->x_ticksleft = x->x_retarget = 0;
+ for(i=0; i<n_out; i++)
+ {
+ x->x_del_samp256_cur[i] = x->x_del_samp256_end[i] = 0;
+ x->x_inc256[i] = x->x_biginc256[i] = 0;
+ }
+ x->x_interpol_ticks = 0;
+ x->x_msi = 0.0f;
+ n_delay2p_line_tilde_init_f(x);
+ return (x);
+}
+
+static void n_delay2p_line_tilde_free(t_n_delay2p_line_tilde *x)
+{
+ freebytes(x->x_del_samp256_end, x->x_n_delays * sizeof(int));
+ freebytes(x->x_del_samp256_cur, x->x_n_delays * sizeof(int));
+ freebytes(x->x_inc256, x->x_n_delays * sizeof(int));
+ freebytes(x->x_biginc256, x->x_n_delays * sizeof(int));
+ freebytes(x->x_io, (x->x_n_delays + 1) * sizeof(t_float *));
+ freebytes(x->x_begmem0, 2 * x->x_mallocsize * sizeof(t_float));
+}
+
+void n_delay2p_line_tilde_setup(void)
+{
+ n_delay2p_line_tilde_class = class_new(gensym("n_delay2p_line~"), (t_newmethod)n_delay2p_line_tilde_new, (t_method)n_delay2p_line_tilde_free,
+ sizeof(t_n_delay2p_line_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(n_delay2p_line_tilde_class, t_n_delay2p_line_tilde, x_msi);
+ class_addlist(n_delay2p_line_tilde_class, (t_method)n_delay2p_line_tilde_list);
+ class_addmethod(n_delay2p_line_tilde_class, (t_method)n_delay2p_line_tilde_dsp, gensym("dsp"), 0);
+ class_addmethod(n_delay2p_line_tilde_class, (t_method)n_delay2p_line_tilde_stop, gensym("stop"), 0);
+ class_addmethod(n_delay2p_line_tilde_class, (t_method)n_delay2p_line_tilde_time, gensym("time"), A_FLOAT, 0);
+ class_sethelpsymbol(n_delay2p_line_tilde_class, gensym("iemhelp2/help-n_delay2p_line~"));
+}
diff --git a/src/nz~.c b/src/nz~.c
new file mode 100644
index 0000000..110e3d9
--- /dev/null
+++ b/src/nz~.c
@@ -0,0 +1,250 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_delay written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include "iem_delay.h"
+
+/* -------------------------- nz_tilde~ ------------------------------ */
+static t_class *nz_tilde_class;
+
+typedef struct _nz_tilde
+{
+ t_object x_obj;
+ t_float *x_begmem1;
+ t_float *x_begmem2;
+ int x_mallocsize;
+ int x_max_delay_samples;
+ int x_n_delays;
+ int x_writeindex;
+ int *x_del_samples;
+ int x_blocksize;
+ t_float **x_io;
+ t_float x_msi;
+} t_nz_tilde;
+
+static void nz_tilde_list(t_nz_tilde *x, t_symbol *s, int argc, t_atom *argv)
+{
+ if(argc == x->x_n_delays)
+ {
+ int i, delay, max=x->x_max_delay_samples;
+
+ for(i=0; i<argc; i++)
+ {
+ delay = atom_getint(argv++);
+ if(delay < 0)
+ delay = 0;
+ if(delay > max)
+ delay = max;
+ x->x_del_samples[i] = delay;
+ }
+ }
+ else
+ post("nz~-ERROR: list need %d delay-values between 0 and %d samples !!!!", x->x_n_delays, x->x_max_delay_samples);
+}
+
+static t_int *nz_tilde_perform(t_int *w)
+{
+ t_nz_tilde *x = (t_nz_tilde *)(w[1]);
+ int n=(int)(w[2]);
+ int num_dels=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int i, j;
+ t_float *writevec1;
+ t_float *writevec2;
+ t_float *readvec;
+
+ writevec2 = x->x_begmem2 + x->x_writeindex;
+ in = x->x_io[0];
+ for(i=0; i<n; i++)
+ writevec2[i] = in[i];
+
+ for(j=0; j<num_dels; j++)
+ {
+ out = x->x_io[j+1];
+ readvec = writevec2 - x->x_del_samples[j];
+ for(i=0; i<n; i++)
+ out[i] = readvec[i];
+ }
+
+ writevec1 = x->x_begmem1 + x->x_writeindex;
+ for(i=0; i<n; i++)
+ writevec1[i] = writevec2[i];
+
+ x->x_writeindex += n;
+ if(x->x_writeindex >= x->x_mallocsize)
+ x->x_writeindex -= x->x_mallocsize;
+
+ return(w+3);
+}
+
+static t_int *nz_tilde_perf8(t_int *w)
+{
+ t_nz_tilde *x = (t_nz_tilde *)(w[1]);
+ int n=(int)(w[2]);
+ int num_dels=x->x_n_delays;
+ t_float *in;
+ t_float *out;
+ int i, j;
+ t_float *writevec1;
+ t_float *writevec2;
+ t_float *readvec;
+
+ writevec2 = x->x_begmem2 + x->x_writeindex;
+ in = x->x_io[0];
+ i = n;
+ while(i)
+ {
+ writevec2[0] = in[0];
+ writevec2[1] = in[1];
+ writevec2[2] = in[2];
+ writevec2[3] = in[3];
+ writevec2[4] = in[4];
+ writevec2[5] = in[5];
+ writevec2[6] = in[6];
+ writevec2[7] = in[7];
+
+ writevec2 += 8;
+ in += 8;
+ i -= 8;
+ }
+
+ for(j=0; j<num_dels; j++)
+ {
+ out = x->x_io[j+1];
+ readvec = writevec2 - x->x_del_samples[j];
+ i = n;
+ while(i)
+ {
+ out[0] = readvec[0];
+ out[1] = readvec[1];
+ out[2] = readvec[2];
+ out[3] = readvec[3];
+ out[4] = readvec[4];
+ out[5] = readvec[5];
+ out[6] = readvec[6];
+ out[7] = readvec[7];
+ out += 8;
+ readvec += 8;
+ i -= 8;
+ }
+ }
+
+ writevec1 = x->x_begmem1 + x->x_writeindex;
+ writevec2 = x->x_begmem2 + x->x_writeindex;
+ i = n;
+ while(i)
+ {
+ writevec1[0] = writevec2[0];
+ writevec1[1] = writevec2[1];
+ writevec1[2] = writevec2[2];
+ writevec1[3] = writevec2[3];
+ writevec1[4] = writevec2[4];
+ writevec1[5] = writevec2[5];
+ writevec1[6] = writevec2[6];
+ writevec1[7] = writevec2[7];
+
+ writevec1 += 8;
+ writevec2 += 8;
+ i -= 8;
+ }
+
+ x->x_writeindex += n;
+ if(x->x_writeindex >= x->x_mallocsize)
+ x->x_writeindex -= x->x_mallocsize;
+
+ return(w+3);
+}
+
+static void nz_tilde_dsp(t_nz_tilde *x, t_signal **sp)
+{
+ int n = sp[0]->s_n;
+ int i, j, max_samps, num_dels = x->x_n_delays + 1;
+
+ if(!x->x_blocksize)/*first time*/
+ {
+ max_samps = x->x_max_delay_samples;
+ i = max_samps / n;
+ j = max_samps - i * n;
+ if(j)
+ max_samps = (i+1) * n;
+ else
+ max_samps = i * n;
+// post("malloc = %d, maxdel = %d", max_samps, x->x_max_delay_samples);
+ x->x_mallocsize = max_samps;
+ x->x_begmem1 = (t_float *)getbytes(2 * x->x_mallocsize * sizeof(t_float));
+ x->x_begmem2 = x->x_begmem1 + x->x_mallocsize;
+ x->x_writeindex = 0;
+ }
+ else if(x->x_blocksize != n)
+ {
+ max_samps = x->x_max_delay_samples;
+ i = max_samps / n;
+ j = max_samps - i * n;
+ if(j)
+ max_samps = (i+1) * n;
+ else
+ max_samps = i * n;
+ x->x_begmem1 = (t_float *)resizebytes(x->x_begmem1, 2*x->x_mallocsize*sizeof(t_float), 2*max_samps*sizeof(t_float));
+ x->x_mallocsize = max_samps;
+ x->x_begmem2 = x->x_begmem1 + x->x_mallocsize;
+ x->x_writeindex = 0;
+ }
+ x->x_blocksize = n;
+ for(i=0; i<num_dels; i++)
+ x->x_io[i] = sp[i]->s_vec;
+ if(n&7)
+ dsp_add(nz_tilde_perform, 2, x, n);
+ else
+ dsp_add(nz_tilde_perf8, 2, x, n);
+}
+
+static void *nz_tilde_new(t_floatarg n_delays, t_floatarg max_delay_samples)
+{
+ t_nz_tilde *x = (t_nz_tilde *)pd_new(nz_tilde_class);
+ int i, n_out = (int)n_delays;
+ int max_samps = (int)max_delay_samples;
+
+ if(n_out < 1)
+ n_out = 1;
+ x->x_n_delays = n_out;
+ if(max_samps < 1)
+ max_samps = 1;
+ x->x_max_delay_samples = max_samps;
+ x->x_mallocsize = 0;
+ x->x_begmem1 = (t_float *)0;
+ x->x_begmem2 = (t_float *)0;
+ x->x_writeindex = 0;
+ x->x_blocksize = 0;
+ x->x_io = (t_float **)getbytes((x->x_n_delays + 1) * sizeof(t_float *));
+ x->x_del_samples = (int *)getbytes(x->x_n_delays * sizeof(int));
+ for(i=0; i<n_out; i++)
+ {
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_del_samples[i] = 0;
+ }
+ x->x_msi = 0.0f;
+ return (x);
+}
+
+static void nz_tilde_free(t_nz_tilde *x)
+{
+ freebytes(x->x_del_samples, x->x_n_delays * sizeof(int));
+ freebytes(x->x_io, (x->x_n_delays + 1) * sizeof(t_float *));
+ if(x->x_begmem1)
+ freebytes(x->x_begmem1, 2 * x->x_mallocsize * sizeof(t_float));
+}
+
+void nz_tilde_setup(void)
+{
+ nz_tilde_class = class_new(gensym("nz~"), (t_newmethod)nz_tilde_new, (t_method)nz_tilde_free,
+ sizeof(t_nz_tilde), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(nz_tilde_class, t_nz_tilde, x_msi);
+ class_addlist(nz_tilde_class, (t_method)nz_tilde_list);
+ class_addmethod(nz_tilde_class, (t_method)nz_tilde_dsp, gensym("dsp"), 0);
+ class_sethelpsymbol(nz_tilde_class, gensym("iemhelp2/help-nz~"));
+}