From a6395245153880a8b67f49631d3c5208c636a940 Mon Sep 17 00:00:00 2001 From: musil Date: Thu, 30 Nov 2006 12:46:20 +0000 Subject: initial commit changed float to t_float -fno-strict-aliasing #pragma obsolete help-*.pd to *-help.pd svn path=/trunk/externals/iem/iem_matrix/; revision=6543 --- src/iem_matrix.c | 44 +++ src/iem_matrix.dsp | 85 ++++++ src/iem_matrix.dsw | 29 ++ src/iemlib.h | 108 +++++++ src/makefile | 55 ++++ src/makefile_linux | 55 ++++ src/makefile_win | 46 +++ src/matrix_bundle_line8~.c | 479 ++++++++++++++++++++++++++++++ src/matrix_bundle_line~.c | 493 +++++++++++++++++++++++++++++++ src/matrix_bundle_stat~.c | 283 ++++++++++++++++++ src/matrix_diag_mul_line8~.c | 409 ++++++++++++++++++++++++++ src/matrix_diag_mul_line~.c | 415 ++++++++++++++++++++++++++ src/matrix_diag_mul_stat~.c | 269 +++++++++++++++++ src/matrix_mul_line8~.c | 657 +++++++++++++++++++++++++++++++++++++++++ src/matrix_mul_line~.c | 686 +++++++++++++++++++++++++++++++++++++++++++ src/matrix_mul_stat~.c | 462 +++++++++++++++++++++++++++++ src/matrix_orthogonal.c | 161 ++++++++++ src/matrix_pinv.c | 600 +++++++++++++++++++++++++++++++++++++ src/spherical_line.c | 264 +++++++++++++++++ 19 files changed, 5600 insertions(+) create mode 100644 src/iem_matrix.c create mode 100644 src/iem_matrix.dsp create mode 100644 src/iem_matrix.dsw create mode 100644 src/iemlib.h create mode 100644 src/makefile create mode 100644 src/makefile_linux create mode 100644 src/makefile_win create mode 100644 src/matrix_bundle_line8~.c create mode 100644 src/matrix_bundle_line~.c create mode 100644 src/matrix_bundle_stat~.c create mode 100644 src/matrix_diag_mul_line8~.c create mode 100644 src/matrix_diag_mul_line~.c create mode 100644 src/matrix_diag_mul_stat~.c create mode 100644 src/matrix_mul_line8~.c create mode 100644 src/matrix_mul_line~.c create mode 100644 src/matrix_mul_stat~.c create mode 100644 src/matrix_orthogonal.c create mode 100644 src/matrix_pinv.c create mode 100644 src/spherical_line.c (limited to 'src') diff --git a/src/iem_matrix.c b/src/iem_matrix.c new file mode 100644 index 0000000..d440162 --- /dev/null +++ b/src/iem_matrix.c @@ -0,0 +1,44 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + +static t_class *iem_matrix_class; + +static void *iem_matrix_new(void) +{ + t_object *x = (t_object *)pd_new(iem_matrix_class); + + return (x); +} + +void matrix_mul_line_tilde_setup(void); +void matrix_mul_line8_tilde_setup(void); +void matrix_mul_stat_tilde_setup(void); +void matrix_diag_mul_line_tilde_setup(void); +void matrix_diag_mul_line8_tilde_setup(void); +void matrix_diag_mul_stat_tilde_setup(void); +void matrix_bundle_line_tilde_setup(void); +void matrix_bundle_line8_tilde_setup(void); +void matrix_bundle_stat_tilde_setup(void); + +/* ------------------------ setup routine ------------------------- */ + +void iem_matrix_setup(void) +{ + matrix_mul_line_tilde_setup(); + matrix_mul_line8_tilde_setup(); + matrix_mul_stat_tilde_setup(); + matrix_diag_mul_line_tilde_setup(); + matrix_diag_mul_line8_tilde_setup(); + matrix_diag_mul_stat_tilde_setup(); + matrix_bundle_line_tilde_setup(); + matrix_bundle_line8_tilde_setup(); + matrix_bundle_stat_tilde_setup(); + + post("iem_matrix (R-1.16) library loaded! (c) Thomas Musil 05.2005"); + post(" musil%ciem.at iem KUG Graz Austria", '@'); +} diff --git a/src/iem_matrix.dsp b/src/iem_matrix.dsp new file mode 100644 index 0000000..1664498 --- /dev/null +++ b/src/iem_matrix.dsp @@ -0,0 +1,85 @@ +# Microsoft Developer Studio Project File - Name="iem_matrix" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=iem_matrix - 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_matrix.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_matrix.mak" CFG="iem_matrix - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "iem_matrix - Win32 Release" (basierend auf "Win32 (x86) External Target") +!MESSAGE "iem_matrix - Win32 Debug" (basierend auf "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "iem_matrix - 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_matrix.exe" +# PROP Bsc_Name "iem_matrix.bsc" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "iem_matrix - 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_matrix.exe" +# PROP Bsc_Name "iem_matrix.bsc" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "iem_matrix - Win32 Release" +# Name "iem_matrix - Win32 Debug" + +!IF "$(CFG)" == "iem_matrix - Win32 Release" + +!ELSEIF "$(CFG)" == "iem_matrix - Win32 Debug" + +!ENDIF + +# Begin Source File + +SOURCE=.\makefile_win +# End Source File +# End Target +# End Project diff --git a/src/iem_matrix.dsw b/src/iem_matrix.dsw new file mode 100644 index 0000000..13eafa1 --- /dev/null +++ b/src/iem_matrix.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_matrix"=.\iem_matrix.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/src/iemlib.h b/src/iemlib.h new file mode 100644 index 0000000..36d47ca --- /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 - 2006 */ + +#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 +#else +extern int sys_noloadbang; +//extern t_symbol *iemgui_key_sym; +#include +#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 +#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 +#define int32 int32_t +#endif +#ifdef __linux__ + +#include + +#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 +#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..45c8748 --- /dev/null +++ b/src/makefile @@ -0,0 +1,55 @@ +current: all + +.SUFFIXES: .pd_linux + +INCLUDE = -I. -I/usr/local/src/pd/src + +LDFLAGS = -export-dynamic -shared +LIB = -ldl -lm -lpthread + +#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 + +SYSTEM = $(shell uname -m) + +# the sources + +SRC = matrix_mul_line~.c \ + matrix_mul_line8~.c \ + matrix_mul_stat~.c \ + matrix_diag_mul_line~.c \ + matrix_diag_mul_line8~.c \ + matrix_diag_mul_stat~.c \ + matrix_bundle_line~.c \ + matrix_bundle_line8~.c \ + matrix_bundle_stat~.c \ + iem_matrix.c + +TARGET = iem_matrix.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) + mv $(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..45c8748 --- /dev/null +++ b/src/makefile_linux @@ -0,0 +1,55 @@ +current: all + +.SUFFIXES: .pd_linux + +INCLUDE = -I. -I/usr/local/src/pd/src + +LDFLAGS = -export-dynamic -shared +LIB = -ldl -lm -lpthread + +#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 + +SYSTEM = $(shell uname -m) + +# the sources + +SRC = matrix_mul_line~.c \ + matrix_mul_line8~.c \ + matrix_mul_stat~.c \ + matrix_diag_mul_line~.c \ + matrix_diag_mul_line8~.c \ + matrix_diag_mul_stat~.c \ + matrix_bundle_line~.c \ + matrix_bundle_line8~.c \ + matrix_bundle_stat~.c \ + iem_matrix.c + +TARGET = iem_matrix.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) + mv $(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..e1cd1da --- /dev/null +++ b/src/makefile_win @@ -0,0 +1,46 @@ + +all: ..\iem_matrix.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 = matrix_mul_line~.c \ + matrix_mul_line8~.c \ + matrix_mul_stat~.c \ + matrix_diag_mul_line~.c \ + matrix_diag_mul_line8~.c \ + matrix_diag_mul_stat~.c \ + matrix_bundle_line~.c \ + matrix_bundle_line8~.c \ + matrix_bundle_stat~.c \ + iem_matrix.c + + +OBJ = $(SRC:.c=.obj) + +.c.obj: + cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c + +..\iem_matrix.dll: $(OBJ) + link $(PD_WIN_L_FLAGS) /dll /export:iem_matrix_setup \ + /out:..\iem_matrix.dll $(OBJ) $(PD_WIN_LIB) + +clean: + del *.obj diff --git a/src/matrix_bundle_line8~.c b/src/matrix_bundle_line8~.c new file mode 100644 index 0000000..86de343 --- /dev/null +++ b/src/matrix_bundle_line8~.c @@ -0,0 +1,479 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_bundle_line8~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_bundle_line8_tilde +{ + t_object x_obj; + int *x_in2out_new; + int *x_in2out_old; + int *x_remaining_ticks; + int *x_retarget; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_inc8; + t_float x_biginc; + t_float x_raise_cur; + t_float x_raise_end; + t_float x_fall_cur; + t_float x_fall_end; + t_float x_msi; + int x_remaining_ticks_start; + t_float x_time_ms; + t_float x_ms2tick; + t_float x_8overn; +} t_matrix_bundle_line8_tilde; + +t_class *matrix_bundle_line8_tilde_class; + +static void matrix_bundle_line8_tilde_time(t_matrix_bundle_line8_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; + + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; +} + +static void matrix_bundle_line8_tilde_element(t_matrix_bundle_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int inindex, outindex; + + if(argc < 2) + { + post("matrix_bundle_line8~ : bad list: output_row_index input_col_index !"); + return; + } + + if(x->x_time_ms <= 0.0f) + { + outindex = (int)atom_getint(argv); + argv++; + inindex = (int)atom_getint(argv) - 1; + + if(inindex >= x->x_n_in) + inindex = x->x_n_in - 1; + if(inindex < 0) + inindex = 0; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + + x->x_in2out_old[inindex] = x->x_in2out_new[inindex] = outindex;/*retarget = 0*/ + x->x_remaining_ticks[inindex] = x->x_retarget[inindex] = 0; + x->x_fall_end = x->x_fall_cur = 0.0f; + x->x_raise_end = x->x_raise_cur = 1.0f; + } + else + { + x->x_inc8 = x->x_8overn / (float)x->x_remaining_ticks_start; + x->x_biginc = 1.0f / (float)x->x_remaining_ticks_start; + + x->x_fall_end = 0.0f; + x->x_fall_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_raise_cur = 0.0f; + + outindex = (int)atom_getint(argv); + argv++; + inindex = (int)atom_getint(argv) - 1; + + if(inindex >= x->x_n_in) + inindex = x->x_n_in - 1; + if(inindex < 0) + inindex = 0; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + + x->x_in2out_new[inindex] = outindex; + if(x->x_in2out_new[inindex] == x->x_in2out_old[inindex]) + x->x_retarget[inindex] = 0; + else + x->x_retarget[inindex] = 1; + } +} + +static void matrix_bundle_line8_tilde_list(t_matrix_bundle_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int outindex, i, n=x->x_n_in; + + if(argc < n) + { + post("matrix_bundle_line8~ : bad list: (number_of_input_cols = %d) * output_row_index !", n); + return; + } + + if(x->x_time_ms <= 0.0f) + { + for(i=0; i= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + x->x_in2out_old[i] = x->x_in2out_new[i] = outindex;/*retarget = 0*/ + x->x_remaining_ticks[i] = x->x_retarget[i] = 0; + } + x->x_fall_end = x->x_fall_cur = 0.0f; + x->x_raise_end = x->x_raise_cur = 1.0f; + } + else + { + x->x_inc8 = x->x_8overn / (float)x->x_remaining_ticks_start; + x->x_biginc = 1.0f / (float)x->x_remaining_ticks_start; + + x->x_fall_end = 0.0f; + x->x_fall_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_raise_cur = 0.0f; + + for(i=0; ix_in2out_old[i] = x->x_in2out_new[i]; + + outindex = (int)atom_getint(argv); + argv++; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + x->x_in2out_new[i] = outindex; + if(x->x_in2out_new[i] == x->x_in2out_old[i]) + x->x_retarget[i] = 0; + else + x->x_retarget[i] = 1; + } + } +} + +static void matrix_bundle_line8_tilde_bundle(t_matrix_bundle_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + matrix_bundle_line8_tilde_list(x, &s_list, argc, argv); +} + +static void matrix_bundle_line8_tilde_stop(t_matrix_bundle_line8_tilde *x) +{ + int i, n=x->x_n_in; + + x->x_fall_end = x->x_fall_cur; + x->x_raise_end = x->x_raise_cur; + for(i=0; ix_in2out_new[i] = x->x_in2out_old[i]; + x->x_remaining_ticks[i] = x->x_retarget[i] = 0; + } +} + +/* the dsp thing */ + +static t_int *matrix_bundle_line8_tilde_perform_zero(t_int *w) +{ + t_matrix_bundle_line8_tilde *x = (t_matrix_bundle_line8_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_in = x->x_n_in; + int n_out = x->x_n_out; + t_float *out; + int j, i; + + for(j=0; jx_io; + t_float *outsum; + int *in2out_new = x->x_in2out_new; + int *in2out_old = x->x_in2out_old; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul; + t_float inc8 = x->x_inc8; + int i, j, endofticks=0; + + for(i=0; ix_retarget[i]) + { + x->x_remaining_ticks[i] = x->x_remaining_ticks_start; + x->x_retarget[i] = 0; + } + } + + for(j=0; jx_outsumbuf + j*n; + for(i=n; i; i -= 8, outsum += 8)/* reset out-buffer */ + { + outsum[0] = 0.0f; + outsum[1] = 0.0f; + outsum[2] = 0.0f; + outsum[3] = 0.0f; + outsum[4] = 0.0f; + outsum[5] = 0.0f; + outsum[6] = 0.0f; + outsum[7] = 0.0f; + } + } + + for(j=0; jx_remaining_ticks[j]) + { + in = io[j]; + if(in2out_new[j]) + { + outsum = x->x_outsumbuf + n*(in2out_new[j] - 1); + mul = x->x_raise_cur; + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each new in */ + { + outsum[0] += in[0]*mul; + outsum[1] += in[1]*mul; + outsum[2] += in[2]*mul; + outsum[3] += in[3]*mul; + outsum[4] += in[4]*mul; + outsum[5] += in[5]*mul; + outsum[6] += in[6]*mul; + outsum[7] += in[7]*mul; + mul += inc8; + } + } + // raise_cur = mul; + + in = io[j]; + if(in2out_old[j]) + { + outsum = x->x_outsumbuf + n*(in2out_old[j] - 1); + mul = x->x_fall_cur; + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each old in */ + { + outsum[0] += in[0]*mul; + outsum[1] += in[1]*mul; + outsum[2] += in[2]*mul; + outsum[3] += in[3]*mul; + outsum[4] += in[4]*mul; + outsum[5] += in[5]*mul; + outsum[6] += in[6]*mul; + outsum[7] += in[7]*mul; + mul -= inc8; + } + } + // fall_cur = mul; + + if(!--x->x_remaining_ticks[j]) + { + endofticks = 1; + } + } + else + { + in = io[j]; + if(in2out_new[j]) + { + outsum = x->x_outsumbuf + n*(in2out_new[j] - 1); + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each in */ + { + outsum[0] += in[0]; + outsum[1] += in[1]; + outsum[2] += in[2]; + outsum[3] += in[3]; + outsum[4] += in[4]; + outsum[5] += in[5]; + outsum[6] += in[6]; + outsum[7] += in[7]; + } + } + } + } + + if(x->x_remaining_ticks[j]) + { + x->x_raise_cur += x->x_biginc; + x->x_fall_cur -= x->x_biginc; + } + + if(endofticks) + { + x->x_fall_cur = x->x_fall_end; + x->x_raise_cur = x->x_raise_end; + } + + outsum = x->x_outsumbuf; + for(j=0; js_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (float)(sp[0]->s_sr) / (float)n; + x->x_8overn = 8.0f / (float)n; + + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; + + if(n&7) + { + dsp_add(matrix_bundle_line8_tilde_perform_zero, 2, x, n); + post("ERROR!!! matrix_bundle_line8_tilde~ : blocksize is %d and not a multiple of 8", n); + } + else + dsp_add(matrix_bundle_line8_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_bundle_line8_tilde_free(t_matrix_bundle_line8_tilde *x) +{ + freebytes(x->x_in2out_new, x->x_n_in * sizeof(int)); + freebytes(x->x_in2out_old, x->x_n_in * sizeof(int)); + freebytes(x->x_remaining_ticks, x->x_n_in * sizeof(int)); + freebytes(x->x_retarget, x->x_n_in * sizeof(int)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_bundle_line8_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_bundle_line8_tilde *x = (t_matrix_bundle_line8_tilde *)pd_new(matrix_bundle_line8_tilde_class); + int i, n; + + switch (argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + case 2: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = atom_getfloat(argv+2); + break; + } + + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + + x->x_in2out_new = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_in2out_old = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_remaining_ticks = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_retarget = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + + x->x_raise_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_fall_cur = 0.0f; + x->x_fall_end = 0.0f; + x->x_inc8 = 0.0f; + x->x_biginc = 0.0f; + x->x_msi = 0; + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_8overn = 8.0f / 64.0f; + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; + + n = x->x_n_in; + for(i=0; ix_in2out_new[i] = 0; + x->x_in2out_old[i] = 0; + x->x_remaining_ticks[i] = 0; + x->x_retarget[i] = 0; + } + return(x); +} + +void matrix_bundle_line8_tilde_setup(void) +{ + matrix_bundle_line8_tilde_class = class_new(gensym("matrix_bundle_line8~"), (t_newmethod)matrix_bundle_line8_tilde_new, (t_method)matrix_bundle_line8_tilde_free, + sizeof(t_matrix_bundle_line8_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_bundle_line8_tilde_class, t_matrix_bundle_line8_tilde, x_msi); + class_addmethod(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_dsp, gensym("dsp"), 0); + class_addlist(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_list); + class_addmethod(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_bundle, gensym("bundle"), A_GIMME, 0); + class_addmethod(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_bundle_line8_tilde_class, (t_method)matrix_bundle_line8_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_bundle_line8_tilde_class, gensym("iemhelp/matrix_bundle_line8~-help")); +} diff --git a/src/matrix_bundle_line~.c b/src/matrix_bundle_line~.c new file mode 100644 index 0000000..bbeb4ef --- /dev/null +++ b/src/matrix_bundle_line~.c @@ -0,0 +1,493 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_bundle_line~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_bundle_line_tilde +{ + t_object x_obj; + int *x_in2out_new; + int *x_in2out_old; + int *x_remaining_ticks; + int *x_retarget; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_inc; + t_float x_biginc; + t_float x_raise_cur; + t_float x_raise_end; + t_float x_fall_cur; + t_float x_fall_end; + t_float x_msi; + int x_remaining_ticks_start; + t_float x_time_ms; + t_float x_ms2tick; + t_float x_1overn; +} t_matrix_bundle_line_tilde; + +t_class *matrix_bundle_line_tilde_class; + +static void matrix_bundle_line_tilde_time(t_matrix_bundle_line_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; + + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; +} + +static void matrix_bundle_line_tilde_element(t_matrix_bundle_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int inindex, outindex; + + if(argc < 2) + { + post("matrix_bundle_line~ : bad list: output_row_index input_col_index !"); + return; + } + + if(x->x_time_ms <= 0.0f) + { + outindex = (int)atom_getint(argv); + argv++; + inindex = (int)atom_getint(argv) - 1; + + if(inindex >= x->x_n_in) + inindex = x->x_n_in - 1; + if(inindex < 0) + inindex = 0; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + + x->x_in2out_old[inindex] = x->x_in2out_new[inindex] = outindex;/*retarget = 0*/ + x->x_remaining_ticks[inindex] = x->x_retarget[inindex] = 0; + x->x_fall_end = x->x_fall_cur = 0.0f; + x->x_raise_end = x->x_raise_cur = 1.0f; + } + else + { + x->x_inc = x->x_1overn / (float)x->x_remaining_ticks_start; + x->x_biginc = 1.0f / (float)x->x_remaining_ticks_start; + + x->x_fall_end = 0.0f; + x->x_fall_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_raise_cur = 0.0f; + + outindex = (int)atom_getint(argv); + argv++; + inindex = (int)atom_getint(argv) - 1; + + if(inindex >= x->x_n_in) + inindex = x->x_n_in - 1; + if(inindex < 0) + inindex = 0; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + + x->x_in2out_new[inindex] = outindex; + if(x->x_in2out_new[inindex] == x->x_in2out_old[inindex]) + x->x_retarget[inindex] = 0; + else + x->x_retarget[inindex] = 1; + } +} + +static void matrix_bundle_line_tilde_list(t_matrix_bundle_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int outindex, i, n=x->x_n_in; + + if(argc < n) + { + post("matrix_bundle_line~ : bad list: (number_of_input_cols = %d) * output_row_index !", n); + return; + } + + if(x->x_time_ms <= 0.0f) + { + for(i=0; i= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + x->x_in2out_old[i] = x->x_in2out_new[i] = outindex;/*retarget = 0*/ + x->x_remaining_ticks[i] = x->x_retarget[i] = 0; + } + x->x_fall_end = x->x_fall_cur = 0.0f; + x->x_raise_end = x->x_raise_cur = 1.0f; + } + else + { + x->x_inc = x->x_1overn / (float)x->x_remaining_ticks_start; + x->x_biginc = 1.0f / (float)x->x_remaining_ticks_start; + + x->x_fall_end = 0.0f; + x->x_fall_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_raise_cur = 0.0f; + + for(i=0; ix_in2out_old[i] = x->x_in2out_new[i]; + + outindex = (int)atom_getint(argv); + argv++; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + x->x_in2out_new[i] = outindex; + if(x->x_in2out_new[i] == x->x_in2out_old[i]) + x->x_retarget[i] = 0; + else + x->x_retarget[i] = 1; + } + } +} + +static void matrix_bundle_line_tilde_bundle(t_matrix_bundle_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + matrix_bundle_line_tilde_list(x, &s_list, argc, argv); +} + +static void matrix_bundle_line_tilde_stop(t_matrix_bundle_line_tilde *x) +{ + int i, n=x->x_n_in; + + x->x_fall_end = x->x_fall_cur; + x->x_raise_end = x->x_raise_cur; + for(i=0; ix_in2out_new[i] = x->x_in2out_old[i]; + x->x_remaining_ticks[i] = x->x_retarget[i] = 0; + } +} + +/* the dsp thing */ + +static t_int *matrix_bundle_line_tilde_perform_zero(t_int *w) +{ + t_matrix_bundle_line_tilde *x = (t_matrix_bundle_line_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_in = x->x_n_in; + int n_out = x->x_n_out; + t_float *out; + int j, i; + + for(j=0; jx_io; + t_float *outsum; + int *in2out_new = x->x_in2out_new; + int *in2out_old = x->x_in2out_old; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul; + t_float inc = x->x_inc; + int i, j, endofticks=0; + + for(i=0; ix_retarget[i]) + { + x->x_remaining_ticks[i] = x->x_remaining_ticks_start; + x->x_retarget[i] = 0; + } + } + + for(j=0; jx_outsumbuf + j*n; + for(i=n; i; i -= 8, outsum += 8)/* reset out-buffer */ + { + outsum[0] = 0.0f; + outsum[1] = 0.0f; + outsum[2] = 0.0f; + outsum[3] = 0.0f; + outsum[4] = 0.0f; + outsum[5] = 0.0f; + outsum[6] = 0.0f; + outsum[7] = 0.0f; + } + } + + for(j=0; jx_remaining_ticks[j]) + { + in = io[j]; + if(in2out_new[j]) + { + outsum = x->x_outsumbuf + n*(in2out_new[j] - 1); + mul = x->x_raise_cur; + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each new in */ + { + outsum[0] += in[0]*mul; + mul += inc; + outsum[1] += in[1]*mul; + mul += inc; + outsum[2] += in[2]*mul; + mul += inc; + outsum[3] += in[3]*mul; + mul += inc; + outsum[4] += in[4]*mul; + mul += inc; + outsum[5] += in[5]*mul; + mul += inc; + outsum[6] += in[6]*mul; + mul += inc; + outsum[7] += in[7]*mul; + mul += inc; + } + } + // raise_cur = mul; + + in = io[j]; + if(in2out_old[j]) + { + outsum = x->x_outsumbuf + n*(in2out_old[j] - 1); + mul = x->x_fall_cur; + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each old in */ + { + outsum[0] += in[0]*mul; + mul -= inc; + outsum[1] += in[1]*mul; + mul -= inc; + outsum[2] += in[2]*mul; + mul -= inc; + outsum[3] += in[3]*mul; + mul -= inc; + outsum[4] += in[4]*mul; + mul -= inc; + outsum[5] += in[5]*mul; + mul -= inc; + outsum[6] += in[6]*mul; + mul -= inc; + outsum[7] += in[7]*mul; + mul -= inc; + } + } + // fall_cur = mul; + + if(!--x->x_remaining_ticks[j]) + { + endofticks = 1; + } + } + else + { + in = io[j]; + if(in2out_new[j]) + { + outsum = x->x_outsumbuf + n*(in2out_new[j] - 1); + for(i=n; i; i -= 8, outsum += 8, in += 8)/* each in */ + { + outsum[0] += in[0]; + outsum[1] += in[1]; + outsum[2] += in[2]; + outsum[3] += in[3]; + outsum[4] += in[4]; + outsum[5] += in[5]; + outsum[6] += in[6]; + outsum[7] += in[7]; + } + } + } + } + + if(x->x_remaining_ticks[j]) + { + x->x_raise_cur += x->x_biginc; + x->x_fall_cur -= x->x_biginc; + } + + if(endofticks) + { + x->x_fall_cur = x->x_fall_end; + x->x_raise_cur = x->x_raise_end; + } + + outsum = x->x_outsumbuf; + for(j=0; js_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (float)(sp[0]->s_sr) / (float)n; + x->x_1overn = 1.0f / (float)n; + + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; + + if(n&7) + { + dsp_add(matrix_bundle_line_tilde_perform_zero, 2, x, n); + post("ERROR!!! matrix_bundle_line_tilde~ : blocksize is %d and not a multiple of 8", n); + } + else + dsp_add(matrix_bundle_line_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_bundle_line_tilde_free(t_matrix_bundle_line_tilde *x) +{ + freebytes(x->x_in2out_new, x->x_n_in * sizeof(int)); + freebytes(x->x_in2out_old, x->x_n_in * sizeof(int)); + freebytes(x->x_remaining_ticks, x->x_n_in * sizeof(int)); + freebytes(x->x_retarget, x->x_n_in * sizeof(int)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_bundle_line_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_bundle_line_tilde *x = (t_matrix_bundle_line_tilde *)pd_new(matrix_bundle_line_tilde_class); + int i, n; + + switch (argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + case 2: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = atom_getfloat(argv+2); + break; + } + + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + + x->x_in2out_new = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_in2out_old = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_remaining_ticks = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_retarget = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + + x->x_raise_cur = 1.0f; + x->x_raise_end = 1.0f; + x->x_fall_cur = 0.0f; + x->x_fall_end = 0.0f; + x->x_inc = 0.0f; + x->x_biginc = 0.0f; + x->x_msi = 0; + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_1overn = 1.0f / 64.0f; + x->x_remaining_ticks_start = (int)(x->x_time_ms * x->x_ms2tick); + if(!x->x_remaining_ticks_start) + x->x_remaining_ticks_start = 1; + + n = x->x_n_in; + for(i=0; ix_in2out_new[i] = 0; + x->x_in2out_old[i] = 0; + x->x_remaining_ticks[i] = 0; + x->x_retarget[i] = 0; + } + return(x); +} + +void matrix_bundle_line_tilde_setup(void) +{ + matrix_bundle_line_tilde_class = class_new(gensym("matrix_bundle_line~"), (t_newmethod)matrix_bundle_line_tilde_new, (t_method)matrix_bundle_line_tilde_free, + sizeof(t_matrix_bundle_line_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_bundle_line_tilde_class, t_matrix_bundle_line_tilde, x_msi); + class_addmethod(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_dsp, gensym("dsp"), 0); + class_addlist(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_list); + class_addmethod(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_bundle, gensym("bundle"), A_GIMME, 0); + class_addmethod(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_bundle_line_tilde_class, (t_method)matrix_bundle_line_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_bundle_line_tilde_class, gensym("iemhelp/matrix_bundle_line~-help")); +} diff --git a/src/matrix_bundle_stat~.c b/src/matrix_bundle_stat~.c new file mode 100644 index 0000000..bee2593 --- /dev/null +++ b/src/matrix_bundle_stat~.c @@ -0,0 +1,283 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_bundle_stat~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_bundle_stat_tilde +{ + t_object x_obj; + int *x_matbuf; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_msi; +} t_matrix_bundle_stat_tilde; + +t_class *matrix_bundle_stat_tilde_class; + +static void matrix_bundle_stat_tilde_element(t_matrix_bundle_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int inindex, outindex; + int *matrix = x->x_matbuf; + + if(argc < 2) + { + post("matrix_bundle_stat~ : bad list: output_row_index input_col_index !"); + return; + } + + outindex = (int)atom_getint(argv); + argv++; + inindex = (int)atom_getint(argv) - 1; + + if(inindex >= x->x_n_in) + inindex = x->x_n_in - 1; + if(inindex < 0) + inindex = 0; + if(outindex >= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + + matrix[inindex] = outindex; +} + +static void matrix_bundle_stat_tilde_list(t_matrix_bundle_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int outindex, i, n=x->x_n_in; + int *matrix = x->x_matbuf; + + if(argc < n) + { + post("matrix_bundle_stat~ : bad list: (number_of_input_cols = %d) * output_row_index !", n); + return; + } + + for(i=0; i= x->x_n_out) + outindex = x->x_n_out; + if(outindex < 0) + outindex = 0; + matrix[i] = outindex; + } +} + +static void matrix_bundle_stat_tilde_bundle(t_matrix_bundle_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + matrix_bundle_stat_tilde_list(x, &s_list, argc, argv); +} + +/* the dsp thing */ + +static t_int *matrix_bundle_stat_tilde_perform(t_int *w) +{ + t_matrix_bundle_stat_tilde *x = (t_matrix_bundle_stat_tilde *)(w[1]); + int n = (int)(w[2]); + + t_float **io = x->x_io; + t_float *outsum; + int *mat = x->x_matbuf; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out; + int i, j, thrw; + + outsum = x->x_outsumbuf; + for(j=0; jx_outsumbuf + n*thrw; + for(i=0; ix_outsumbuf; + for(j=0; jx_io; + t_float *outsum; + int *mat = x->x_matbuf; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out; + int i, j, thrw; + + outsum = x->x_outsumbuf; + for(j=0; jx_outsumbuf + n*thrw; + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] += in[0]; + outsum[1] += in[1]; + outsum[2] += in[2]; + outsum[3] += in[3]; + outsum[4] += in[4]; + outsum[5] += in[5]; + outsum[6] += in[6]; + outsum[7] += in[7]; + } + } + } + + outsum = x->x_outsumbuf; + for(j=0; js_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + /*post("iovec_addr = %d", (unsigned int)x->x_io[i]);*/ + } + + n = sp[0]->s_n; + if(n&7) + dsp_add(matrix_bundle_stat_tilde_perform, 2, x, sp[0]->s_n); + else + dsp_add(matrix_bundle_stat_tilde_perf8, 2, x, sp[0]->s_n); +} + + +/* setup/setdown things */ + +static void matrix_bundle_stat_tilde_free(t_matrix_bundle_stat_tilde *x) +{ + freebytes(x->x_matbuf, x->x_n_in * sizeof(int)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_bundle_stat_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_bundle_stat_tilde *x = (t_matrix_bundle_stat_tilde *)pd_new(matrix_bundle_stat_tilde_class); + int i; + + switch (argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + break; + } + + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + x->x_matbuf = (int *)getbytes(x->x_n_in * sizeof(int)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + return (x); +} + +void matrix_bundle_stat_tilde_setup(void) +{ + matrix_bundle_stat_tilde_class = class_new(gensym("matrix_bundle_stat~"), (t_newmethod)matrix_bundle_stat_tilde_new, (t_method)matrix_bundle_stat_tilde_free, + sizeof(t_matrix_bundle_stat_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_bundle_stat_tilde_class, t_matrix_bundle_stat_tilde, x_msi); + class_addmethod(matrix_bundle_stat_tilde_class, (t_method)matrix_bundle_stat_tilde_dsp, gensym("dsp"), 0); + class_addlist(matrix_bundle_stat_tilde_class, (t_method)matrix_bundle_stat_tilde_list); + class_addmethod(matrix_bundle_stat_tilde_class, (t_method)matrix_bundle_stat_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_bundle_stat_tilde_class, (t_method)matrix_bundle_stat_tilde_bundle, gensym("bundle"), A_GIMME, 0); + class_sethelpsymbol(matrix_bundle_stat_tilde_class, gensym("iemhelp2/matrix_bundle_stat~-help")); +} diff --git a/src/matrix_diag_mul_line8~.c b/src/matrix_diag_mul_line8~.c new file mode 100644 index 0000000..6de4150 --- /dev/null +++ b/src/matrix_diag_mul_line8~.c @@ -0,0 +1,409 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_diag_mul_line8~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_diag_mul_line8_tilde +{ + t_object x_obj; + t_float *x_matcur; + t_float *x_matend; + t_float *x_inc8; + t_float *x_biginc; + t_float **x_io; + t_float *x_buf; + int x_bufsize; + int x_n_io; + t_float x_msi; + int x_retarget; + t_float x_time_ms; + int x_remaining_ticks; + t_float x_ms2tick; + t_float x_8overn; +} t_matrix_diag_mul_line8_tilde; + +t_class *matrix_diag_mul_line8_tilde_class; + +static void matrix_diag_mul_line8_tilde_time(t_matrix_diag_mul_line8_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; +} + +static void matrix_diag_mul_line8_tilde_element(t_matrix_diag_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int i, j, n=x->x_n_io; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(x->x_time_ms <= 0.0f) + { + if(argc == 2) + { + i = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n)) + matend[i-1] = matcur[i-1] = atom_getfloat(argv); + } + else if(argc == 3) + { + i = (int)(atom_getint(argv)); + argv++; + j = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n) && (i == j)) + matend[i-1] = matcur[i-1] = atom_getfloat(argv); + } + x->x_remaining_ticks = x->x_retarget = 0; + } + else + { + if(argc == 2) + { + i = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n)) + matend[i-1] = atom_getfloat(argv); + } + else if(argc == 3) + { + i = (int)(atom_getint(argv)); + argv++; + j = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n) && (i == j)) + matend[i-1] = atom_getfloat(argv); + } + x->x_retarget = 1; + } +} + +static void matrix_diag_mul_line8_tilde_list(t_matrix_diag_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int i, n=x->x_n_io; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc < n) + { + post("matrix_diag_mul_line8~ : dimensions do not match !!"); + return; + } + + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_diag_mul_line8_tilde_diag(t_matrix_diag_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + matrix_diag_mul_line8_tilde_list(x, &s_list, argc, argv); +} + +static void matrix_diag_mul_line8_tilde_stop(t_matrix_diag_mul_line8_tilde *x) +{ + int i = x->x_n_io; + t_float *matend=x->x_matend; + t_float *matcur=x->x_matcur; + + while(i--) + { + *matend++ = *matcur++; + } + x->x_remaining_ticks = x->x_retarget = 0; +} + +/* the dsp thing */ + +static t_int *matrix_diag_mul_line8_tilde_perform_zero(t_int *w) +{ + t_matrix_diag_mul_line8_tilde *x = (t_matrix_diag_mul_line8_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_io = x->x_n_io; + t_float *out; + int i, j; + + for(j=0; jx_io; + t_float *buf; + t_float *matcur, *matend; + t_float *inc8, *biginc, inc; + int n_io = x->x_n_io; + int hn_io = n_io / 2; + int dn_io = 2 * n_io; + t_float *in, *out1, *out2, mul; + int i, j; + + if(x->x_retarget) + { + int nticks = (int)(x->x_time_ms * x->x_ms2tick); + + if(!nticks) + nticks = 1; + x->x_remaining_ticks = nticks; + j = n_io; + inc8 = x->x_inc8; + matcur = x->x_matcur; + matend = x->x_matend; + mul = x->x_8overn / (t_float)nticks; + while(j--) + { + *inc8++ = (*matend++ - *matcur++) * mul; + } + j = n_io; + biginc = x->x_biginc; + matcur = x->x_matcur; + matend = x->x_matend; + mul = 1.0f / (t_float)nticks; + while(j--) + { + *biginc++ = (*matend++ - *matcur++) * mul; + } + x->x_retarget = 0; + } + + if(x->x_remaining_ticks) + { + inc8 = x->x_inc8; + biginc = x->x_biginc; + matcur = x->x_matcur; + for(j=0; jx_remaining_ticks) + { + matcur = x->x_matcur; + matend = x->x_matend; + i = n_io; + while(i--) + *matcur++ = *matend++; + } + } + else + { + matend = x->x_matend; + for(j=0; jx_buf; + for(i=n; i; i -= 8, buf += 8, in += 8) + { + buf[0] = in[0]; + buf[1] = in[1]; + buf[2] = in[2]; + buf[3] = in[3]; + buf[4] = in[4]; + buf[5] = in[5]; + buf[6] = in[6]; + buf[7] = in[7]; + } + in = io[n_io-j-1]; + out1 = io[j+n_io]; + out2 = io[dn_io-j-1]; + buf = x->x_buf; + for(i=n; i; i -= 8, buf += 8, in += 8, out1 += 8, out2 += 8) + { + out2[0] = in[0]; + out2[1] = in[1]; + out2[2] = in[2]; + out2[3] = in[3]; + out2[4] = in[4]; + out2[5] = in[5]; + out2[6] = in[6]; + out2[7] = in[7]; + out1[0] = buf[0]; + out1[1] = buf[1]; + out1[2] = buf[2]; + out1[3] = buf[3]; + out1[4] = buf[4]; + out1[5] = buf[5]; + out1[6] = buf[6]; + out1[7] = buf[7]; + } + } + return (w+3); +} + +static void matrix_diag_mul_line8_tilde_dsp(t_matrix_diag_mul_line8_tilde *x, t_signal **sp) +{ + int i, n=sp[0]->s_n; + + if(!x->x_buf) + { + x->x_bufsize = n; + x->x_buf = (t_float *)getbytes(x->x_bufsize * sizeof(t_float)); + } + else if(x->x_bufsize != n) + { + x->x_buf = (t_float *)resizebytes(x->x_buf, x->x_bufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_bufsize = n; + } + + n = 2 * x->x_n_io; + for(i=0; ix_io[i] = sp[i]->s_vec; + // post("iovec_addr = %d", (unsigned int)x->x_io[i]); + } + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (t_float)(sp[0]->s_sr) / (t_float)n; + x->x_8overn = 8.0f / (t_float)n; + + if(n&7) + dsp_add(matrix_diag_mul_line8_tilde_perform_zero, 2, x, n); + else + dsp_add(matrix_diag_mul_line8_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_diag_mul_line8_tilde_free(t_matrix_diag_mul_line8_tilde *x) +{ + freebytes(x->x_matcur, x->x_n_io * sizeof(t_float)); + freebytes(x->x_matend, x->x_n_io * sizeof(t_float)); + freebytes(x->x_inc8, x->x_n_io * sizeof(t_float)); + freebytes(x->x_biginc, x->x_n_io * sizeof(t_float)); + freebytes(x->x_io, 2 * x->x_n_io * sizeof(t_float *)); + if(x->x_buf) + freebytes(x->x_buf, x->x_bufsize * sizeof(t_float)); +} + +static void *matrix_diag_mul_line8_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_diag_mul_line8_tilde *x = (t_matrix_diag_mul_line8_tilde *)pd_new(matrix_diag_mul_line8_tilde_class); + int i, n; + + switch (argc) + { + case 0: + x->x_n_io = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_io = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_io = (int)atom_getint(argv); + x->x_time_ms = atom_getfloat(argv+1); + break; + } + + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + if(x->x_n_io < 1) + x->x_n_io = 1; + i = x->x_n_io - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_io; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_buf = (t_float *)0; + x->x_bufsize = 0; + x->x_matcur = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_matend = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_inc8 = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_biginc = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_io = (t_float **)getbytes(2 * x->x_n_io * sizeof(t_float *)); + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_8overn = 8.0f / 64.0f; + x->x_remaining_ticks = 0; + x->x_retarget = 0; + + n = x->x_n_io; + for(i=0; ix_matcur[i] = 0.0f; + x->x_matend[i] = 0.0f; + x->x_inc8[i] = 0.0f; + x->x_biginc[i] = 0.0f; + } + return(x); +} + +void matrix_diag_mul_line8_tilde_setup(void) +{ + matrix_diag_mul_line8_tilde_class = class_new(gensym("matrix_diag_mul_line8~"), (t_newmethod)matrix_diag_mul_line8_tilde_new, (t_method)matrix_diag_mul_line8_tilde_free, + sizeof(t_matrix_diag_mul_line8_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_diag_mul_line8_tilde_class, t_matrix_diag_mul_line8_tilde, x_msi); + class_addmethod(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_dsp, gensym("dsp"), 0); + class_addlist(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_list); + class_addmethod(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_diag, gensym("diag"), A_GIMME, 0); + class_addmethod(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_diag_mul_line8_tilde_class, (t_method)matrix_diag_mul_line8_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_diag_mul_line8_tilde_class, gensym("iemhelp2/matrix_diag_mul_line8~-help")); +} diff --git a/src/matrix_diag_mul_line~.c b/src/matrix_diag_mul_line~.c new file mode 100644 index 0000000..bb4c9e7 --- /dev/null +++ b/src/matrix_diag_mul_line~.c @@ -0,0 +1,415 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + +/* ---------- matrix_diag_mul_line~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_diag_mul_line_tilde +{ + t_object x_obj; + t_float *x_matcur; + t_float *x_matend; + t_float *x_inc; + t_float *x_biginc; + t_float **x_io; + t_float *x_buf; + int x_bufsize; + int x_n_io; + t_float x_msi; + int x_retarget; + t_float x_time_ms; + int x_remaining_ticks; + t_float x_ms2tick; + t_float x_1overn; +} t_matrix_diag_mul_line_tilde; + +t_class *matrix_diag_mul_line_tilde_class; + +static void matrix_diag_mul_line_tilde_time(t_matrix_diag_mul_line_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; +} + +static void matrix_diag_mul_line_tilde_element(t_matrix_diag_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int i, j, n=x->x_n_io; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(x->x_time_ms <= 0.0f) + { + if(argc == 2) + { + i = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n)) + matend[i-1] = matcur[i-1] = atom_getfloat(argv); + } + else if(argc == 3) + { + i = (int)(atom_getint(argv)); + argv++; + j = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n) && (i == j)) + matend[i-1] = matcur[i-1] = atom_getfloat(argv); + } + x->x_remaining_ticks = x->x_retarget = 0; + } + else + { + if(argc == 2) + { + i = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n)) + matend[i-1] = atom_getfloat(argv); + } + else if(argc == 3) + { + i = (int)(atom_getint(argv)); + argv++; + j = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n) && (i == j)) + matend[i-1] = atom_getfloat(argv); + } + x->x_retarget = 1; + } +} + +static void matrix_diag_mul_line_tilde_list(t_matrix_diag_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int i, n=x->x_n_io; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc < n) + { + post("matrix_diag_mul_line~ : dimensions do not match !!"); + return; + } + + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_diag_mul_line_tilde_diag(t_matrix_diag_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + matrix_diag_mul_line_tilde_list(x, &s_list, argc, argv); +} + +static void matrix_diag_mul_line_tilde_stop(t_matrix_diag_mul_line_tilde *x) +{ + int i = x->x_n_io; + t_float *matend=x->x_matend; + t_float *matcur=x->x_matcur; + + while(i--) + { + *matend++ = *matcur++; + } + x->x_remaining_ticks = x->x_retarget = 0; +} + +/* the dsp thing */ + +static t_int *matrix_diag_mul_line_tilde_perform_zero(t_int *w) +{ + t_matrix_diag_mul_line_tilde *x = (t_matrix_diag_mul_line_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_io = x->x_n_io; + t_float *out; + int i, j; + + for(j=0; jx_io; + t_float *buf; + t_float *matcur, *matend; + t_float *incp, *biginc, inc; + int n_io = x->x_n_io; + int hn_io = n_io / 2; + int dn_io = 2 * n_io; + t_float *in, *out1, *out2, mul; + int i, j; + + if(x->x_retarget) + { + int nticks = (int)(x->x_time_ms * x->x_ms2tick); + + if(!nticks) + nticks = 1; + x->x_remaining_ticks = nticks; + j = n_io; + incp = x->x_inc; + matcur = x->x_matcur; + matend = x->x_matend; + mul = x->x_1overn / (t_float)nticks; + while(j--) + { + *incp++ = (*matend++ - *matcur++) * mul; + } + j = n_io; + biginc = x->x_biginc; + matcur = x->x_matcur; + matend = x->x_matend; + mul = 1.0f / (t_float)nticks; + while(j--) + { + *biginc++ = (*matend++ - *matcur++) * mul; + } + x->x_retarget = 0; + } + + if(x->x_remaining_ticks) + { + incp = x->x_inc; + biginc = x->x_biginc; + matcur = x->x_matcur; + for(j=0; jx_remaining_ticks) + { + matcur = x->x_matcur; + matend = x->x_matend; + i = n_io; + while(i--) + *matcur++ = *matend++; + } + } + else + { + matend = x->x_matend; + for(j=0; jx_buf; + for(i=n; i; i -= 8, buf += 8, in += 8) + { + buf[0] = in[0]; + buf[1] = in[1]; + buf[2] = in[2]; + buf[3] = in[3]; + buf[4] = in[4]; + buf[5] = in[5]; + buf[6] = in[6]; + buf[7] = in[7]; + } + in = io[n_io-j-1]; + out1 = io[j+n_io]; + out2 = io[dn_io-j-1]; + buf = x->x_buf; + for(i=n; i; i -= 8, buf += 8, in += 8, out1 += 8, out2 += 8) + { + out2[0] = in[0]; + out2[1] = in[1]; + out2[2] = in[2]; + out2[3] = in[3]; + out2[4] = in[4]; + out2[5] = in[5]; + out2[6] = in[6]; + out2[7] = in[7]; + out1[0] = buf[0]; + out1[1] = buf[1]; + out1[2] = buf[2]; + out1[3] = buf[3]; + out1[4] = buf[4]; + out1[5] = buf[5]; + out1[6] = buf[6]; + out1[7] = buf[7]; + } + } + return (w+3); +} + +static void matrix_diag_mul_line_tilde_dsp(t_matrix_diag_mul_line_tilde *x, t_signal **sp) +{ + int i, n=sp[0]->s_n; + + if(!x->x_buf) + { + x->x_bufsize = n; + x->x_buf = (t_float *)getbytes(x->x_bufsize * sizeof(t_float)); + } + else if(x->x_bufsize != n) + { + x->x_buf = (t_float *)resizebytes(x->x_buf, x->x_bufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_bufsize = n; + } + + n = 2 * x->x_n_io; + for(i=0; ix_io[i] = sp[i]->s_vec; + // post("iovec_addr = %d", (unsigned int)x->x_io[i]); + } + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (t_float)(sp[0]->s_sr) / (t_float)n; + x->x_1overn = 1.0f / (t_float)n; + + if(n&7) + dsp_add(matrix_diag_mul_line_tilde_perform_zero, 2, x, n); + else + dsp_add(matrix_diag_mul_line_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_diag_mul_line_tilde_free(t_matrix_diag_mul_line_tilde *x) +{ + freebytes(x->x_matcur, x->x_n_io * sizeof(t_float)); + freebytes(x->x_matend, x->x_n_io * sizeof(t_float)); + freebytes(x->x_inc, x->x_n_io * sizeof(t_float)); + freebytes(x->x_biginc, x->x_n_io * sizeof(t_float)); + freebytes(x->x_io, 2 * x->x_n_io * sizeof(t_float *)); + if(x->x_buf) + freebytes(x->x_buf, x->x_bufsize * sizeof(t_float)); +} + +static void *matrix_diag_mul_line_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_diag_mul_line_tilde *x = (t_matrix_diag_mul_line_tilde *)pd_new(matrix_diag_mul_line_tilde_class); + int i, n; + + switch (argc) + { + case 0: + x->x_n_io = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_io = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_io = (int)atom_getint(argv); + x->x_time_ms = atom_getfloat(argv+1); + break; + } + + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + if(x->x_n_io < 1) + x->x_n_io = 1; + i = x->x_n_io - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_io; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_buf = (t_float *)0; + x->x_bufsize = 0; + x->x_matcur = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_matend = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_inc = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_biginc = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + x->x_io = (t_float **)getbytes(2 * x->x_n_io * sizeof(t_float *)); + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_1overn = 1.0f / 64.0f; + x->x_remaining_ticks = 0; + x->x_retarget = 0; + + n = x->x_n_io; + for(i=0; ix_matcur[i] = 0.0f; + x->x_matend[i] = 0.0f; + x->x_inc[i] = 0.0f; + x->x_biginc[i] = 0.0f; + } + return(x); +} + +void matrix_diag_mul_line_tilde_setup(void) +{ + matrix_diag_mul_line_tilde_class = class_new(gensym("matrix_diag_mul_line~"), (t_newmethod)matrix_diag_mul_line_tilde_new, (t_method)matrix_diag_mul_line_tilde_free, + sizeof(t_matrix_diag_mul_line_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_diag_mul_line_tilde_class, t_matrix_diag_mul_line_tilde, x_msi); + class_addmethod(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_dsp, gensym("dsp"), 0); + class_addmethod(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_diag, gensym("diag"), A_GIMME, 0); + class_addmethod(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_element, gensym("element"), A_GIMME, 0); + class_addlist(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_list); + class_addmethod(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_diag_mul_line_tilde_class, (t_method)matrix_diag_mul_line_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_diag_mul_line_tilde_class, gensym("iemhelp2/matrix_diag_mul_line~-help")); +} diff --git a/src/matrix_diag_mul_stat~.c b/src/matrix_diag_mul_stat~.c new file mode 100644 index 0000000..3b9e9e5 --- /dev/null +++ b/src/matrix_diag_mul_stat~.c @@ -0,0 +1,269 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_diag_mul_stat~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_diag_mul_stat_tilde +{ + t_object x_obj; + t_float *x_matbuf; + t_float **x_io; + t_float *x_buf; + int x_bufsize; + int x_n_io; + t_float x_msi; +} t_matrix_diag_mul_stat_tilde; + +t_class *matrix_diag_mul_stat_tilde_class; + +static void matrix_diag_mul_stat_tilde_list(t_matrix_diag_mul_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int i, n=x->x_n_io; + t_float *matrix = x->x_matbuf; + + if(argc < n) + { + post("matrix_diag_mul_stat~ : dimensions do not match !!"); + return; + } + + for(i=0; ix_n_io; + t_float *matrix = x->x_matbuf; + + if(argc == 2) + { + i = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n)) + matrix[i-1] = atom_getfloat(argv); + } + else if(argc == 3) + { + i = (int)(atom_getint(argv)); + argv++; + j = (int)(atom_getint(argv)); + argv++; + if((i >= 1) && (i <= n) && (i == j)) + matrix[i-1] = atom_getfloat(argv); + } +} + +/* the dsp thing */ + +static t_int *matrix_diag_mul_stat_tilde_perform(t_int *w) +{ + t_matrix_diag_mul_stat_tilde *x = (t_matrix_diag_mul_stat_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + t_float *buf = x->x_buf; + t_float *mat = x->x_matbuf; + int n_io = x->x_n_io; + int hn_io = n_io / 2; + int dn_io = 2 * n_io; + t_float *in, *out1, *out2, mul; + int i, j; + + for(j=0; jx_io; + t_float *buf; + t_float *mat = x->x_matbuf; + int n_io = x->x_n_io; + int hn_io = n_io / 2; + int dn_io = 2 * n_io; + t_float *in, *out1, *out2, mul; + int i, j; + + for(j=0; jx_buf; + for(i=n; i; i -= 8, buf += 8, in += 8) + { + buf[0] = in[0]; + buf[1] = in[1]; + buf[2] = in[2]; + buf[3] = in[3]; + buf[4] = in[4]; + buf[5] = in[5]; + buf[6] = in[6]; + buf[7] = in[7]; + } + in = io[n_io-j-1]; + out1 = io[j+n_io]; + out2 = io[dn_io-j-1]; + buf = x->x_buf; + for(i=n; i; i -= 8, buf += 8, in += 8, out1 += 8, out2 += 8) + { + out2[0] = in[0]; + out2[1] = in[1]; + out2[2] = in[2]; + out2[3] = in[3]; + out2[4] = in[4]; + out2[5] = in[5]; + out2[6] = in[6]; + out2[7] = in[7]; + out1[0] = buf[0]; + out1[1] = buf[1]; + out1[2] = buf[2]; + out1[3] = buf[3]; + out1[4] = buf[4]; + out1[5] = buf[5]; + out1[6] = buf[6]; + out1[7] = buf[7]; + } + } + return (w+3); +} + +static void matrix_diag_mul_stat_tilde_dsp(t_matrix_diag_mul_stat_tilde *x, t_signal **sp) +{ + int i, n=sp[0]->s_n; + + if(!x->x_buf) + { + x->x_bufsize = n; + x->x_buf = (t_float *)getbytes(x->x_bufsize * sizeof(t_float)); + } + else if(x->x_bufsize != n) + { + x->x_buf = (t_float *)resizebytes(x->x_buf, x->x_bufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_bufsize = n; + } + + n = 2 * x->x_n_io; + for(i=0; ix_io[i] = sp[i]->s_vec; + // post("iovec_addr = %d", (unsigned int)x->x_io[i]); + } + + n = sp[0]->s_n; + if(n&7) + dsp_add(matrix_diag_mul_stat_tilde_perform, 2, x, n); + else + dsp_add(matrix_diag_mul_stat_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_diag_mul_stat_tilde_free(t_matrix_diag_mul_stat_tilde *x) +{ + freebytes(x->x_matbuf, x->x_n_io * sizeof(t_float)); + freebytes(x->x_io, 2 * x->x_n_io * sizeof(t_float *)); + if(x->x_buf) + freebytes(x->x_buf, x->x_bufsize * sizeof(t_float)); +} + +static void *matrix_diag_mul_stat_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_diag_mul_stat_tilde *x = (t_matrix_diag_mul_stat_tilde *)pd_new(matrix_diag_mul_stat_tilde_class); + int i; + + switch (argc) + { + case 0: + x->x_n_io = 1; + break; + default: + x->x_n_io = (int)atom_getint(argv); + break; + } + + if(x->x_n_io < 1) + x->x_n_io = 1; + i = x->x_n_io - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_io; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_buf = (t_float *)0; + x->x_bufsize = 0; + x->x_matbuf = (t_float *)getbytes(x->x_n_io * sizeof(t_float)); + i = x->x_n_io; + while(i--) + x->x_matbuf[i] = 0.0f; + x->x_io = (t_float **)getbytes(2 * x->x_n_io * sizeof(t_float *)); + return(x); +} + +void matrix_diag_mul_stat_tilde_setup(void) +{ + matrix_diag_mul_stat_tilde_class = class_new(gensym("matrix_diag_mul_stat~"), (t_newmethod)matrix_diag_mul_stat_tilde_new, (t_method)matrix_diag_mul_stat_tilde_free, + sizeof(t_matrix_diag_mul_stat_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_diag_mul_stat_tilde_class, t_matrix_diag_mul_stat_tilde, x_msi); + class_addmethod(matrix_diag_mul_stat_tilde_class, (t_method)matrix_diag_mul_stat_tilde_dsp, gensym("dsp"), 0); + class_addmethod(matrix_diag_mul_stat_tilde_class, (t_method)matrix_diag_mul_stat_tilde_diag, gensym("diag"), A_GIMME, 0); + class_addmethod(matrix_diag_mul_stat_tilde_class, (t_method)matrix_diag_mul_stat_tilde_element, gensym("element"), A_GIMME, 0); + class_addlist(matrix_diag_mul_stat_tilde_class, (t_method)matrix_diag_mul_stat_tilde_list); + class_sethelpsymbol(matrix_diag_mul_stat_tilde_class, gensym("iemhelp2/matrix_diag_mul_stat~-help")); +} diff --git a/src/matrix_mul_line8~.c b/src/matrix_mul_line8~.c new file mode 100644 index 0000000..5f15bb4 --- /dev/null +++ b/src/matrix_mul_line8~.c @@ -0,0 +1,657 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + +/* ---------- matrix_mul_line8~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_mul_line8_tilde +{ + t_object x_obj; + t_float *x_matcur; + t_float *x_matend; + t_float *x_inc8; + t_float *x_biginc; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_msi; + int x_retarget; + t_float x_time_ms; + int x_remaining_ticks; + t_float x_ms2tick; + t_float x_8overn; +} t_matrix_mul_line8_tilde; + +t_class *matrix_mul_line8_tilde_class; + +static void matrix_mul_line8_tilde_time(t_matrix_mul_line8_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; +} + +static void matrix_mul_line8_tilde_matrix(t_matrix_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, row, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<2) + { + post("matrix_mul_line8~ : bad matrix: out_rows in_cols !"); + return; + } + + row = atom_getint(argv); + argv++; + col = atom_getint(argv); + argv++; + argc-=2; + + if((col!=x->x_n_in)||(row!=x->x_n_out)) + { + post("matrix_mul_line8~ : matrix dimensions do not match !!"); + return; + } + if(argcx_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line8_tilde_element(t_matrix_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, row, n_in_cols=x->x_n_in; + t_float element; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc != 3) + { + post("matrix_mul_line8~ : bad element: 3 floats: out_row in_col element !"); + return; + } + + row = atom_getint(argv) - 1; + col = atom_getint(argv+1) - 1; + element = atom_getfloat(argv+2); + + if((row >= x->x_n_out) || (row < 0)) + { + post("matrix_mul_line8~ : row dimensions do not match !!"); + return; + } + if((col >= n_in_cols) || (col < 0)) + { + post("matrix_mul_line8~ : col dimensions do not match !!"); + return; + } + + matend += row * n_in_cols + col; + matcur += row * n_in_cols + col; + + if(x->x_time_ms <= 0.0f) + { + *matend = *matcur = element; + x->x_remaining_ticks = x->x_retarget = 0; + } + else + { + *matend = element; + x->x_retarget = 1; + } +} + +static void matrix_mul_line8_tilde_row(t_matrix_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, nth_row, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<1) + { + post("matrix_mul_line8~ : bad row: in_row !"); + return; + } + + nth_row = atom_getint(argv) - 1; + argv++; + argc--; + + if((nth_row >= x->x_n_out) || (nth_row < 0)) + { + post("matrix_mul_line8~ : row dimensions do not match !!"); + return; + } + col = x->x_n_in; + if(argc < col) + { + post("matrix_mul_line8~ : col dimensions do not match !!"); + return; + } + + matend += nth_row * col; + matcur += nth_row * col; + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line8_tilde_col(t_matrix_mul_line8_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int row, col, nth_col, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<1) + { + post("matrix_mul_line8~ : bad col: in_cols !"); + return; + } + + nth_col = atom_getint(argv) - 1; + argv++; + argc--; + + col = x->x_n_in; + if((nth_col < 0)||(nth_col >= col)) + { + post("matrix_mul_line8~ : col dimensions do not match !!"); + return; + } + row = x->x_n_out; + if(argc < row) + { + post("matrix_mul_line8~ : row dimensions do not match !!"); + return; + } + + matend += nth_col; + matcur += nth_col; + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line8_tilde_stop(t_matrix_mul_line8_tilde *x) +{ + int i = x->x_n_out*x->x_n_in; + t_float *matend=x->x_matend; + t_float *matcur=x->x_matcur; + + while(i--) + { + *matend++ = *matcur++; + } + x->x_remaining_ticks = x->x_retarget = 0; +} + +/* the dsp thing */ + +static t_int *matrix_mul_line8_tilde_perform_zero(t_int *w) +{ + t_matrix_mul_line8_tilde *x = (t_matrix_mul_line8_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *out; + int r, i; + + for(r=0; rx_io; + t_float *outsum, *houtsum; + t_float *matcur, *matend; + t_float *inc8 ,*biginc, inc; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul, bigmul; + int r, c, i; + + if(x->x_retarget) + { + int nticks = (int)(x->x_time_ms * x->x_ms2tick); + + if(!nticks) + nticks = 1; + x->x_remaining_ticks = nticks; + inc8 = x->x_inc8; + biginc = x->x_biginc; + matcur = x->x_matcur; + matend = x->x_matend; + mul = x->x_8overn / (t_float)nticks; + bigmul = 1.0f / (t_float)nticks; + i = n_out*n_in; + while(i--) + { + inc = *matend++ - *matcur++; + *inc8++ = inc * mul; + *biginc++ = inc * bigmul; + } + x->x_retarget = 0; + //post("time = %f ms, ticks = %d, inc = %f", x->x_time_ms, nticks, *inc); + } + + if(x->x_remaining_ticks) + { + inc8 = x->x_inc8; + biginc = x->x_biginc; + matcur = x->x_matcur; + /* 1. output-vector-row */ + in = io[0]; + houtsum = x->x_outsumbuf; + outsum = houtsum; + inc = *inc8++; + mul = *matcur; + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = in[0] * mul; + outsum[1] = in[1] * mul; + outsum[2] = in[2] * mul; + outsum[3] = in[3] * mul; + outsum[4] = in[4] * mul; + outsum[5] = in[5] * mul; + outsum[6] = in[6] * mul; + outsum[7] = in[7] * mul; + mul += inc; + } + *matcur++ += *biginc++; + for(c=1; cx_remaining_ticks) + { + matcur = x->x_matcur; + matend = x->x_matend; + i = n_in * n_out; + while(i--) + *matcur++ = *matend++; + } + } + else + { + matend = x->x_matend; + /* 1. output-vector-row */ + in = io[0]; + houtsum = x->x_outsumbuf; + outsum = houtsum; + mul = *matend++; + if(mul == 0.0f) + { + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = 0.0f; + outsum[1] = 0.0f; + outsum[2] = 0.0f; + outsum[3] = 0.0f; + outsum[4] = 0.0f; + outsum[5] = 0.0f; + outsum[6] = 0.0f; + outsum[7] = 0.0f; + } + } + else + { + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = in[0] * mul; + outsum[1] = in[1] * mul; + outsum[2] = in[2] * mul; + outsum[3] = in[3] * mul; + outsum[4] = in[4] * mul; + outsum[5] = in[5] * mul; + outsum[6] = in[6] * mul; + outsum[7] = in[7] * mul; + } + } + for(c=1; cx_outsumbuf; + for(r=0; rs_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (t_float)(sp[0]->s_sr) / (t_float)n; + x->x_8overn = 8.0f / (t_float)n; + + if(n&7) + { + dsp_add(matrix_mul_line8_tilde_perform_zero, 2, x, n); + post("ERROR!!! matrix_mul_line8~ : blocksize is %d and not a multiple of 8", n); + } + else + dsp_add(matrix_mul_line8_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_mul_line8_tilde_free(t_matrix_mul_line8_tilde *x) +{ + freebytes(x->x_matcur, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_matend, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_inc8, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_biginc, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_mul_line8_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_mul_line8_tilde *x = (t_matrix_mul_line8_tilde *)pd_new(matrix_mul_line8_tilde_class); + int i, n; + + switch(argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + case 2: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = atom_getfloat(argv+2); + break; + } + + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + x->x_matcur = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_matend = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_inc8 = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_biginc = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_8overn = 8.0f / 64.0f; + x->x_remaining_ticks = 0; + x->x_retarget = 0; + + n = x->x_n_in * x->x_n_out; + for(i=0; ix_matcur[i] = 0.0f; + x->x_matend[i] = 0.0f; + x->x_inc8[i] = 0.0f; + x->x_biginc[i] = 0.0f; + } + return (x); +} + +void matrix_mul_line8_tilde_setup(void) +{ + matrix_mul_line8_tilde_class = class_new(gensym("matrix_mul_line8~"), (t_newmethod)matrix_mul_line8_tilde_new, (t_method)matrix_mul_line8_tilde_free, + sizeof(t_matrix_mul_line8_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_mul_line8_tilde_class, t_matrix_mul_line8_tilde, x_msi); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_dsp, gensym("dsp"), 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_matrix, gensym("matrix"), A_GIMME, 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_row, gensym("row"), A_GIMME, 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_col, gensym("col"), A_GIMME, 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_mul_line8_tilde_class, (t_method)matrix_mul_line8_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_mul_line8_tilde_class, gensym("iemhelp2/matrix_mul_line8~-help")); +} diff --git a/src/matrix_mul_line~.c b/src/matrix_mul_line~.c new file mode 100644 index 0000000..bc61cec --- /dev/null +++ b/src/matrix_mul_line~.c @@ -0,0 +1,686 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_mul_line~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_mul_line_tilde +{ + t_object x_obj; + t_float *x_matcur; + t_float *x_matend; + t_float *x_inc; + t_float *x_biginc; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_msi; + int x_retarget; + t_float x_time_ms; + int x_remaining_ticks; + t_float x_ms2tick; + t_float x_1overn; +} t_matrix_mul_line_tilde; + +t_class *matrix_mul_line_tilde_class; + +static void matrix_mul_line_tilde_time(t_matrix_mul_line_tilde *x, t_floatarg time_ms) +{ + if(time_ms <= 0.0f) + time_ms = 0.0f; + x->x_time_ms = time_ms; +} + +static void matrix_mul_line_tilde_matrix(t_matrix_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, row, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<2) + { + post("matrix_mul_line~ : bad matrix: out_rows in_cols !"); + return; + } + + row = atom_getint(argv); + argv++; + col = atom_getint(argv); + argv++; + argc-=2; + + if((col!=x->x_n_in)||(row!=x->x_n_out)) + { + post("matrix_mul_line~ : matrix dimensions do not match !!"); + return; + } + if(argcx_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line_tilde_element(t_matrix_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, row, n_in_cols=x->x_n_in; + t_float element; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc != 3) + { + post("matrix_mul_line~ : bad element: 3 floats: out_row in_col element !"); + return; + } + + row = atom_getint(argv) - 1; + col = atom_getint(argv+1) - 1; + element = atom_getfloat(argv+2); + + if((row >= x->x_n_out) || (row < 0)) + { + post("matrix_mul_line~ : row dimensions do not match !!"); + return; + } + if((col >= n_in_cols) || (col < 0)) + { + post("matrix_mul_line~ : col dimensions do not match !!"); + return; + } + + matend += row * n_in_cols + col; + matcur += row * n_in_cols + col; + + if(x->x_time_ms <= 0.0f) + { + *matend = *matcur = element; + x->x_remaining_ticks = x->x_retarget = 0; + } + else + { + *matend = element; + x->x_retarget = 1; + } +} + +static void matrix_mul_line_tilde_row(t_matrix_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, nth_row, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<1) + { + post("matrix_mul_line~ : bad row: in_row !"); + return; + } + + nth_row = atom_getint(argv) - 1; + argv++; + argc--; + + if((nth_row >= x->x_n_out) || (nth_row < 0)) + { + post("matrix_mul_line~ : row dimensions do not match !!"); + return; + } + col = x->x_n_in; + if(argc < col) + { + post("matrix_mul_line~ : col dimensions do not match !!"); + return; + } + + matend += nth_row * col; + matcur += nth_row * col; + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line_tilde_col(t_matrix_mul_line_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int row, col, nth_col, i; + t_float *matcur = x->x_matcur; + t_float *matend = x->x_matend; + + if(argc<1) + { + post("matrix_mul_line~ : bad col: in_cols !"); + return; + } + + nth_col = atom_getint(argv) - 1; + argv++; + argc--; + + col = x->x_n_in; + if((nth_col < 0)||(nth_col >= col)) + { + post("matrix_mul_line~ : col dimensions do not match !!"); + return; + } + row = x->x_n_out; + if(argc < row) + { + post("matrix_mul_line~ : row dimensions do not match !!"); + return; + } + + matend += nth_col; + matcur += nth_col; + if(x->x_time_ms <= 0.0f) + { + for(i=0; ix_remaining_ticks = x->x_retarget = 0; + } + else + { + for(i=0; ix_retarget = 1; + } +} + +static void matrix_mul_line_tilde_stop(t_matrix_mul_line_tilde *x) +{ + int i = x->x_n_out*x->x_n_in; + t_float *matend=x->x_matend; + t_float *matcur=x->x_matcur; + + while(i--) + { + *matend++ = *matcur++; + } + x->x_remaining_ticks = x->x_retarget = 0; +} + +/* the dsp thing */ + +static t_int *matrix_mul_line_tilde_perform_zero(t_int *w) +{ + t_matrix_mul_line_tilde *x = (t_matrix_mul_line_tilde *)(w[1]); + int n = (int)(w[2]); + t_float **io = x->x_io; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *out; + int r, i; + + for(r=0; rx_io; + t_float *outsum, *houtsum; + t_float *matcur, *matend; + t_float *inc1 ,*biginc, inc; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul, bigmul; + int r, c, i; + + if(x->x_retarget) + { + int nticks = (int)(x->x_time_ms * x->x_ms2tick); + + if(!nticks) + nticks = 1; + x->x_remaining_ticks = nticks; + inc1 = x->x_inc; + biginc = x->x_biginc; + matcur = x->x_matcur; + matend = x->x_matend; + mul = x->x_1overn / (t_float)nticks; + bigmul = 1.0f / (t_float)nticks; + i = n_out*n_in; + while(i--) + { + inc = *matend++ - *matcur++; + *inc1++ = inc * mul; + *biginc++ = inc * bigmul; + } + x->x_retarget = 0; + //post("time = %f ms, ticks = %d, inc = %f", x->x_time_ms, nticks, *inc); + } + + if(x->x_remaining_ticks) + { + inc1 = x->x_inc; + biginc = x->x_biginc; + matcur = x->x_matcur; + /* 1. output-vector-row */ + in = io[0]; + houtsum = x->x_outsumbuf; + outsum = houtsum; + inc = *inc1++; + mul = *matcur; + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = in[0] * mul; + mul += inc; + outsum[1] = in[1] * mul; + mul += inc; + outsum[2] = in[2] * mul; + mul += inc; + outsum[3] = in[3] * mul; + mul += inc; + outsum[4] = in[4] * mul; + mul += inc; + outsum[5] = in[5] * mul; + mul += inc; + outsum[6] = in[6] * mul; + mul += inc; + outsum[7] = in[7] * mul; + mul += inc; + } + *matcur++ += *biginc++; + for(c=1; cx_remaining_ticks) + { + matcur = x->x_matcur; + matend = x->x_matend; + i = n_in * n_out; + while(i--) + *matcur++ = *matend++; + } + } + else + { + matend = x->x_matend; + /* 1. output-vector-row */ + in = io[0]; + houtsum = x->x_outsumbuf; + outsum = houtsum; + mul = *matend++; + if(mul == 0.0f) + { + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = 0.0f; + outsum[1] = 0.0f; + outsum[2] = 0.0f; + outsum[3] = 0.0f; + outsum[4] = 0.0f; + outsum[5] = 0.0f; + outsum[6] = 0.0f; + outsum[7] = 0.0f; + } + } + else + { + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = in[0] * mul; + outsum[1] = in[1] * mul; + outsum[2] = in[2] * mul; + outsum[3] = in[3] * mul; + outsum[4] = in[4] * mul; + outsum[5] = in[5] * mul; + outsum[6] = in[6] * mul; + outsum[7] = in[7] * mul; + } + } + for(c=1; cx_outsumbuf; + for(r=0; rs_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + + n = sp[0]->s_n; + x->x_ms2tick = 0.001f * (t_float)(sp[0]->s_sr) / (t_float)n; + x->x_1overn = 1.0f / (t_float)n; + + if(n&7) + { + dsp_add(matrix_mul_line_tilde_perform_zero, 2, x, n); + post("ERROR!!! matrix_mul_line~ : blocksize is %d and not a multiple of 8", n); + } + else + dsp_add(matrix_mul_line_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_mul_line_tilde_free(t_matrix_mul_line_tilde *x) +{ + freebytes(x->x_matcur, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_matend, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_inc, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_biginc, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_mul_line_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_mul_line_tilde *x = (t_matrix_mul_line_tilde *)pd_new(matrix_mul_line_tilde_class); + int i, n; + + switch(argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + x->x_time_ms = 50.0f; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + x->x_time_ms = 50.0f; + break; + case 2: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = 50.0f; + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + x->x_time_ms = atom_getfloat(argv+2); + break; + } + + if(x->x_time_ms < 0.0f) + x->x_time_ms = 50.0f; + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + x->x_matcur = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_matend = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_inc = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_biginc = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + x->x_ms2tick = 0.001f * 44100.0f / 64.0f; + x->x_1overn = 1.0f / 64.0f; + x->x_remaining_ticks = 0; + x->x_retarget = 0; + + n = x->x_n_in * x->x_n_out; + for(i=0; ix_matcur[i] = 0.0f; + x->x_matend[i] = 0.0f; + x->x_inc[i] = 0.0f; + x->x_biginc[i] = 0.0f; + } + return (x); +} + +void matrix_mul_line_tilde_setup(void) +{ + matrix_mul_line_tilde_class = class_new(gensym("matrix_mul_line~"), (t_newmethod)matrix_mul_line_tilde_new, (t_method)matrix_mul_line_tilde_free, + sizeof(t_matrix_mul_line_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_mul_line_tilde_class, t_matrix_mul_line_tilde, x_msi); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_dsp, gensym("dsp"), 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_matrix, gensym("matrix"), A_GIMME, 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_row, gensym("row"), A_GIMME, 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_col, gensym("col"), A_GIMME, 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_stop, gensym("stop"), 0); + class_addmethod(matrix_mul_line_tilde_class, (t_method)matrix_mul_line_tilde_time, gensym("time"), A_FLOAT, 0); + class_sethelpsymbol(matrix_mul_line_tilde_class, gensym("iemhelp2/matrix_mul_line~-help")); +} diff --git a/src/matrix_mul_stat~.c b/src/matrix_mul_stat~.c new file mode 100644 index 0000000..a2fc04d --- /dev/null +++ b/src/matrix_mul_stat~.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_matrix written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */ + +#include "m_pd.h" +#include "iemlib.h" + + +/* ---------- matrix_mul_stat~ - signal matrix multiplication object with message matrix-coeff. ----------- */ + +typedef struct matrix_mul_stat_tilde +{ + t_object x_obj; + t_float *x_matbuf; + t_float **x_io; + t_float *x_outsumbuf; + int x_outsumbufsize; + int x_n_in; /* columns */ + int x_n_out; /* rows */ + t_float x_msi; +} t_matrix_mul_stat_tilde; + +t_class *matrix_mul_stat_tilde_class; + +static void matrix_mul_stat_tilde_matrix(t_matrix_mul_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, row, i; + t_float *matrix = x->x_matbuf; + + if(argc<2) + { + post("matrix_mul_stat~ : bad matrix: out_rows in_cols !"); + return; + } + + row = atom_getint(argv); + argv++; + col = atom_getint(argv); + argv++; + argc-=2; + + if((col!=x->x_n_in)||(row!=x->x_n_out)) + { + post("matrix_mul_stat~ : matrix dimensions do not match !!"); + return; + } + if(argcx_n_in; + t_float element; + t_float *matrix = x->x_matbuf; + + if(argc != 3) + { + post("matrix_mul_stat~ : bad element: 3 floats: out_row in_col element !"); + return; + } + + row = atom_getint(argv) - 1; + col = atom_getint(argv+1) - 1; + element = atom_getfloat(argv+2); + + if((row >= x->x_n_out) || (row < 0)) + { + post("matrix_mul_stat~ : row dimensions do not match !!"); + return; + } + if((col >= n_in_cols) || (col < 0)) + { + post("matrix_mul_stat~ : col dimensions do not match !!"); + return; + } + + matrix += row * n_in_cols + col; + + *matrix = element; +} + +static void matrix_mul_stat_tilde_row(t_matrix_mul_stat_tilde *x, t_symbol *s, int argc, t_atom *argv) +{ + int col, nth_row, i; + t_float *matrix = x->x_matbuf; + + if(argc<1) + { + post("matrix_mul_stat~ : bad row: in_rows !"); + return; + } + + nth_row = atom_getint(argv) - 1; + argv++; + argc--; + + if((nth_row < 0)||(nth_row >= x->x_n_out)) + { + post("matrix_mul_stat~ : row dimensions do not match !!"); + return; + } + col = x->x_n_in; + if(argc < col) + { + post("matrix_mul_stat~ : col dimensions do not match !!"); + return; + } + + matrix += nth_row * col; + for(i=0; ix_matbuf; + + if(argc<1) + { + post("matrix_mul_stat~ : bad col: in_cols !"); + return; + } + + nth_col = atom_getint(argv) - 1; + argv++; + argc--; + + col = x->x_n_in; + if((nth_col < 0)||(nth_col >= col)) + { + post("matrix_mul_stat~ : col dimensions do not match !!"); + return; + } + row = x->x_n_out; + if(argc < row) + { + post("matrix_mul_stat~ : row dimensions do not match !!"); + return; + } + + matrix += nth_col; + for(i=0; ix_io; + t_float *outsum, *houtsum; + t_float *mat = x->x_matbuf; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul; + int r, c, i; + + /* 1. output-vector-row */ + in = io[0]; + houtsum = x->x_outsumbuf; + outsum = houtsum; + mul = *mat++; + for(i=0; ix_outsumbuf; + mul = *mat++; + for(i=0; ix_outsumbuf; + for(r=0; rx_io; + t_float *outsum, *houtsum; + t_float *mat = x->x_matbuf; + int n_in = x->x_n_in; /* columns */ + int n_out = x->x_n_out; /* rows */ + t_float *in, *out, mul; + int r, c, i; + + /* 1. output-vector-row */ + houtsum = x->x_outsumbuf; + outsum = houtsum; + mul = *mat++; + if(mul == 0.0f) + { + for(i=n; i; i -= 8, outsum += 8) + { + outsum[0] = 0.0f; + outsum[1] = 0.0f; + outsum[2] = 0.0f; + outsum[3] = 0.0f; + outsum[4] = 0.0f; + outsum[5] = 0.0f; + outsum[6] = 0.0f; + outsum[7] = 0.0f; + } + } + else + { + in = io[0]; + for(i=n; i; i -= 8, outsum += 8, in += 8) + { + outsum[0] = in[0] * mul; + outsum[1] = in[1] * mul; + outsum[2] = in[2] * mul; + outsum[3] = in[3] * mul; + outsum[4] = in[4] * mul; + outsum[5] = in[5] * mul; + outsum[6] = in[6] * mul; + outsum[7] = in[7] * mul; + } + } + + for(c=1; cx_outsumbuf; + for(r=0; rs_n*x->x_n_out; + + if(!x->x_outsumbuf) + { + x->x_outsumbufsize = n; + x->x_outsumbuf = (t_float *)getbytes(x->x_outsumbufsize * sizeof(t_float)); + } + else if(x->x_outsumbufsize != n) + { + x->x_outsumbuf = (t_float *)resizebytes(x->x_outsumbuf, x->x_outsumbufsize*sizeof(t_float), n*sizeof(t_float)); + x->x_outsumbufsize = n; + } + + n = x->x_n_in + x->x_n_out; + for(i=0; ix_io[i] = sp[i]->s_vec; + /*post("iovec_addr = %d", (unsigned int)x->x_io[i]);*/ + } + + n = sp[0]->s_n; + if(n&7) + dsp_add(matrix_mul_stat_tilde_perform, 2, x, n); + else + dsp_add(matrix_mul_stat_tilde_perf8, 2, x, n); +} + + +/* setup/setdown things */ + +static void matrix_mul_stat_tilde_free(t_matrix_mul_stat_tilde *x) +{ + freebytes(x->x_matbuf, x->x_n_in * x->x_n_out * sizeof(t_float)); + freebytes(x->x_io, (x->x_n_in + x->x_n_out) * sizeof(t_float *)); + if(x->x_outsumbuf) + freebytes(x->x_outsumbuf, x->x_outsumbufsize * sizeof(t_float)); +} + +static void *matrix_mul_stat_tilde_new(t_symbol *s, int argc, t_atom *argv) +{ + t_matrix_mul_stat_tilde *x = (t_matrix_mul_stat_tilde *)pd_new(matrix_mul_stat_tilde_class); + int i; + + switch (argc) + { + case 0: + x->x_n_in = x->x_n_out = 1; + break; + case 1: + x->x_n_in = x->x_n_out = (int)atom_getint(argv); + break; + default: + x->x_n_in = (int)atom_getint(argv); + x->x_n_out = (int)atom_getint(argv+1); + break; + } + + if(x->x_n_in < 1) + x->x_n_in = 1; + if(x->x_n_out < 1) + x->x_n_out = 1; + i = x->x_n_in - 1; + while(i--) + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); + i = x->x_n_out; + while(i--) + outlet_new(&x->x_obj, &s_signal); + x->x_msi = 0; + x->x_outsumbuf = (t_float *)0; + x->x_outsumbufsize = 0; + x->x_matbuf = (t_float *)getbytes(x->x_n_in * x->x_n_out * sizeof(t_float)); + x->x_io = (t_float **)getbytes((x->x_n_in + x->x_n_out) * sizeof(t_float *)); + return (x); +} + +void matrix_mul_stat_tilde_setup(void) +{ + matrix_mul_stat_tilde_class = class_new(gensym("matrix_mul_stat~"), (t_newmethod)matrix_mul_stat_tilde_new, (t_method)matrix_mul_stat_tilde_free, + sizeof(t_matrix_mul_stat_tilde), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(matrix_mul_stat_tilde_class, t_matrix_mul_stat_tilde, x_msi); + class_addmethod(matrix_mul_stat_tilde_class, (t_method)matrix_mul_stat_tilde_dsp, gensym("dsp"), 0); + class_addmethod(matrix_mul_stat_tilde_class, (t_method)matrix_mul_stat_tilde_matrix, gensym("matrix"), A_GIMME, 0); + class_addmethod(matrix_mul_stat_tilde_class, (t_method)matrix_mul_stat_tilde_element, gensym("element"), A_GIMME, 0); + class_addmethod(matrix_mul_stat_tilde_class, (t_method)matrix_mul_stat_tilde_row, gensym("row"), A_GIMME, 0); + class_addmethod(matrix_mul_stat_tilde_class, (t_method)matrix_mul_stat_tilde_col, gensym("col"), A_GIMME, 0); + class_sethelpsymbol(matrix_mul_stat_tilde_class, gensym("iemhelp2/matrix_mul_stat~-help")); +} diff --git a/src/matrix_orthogonal.c b/src/matrix_orthogonal.c new file mode 100644 index 0000000..42fb86d --- /dev/null +++ b/src/matrix_orthogonal.c @@ -0,0 +1,161 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */ + + +/* -------------------------- matrix_orthogonal ------------------------------ */ + +/* +versucht, eine eingehende matrix (quadratisch) zu orthogonalisiern (Transponierte = Inverse) + + und zwar wie folgt: + + 1. zeile orthonarmalisieren (summe aller zeilen-elemente-quadrate = 1) + K = summe aller a_1i (1 <= i <= N) + fuer alle an_1i = a_1i / sqrt(K) (1 <= i <= N) + + 2. zeile: + K = summe aller a_2i (2 <= i <= N) - an_12 + an_21 = an_12 + fuer alle an_2i = a_2i / sqrt(K) (2 <= i <= N) + + 3. zeile: + K = summe aller a_3i (3 <= i <= N) - an_13 - an_23 + an_31 = an_13 + an_32 = an_23 + fuer alle an_3i = a_3i / sqrt(K) (3 <= i <= N) + + usw. + +*/ + +typedef struct _matrix_orthogonal +{ + t_object x_obj; + int x_dim; + double *x_work; + t_atom *x_at; +} t_matrix_orthogonal; + +static t_class *matrix_orthogonal_class; + +static void matrix_orthogonal_matrix(t_matrix_orthogonal *x, t_symbol *s, int argc, t_atom *argv) +{ + int oldsize = x->x_dim; + int dim; + int i, j; + int r, c; + double sum1, sum2, el, *v, *u; + t_atom *at=x->x_at; + + if(argc > 2) + { + r = (int)(atom_getint(argv++)); + c = (int)(atom_getint(argv++)); + if(r == c) + { + dim = r; + if(dim < 1) + dim = 1; + if(dim > oldsize) + { + if(oldsize) + { + x->x_work = (double *)resizebytes(x->x_work, oldsize * oldsize * sizeof(double), dim * dim * sizeof(double)); + x->x_at = (t_atom *)resizebytes(x->x_at, (oldsize * oldsize + 2) * sizeof(t_atom), (dim * dim + 2) * sizeof(t_atom)); + x->x_dim = dim; + } + else + { + x->x_work = (double *)getbytes(dim * dim * sizeof(double)); + x->x_at = (t_atom *)getbytes((dim * dim + 2) * sizeof(t_atom)); + x->x_dim = dim; + } + } + v = x->x_work; + for(i=0; ix_work + i*dim + i; + for(j=i; jx_work + i; + u = x->x_work + i*dim; + sum2 = 1.0; + for(j=0; jx_at; + SETFLOAT(at, (t_float)dim); + at++; + SETFLOAT(at, (t_float)dim); + at++; + v = x->x_work; + for(i=0; ix_obj.ob_outlet, gensym("matrix"), dim*dim+2, x->x_at); + } + } +} + +static void matrix_orthogonal_free(t_matrix_orthogonal *x) +{ + if(x->x_dim) + { + freebytes(x->x_work, x->x_dim * x->x_dim * sizeof(double)); + freebytes(x->x_at, (x->x_dim * x->x_dim + 2) * sizeof(t_atom)); + } +} + +static void *matrix_orthogonal_new(void) +{ + t_matrix_orthogonal *x = (t_matrix_orthogonal *)pd_new(matrix_orthogonal_class); + + x->x_dim = 0; + x->x_work = (double *)0; + x->x_at = (t_atom *)0; + outlet_new(&x->x_obj, &s_list); + return (x); +} + +static void matrix_orthogonal_setup(void) +{ + matrix_orthogonal_class = class_new(gensym("matrix_orthogonal"), (t_newmethod)matrix_orthogonal_new, (t_method)matrix_orthogonal_free, + sizeof(t_matrix_orthogonal), 0, 0); + class_addmethod(matrix_orthogonal_class, (t_method)matrix_orthogonal_matrix, gensym("matrix"), A_GIMME, 0); + class_sethelpsymbol(matrix_orthogonal_class, gensym("iemhelp/matrix_orthogonal-help")); +} diff --git a/src/matrix_pinv.c b/src/matrix_pinv.c new file mode 100644 index 0000000..452df50 --- /dev/null +++ b/src/matrix_pinv.c @@ -0,0 +1,600 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */ + +/* -------------------------- matrix_pinv ------------------------------ */ + +typedef struct _matrix_pinv +{ + t_object x_obj; + int x_dim; + int x_size; + double *x_work2; + double *x_buf2; + t_atom *x_at; +} t_matrix_pinv; + +static t_class *matrix_pinv_class; + + + + +static void matrix_pinv_copy_row2buf(t_matrix_pinv *x, int row) +{ + int dim2 = 2*x->x_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw_src=x->x_work2; + double *dw_dst=x->x_work2; + + dw_src += src_row*dim2; + dw_dst += dst_row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + + dw += row*dim2; + for(i=0; ix_dim; + int dim2 = 2*dim; + int i; + double *dw=x->x_work2; + + dw += col; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int dim2 = 2*dim; + int i, j; + double *dw=x->x_work2; + int ret=-1; + + dw += start_row*dim2 + col; + j = 0; + for(i=start_row; i 1.0e-10) || (*dw < -1.0e-10)) + { + ret = i; + i = dim+1; + } + dw += dim2; + } + return(ret); +} + + +static void matrix_pinv_inverse(t_matrix_pinv *x) +{ + int n_ambi = x->x_n_ambi; + int n_ambi2 = 2*n_ambi; + int i, j, nz; + int r,c; + double *src=x->x_inv_work1; + double *db=x->x_inv_work2; + double *acw_vec=x->x_ambi_channel_weight; + double rcp, *dv; + + dv = db; + for(i=0; i=0; i--) + { + dv = db + i*n_ambi2 + i; + matrix_pinv_copy_row2buf(x, i); + for(j=i-1; j>=0; j--) + { + dv -= n_ambi2; + rcp = -(*dv); + matrix_pinv_mul_buf_and_add2row(x, j, rcp); + } + } + + for(i=0; ix_dim; + int dim2 = 2*dim; + int i, j, nz; + int r,c; + double *db=x->x_work2; + double rcp, *dv=db; + t_atom *at=x->x_at; + + if(argc != (dim*dim + 2)) + { + post("matrix_pinv ERROR: wrong dimension of input-list"); + return; + + + if(ac > x->x_size) + { + x->x_at = (t_atom *)resizebytes(x->x_at, x->x_size*sizeof(t_atom), ac*sizeof(t_atom)); + x->x_size = ac; + } + x->x_ac = ac; + x->x_sym = &s_list; + + } + r = (int)(atom_getint(argv++)); + c = (int)(atom_getint(argv++)); + if(r != dim) + { + post("matrix_pinv ERROR: wrong number of rows of input-list"); + return; + } + if(c != dim) + { + post("matrix_pinv ERROR: wrong number of cols of input-list"); + return; + } + for(i=0; i=0; i--) + { + dv = db + i*dim2 + i; + matrix_pinv_copy_row2buf(x, i); + for(j=i-1; j>=0; j--) + { + dv -= dim2; + rcp = -(*dv); + matrix_pinv_mul_buf_and_add2row(x, j, rcp); + } + } + + + at = x->x_at; + SETFLOAT(at, (t_float)dim); + at++; + SETFLOAT(at, (t_float)dim); + at++; + dv = db; + dv += dim; + for(i=0; ix_obj.ob_outlet, gensym("matrix"), argc, x->x_at); +} + + + + + + + + + + + + + + + + + + + + + + + + + +static void matrix_pinv_mul1(t_matrix_pinv *x) +{ + double *vec1, *beg1=x->x_ls_encode; + double *vec2, *beg2=x->x_ls_encode; + double *inv=x->x_inv_work1; + double sum; + int n_ls=x->x_n_ls+x->x_n_phls; + int n_ambi=x->x_n_ambi; + int i, j, k; + + for(k=0; kx_ls_encode; + for(j=0; jx_n_ls+x->x_n_phls; + int n_ambi=x->x_n_ambi; + int n_ambi2=2*n_ambi; + int i, j, k; + double *vec1, *beg1=x->x_transp; + double *vec2, *beg2=x->x_inv_work2+n_ambi; + double *vec3=x->x_prod; + double *acw_vec=x->x_ambi_channel_weight; + double sum; + + for(k=0; kx_inv_work2+n_ambi; + for(j=0; jx_transp; + double *straight=x->x_ls_encode; + int n_ls=x->x_n_ls+x->x_n_phls; + int n_ambi=x->x_n_ambi; + int i, j; + + for(j=0; jx_n_ambi; + int n_ambi2 = 2*n_ambi; + int i, j, nz; + int r,c; + double *src=x->x_inv_work1; + double *db=x->x_inv_work2; + double rcp, *dv; + + dv = db; + for(i=0; i=0; i--) + { + dv = db + i*n_ambi2 + i; + matrix_pinv_copy_row2buf(x, i); + for(j=i-1; j>=0; j--) + { + dv -= n_ambi2; + rcp = -(*dv); + matrix_pinv_mul_buf_and_add2row(x, j, rcp); + } + } + + post("matrix_inverse regular"); +} + +static void matrix_pinv_pinv(t_matrix_pinv *x) +{ + t_atom *at=x->x_at; + + matrix_pinv_transp_back(x); + matrix_pinv_mul1(x); + matrix_pinv_inverse(x); + matrix_pinv_mul2(x); + if((x->x_mirrorsum_end > x->x_mirrorsum_beg)&& + (x->x_realsum_end > x->x_realsum_beg)&& + ((x->x_mirrorsum_end - x->x_mirrorsum_beg) == (x->x_realsum_end - x->x_realsum_beg))) + { + double *mir=x->x_prod+x->x_mirrorsum_beg*x->x_n_ambi; + double *real=x->x_prod+x->x_realsum_beg*x->x_n_ambi; + double mwght=x->x_mir_wght; + int i, n=(x->x_mirrorsum_end - x->x_mirrorsum_beg)*x->x_n_ambi; + + // post("mirror"); + for(i=0; ix_mirrorsum_beg*x->x_n_ambi; + real=x->x_prod; + SETFLOAT(at, (t_float)x->x_n_ambi); + at++; + SETFLOAT(at, (t_float)x->x_mirrorsum_beg); + at++; + for(i=0; ix_obj.ob_outlet, x->x_s_matrix, n+2, x->x_at); + } + else + { + int i, n=x->x_n_ls*x->x_n_ambi; + double *dv=x->x_prod; + + // post("real"); + SETFLOAT(at, (t_float)x->x_n_ambi); + at++; + SETFLOAT(at, (t_float)x->x_n_ls); + at++; + for(i=0; ix_obj.ob_outlet, x->x_s_matrix, n+2, x->x_at); + } +} + +static void matrix_pinv_free(t_matrix_pinv *x) +{ + freebytes(x->x_work2, 2 * x->x_dim * x->x_dim * sizeof(double)); + freebytes(x->x_buf2, 2 * x->x_dim * sizeof(double)); + freebytes(x->x_at, x->x_size * sizeof(t_atom)); +} + +static void *matrix_pinv_new(void) +{ + t_matrix_pinv *x = (t_matrix_pinv *)pd_new(matrix_pinv_class); + + x->x_dim = 10; + x->x_size = 102; + x->x_work2 = (double *)getbytes(2 * x->x_dim * x->x_dim * sizeof(double)); + x->x_buf2 = (double *)getbytes(2 * x->x_dim * sizeof(double)); + x->x_at = (t_atom *)getbytes(x->x_size * sizeof(t_atom)); + outlet_new(&x->x_obj, &s_list); + return (x); +} + +void matrix_pinv_setup(void) +{ + matrix_pinv_class = class_new(gensym("matrix_pinv"), (t_newmethod)matrix_pinv_new, (t_method)matrix_pinv_free, + sizeof(t_matrix_pinv), 0, 0); + class_addmethod(matrix_pinv_class, (t_method)matrix_pinv_matrix, gensym("matrix"), A_GIMME, 0); + class_sethelpsymbol(matrix_pinv_class, gensym("iemhelp/matrix_pinv-help")); +} diff --git a/src/spherical_line.c b/src/spherical_line.c new file mode 100644 index 0000000..b2c6927 --- /dev/null +++ b/src/spherical_line.c @@ -0,0 +1,264 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_matrix written by Thomas Musil (c) IEM KUG Graz Austria 2002 - 2006 */ + +/* -------------------------- spherical_line ------------------------------ */ + +typedef struct _spherical_line +{ + t_object x_obj; + int x_dim; + double *x_work2; + double *x_buf2; + t_atom *x_at; +} t_spherical_line; + +static t_class *spherical_line_class; + +static void spherical_line_rot_z(t_spherical_line *x, double *vec, double angle) +{ + int i; + double s=sin(angle); + double c=cos(angle); + double sum=0.0; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw_src=x->x_work2; + double *dw_dst=x->x_work2; + + dw_src += src_row*dim2; + dw_dst += dst_row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + + dw += row*dim2; + for(i=0; ix_dim; + int i; + double *dw=x->x_work2; + double *db=x->x_buf2; + + dw += row*dim2; + for(i=0; ix_dim; + int dim2 = 2*dim; + int i, j; + double *dw=x->x_work2; + int ret=-1; + + dw += start_row*dim2 + col; + j = 0; + for(i=start_row; i 1.0e-10) || (*dw < -1.0e-10) ) + { + ret = i; + i = dim+1; + } + dw += dim2; + } + return(ret); +} + +static void spherical_line_matrix(t_spherical_line *x, t_symbol *s, int argc, t_atom *argv) +{ + int dim = x->x_dim; + int dim2 = 2*dim; + int i, j, nz; + int r,c; + double *db=x->x_work2; + double rcp, *dv=db; + t_atom *at=x->x_at; + + if(argc != (dim*dim + 2)) + { + post("spherical_line ERROR: wrong dimension of input-list"); + return; + } + r = (int)(atom_getint(argv++)); + c = (int)(atom_getint(argv++)); + if(r != dim) + { + post("spherical_line ERROR: wrong number of rows of input-list"); + return; + } + if(c != dim) + { + post("spherical_line ERROR: wrong number of cols of input-list"); + return; + } + for(i=0; i=0; i--) + { + dv = db + i*dim2 + i; + spherical_line_copy_row2buf(x, i); + for(j=i-1; j>=0; j--) + { + dv -= dim2; + rcp = -(*dv); + spherical_line_mul_buf_and_add2row(x, j, rcp); + } + } + + + at = x->x_at; + SETFLOAT(at, (t_float)dim); + at++; + SETFLOAT(at, (t_float)dim); + at++; + dv = db; + dv += dim; + for(i=0; ix_obj.ob_outlet, gensym("matrix"), argc, x->x_at); +} + +static void spherical_line_free(t_spherical_line *x) +{ + freebytes(x->x_work2, 2 * x->x_dim * x->x_dim * sizeof(double)); + freebytes(x->x_buf2, 2 * x->x_dim * sizeof(double)); + freebytes(x->x_at, (x->x_dim * x->x_dim + 2) * sizeof(t_atom)); +} + +static void *spherical_line_new(t_floatarg fdim) +{ + t_spherical_line *x = (t_spherical_line *)pd_new(spherical_line_class); + int dim = (int)fdim; + + if(dim < 1) + dim = 1; + x->x_dim = dim; + x->x_work2 = (double *)getbytes(2 * x->x_dim * x->x_dim * sizeof(double)); + x->x_buf2 = (double *)getbytes(2 * x->x_dim * sizeof(double)); + x->x_at = (t_atom *)getbytes((x->x_dim * x->x_dim + 2) * sizeof(t_atom)); + outlet_new(&x->x_obj, &s_list); + return (x); +} + +static void spherical_line_setup(void) +{ + spherical_line_class = class_new(gensym("spherical_line"), (t_newmethod)spherical_line_new, (t_method)spherical_line_free, + sizeof(t_spherical_line), 0, A_FLOAT, 0); + class_addmethod(spherical_line_class, (t_method)spherical_line_matrix, gensym("matrix"), A_GIMME, 0); + class_sethelpsymbol(spherical_line_class, gensym("iemhelp/spherical_line-help")); +} -- cgit v1.2.1