diff options
Diffstat (limited to 'src/iem_t3_lib')
-rw-r--r-- | src/iem_t3_lib/iem_t3_lib.c | 65 | ||||
-rw-r--r-- | src/iem_t3_lib/iem_t3_lib.dsp | 85 | ||||
-rw-r--r-- | src/iem_t3_lib/iem_t3_lib.dsw | 29 | ||||
-rw-r--r-- | src/iem_t3_lib/iemlib.h | 98 | ||||
-rw-r--r-- | src/iem_t3_lib/makefile | 56 | ||||
-rw-r--r-- | src/iem_t3_lib/makefile_win | 43 | ||||
-rw-r--r-- | src/iem_t3_lib/sigt3_line.c | 279 | ||||
-rw-r--r-- | src/iem_t3_lib/sigt3_sig.c | 200 | ||||
-rw-r--r-- | src/iem_t3_lib/t3_bpe.c | 142 | ||||
-rw-r--r-- | src/iem_t3_lib/t3_delay.c | 97 | ||||
-rw-r--r-- | src/iem_t3_lib/t3_metro.c | 121 | ||||
-rw-r--r-- | src/iem_t3_lib/t3_timer.c | 55 |
12 files changed, 1270 insertions, 0 deletions
diff --git a/src/iem_t3_lib/iem_t3_lib.c b/src/iem_t3_lib/iem_t3_lib.c new file mode 100644 index 0000000..1e19576 --- /dev/null +++ b/src/iem_t3_lib/iem_t3_lib.c @@ -0,0 +1,65 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <math.h> +/* +#include <ctype.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#ifndef NT +#include <sys/signal.h> +#include <unistd.h> +#endif + +#ifdef NT +#include <io.h> +#endif + */ + +static t_class *iem_t3_lib_class; + +static void *iem_t3_lib_new(void) +{ + t_object *x = (t_object *)pd_new(iem_t3_lib_class); + + return (x); +} + +void sigt3_line_setup(void); +void sigt3_sig_setup(void); +void t3_bpe_setup(void); +void t3_delay_setup(void); +void t3_metro_setup(void); +void t3_timer_setup(void); + +/* ------------------------ setup routine ------------------------- */ + +void iem_t3_lib_setup(void) +{ + iem_t3_lib_class = class_new(gensym("iem_t3_lib"), iem_t3_lib_new, 0, + sizeof(t_object), CLASS_NOINLET, 0); + + sigt3_line_setup(); + sigt3_sig_setup(); + t3_bpe_setup(); + t3_delay_setup(); + t3_metro_setup(); + t3_timer_setup(); + + post("iem_t3_lib (R-1.15) library loaded!"); +} diff --git a/src/iem_t3_lib/iem_t3_lib.dsp b/src/iem_t3_lib/iem_t3_lib.dsp new file mode 100644 index 0000000..e6a61be --- /dev/null +++ b/src/iem_t3_lib/iem_t3_lib.dsp @@ -0,0 +1,85 @@ +# Microsoft Developer Studio Project File - Name="iem_t3_lib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** NICHT BEARBEITEN ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=iem_t3_lib - 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_t3_lib.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_t3_lib.mak" CFG="iem_t3_lib - Win32 Debug" +!MESSAGE +!MESSAGE Für die Konfiguration stehen zur Auswahl: +!MESSAGE +!MESSAGE "iem_t3_lib - Win32 Release" (basierend auf "Win32 (x86) External Target") +!MESSAGE "iem_t3_lib - Win32 Debug" (basierend auf "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "iem_t3_lib - 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_t3_lib.exe" +# PROP Bsc_Name "iem_t3_lib.bsc" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "iem_t3_lib - 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_t3_lib.exe" +# PROP Bsc_Name "iem_t3_lib.bsc" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "iem_t3_lib - Win32 Release" +# Name "iem_t3_lib - Win32 Debug" + +!IF "$(CFG)" == "iem_t3_lib - Win32 Release" + +!ELSEIF "$(CFG)" == "iem_t3_lib - Win32 Debug" + +!ENDIF + +# Begin Source File + +SOURCE=.\makefile_win +# End Source File +# End Target +# End Project diff --git a/src/iem_t3_lib/iem_t3_lib.dsw b/src/iem_t3_lib/iem_t3_lib.dsw new file mode 100644 index 0000000..2b4e202 --- /dev/null +++ b/src/iem_t3_lib/iem_t3_lib.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_t3_lib"=.\iem_t3_lib.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/src/iem_t3_lib/iemlib.h b/src/iem_t3_lib/iemlib.h new file mode 100644 index 0000000..d518565 --- /dev/null +++ b/src/iem_t3_lib/iemlib.h @@ -0,0 +1,98 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib1 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifndef __IEMLIB_H__ +#define __IEMLIB_H__ + + +#define IS_A_POINTER(atom,index) ((atom+index)->a_type == A_POINTER) +#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT) +#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL) +#define IS_A_DOLLAR(atom,index) ((atom+index)->a_type == A_DOLLAR) +#define IS_A_DOLLSYM(atom,index) ((atom+index)->a_type == A_DOLLSYM) +#define IS_A_SEMI(atom,index) ((atom+index)->a_type == A_SEMI) +#define IS_A_COMMA(atom,index) ((atom+index)->a_type == A_COMMA) + + +#ifdef NT +int sys_noloadbang; +//t_symbol *iemgui_key_sym=0; +#include <io.h> +#else +extern int sys_noloadbang; +//extern t_symbol *iemgui_key_sym; +#include <unistd.h> +#endif + +#define DEFDELVS 64 +#define XTRASAMPS 4 +#define SAMPBLK 4 + + +#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */ + + /* machine-dependent definitions. These ifdefs really + should have been by CPU type and not by operating system! */ +#ifdef IRIX + /* big-endian. Most significant byte is at low address in memory */ +#define HIOFFSET 0 /* word offset to find MSB */ +#define LOWOFFSET 1 /* word offset to find LSB */ +#define int32 long /* a data type that has 32 bits */ +#else +#ifdef MSW + /* little-endian; most significant byte is at highest address */ +#define HIOFFSET 1 +#define LOWOFFSET 0 +#define int32 long +#else +#ifdef __FreeBSD__ +#include <machine/endian.h> +#if BYTE_ORDER == LITTLE_ENDIAN +#define HIOFFSET 1 +#define LOWOFFSET 0 +#else +#define HIOFFSET 0 /* word offset to find MSB */ +#define LOWOFFSET 1 /* word offset to find LSB */ +#endif /* BYTE_ORDER */ +#include <sys/types.h> +#define int32 int32_t +#endif +#ifdef __linux__ + +#include <endian.h> + +#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN) +#error No byte order defined +#endif + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define HIOFFSET 1 +#define LOWOFFSET 0 +#else +#define HIOFFSET 0 /* word offset to find MSB */ +#define LOWOFFSET 1 /* word offset to find LSB */ +#endif /* __BYTE_ORDER */ + +#include <sys/types.h> +#define int32 int32_t + +#else +#ifdef MACOSX +#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 /* MACOSX */ +#endif /* __linux__ */ +#endif /* MSW */ +#endif /* SGI */ + +union tabfudge +{ + double tf_d; + int32 tf_i[2]; +}; + +#endif diff --git a/src/iem_t3_lib/makefile b/src/iem_t3_lib/makefile new file mode 100644 index 0000000..34d19d6 --- /dev/null +++ b/src/iem_t3_lib/makefile @@ -0,0 +1,56 @@ +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 -Wall -W -Werror -Wno-unused \ + -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer \ + -DDL_OPEN + +SYSTEM = $(shell uname -m) + +# the sources + +SRC = sigt3_line.c \ + sigt3_sig.c \ + t3_bpe.c \ + t3_delay.c \ + t3_metro.c \ + t3_timer.c \ + iem_t3_lib.c + +TARGET = iem_t3_lib.pd_linux + + +OBJ = $(SRC:.c=.o) + +# +# ------------------ targets ------------------------------------ +# + +clean: + rm ../../lib/$(TARGET) + rm *.o + +all: $(OBJ) + + @echo :: $(OBJ) + + ld $(LDFLAGS) -o $(TARGET) *.o $(LIB) + strip --strip-unneeded $(TARGET) + mv $(TARGET) ../../lib + rm *.o + +$(OBJ) : %.o : %.c + touch $*.c + cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c + + + + diff --git a/src/iem_t3_lib/makefile_win b/src/iem_t3_lib/makefile_win new file mode 100644 index 0000000..6f31894 --- /dev/null +++ b/src/iem_t3_lib/makefile_win @@ -0,0 +1,43 @@ + +all: ..\..\lib\iem_t3_lib.dll + +VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98" + +PD_INST_PATH = "C:\Programme\pd" + +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 = sigt3_line.c \ + sigt3_sig.c \ + t3_bpe.c \ + t3_delay.c \ + t3_metro.c \ + t3_timer.c \ + iem_t3_lib.c + + +OBJ = $(SRC:.c=.obj) + +.c.obj: + cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c + +..\..\lib\iem_t3_lib.dll: $(OBJ) + link $(PD_WIN_L_FLAGS) /dll /export:iem_t3_lib_setup \ + /out:..\..\lib\iem_t3_lib.dll $(OBJ) $(PD_WIN_LIB) + +clean: + del *.obj diff --git a/src/iem_t3_lib/sigt3_line.c b/src/iem_t3_lib/sigt3_line.c new file mode 100644 index 0000000..525f7f7 --- /dev/null +++ b/src/iem_t3_lib/sigt3_line.c @@ -0,0 +1,279 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* -------------------------- t3_line~ ------------------------------ */ +static t_class *sigt3_line_class; + +typedef struct _sigt3_line +{ + t_object x_obj; + t_clock *x_clock; + float *x_beg; + double x_cur_val; + double x_dst_val; + double x_inlet_val; + double x_inc64; + double x_inc; + double x_ms2samps; + double x_ticks2ms; + double x_inlet_time; + double x_dst_time; + int x_cur_samps; + int x_dur_samps; + int x_n; + int x_t3_bang_samps; + int x_transient; +} t_sigt3_line; + +static void sigt3_line_nontransient(float *vec, t_sigt3_line *x, int n) +{ + int cur_samps = x->x_cur_samps, i; + double inc = x->x_inc; + double cur_val = x->x_cur_val; + + if(cur_samps) + { + if(cur_samps > n) + { + x->x_cur_samps -= n; + while(n--) + { + cur_val += inc; + *vec++ = (float)cur_val; + } + x->x_cur_val += x->x_inc64; + } + else if(cur_samps == n) + { + x->x_cur_samps = 0; + while(n--) + { + cur_val += inc; + *vec++ = (float)cur_val; + } + x->x_cur_val = x->x_dst_val; + } + else + { + for(i=0; i<cur_samps; i++) + { + cur_val += inc; + *vec++ = (float)cur_val; + } + x->x_cur_val = cur_val = x->x_dst_val; + for(i=cur_samps; i<n; i++) + *vec++ = (float)cur_val; + x->x_cur_samps = 0; + } + } + else + { + while(n--) + *vec++ = (float)cur_val; + } +} + +static t_int *sigt3_line_perform(t_int *w) +{ + t_float *out = (t_float *)(w[1]); + t_sigt3_line *x = (t_sigt3_line *)(w[2]); + int n = (int)(w[3]); + + if(x->x_transient) + { + float *trans = x->x_beg; + + while(n--) + *out++ = *trans++; + x->x_transient = 0; + } + else + sigt3_line_nontransient(out, x, n); + return(w+4); +} + +static void sigt3_line_tick(t_sigt3_line *x) +{ + float *trans = x->x_beg; + int n = x->x_n, t3_bang_samps, cur_samps, i; + double inc, cur_val; + + if(!x->x_transient) + sigt3_line_nontransient(trans, x, n); + t3_bang_samps = x->x_t3_bang_samps; + x->x_dst_val = x->x_inlet_val; + if(x->x_inlet_time <= 0.0) + { + x->x_inlet_time = 0.0; + x->x_dst_time = 0.0; + x->x_dur_samps = 0; + x->x_cur_samps = 0; + cur_val = x->x_cur_val = x->x_dst_val; + for(i=t3_bang_samps; i<n; i++) + trans[i] = (float)cur_val; + } + else + { + int diff, end; + + x->x_dst_time = x->x_inlet_time; + x->x_inlet_time = 0.0; + cur_samps = (int)(x->x_dst_time * x->x_ms2samps); + if(!cur_samps) + cur_samps = 1; + x->x_dur_samps = cur_samps; + x->x_cur_samps = cur_samps; + cur_val = x->x_cur_val = (double)trans[t3_bang_samps]; + inc = x->x_inc = (x->x_dst_val - cur_val)/(double)cur_samps; + x->x_inc64 = (double)x->x_n * inc; + diff = n - t3_bang_samps; + if(cur_samps > diff) + { + for(i=t3_bang_samps; i<n; i++) + { + cur_val += inc; + trans[i] = (float)cur_val; + } + x->x_cur_val += (double)diff * inc; + x->x_cur_samps -= diff; + } + else if(cur_samps == diff) + { + for(i=t3_bang_samps; i<n; i++) + { + cur_val += inc; + trans[i] = (float)cur_val; + } + x->x_cur_val = x->x_dst_val; + x->x_cur_samps = 0; + } + else + { + end = t3_bang_samps + cur_samps; + for(i=t3_bang_samps; i<end; i++) + { + cur_val += inc; + trans[i] = (float)cur_val; + } + cur_val = x->x_cur_val = x->x_dst_val; + x->x_cur_samps = 0; + for(i=end; i<n; i++) + trans[i] = (float)cur_val; + } + } + x->x_transient = 1; +} + +static void sigt3_line_list(t_sigt3_line *x, t_symbol *s, int ac, t_atom *av) +{ + if((ac >= 2)&&IS_A_FLOAT(av,0)&&IS_A_FLOAT(av,1)) + { + int t3_bang_samps, ticks; + double time; + + x->x_inlet_val = (double)atom_getfloatarg(1, ac, av); + t3_bang_samps = (int)((float)atom_getfloatarg(0, ac, av)*x->x_ms2samps); + if(t3_bang_samps < 0) + t3_bang_samps = 0; + ticks = t3_bang_samps / x->x_n; + x->x_t3_bang_samps = t3_bang_samps - x->x_n * ticks; + if((ac >= 3)&&IS_A_FLOAT(av,2)) + { + time = (double)atom_getfloatarg(2, ac, av); + if(time < 0.0) + time = 0.0; + x->x_inlet_time = time; + } + if(ticks < 1) + sigt3_line_tick(x); + else + clock_delay(x->x_clock, (double)ticks * x->x_ticks2ms); + } +} + +static void sigt3_line_ft1(t_sigt3_line *x, t_float time) +{ + if(time < 0.0) + time = 0.0; + x->x_inlet_time = (double)time; +} + +static void sigt3_line_stop(t_sigt3_line *x) +{ + clock_unset(x->x_clock); + x->x_cur_samps = x->x_dur_samps = x->x_transient = 0; + x->x_inc = x->x_inc64 = x->x_inlet_time = x->x_dst_time = 0.0; +} + +static void sigt3_line_dsp(t_sigt3_line *x, t_signal **sp) +{ + int i; + float val, *trans; + + if(sp[0]->s_n > x->x_n) + { + freebytes(x->x_beg, x->x_n*sizeof(float)); + x->x_n = (int)sp[0]->s_n; + x->x_beg = (float *)getbytes(x->x_n*sizeof(float)); + } + else + x->x_n = (int)sp[0]->s_n; + i = x->x_n; + val = x->x_cur_val; + trans = x->x_beg; + while(i--) + *trans++ = val; + x->x_ms2samps = 0.001*(double)sp[0]->s_sr; + x->x_ticks2ms = (double)x->x_n / x->x_ms2samps; + dsp_add(sigt3_line_perform, 3, sp[0]->s_vec, x, sp[0]->s_n); +} + +static void sigt3_line_free(t_sigt3_line *x) +{ + if(x->x_beg) + freebytes(x->x_beg, x->x_n*sizeof(float)); + clock_free(x->x_clock); +} + +static void *sigt3_line_new(t_floatarg init_val) +{ + t_sigt3_line *x = (t_sigt3_line *)pd_new(sigt3_line_class); + int i; + + x->x_n = (int)sys_getblksize(); + x->x_beg = (float *)getbytes(x->x_n*sizeof(float)); + x->x_inlet_val = x->x_cur_val = x->x_dst_val = init_val; + x->x_t3_bang_samps = x->x_cur_samps = x->x_dur_samps = x->x_transient = 0; + x->x_inlet_time = x->x_dst_time = 0.0; + x->x_inc64 = x->x_inc = 0.0; + x->x_ms2samps = 0.001 * (double)sys_getsr(); + x->x_ticks2ms = (double)x->x_n / x->x_ms2samps; + x->x_clock = clock_new(x, (t_method)sigt3_line_tick); + outlet_new(&x->x_obj, &s_signal); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); + return (x); +} + +void sigt3_line_setup(void) +{ + sigt3_line_class = class_new(gensym("t3_line~"), (t_newmethod)sigt3_line_new, + (t_method)sigt3_line_free, sizeof(t_sigt3_line), 0, A_DEFFLOAT, 0); + class_addmethod(sigt3_line_class, (t_method)sigt3_line_dsp, gensym("dsp"), 0); + class_addmethod(sigt3_line_class, (t_method)sigt3_line_stop, gensym("stop"), 0); + class_addmethod(sigt3_line_class, (t_method)sigt3_line_ft1, gensym("ft1"), A_FLOAT, 0); + class_addlist(sigt3_line_class, (t_method)sigt3_line_list); + class_sethelpsymbol(sigt3_line_class, gensym("iemhelp/help-t3_line~")); +} diff --git a/src/iem_t3_lib/sigt3_sig.c b/src/iem_t3_lib/sigt3_sig.c new file mode 100644 index 0000000..84429b6 --- /dev/null +++ b/src/iem_t3_lib/sigt3_sig.c @@ -0,0 +1,200 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* -------------------------- sigt3_sig~ ------------------------------ */ +static t_class *sigt3_sig_class; + +typedef struct _sigt3_sig +{ + t_object x_obj; + t_clock *x_clock; + float x_old_val; + float x_new_val; + float *x_beg; + int x_n; + int x_t3_bang_samps; + int x_transient; + float x_ms2samps; + float x_ticks2ms; +} t_sigt3_sig; + +static void sigt3_sig_tick(t_sigt3_sig *x) +{ + float *trans = x->x_beg, val; + int n = x->x_n, t3_bang_samps, i; + + t3_bang_samps = x->x_t3_bang_samps; + if(!x->x_transient) + { + val = x->x_old_val; + for(i=0; i<t3_bang_samps; i++) + trans[i] = val; + x->x_transient = 1; + } + val = x->x_old_val = x->x_new_val; + for(i=t3_bang_samps; i<n; i++) + trans[i] = val; +} + +static void sigt3_sig_stop(t_sigt3_sig *x) +{ + clock_unset(x->x_clock); + x->x_new_val = x->x_old_val; +} + +static void sigt3_sig_list(t_sigt3_sig *x, t_symbol *s, int ac, t_atom *av) +{ + if((ac == 2)&&IS_A_FLOAT(av,0)&&IS_A_FLOAT(av,1)) + { + int n = x->x_n, t3_bang_samps, ticks; + + t3_bang_samps = (int)((float)atom_getfloatarg(0, ac, av)*x->x_ms2samps); + x->x_new_val = (float)atom_getfloatarg(1, ac, av); + if(t3_bang_samps < 0) + t3_bang_samps = 0; + ticks = t3_bang_samps / n; + x->x_t3_bang_samps = t3_bang_samps - n*ticks; + if(ticks < 1) + sigt3_sig_tick(x); + else + clock_delay(x->x_clock, (double)ticks * (double)x->x_ticks2ms); + } +} + +static t_int *sigt3_sig_perform(t_int *w) +{ + t_float *out = (t_float *)(w[1]); + t_sigt3_sig *x = (t_sigt3_sig *)(w[2]); + int n = (int)(w[3]); + + if(x->x_transient) + { + float *trans = x->x_beg; + + while(n--) + *out++ = *trans++; + x->x_transient = 0; + } + else + { + float val = x->x_new_val; + + while(n--) + *out++ = val; + } + return (w+4); +} + +static t_int *sigt3_sig_perf8(t_int *w) +{ + t_float *out = (t_float *)(w[1]); + t_sigt3_sig *x = (t_sigt3_sig *)(w[2]); + int n = (int)(w[3]), i; + + if(x->x_transient) + { + float *trans = x->x_beg; + + for(i=0; i<n; i+=8, out+=8, trans+=8) + { + out[0] = trans[0]; + out[1] = trans[1]; + out[2] = trans[2]; + out[3] = trans[3]; + out[4] = trans[4]; + out[5] = trans[5]; + out[6] = trans[6]; + out[7] = trans[7]; + } + x->x_transient = 0; + } + else + { + float val = x->x_new_val; + + for(i=0; i<n; i+=8, out+=8) + { + out[0] = val; + out[1] = val; + out[2] = val; + out[3] = val; + out[4] = val; + out[5] = val; + out[6] = val; + out[7] = val; + } + } + return (w+4); +} + +static void sigt3_sig_dsp(t_sigt3_sig *x, t_signal **sp) +{ + int i; + float *trans, val; + + if(sp[0]->s_n > x->x_n) + { + freebytes(x->x_beg, x->x_n*sizeof(float)); + x->x_n = sp[0]->s_n; + x->x_beg = (float *)getbytes(x->x_n*sizeof(float)); + } + else + x->x_n = sp[0]->s_n; + x->x_ms2samps = 0.001*(float)sp[0]->s_sr; + x->x_ticks2ms = (float)x->x_n / x->x_ms2samps; + i = x->x_n; + val = x->x_new_val; + trans = x->x_beg; + while(i--) + *trans++ = val; + + if((sp[0]->s_n)&7) + dsp_add(sigt3_sig_perform, 3, sp[0]->s_vec, x, sp[0]->s_n); + else + dsp_add(sigt3_sig_perf8, 3, sp[0]->s_vec, x, sp[0]->s_n); +} + +static void sigt3_sig_free(t_sigt3_sig *x) +{ + if(x->x_beg) + freebytes(x->x_beg, x->x_n*sizeof(float)); + clock_free(x->x_clock); +} + +static void *sigt3_sig_new(t_floatarg init_val) +{ + t_sigt3_sig *x = (t_sigt3_sig *)pd_new(sigt3_sig_class); + + x->x_new_val = x->x_old_val = init_val; + x->x_n = (int)sys_getblksize(); + x->x_beg = (float *)getbytes(x->x_n*sizeof(float)); + x->x_t3_bang_samps = x->x_transient = 0; + x->x_ms2samps = 0.001 * (float)sys_getsr(); + x->x_ticks2ms = (float)x->x_n / x->x_ms2samps; + x->x_clock = clock_new(x, (t_method)sigt3_sig_tick); + outlet_new(&x->x_obj, &s_signal); + return (x); +} + +void sigt3_sig_setup(void) +{ + sigt3_sig_class = class_new(gensym("t3_sig~"), (t_newmethod)sigt3_sig_new, + (t_method)sigt3_sig_free, sizeof(t_sigt3_sig), 0, A_DEFFLOAT, 0); + class_addmethod(sigt3_sig_class, (t_method)sigt3_sig_dsp, gensym("dsp"), 0); + class_addmethod(sigt3_sig_class, (t_method)sigt3_sig_stop, gensym("stop"), 0); + class_addlist(sigt3_sig_class, (t_method)sigt3_sig_list); + class_sethelpsymbol(sigt3_sig_class, gensym("iemhelp/help-t3_sig~")); +} diff --git a/src/iem_t3_lib/t3_bpe.c b/src/iem_t3_lib/t3_bpe.c new file mode 100644 index 0000000..6a2dbe0 --- /dev/null +++ b/src/iem_t3_lib/t3_bpe.c @@ -0,0 +1,142 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* ------------------------ t3_bpe ---------------------------- */ +static t_class *t3_bpe_class; + +typedef struct _t3_bpe +{ + t_object x_obj; + t_atom x_at[2]; + t_clock *x_clock; + int x_maxnum; + int x_curnum; + int x_curindex; + t_atom *x_beg; + double x_t3_bang; + double x_ticks2ms; + int x_hit; + void *x_out_val; + void *x_out_time; + void *x_out_finished; +} t_t3_bpe; + +static void t3_bpe_stop(t_t3_bpe *x) +{ + clock_unset(x->x_clock); +} + +static void t3_bpe_tick(t_t3_bpe *x) +{ + t_atom *vec = x->x_beg; + float val; + double dticks, time; + int iticks; + + if(x->x_curindex >= x->x_curnum) + { + t3_bpe_stop(x); + outlet_float(x->x_out_finished, x->x_t3_bang); + } + else + { + x->x_hit = 0; + vec += x->x_curindex; + val = atom_getfloat(vec++); + time = (double)atom_getfloat(vec); + outlet_float(x->x_out_time, (float)time); + x->x_at[1].a_w.w_float = val; + x->x_at[0].a_w.w_float = x->x_t3_bang; + outlet_list(x->x_obj.ob_outlet, &s_list, 2, x->x_at); + dticks = (time + x->x_t3_bang)/x->x_ticks2ms; + iticks = (int)dticks; + x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; + if(!x->x_hit) + clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); + x->x_curindex += 2; + } +} + +static void t3_bpe_float(t_t3_bpe *x, t_floatarg f) +{ + double dticks; + int iticks; + + if(x->x_curnum) + { + x->x_curindex = 0; + dticks = (double)f/x->x_ticks2ms; + iticks = (int)dticks; + x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; + clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); + x->x_hit = 1; + } +} + +static void t3_bpe_list(t_t3_bpe *x, t_symbol *s, int ac, t_atom *av) +{ + int n = ac & 0xfffffffe, i; + t_atom *vec = x->x_beg; + if(n > x->x_maxnum) + { + freebytes(x->x_beg, x->x_maxnum*sizeof(t_atom)); + x->x_maxnum = 2 + n; + x->x_beg = (t_atom *)getbytes(x->x_maxnum*sizeof(t_atom)); + vec = x->x_beg; + } + x->x_curnum = n; + for(i=0; i<n; i++) + { + *vec++ = *av++; + } +} + +static void t3_bpe_free(t_t3_bpe *x) +{ + freebytes(x->x_beg, x->x_maxnum*sizeof(t_atom)); + clock_free(x->x_clock); +} + +static void *t3_bpe_new(void) +{ + t_t3_bpe *x = (t_t3_bpe *)pd_new(t3_bpe_class); + + x->x_t3_bang = 0.0; + x->x_ticks2ms = 1000.0*(double)sys_getblksize()/(double)sys_getsr(); + x->x_curindex = 0; + x->x_maxnum = 20; + x->x_curnum = 0; + x->x_hit = 0; + x->x_beg = (t_atom *)getbytes(x->x_maxnum*sizeof(t_atom)); + x->x_clock = clock_new(x, (t_method)t3_bpe_tick); + outlet_new(&x->x_obj, &s_list); + x->x_out_time = outlet_new(&x->x_obj, &s_float); + x->x_out_finished = outlet_new(&x->x_obj, &s_float); + x->x_at[0].a_type = A_FLOAT; + x->x_at[1].a_type = A_FLOAT; + return (x); +} + +void t3_bpe_setup(void) +{ + t3_bpe_class = class_new(gensym("t3_bpe"), (t_newmethod)t3_bpe_new, + (t_method)t3_bpe_free, sizeof(t_t3_bpe), 0, 0); + class_addmethod(t3_bpe_class, (t_method)t3_bpe_stop, gensym("stop"), 0); + class_addfloat(t3_bpe_class, (t_method)t3_bpe_float); + class_addlist(t3_bpe_class, (t_method)t3_bpe_list); + class_sethelpsymbol(t3_bpe_class, gensym("iemhelp/help-t3_bpe")); +} + diff --git a/src/iem_t3_lib/t3_delay.c b/src/iem_t3_lib/t3_delay.c new file mode 100644 index 0000000..a422718 --- /dev/null +++ b/src/iem_t3_lib/t3_delay.c @@ -0,0 +1,97 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* ------------------------ t3_delay ---------------------------- */ +static t_class *t3_delay_class; + +typedef struct _t3_delay +{ + t_object x_obj; + t_clock *x_clock; + double x_deltime; + double x_ticks2ms; + double x_t3_bang; +} t_t3_delay; + +static void t3_delay_tick(t_t3_delay *x) +{ + outlet_float(x->x_obj.ob_outlet, x->x_t3_bang); +} + +static void t3_delay_stop(t_t3_delay *x) +{ + clock_unset(x->x_clock); +} + +static void t3_delay_float(t_t3_delay *x, t_floatarg t3_bang) +{ + double dticks; + int iticks; + + if(t3_bang < 0) + t3_bang = 0; + dticks = (x->x_deltime + (double)t3_bang)/x->x_ticks2ms; + iticks = (int)dticks; + x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; + clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); +} + +static void t3_delay_ft1(t_t3_delay *x, t_floatarg f) +{ + if(f < 0) + f = 0; + x->x_deltime = f; +} + +static void t3_delay_list(t_t3_delay *x, t_symbol *s, int ac, t_atom *av) +{ + if((ac == 2)&&IS_A_FLOAT(av,0)&&IS_A_FLOAT(av,1)) + { + t3_delay_ft1(x, atom_getfloatarg(1, ac, av)); + t3_delay_float(x, atom_getfloatarg(0, ac, av)); + } +} + +static void t3_delay_free(t_t3_delay *x) +{ + clock_free(x->x_clock); +} + +static void *t3_delay_new(t_floatarg f) +{ + t_t3_delay *x = (t_t3_delay *)pd_new(t3_delay_class); + + x->x_ticks2ms = 1000.0*(double)sys_getblksize()/(double)sys_getsr(); + t3_delay_ft1(x, f); + x->x_clock = clock_new(x, (t_method)t3_delay_tick); + outlet_new(&x->x_obj, &s_float); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); + return (x); +} + +void t3_delay_setup(void) +{ + t3_delay_class = class_new(gensym("t3_delay"), (t_newmethod)t3_delay_new, + (t_method)t3_delay_free, sizeof(t_t3_delay), 0, A_DEFFLOAT, 0); + class_addcreator((t_newmethod)t3_delay_new, gensym("t3_del"), A_DEFFLOAT, 0); + class_addmethod(t3_delay_class, (t_method)t3_delay_stop, gensym("stop"), 0); + class_addmethod(t3_delay_class, (t_method)t3_delay_ft1, + gensym("ft1"), A_FLOAT, 0); + class_addfloat(t3_delay_class, (t_method)t3_delay_float); + class_addlist(t3_delay_class, (t_method)t3_delay_list); + class_sethelpsymbol(t3_delay_class, gensym("iemhelp/help-t3_delay")); +} + diff --git a/src/iem_t3_lib/t3_metro.c b/src/iem_t3_lib/t3_metro.c new file mode 100644 index 0000000..b33ad7e --- /dev/null +++ b/src/iem_t3_lib/t3_metro.c @@ -0,0 +1,121 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* ------------------------ t3_metro ---------------------------- */ +static t_class *t3_metro_class; + +typedef struct _t3_metro +{ + t_object x_obj; + t_clock *x_clock; + double x_metrotime; + double x_ticks2ms; + double x_t3_bang; + int x_hit; + void *x_out_next; +} t_t3_metro; + +static void t3_metro_stop(t_t3_metro *x) +{ + clock_unset(x->x_clock); +} + +static void t3_metro_tick(t_t3_metro *x) +{ + double dticks; + int iticks; + + x->x_hit = 0; + outlet_float(x->x_out_next, x->x_metrotime); + outlet_float(x->x_obj.ob_outlet, x->x_t3_bang); + dticks = (x->x_metrotime + x->x_t3_bang)/x->x_ticks2ms; + iticks = (int)dticks; + x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; + if(!x->x_hit) + clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); +} + +static void t3_metro_float(t_t3_metro *x, t_floatarg t3_bang) +{ + double dticks; + int iticks; + + if(t3_bang < 0) + t3_bang = 0; + dticks = (double)t3_bang/x->x_ticks2ms; + iticks = (int)dticks; + x->x_t3_bang = (dticks - (double)iticks)*x->x_ticks2ms; + clock_delay(x->x_clock, (double)iticks*x->x_ticks2ms); + x->x_hit = 1; +} + +static void t3_metro_start(t_t3_metro *x, t_floatarg f) +{ + t3_metro_float(x, f); + x->x_hit = 1; +} + +static void t3_metro_ft1(t_t3_metro *x, t_floatarg f) +{ + if(f < 0.01) f = 0.01; + x->x_metrotime = (double)f; +} + +static void t3_metro_list(t_t3_metro *x, t_symbol *s, int ac, t_atom *av) +{ + if((ac == 2)&&IS_A_FLOAT(av,0)&&IS_A_FLOAT(av,1)) + { + t3_metro_ft1(x, atom_getfloatarg(1, ac, av)); + t3_metro_float(x, atom_getfloatarg(0, ac, av)); + } +} + +static void t3_metro_free(t_t3_metro *x) +{ + clock_free(x->x_clock); +} + +static void *t3_metro_new(t_symbol *s, int ac, t_atom *av) +{ + t_t3_metro *x = (t_t3_metro *)pd_new(t3_metro_class); + + x->x_metrotime = 10.0; + x->x_t3_bang = 0.0; + x->x_hit = 0; + if((ac == 1)&&IS_A_FLOAT(av,0)) + { + t3_metro_ft1(x, atom_getfloatarg(0, ac, av)); + } + x->x_ticks2ms = 1000.0*(double)sys_getblksize()/(double)sys_getsr(); + x->x_clock = clock_new(x, (t_method)t3_metro_tick); + outlet_new(&x->x_obj, &s_float); + x->x_out_next = outlet_new(&x->x_obj, &s_float); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1")); + return (x); +} + +void t3_metro_setup(void) +{ + t3_metro_class = class_new(gensym("t3_metro"), (t_newmethod)t3_metro_new, + (t_method)t3_metro_free, sizeof(t_t3_metro), 0, A_GIMME, 0); + class_addmethod(t3_metro_class, (t_method)t3_metro_stop, gensym("stop"), 0); + class_addmethod(t3_metro_class, (t_method)t3_metro_start, gensym("start"), A_FLOAT, 0); + class_addmethod(t3_metro_class, (t_method)t3_metro_ft1, gensym("ft1"), A_FLOAT, 0); + class_addfloat(t3_metro_class, (t_method)t3_metro_float); + class_addlist(t3_metro_class, (t_method)t3_metro_list); + class_sethelpsymbol(t3_metro_class, gensym("iemhelp/help-t3_metro")); +} + diff --git a/src/iem_t3_lib/t3_timer.c b/src/iem_t3_lib/t3_timer.c new file mode 100644 index 0000000..c52a926 --- /dev/null +++ b/src/iem_t3_lib/t3_timer.c @@ -0,0 +1,55 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iem_t3_lib written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <math.h> +#include <stdio.h> +#include <string.h> + +/* -------------------------- t3_timer ------------------------------ */ +static t_class *t3_timer_class; + +typedef struct _t3_timer +{ + t_object x_obj; + double x_settime; + double x_t3_off; +} t_t3_timer; + +static void t3_timer_float(t_t3_timer *x, t_float t3_bang) +{ + x->x_settime = (double)clock_getsystime(); + x->x_t3_off = (double)t3_bang; +} + +static void t3_timer_ft1(t_t3_timer *x, t_float t3_bang) +{ + outlet_float(x->x_obj.ob_outlet, clock_gettimesince(x->x_settime) + + (double)t3_bang - x->x_t3_off); +} + +static void *t3_timer_new(void) +{ + t_t3_timer *x = (t_t3_timer *)pd_new(t3_timer_class); + t3_timer_float(x, 0.0); + outlet_new(&x->x_obj, &s_float); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1")); + return (x); +} + +void t3_timer_setup(void) +{ + t3_timer_class = class_new(gensym("t3_timer"), (t_newmethod)t3_timer_new, 0, + sizeof(t_t3_timer), 0, 0); + class_addfloat(t3_timer_class, t3_timer_float); + class_addmethod(t3_timer_class, (t_method)t3_timer_ft1, gensym("ft1"), A_FLOAT, 0); + class_sethelpsymbol(t3_timer_class, gensym("iemhelp/help-t3_timer")); +} |