Update of /cvsroot/pure-data/externals/iem/iem_tab/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5595/iem/iem_tab/src
Added Files:
iem_tab.c iem_tab.dsp iem_tab.dsw iem_tab.h iemlib.h makefile
makefile_win tab_abs.c tab_add.c tab_add_scalar.c
tab_complex_inv.c tab_complex_mul.c tab_const.c tab_conv.c
tab_copy.c tab_counter.c tab_cross_corr.c tab_div.c tab_eq.c
tab_eq_scalar.c tab_fft.c tab_find_peaks.c tab_ge.c
tab_ge_scalar.c tab_gt.c tab_gt_scalar.c tab_ifft.c tab_le.c
tab_le_scalar.c tab_lt.c tab_lt_scalar.c tab_max_index.c
tab_mean.c tab_min_index.c tab_min_max.c tab_mls.c tab_mul.c
tab_mul_scalar.c tab_ne.c tab_ne_scalar.c tab_reverse.c
tab_rfft.c tab_rifft.c tab_sin.c tab_sqrt.c tab_sub.c
tab_sum.c
Log Message:
initial check in
--- NEW FILE: iem_tab.dsw ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: tab_min_max.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_min_max ------------------------------ */
typedef struct _tab_min_max
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
t_symbol *x_sym_scr1;
void *x_bang_out;
void *x_min_out;
void *x_max_out;
} t_tab_min_max;
static t_class *tab_min_max_class;
static void tab_min_max_src(t_tab_min_max *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_min_max_bang(t_tab_min_max *x)
{
int i, n;
int ok_src;
t_float *vec_src;
t_float min=1.0e37, max=-1.0e37;
ok_src = iem_tab_check_arrays(gensym("tab_min_max"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
vec_src = x->x_beg_mem_src1;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] > max)
max = vec_src[i];
if(vec_src[i] < min)
min = vec_src[i];
}
outlet_float(x->x_max_out, max);
outlet_float(x->x_min_out, min);
outlet_bang(x->x_bang_out);
}
}
}
static void tab_min_max_list(t_tab_min_max *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src;
t_float *vec_src;
t_float min=1.0e37, max=-1.0e37;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_min_max"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] > max)
max = vec_src[i];
if(vec_src[i] < min)
min = vec_src[i];
}
outlet_float(x->x_max_out, max);
outlet_float(x->x_min_out, min);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_min_max-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_min_max");
}
}
static void tab_min_max_free(t_tab_min_max *x)
{
}
static void *tab_min_max_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_min_max *x = (t_tab_min_max *)pd_new(tab_min_max_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_min_max-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_bang_out = outlet_new(&x->x_obj, &s_bang);
x->x_min_out = outlet_new(&x->x_obj, &s_float);
x->x_max_out = outlet_new(&x->x_obj, &s_float);
return(x);
}
void tab_min_max_setup(void)
{
tab_min_max_class = class_new(gensym("tab_min_max"), (t_newmethod)tab_min_max_new, (t_method)tab_min_max_free,
sizeof(t_tab_min_max), 0, A_GIMME, 0);
class_addbang(tab_min_max_class, (t_method)tab_min_max_bang);
class_addlist(tab_min_max_class, (t_method)tab_min_max_list);
class_addmethod(tab_min_max_class, (t_method)tab_min_max_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_min_max_class, (t_method)tab_min_max_src, gensym("src1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_min_max_class, gensym("iemhelp2/tab_min_max-help"));
}
--- NEW FILE: makefile ---
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 \
-DDL_OPEN
SYSTEM = $(shell uname -m)
# the sources
SRC = tab_copy.c \
tab_reverse.c \
tab_min_max.c \
tab_min_index.c \
tab_max_index.c \
tab_find_peaks.c \
tab_abs.c \
tab_sqrt.c \
tab_sum.c \
tab_add.c \
tab_sub.c \
tab_mul.c \
tab_div.c \
tab_complex_mul.c \
tab_complex_inv.c \
tab_add_scalar.c \
tab_mul_scalar.c \
tab_const.c \
tab_fft.c \
tab_ifft.c \
tab_rfft.c \
tab_rifft.c \
tab_cross_corr.c \
tab_conv.c \
tab_gt_scalar.c \
tab_ge_scalar.c \
tab_lt_scalar.c \
tab_le_scalar.c \
tab_ne_scalar.c \
tab_eq_scalar.c \
tab_gt.c \
tab_ge.c \
tab_lt.c \
tab_le.c \
tab_ne.c \
tab_eq.c \
tab_counter.c \
iem_tab.c
TARGET = iem_tab.pd_linux
OBJ = $(SRC:.c=.o)
#
# ------------------ targets ------------------------------------
#
clean:
rm $(TARGET)
rm *.o
all: $(OBJ)
@echo :: $(OBJ)
ld $(LDFLAGS) -o $(TARGET) *.o $(LIB)
strip --strip-unneeded $(TARGET)
$(OBJ) : %.o : %.c
touch $*.c
cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
--- NEW FILE: tab_mul.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_mul ------------------------------ */
typedef struct _tab_mul
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_mul;
static t_class *tab_mul_class;
static void tab_mul_src1(t_tab_mul *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_mul_src2(t_tab_mul *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_mul_dst(t_tab_mul *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_mul_bang(t_tab_mul *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i]*vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_mul_list(t_tab_mul *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_mul"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i]*vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_mul-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_mul");
}
}
static void tab_mul_free(t_tab_mul *x)
{
}
static void *tab_mul_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_mul *x = (t_tab_mul *)pd_new(tab_mul_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_mul-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_mul_setup(void)
{
tab_mul_class = class_new(gensym("tab_mul"), (t_newmethod)tab_mul_new, (t_method)tab_mul_free,
sizeof(t_tab_mul), 0, A_GIMME, 0);
class_addbang(tab_mul_class, (t_method)tab_mul_bang);
class_addlist(tab_mul_class, (t_method)tab_mul_list);
class_addmethod(tab_mul_class, (t_method)tab_mul_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_mul_class, (t_method)tab_mul_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_mul_class, (t_method)tab_mul_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_mul_class, gensym("iemhelp2/tab_mul-help"));
}
--- NEW FILE: makefile_win ---
all: iem_tab.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\pd.lib
SRC = tab_copy.c \
tab_reverse.c \
tab_min_max.c \
tab_min_index.c \
tab_max_index.c \
tab_find_peaks.c \
tab_abs.c \
tab_sqrt.c \
tab_sum.c \
tab_add.c \
tab_sub.c \
tab_mul.c \
tab_div.c \
tab_complex_mul.c \
tab_complex_inv.c \
tab_add_scalar.c \
tab_mul_scalar.c \
tab_const.c \
tab_fft.c \
tab_ifft.c \
tab_rfft.c \
tab_rifft.c \
tab_cross_corr.c \
tab_conv.c \
tab_gt_scalar.c \
tab_ge_scalar.c \
tab_lt_scalar.c \
tab_le_scalar.c \
tab_ne_scalar.c \
tab_eq_scalar.c \
tab_gt.c \
tab_ge.c \
tab_lt.c \
tab_le.c \
tab_ne.c \
tab_eq.c \
tab_counter.c \
iem_tab.c
OBJ = $(SRC:.c=.obj)
.c.obj:
cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c
iem_tab.dll: $(OBJ)
link $(PD_WIN_L_FLAGS) /dll /export:iem_tab_setup \
/out:iem_tab.dll $(OBJ) $(PD_WIN_LIB)
clean:
del *.obj
--- NEW FILE: tab_gt.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_gt ------------------------------ */
typedef struct _tab_gt
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_gt;
static t_class *tab_gt_class;
static void tab_gt_src1(t_tab_gt *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_gt_src2(t_tab_gt *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_gt_dst(t_tab_gt *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_gt_bang(t_tab_gt *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] > vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_gt_list(t_tab_gt *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_gt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] > vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_gt-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_gt_free(t_tab_gt *x)
{
}
static void *tab_gt_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_gt *x = (t_tab_gt *)pd_new(tab_gt_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_gt-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_gt_setup(void)
{
tab_gt_class = class_new(gensym("tab_gt"), (t_newmethod)tab_gt_new, (t_method)tab_gt_free,
sizeof(t_tab_gt), 0, A_GIMME, 0);
class_addbang(tab_gt_class, (t_method)tab_gt_bang);
class_addlist(tab_gt_class, (t_method)tab_gt_list);
class_addmethod(tab_gt_class, (t_method)tab_gt_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_gt_class, (t_method)tab_gt_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_gt_class, (t_method)tab_gt_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_gt_class, gensym("iemhelp2/tab_gt-help"));
}
--- NEW FILE: tab_copy.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_copy ------------------------------ */
typedef struct _tab_copy
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_copy;
static t_class *tab_copy_class;
static void tab_copy_src(t_tab_copy *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_copy_dst(t_tab_copy *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_copy_bang(t_tab_copy *x)
{
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
ok_src = iem_tab_check_arrays(gensym("tab_copy"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_copy"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_copy_list(t_tab_copy *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst;
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_copy"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
ok_dst = iem_tab_check_arrays(gensym("tab_copy"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src && ok_dst)
{
vec_src = x->x_beg_mem_src1 + beg_src;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_copy-ERROR: list need 3 float arguments:");
post(" source_offset + destination_offset + number_of_samples_to_copy");
}
}
static void tab_copy_free(t_tab_copy *x)
{
}
static void *tab_copy_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_copy *x = (t_tab_copy *)pd_new(tab_copy_class);
t_symbol *src, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src;
}
else
{
post("tab_copy-ERROR: need 2 symbols arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_copy_setup(void)
{
tab_copy_class = class_new(gensym("tab_copy"), (t_newmethod)tab_copy_new, (t_method)tab_copy_free,
sizeof(t_tab_copy), 0, A_GIMME, 0);
class_addbang(tab_copy_class, (t_method)tab_copy_bang);
class_addlist(tab_copy_class, (t_method)tab_copy_list);
class_addmethod(tab_copy_class, (t_method)tab_copy_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_copy_class, (t_method)tab_copy_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_copy_class, (t_method)tab_copy_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_copy_class, gensym("iemhelp2/tab_copy-help"));
}
--- NEW FILE: iem_tab.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
static t_class *iem_tab_class;
int iem_tab_check_arrays(t_symbol *obj_name, t_symbol *array_name, t_float **beg_mem, int *array_size, int max_index)
{
int ok=1;
t_garray *a;
if(!(a = (t_garray *)pd_findbyclass(array_name, garray_class)))
{
error("%s: no such array", array_name->s_name);
ok = 0;
}
else if(!garray_getfloatarray(a, array_size, beg_mem))
{
error("%s: bad template for %s", array_name->s_name, obj_name->s_name);
ok = 0;
}
else if(*array_size < max_index)
{
error("%s: bad array-size: %d", array_name->s_name, *array_size);
ok = 0;
}
return(ok);
}
static void *iem_tab_new(void)
{
t_object *x = (t_object *)pd_new(iem_tab_class);
return (x);
}
void tab_copy_setup(void);
void tab_reverse_setup(void);
void tab_min_max_setup(void);
void tab_min_index_setup(void);
void tab_max_index_setup(void);
void tab_find_peaks_setup(void);
void tab_abs_setup(void);
void tab_sqrt_setup(void);
void tab_sum_setup(void);
void tab_add_setup(void);
void tab_sub_setup(void);
void tab_mul_setup(void);
void tab_div_setup(void);
void tab_complex_mul_setup(void);
void tab_complex_inv_setup(void);
void tab_mul_scalar_setup(void);
void tab_add_scalar_setup(void);
void tab_const_setup(void);
void tab_fft_setup(void);
void tab_ifft_setup(void);
void tab_rfft_setup(void);
void tab_rifft_setup(void);
void tab_cross_corr_setup(void);
void tab_conv_setup(void);
void tab_gt_scalar_setup(void);
void tab_ge_scalar_setup(void);
void tab_lt_scalar_setup(void);
void tab_le_scalar_setup(void);
void tab_ne_scalar_setup(void);
void tab_eq_scalar_setup(void);
void tab_gt_setup(void);
void tab_ge_setup(void);
void tab_lt_setup(void);
void tab_le_setup(void);
void tab_ne_setup(void);
void tab_eq_setup(void);
void tab_counter_setup(void);
//void tab_mls_setup(void);
/* ------------------------ setup routine ------------------------- */
void iem_tab_setup(void)
{
iem_tab_class = class_new(gensym("iem_tab"), iem_tab_new, 0,
sizeof(t_object), CLASS_NOINLET, 0);
tab_copy_setup();
tab_reverse_setup();
tab_min_max_setup();
tab_min_index_setup();
tab_max_index_setup();
tab_find_peaks_setup();
tab_abs_setup();
tab_sqrt_setup();
tab_sum_setup();
tab_add_setup();
tab_sub_setup();
tab_mul_setup();
tab_div_setup();
tab_complex_mul_setup();
tab_complex_inv_setup();
tab_mul_scalar_setup();
tab_add_scalar_setup();
tab_const_setup();
tab_fft_setup();
tab_ifft_setup();
tab_rfft_setup();
tab_rifft_setup();
tab_cross_corr_setup();
tab_conv_setup();
tab_gt_scalar_setup();
tab_ge_scalar_setup();
tab_lt_scalar_setup();
tab_le_scalar_setup();
tab_ne_scalar_setup();
tab_eq_scalar_setup();
tab_gt_setup();
tab_ge_setup();
tab_lt_setup();
tab_le_setup();
tab_ne_setup();
tab_eq_setup();
tab_counter_setup();
// tab_mls_setup();
post("iem_tab (R-1.16) library loaded! (c) Thomas Musil 05.2005");
post(" musil%ciem.at iem KUG Graz Austria", '@');
}
--- NEW FILE: tab_mean.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_mean ------------------------------ */
typedef struct _tab_mean
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
t_symbol *x_sym_scr1;
void *x_bang_out;
void *x_mean_out;
} t_tab_mean;
static t_class *tab_mean_class;
static void tab_mean_src(t_tab_mean *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_mean_bang(t_tab_mean *x)
{
int i, n;
int ok_src;
t_float *vec_src;
t_float mean=0.0f;
ok_src = iem_tab_check_arrays(gensym("tab_mean"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
vec_src = x->x_beg_mem_src1;
if(n)
{
for(i=0; i<n; i++)
{
mean += vec_src[i];
}
outlet_float(x->x_mean_out, mean);
outlet_bang(x->x_bang_out);
}
}
}
static void tab_mean_list(t_tab_mean *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src;
t_float *vec_src;
t_float mean=0.0f;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_mean"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
mean += vec_src[i];
}
outlet_float(x->x_mean_out, mean);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_mean-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_mean-value");
}
}
static void tab_mean_free(t_tab_mean *x)
{
}
static void *tab_mean_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_mean *x = (t_tab_mean *)pd_new(tab_mean_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_mean-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_bang_out = outlet_new(&x->x_obj, &s_bang);
x->x_mean_out = outlet_new(&x->x_obj, &s_float);
return(x);
}
void tab_mean_setup(void)
{
tab_mean_class = class_new(gensym("tab_mean"), (t_newmethod)tab_mean_new, (t_method)tab_mean_free,
sizeof(t_tab_mean), 0, A_GIMME, 0);
class_addbang(tab_mean_class, (t_method)tab_mean_bang);
class_addlist(tab_mean_class, (t_method)tab_mean_list);
class_addmethod(tab_mean_class, (t_method)tab_mean_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_mean_class, (t_method)tab_mean_src, gensym("src1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_mean_class, gensym("iemhelp2/tab_mean-help"));
}
--- NEW FILE: tab_reverse.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_reverse ------------------------------ */
typedef struct _tab_reverse
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_reverse;
static t_class *tab_reverse_class;
static void tab_reverse_src(t_tab_reverse *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_reverse_dst(t_tab_reverse *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_reverse_bang(t_tab_reverse *x)
{
int i, j, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
ok_src = iem_tab_check_arrays(gensym("tab_reverse"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_reverse"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src && ok_dst)
{
if(x->x_size_src1 > x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0, j=n-1; i<n; i++, j--)
vec_dst[i] = vec_src[j];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_reverse_list(t_tab_reverse *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst;
int i, j, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_reverse"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
ok_dst = iem_tab_check_arrays(gensym("tab_reverse"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src && ok_dst)
{
vec_src = x->x_beg_mem_src1 + beg_src;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0, j=n-1; i<n; i++, j--)
vec_dst[i] = vec_src[j];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_reverse-ERROR: list need 3 float arguments:");
post(" source_offset + destination_offset + number_of_samples_to_copy");
}
}
static void tab_reverse_free(t_tab_reverse *x)
{
}
static void *tab_reverse_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_reverse *x = (t_tab_reverse *)pd_new(tab_reverse_class);
t_symbol *src, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src;
}
else
{
post("tab_reverse-ERROR: need 2 symbols arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_reverse_setup(void)
{
tab_reverse_class = class_new(gensym("tab_reverse"), (t_newmethod)tab_reverse_new, (t_method)tab_reverse_free,
sizeof(t_tab_reverse), 0, A_GIMME, 0);
class_addbang(tab_reverse_class, (t_method)tab_reverse_bang);
class_addlist(tab_reverse_class, (t_method)tab_reverse_list);
class_addmethod(tab_reverse_class, (t_method)tab_reverse_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_reverse_class, (t_method)tab_reverse_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_reverse_class, (t_method)tab_reverse_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_reverse_class, gensym("iemhelp2/tab_reverse-help"));
}
--- NEW FILE: tab_min_index.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_min_index ------------------------------ */
typedef struct _tab_min_index
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
t_symbol *x_sym_scr1;
void *x_bang_out;
void *x_min_out;
void *x_min_index_out;
} t_tab_min_index;
static t_class *tab_min_index_class;
static void tab_min_index_src(t_tab_min_index *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_min_index_bang(t_tab_min_index *x)
{
int i, n;
int ok_src, min_index=0;
t_float *vec_src;
t_float min=1.0e37;
ok_src = iem_tab_check_arrays(gensym("tab_min_index"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
vec_src = x->x_beg_mem_src1;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] < min)
{
min = vec_src[i];
min_index = i;
}
}
outlet_float(x->x_min_out, min);
outlet_float(x->x_min_index_out, (float)min_index);
outlet_bang(x->x_bang_out);
}
}
}
static void tab_min_index_list(t_tab_min_index *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src, min_index=0;
t_float *vec_src;
t_float min=1.0e37;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_min_index"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] < min)
{
min = vec_src[i];
min_index = i + beg_src;
}
}
outlet_float(x->x_min_out, min);
outlet_float(x->x_min_index_out, (float)min_index);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_min_index-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_min_index");
}
}
static void tab_min_index_free(t_tab_min_index *x)
{
}
static void *tab_min_index_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_min_index *x = (t_tab_min_index *)pd_new(tab_min_index_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_min_index-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_bang_out = outlet_new(&x->x_obj, &s_bang);
x->x_min_index_out = outlet_new(&x->x_obj, &s_float);
x->x_min_out = outlet_new(&x->x_obj, &s_float);
return(x);
}
void tab_min_index_setup(void)
{
tab_min_index_class = class_new(gensym("tab_min_index"), (t_newmethod)tab_min_index_new, (t_method)tab_min_index_free,
sizeof(t_tab_min_index), 0, A_GIMME, 0);
class_addbang(tab_min_index_class, (t_method)tab_min_index_bang);
class_addlist(tab_min_index_class, (t_method)tab_min_index_list);
class_addmethod(tab_min_index_class, (t_method)tab_min_index_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_min_index_class, (t_method)tab_min_index_src, gensym("src1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_min_index_class, gensym("iemhelp2/tab_min_index-help"));
}
--- NEW FILE: tab_ne_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_ne_scalar ------------------------------ */
typedef struct _tab_ne_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_ne_scalar;
static t_class *tab_ne_scalar_class;
static void tab_ne_scalar_src(t_tab_ne_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_ne_scalar_float(t_tab_ne_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_ne_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_ne_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] != compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_ne_scalar_dst(t_tab_ne_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_ne_scalar_list(t_tab_ne_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_ne_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_ne_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] != compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_ne_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_ne_scalar_free(t_tab_ne_scalar *x)
{
}
static void *tab_ne_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_ne_scalar *x = (t_tab_ne_scalar *)pd_new(tab_ne_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_ne_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_ne_scalar_setup(void)
{
tab_ne_scalar_class = class_new(gensym("tab_ne_scalar"), (t_newmethod)tab_ne_scalar_new, (t_method)tab_ne_scalar_free,
sizeof(t_tab_ne_scalar), 0, A_GIMME, 0);
class_addfloat(tab_ne_scalar_class, (t_method)tab_ne_scalar_float);
class_addlist(tab_ne_scalar_class, (t_method)tab_ne_scalar_list);
class_addmethod(tab_ne_scalar_class, (t_method)tab_ne_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ne_scalar_class, (t_method)tab_ne_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_ne_scalar_class, (t_method)tab_ne_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_ne_scalar_class, gensym("iemhelp2/tab_ne_scalar-help"));
}
--- NEW FILE: tab_gt_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_gt_scalar ------------------------------ */
typedef struct _tab_gt_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_gt_scalar;
static t_class *tab_gt_scalar_class;
static void tab_gt_scalar_src(t_tab_gt_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_gt_scalar_float(t_tab_gt_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_gt_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_gt_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] > compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_gt_scalar_dst(t_tab_gt_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_gt_scalar_list(t_tab_gt_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_gt_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_gt_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] > compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_gt_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_gt_scalar_free(t_tab_gt_scalar *x)
{
}
static void *tab_gt_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_gt_scalar *x = (t_tab_gt_scalar *)pd_new(tab_gt_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_gt_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_gt_scalar_setup(void)
{
tab_gt_scalar_class = class_new(gensym("tab_gt_scalar"), (t_newmethod)tab_gt_scalar_new, (t_method)tab_gt_scalar_free,
sizeof(t_tab_gt_scalar), 0, A_GIMME, 0);
class_addfloat(tab_gt_scalar_class, (t_method)tab_gt_scalar_float);
class_addlist(tab_gt_scalar_class, (t_method)tab_gt_scalar_list);
class_addmethod(tab_gt_scalar_class, (t_method)tab_gt_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_gt_scalar_class, (t_method)tab_gt_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_gt_scalar_class, (t_method)tab_gt_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_gt_scalar_class, gensym("iemhelp2/tab_gt_scalar-help"));
}
--- NEW FILE: tab_rifft.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_rifft ------------------------------ */
typedef struct _tab_rifft
{
t_object x_obj;
int x_size_src_re;
int x_size_src_im;
int x_size_dst;
int x_offset_src_re;
int x_offset_src_im;
int x_offset_dst;
int x_fftsize;
float *x_beg_mem_src_re;
float *x_beg_mem_src_im;
float *x_beg_mem_dst_re;
float *x_beg_mem_dst_im;
TAB_COMPLEX *x_sin_cos;
t_symbol *x_sym_src_re;
t_symbol *x_sym_src_im;
t_symbol *x_sym_dst;
} t_tab_rifft;
static t_class *tab_rifft_class;
static void tab_rifft_init(t_tab_rifft *x)
{
int i, fftsize = x->x_fftsize;
float f, g;
TAB_COMPLEX *sincos = x->x_sin_cos;
g = 2.0f * 3.1415926538f / (float)fftsize;
for(i=0; i<fftsize; i++)
{
f = g * (float)i;
(*sincos).real = cos(f);
(*sincos).imag = sin(f);/*IFFT*/
sincos++;
}
}
static void tab_rifft_ifftsize(t_tab_rifft *x, t_floatarg f)
{
int i=1, fftsize = (int)f;
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
if(i != x->x_fftsize)
{
x->x_sin_cos = (TAB_COMPLEX *)resizebytes(x->x_sin_cos, x->x_fftsize*sizeof(TAB_COMPLEX), i*sizeof(TAB_COMPLEX));
x->x_beg_mem_dst_im = (float *)resizebytes(x->x_beg_mem_dst_im, x->x_fftsize*sizeof(float), i*sizeof(float));
x->x_fftsize = i;
}
tab_rifft_init(x);
}
static void tab_rifft_dst(t_tab_rifft *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_rifft_src_re(t_tab_rifft *x, t_symbol *s)
{
x->x_sym_src_re = s;
}
static void tab_rifft_src_im(t_tab_rifft *x, t_symbol *s)
{
x->x_sym_src_im = s;
}
static void tab_rifft_bang(t_tab_rifft *x)
{
int i, j, k;
int ok_src_re, ok_src_im, ok_dst;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im, g;
ok_src_re = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, fftsize);
ok_dst = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_dst, &x->x_beg_mem_dst_re, &x->x_size_dst, fftsize);
if(ok_src_re && ok_src_im && ok_dst)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re;
vec_src_im=x->x_beg_mem_src_im;
vec_dst_re=x->x_beg_mem_dst_re;
vec_dst_im=x->x_beg_mem_dst_im;
for(j=0; j<fs2; j++)
{
vec_dst_re[j] = vec_src_re[j];
vec_dst_im[j] = vec_src_im[j];
}
vec_dst_re[fs2] = vec_src_re[fs2];
vec_dst_im[fs2] = 0.0f;
for(k=1, j=fftsize-1; k<fs2; k++, j--)
{
vec_dst_re[j] = vec_src_re[k];
vec_dst_im[j] = -vec_src_im[k];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
g = 1.0f / (float)fftsize;
for(i = 0; i < fftsize; i++)
{
vec_dst_re[i] *= g;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
static void tab_rifft_list(t_tab_rifft *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src_re, beg_src_im, beg_dst;
int i, j, k;
int ok_src_re, ok_src_im, ok_dst;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im, g;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src_re = (int)atom_getintarg(0, argc, argv);
beg_src_im = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
if(beg_src_re < 0)
beg_src_re = 0;
if(beg_src_im < 0)
beg_src_im = 0;
if(beg_dst < 0)
beg_dst = 0;
ok_src_re = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, beg_src_re+fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, beg_src_im+fftsize);
ok_dst = iem_tab_check_arrays(gensym("tab_rifft"), x->x_sym_dst, &x->x_beg_mem_dst_re, &x->x_size_dst, beg_dst+fftsize);
if(ok_src_re && ok_src_im && ok_dst)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re + beg_src_re;
vec_src_im=x->x_beg_mem_src_im + beg_src_im;
vec_dst_re=x->x_beg_mem_dst_re + beg_dst;
vec_dst_im=x->x_beg_mem_dst_im;
for(j=0; j<fs2; j++)
{
vec_dst_re[j] = vec_src_re[j];
vec_dst_im[j] = vec_src_im[j];
}
vec_dst_re[fs2] = vec_src_re[fs2];
vec_dst_im[fs2] = 0.0f;
for(k=1, j=fftsize-1; k<fs2; k++, j--)
{
vec_dst_re[j] = vec_src_re[k];
vec_dst_im[j] = -vec_src_im[k];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_src_re[i] *= g;
vec_src_im[i] *= g;
}
*/
g = 1.0f / (float)fftsize;
for(i = 0; i < fftsize; i++)
{
vec_dst_re[i] *= g;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
else
{
post("tab_rifft-ERROR: list need 3 float arguments:");
post(" source_real_offset + source_imag_offset + destination_offset");
}
}
static void tab_rifft_free(t_tab_rifft *x)
{
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(TAB_COMPLEX));
freebytes(x->x_beg_mem_dst_im, x->x_fftsize * sizeof(float));
}
static void *tab_rifft_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_rifft *x = (t_tab_rifft *)pd_new(tab_rifft_class);
t_symbol *src_re, *src_im, *dst;
int fftsize, i=1;
if((argc >= 4) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_FLOAT(argv,3))
{
src_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
fftsize = (int)atom_getintarg(3, argc, argv);
}
else
{
post("tab_rifft-ERROR: need 3 symbols + 1 float arguments:");
post(" source_real_array_name + source_imag_array_name + destination_array_name + IFFT-size");
return(0);
}
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
fftsize = i;
x->x_fftsize = fftsize;
x->x_sym_src_re = src_re;
x->x_sym_src_im = src_im;
x->x_sym_dst = dst;
x->x_sin_cos = (TAB_COMPLEX *)getbytes(x->x_fftsize * sizeof(TAB_COMPLEX));
x->x_beg_mem_dst_im = (float *)getbytes(x->x_fftsize * sizeof(float));
tab_rifft_init(x);
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_rifft_setup(void)
{
tab_rifft_class = class_new(gensym("tab_rifft"), (t_newmethod)tab_rifft_new, (t_method)tab_rifft_free,
sizeof(t_tab_rifft), 0, A_GIMME, 0);
class_addbang(tab_rifft_class, (t_method)tab_rifft_bang);
class_addlist(tab_rifft_class, (t_method)tab_rifft_list);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_ifftsize, gensym("ifftsize"), A_DEFFLOAT, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_src_re, gensym("src_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_src_im, gensym("src_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_src_re, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_src_im, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_addmethod(tab_rifft_class, (t_method)tab_rifft_dst, gensym("dst1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_rifft_class, gensym("iemhelp2/tab_rifft-help"));
}
--- NEW FILE: tab_abs.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_abs ------------------------------ */
typedef struct _tab_abs
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_abs;
static t_class *tab_abs_class;
static void tab_abs_src(t_tab_abs *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_abs_dst(t_tab_abs *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_abs_bang(t_tab_abs *x)
{
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
ok_src = iem_tab_check_arrays(gensym("tab_abs"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_abs"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = fabs(vec_src[i]);
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_abs_list(t_tab_abs *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst;
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_abs"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
ok_dst = iem_tab_check_arrays(gensym("tab_abs"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src && ok_dst)
{
vec_src = x->x_beg_mem_src1 + beg_src;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = fabs(vec_src[i]);
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_abs-ERROR: list need 3 float arguments:");
post(" source_offset + destination_offset + number_of_samples_to_abs");
}
}
static void tab_abs_free(t_tab_abs *x)
{
}
static void *tab_abs_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_abs *x = (t_tab_abs *)pd_new(tab_abs_class);
t_symbol *src, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src;
}
else
{
post("tab_abs-ERROR: need 2 symbols arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_abs_setup(void)
{
tab_abs_class = class_new(gensym("tab_abs"), (t_newmethod)tab_abs_new, (t_method)tab_abs_free,
sizeof(t_tab_abs), 0, A_GIMME, 0);
class_addbang(tab_abs_class, (t_method)tab_abs_bang);
class_addlist(tab_abs_class, (t_method)tab_abs_list);
class_addmethod(tab_abs_class, (t_method)tab_abs_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_abs_class, (t_method)tab_abs_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_abs_class, (t_method)tab_abs_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_abs_class, gensym("iemhelp2/tab_abs-help"));
}
--- NEW FILE: tab_ne.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_ne ------------------------------ */
typedef struct _tab_ne
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_ne;
static t_class *tab_ne_class;
static void tab_ne_src1(t_tab_ne *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_ne_src2(t_tab_ne *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_ne_dst(t_tab_ne *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_ne_bang(t_tab_ne *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] != vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_ne_list(t_tab_ne *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_ne"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] != vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_ne-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_ne_free(t_tab_ne *x)
{
}
static void *tab_ne_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_ne *x = (t_tab_ne *)pd_new(tab_ne_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_ne-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_ne_setup(void)
{
tab_ne_class = class_new(gensym("tab_ne"), (t_newmethod)tab_ne_new, (t_method)tab_ne_free,
sizeof(t_tab_ne), 0, A_GIMME, 0);
class_addbang(tab_ne_class, (t_method)tab_ne_bang);
class_addlist(tab_ne_class, (t_method)tab_ne_list);
class_addmethod(tab_ne_class, (t_method)tab_ne_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ne_class, (t_method)tab_ne_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_ne_class, (t_method)tab_ne_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_ne_class, gensym("iemhelp2/tab_ne-help"));
}
--- NEW FILE: tab_eq_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_eq_scalar ------------------------------ */
typedef struct _tab_eq_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_eq_scalar;
static t_class *tab_eq_scalar_class;
static void tab_eq_scalar_src(t_tab_eq_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_eq_scalar_float(t_tab_eq_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_eq_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_eq_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_eq_scalar_dst(t_tab_eq_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_eq_scalar_list(t_tab_eq_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_eq_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_eq_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_eq_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_eq_scalar_free(t_tab_eq_scalar *x)
{
}
static void *tab_eq_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_eq_scalar *x = (t_tab_eq_scalar *)pd_new(tab_eq_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_eq_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_eq_scalar_setup(void)
{
tab_eq_scalar_class = class_new(gensym("tab_eq_scalar"), (t_newmethod)tab_eq_scalar_new, (t_method)tab_eq_scalar_free,
sizeof(t_tab_eq_scalar), 0, A_GIMME, 0);
class_addfloat(tab_eq_scalar_class, (t_method)tab_eq_scalar_float);
class_addlist(tab_eq_scalar_class, (t_method)tab_eq_scalar_list);
class_addmethod(tab_eq_scalar_class, (t_method)tab_eq_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_eq_scalar_class, (t_method)tab_eq_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_eq_scalar_class, (t_method)tab_eq_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_eq_scalar_class, gensym("iemhelp2/tab_eq_scalar-help"));
}
--- NEW FILE: tab_cross_corr.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_cross_corr ------------------------------ */
typedef struct _tab_cross_corr
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_n;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
float x_factor;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
float x_delay;
int x_counter;
void *x_clock;
} t_tab_cross_corr;
static t_class *tab_cross_corr_class;
static void tab_cross_corr_tick(t_tab_cross_corr *x)
{
x->x_counter++;
if(x->x_counter < x->x_n)
{
t_float *vec_src1, *vec_src2, *vec_dst, sum;
int j, m;
vec_src1 = x->x_beg_mem_src1 + x->x_counter;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst + x->x_counter;
m = x->x_size_src2;
sum = 0.0f;
for(j=0; j<m; j++)
{
sum += vec_src1[j]*vec_src2[j];
}
vec_dst[0] = sum*x->x_factor;
clock_delay(x->x_clock, x->x_delay);
}
else
{
t_garray *a;
clock_unset(x->x_clock);
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
static void tab_cross_corr_time(t_tab_cross_corr *x, t_floatarg time)
{
if(time < 0.0f)
time = 0.0f;
x->x_delay = time;
}
static void tab_cross_corr_factor(t_tab_cross_corr *x, t_floatarg factor)
{
x->x_factor = factor;
}
static void tab_cross_corr_src1(t_tab_cross_corr *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_cross_corr_src2(t_tab_cross_corr *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_cross_corr_dst(t_tab_cross_corr *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_cross_corr_bang(t_tab_cross_corr *x)
{
int i, j, m, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
t_float sum, f;
ok_src1 = iem_tab_check_arrays(gensym("tab_cross_corr"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_cross_corr"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_cross_corr"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 > x->x_size_src2)
n = x->x_size_src1 - x->x_size_src2;
else
n = 0;
if(n > x->x_size_dst)
x->x_n = x->x_size_dst;
else
x->x_n = n;
f = x->x_factor;
if(n)
{
if(x->x_delay == 0.0f)
{
t_garray *a;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
m = x->x_size_src2;
for(i=0; i<n; i++)
{
sum = 0.0f;
for(j=0; j<m; j++)
{
sum += vec_src1[i+j]*vec_src2[j];
}
vec_dst[i] = sum*f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
else
{
x->x_counter = 0;
vec_src1 = x->x_beg_mem_src1 + x->x_counter;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst + x->x_counter;
m = x->x_size_src2;
sum = 0.0f;
for(j=0; j<m; j++)
{
sum += vec_src1[j]*vec_src2[j];
}
vec_dst[0] = sum*f;
clock_delay(x->x_clock, x->x_delay);
}
}
}
}
static void tab_cross_corr_free(t_tab_cross_corr *x)
{
clock_free(x->x_clock);
}
static void *tab_cross_corr_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_cross_corr *x = (t_tab_cross_corr *)pd_new(tab_cross_corr_class);
t_symbol *src1, *src2, *dst;
t_float time, factor;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_FLOAT(argv,3) &&
IS_A_FLOAT(argv,4))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
factor = (t_float)atom_getfloatarg(3, argc, argv);
time = (t_float)atom_getfloatarg(4, argc, argv);
}
else
{
post("tab_cross_corr-ERROR: need 3 symbol + 2 float arguments:");
post(" source_reference_array_name + source_measure_array_name + destination_array_name + norm_factor + calculation-time-per-sample_ms");
return(0);
}
if(time < 0.0f)
time = 0.0f;
x->x_delay = time;
x->x_factor = factor;
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
x->x_clock = clock_new(x, (t_method)tab_cross_corr_tick);
return(x);
}
void tab_cross_corr_setup(void)
{
tab_cross_corr_class = class_new(gensym("tab_cross_corr"), (t_newmethod)tab_cross_corr_new, (t_method)tab_cross_corr_free,
sizeof(t_tab_cross_corr), 0, A_GIMME, 0);
class_addbang(tab_cross_corr_class, (t_method)tab_cross_corr_bang);
class_addmethod(tab_cross_corr_class, (t_method)tab_cross_corr_time, gensym("time"), A_DEFFLOAT, 0);
class_addmethod(tab_cross_corr_class, (t_method)tab_cross_corr_factor, gensym("factor"), A_DEFFLOAT, 0);
class_addmethod(tab_cross_corr_class, (t_method)tab_cross_corr_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_cross_corr_class, (t_method)tab_cross_corr_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_cross_corr_class, (t_method)tab_cross_corr_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_cross_corr_class, gensym("iemhelp2/tab_cross_corr-help"));
}
--- NEW FILE: iem_tab.dsp ---
# Microsoft Developer Studio Project File - Name="iem_tab" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** NICHT BEARBEITEN **
# TARGTYPE "Win32 (x86) External Target" 0x0106
CFG=iem_tab - 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_tab.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_tab.mak" CFG="iem_tab - Win32 Debug"
!MESSAGE
!MESSAGE Für die Konfiguration stehen zur Auswahl:
!MESSAGE
!MESSAGE "iem_tab - Win32 Release" (basierend auf "Win32 (x86) External Target")
!MESSAGE "iem_tab - Win32 Debug" (basierend auf "Win32 (x86) External Target")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
!IF "$(CFG)" == "iem_tab - 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_tab.exe"
# PROP Bsc_Name "iem_tab.bsc"
# PROP Target_Dir ""
!ELSEIF "$(CFG)" == "iem_tab - 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_tab.exe"
# PROP Bsc_Name "iem_tab.bsc"
# PROP Target_Dir ""
!ENDIF
# Begin Target
# Name "iem_tab - Win32 Release"
# Name "iem_tab - Win32 Debug"
!IF "$(CFG)" == "iem_tab - Win32 Release"
!ELSEIF "$(CFG)" == "iem_tab - Win32 Debug"
!ENDIF
# Begin Source File
SOURCE=.\makefile_win
# End Source File
# End Target
# End Project
--- NEW FILE: tab_le.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_le ------------------------------ */
typedef struct _tab_le
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_le;
static t_class *tab_le_class;
static void tab_le_src1(t_tab_le *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_le_src2(t_tab_le *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_le_dst(t_tab_le *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_le_bang(t_tab_le *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] <= vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_le_list(t_tab_le *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_le"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] <= vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_le-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_le_free(t_tab_le *x)
{
}
static void *tab_le_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_le *x = (t_tab_le *)pd_new(tab_le_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_le-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_le_setup(void)
{
tab_le_class = class_new(gensym("tab_le"), (t_newmethod)tab_le_new, (t_method)tab_le_free,
sizeof(t_tab_le), 0, A_GIMME, 0);
class_addbang(tab_le_class, (t_method)tab_le_bang);
class_addlist(tab_le_class, (t_method)tab_le_list);
class_addmethod(tab_le_class, (t_method)tab_le_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_le_class, (t_method)tab_le_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_le_class, (t_method)tab_le_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_le_class, gensym("iemhelp2/tab_le-help"));
}
--- NEW FILE: tab_const.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_const ------------------------------ */
typedef struct _tab_const
{
t_object x_obj;
int x_size_dst;
int x_offset_dst;
t_float x_const;
t_float *x_beg_mem_dst;
t_symbol *x_sym_dst;
} t_tab_const;
static t_class *tab_const_class;
static void tab_const_dst(t_tab_const *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_const_bang(t_tab_const *x)
{
int i, n;
int ok_dst;
t_float *vec_dst;
ok_dst = iem_tab_check_arrays(gensym("tab_const"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_dst)
{
n = x->x_size_dst;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = 0.0f;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_const_float(t_tab_const *x, t_floatarg c)
{
int i, n;
int ok_dst;
t_float *vec_dst;
ok_dst = iem_tab_check_arrays(gensym("tab_const"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_dst)
{
n = x->x_size_dst;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = c;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_const_list(t_tab_const *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_dst;
int i, n;
int ok_dst;
t_float *vec_dst, c;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_dst = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
c = (t_float)atom_getfloatarg(2, argc, argv);
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_dst = iem_tab_check_arrays(gensym("tab_const"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_dst)
{
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = c;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_const-ERROR: list need 3 float arguments:");
post(" destination_offset + number_of_samples_to_copy + constant-value");
}
}
static void tab_const_free(t_tab_const *x)
{
}
static void *tab_const_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_const *x = (t_tab_const *)pd_new(tab_const_class);
t_symbol *dst;
t_float time;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
dst = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_const-ERROR: need 1 symbol argument:");
post(" destination_array_name");
return(0);
}
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_const_setup(void)
{
tab_const_class = class_new(gensym("tab_const"), (t_newmethod)tab_const_new, (t_method)tab_const_free,
sizeof(t_tab_const), 0, A_GIMME, 0);
class_addbang(tab_const_class, (t_method)tab_const_bang);
class_addfloat(tab_const_class, (t_method)tab_const_float);
class_addlist(tab_const_class, (t_method)tab_const_list);
class_addmethod(tab_const_class, (t_method)tab_const_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_const_class, gensym("iemhelp2/tab_const-help"));
}
--- NEW FILE: tab_conv.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_conv ------------------------------ */
typedef struct _tab_conv
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_conv;
static t_class *tab_conv_class;
static void tab_conv_src1(t_tab_conv *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_conv_src2(t_tab_conv *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_conv_dst(t_tab_conv *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_conv_bang(t_tab_conv *x)
{
int i, j, k, l, min_s2, plu_s2, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
t_float sum=0.0f;
ok_src1 = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
{
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
min_s2 = -x->x_size_src2 / 2;
plu_s2 = min_s2 + x->x_size_src2;
for(i=0; i<n; i++)
{
sum = 0.0f;
for(j=min_s2, l=0; j<plu_s2; j++, l++)
{
k = j + i;
if((k >= 0) && (k < n))
sum += vec_src1[k] * vec_src2[l];
}
vec_dst[i] = sum;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
}
static void tab_conv_list(t_tab_conv *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int n_src1, n_src2;
int i, j, k, l, min_s2, plu_s2;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
t_float sum=0.0f;
if((argc >= 5) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3) &&
IS_A_FLOAT(argv,4))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n_src1 = (int)atom_getintarg(3, argc, argv);
n_src2 = (int)atom_getintarg(4, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n_src1 < 0)
n_src1 = 0;
if(n_src2 < 0)
n_src2 = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n_src1);
ok_src2 = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n_src2);
ok_dst = iem_tab_check_arrays(gensym("tab_conv"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n_src1);
if(ok_src1 && ok_src2 && ok_dst)
{
if(n_src2 < n_src1)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n_src1)
{
t_garray *a;
min_s2 = -n_src2 / 2;
plu_s2 = min_s2 + n_src2;
for(i=0; i<n_src1; i++)
{
sum = 0.0f;
for(j=min_s2, l=0; j<plu_s2; j++, l++)
{
k = j + i;
if((k >= 0) && (k < n_src1))
sum += vec_src1[k] * vec_src2[l];
}
vec_dst[i] = sum;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
}
else
{
post("tab_conv-ERROR: list need 5 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_convolute + convolution_window_width");
}
}
static void tab_conv_free(t_tab_conv *x)
{
}
static void *tab_conv_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_conv *x = (t_tab_conv *)pd_new(tab_conv_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_conv-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_conv_setup(void)
{
tab_conv_class = class_new(gensym("tab_conv"), (t_newmethod)tab_conv_new, (t_method)tab_conv_free,
sizeof(t_tab_conv), 0, A_GIMME, 0);
class_addbang(tab_conv_class, (t_method)tab_conv_bang);
class_addlist(tab_conv_class, (t_method)tab_conv_list);
class_addmethod(tab_conv_class, (t_method)tab_conv_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_conv_class, (t_method)tab_conv_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_conv_class, (t_method)tab_conv_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_conv_class, gensym("iemhelp2/tab_conv-help"));
}
--- NEW FILE: tab_sum.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_sum ------------------------------ */
typedef struct _tab_sum
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
t_symbol *x_sym_scr1;
void *x_bang_out;
void *x_sum_out;
} t_tab_sum;
static t_class *tab_sum_class;
static void tab_sum_src(t_tab_sum *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_sum_bang(t_tab_sum *x)
{
int i, n;
int ok_src;
t_float *vec_src;
t_float sum=0.0f;
ok_src = iem_tab_check_arrays(gensym("tab_sum"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
vec_src = x->x_beg_mem_src1;
if(n)
{
for(i=0; i<n; i++)
{
sum += vec_src[i];
}
outlet_float(x->x_sum_out, sum);
outlet_bang(x->x_bang_out);
}
}
}
static void tab_sum_list(t_tab_sum *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src;
t_float *vec_src;
t_float sum=0.0f;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_sum"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
sum += vec_src[i];
}
outlet_float(x->x_sum_out, sum);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_sum-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_sum-value");
}
}
static void tab_sum_free(t_tab_sum *x)
{
}
static void *tab_sum_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_sum *x = (t_tab_sum *)pd_new(tab_sum_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_sum-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_bang_out = outlet_new(&x->x_obj, &s_bang);
x->x_sum_out = outlet_new(&x->x_obj, &s_float);
return(x);
}
void tab_sum_setup(void)
{
tab_sum_class = class_new(gensym("tab_sum"), (t_newmethod)tab_sum_new, (t_method)tab_sum_free,
sizeof(t_tab_sum), 0, A_GIMME, 0);
class_addbang(tab_sum_class, (t_method)tab_sum_bang);
class_addlist(tab_sum_class, (t_method)tab_sum_list);
class_addmethod(tab_sum_class, (t_method)tab_sum_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_sum_class, (t_method)tab_sum_src, gensym("src1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_sum_class, gensym("iemhelp2/tab_sum-help"));
}
--- NEW FILE: iemlib.h ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemlib.h written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifndef __IEMLIB_H__
#define __IEMLIB_H__
#define IS_A_POINTER(atom,index) ((atom+index)->a_type == A_POINTER)
#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
#define IS_A_DOLLAR(atom,index) ((atom+index)->a_type == A_DOLLAR)
#define IS_A_DOLLSYM(atom,index) ((atom+index)->a_type == A_DOLLSYM)
#define IS_A_SEMI(atom,index) ((atom+index)->a_type == A_SEMI)
#define IS_A_COMMA(atom,index) ((atom+index)->a_type == A_COMMA)
#ifdef NT
int sys_noloadbang;
//t_symbol *iemgui_key_sym=0;
#include <io.h>
#else
extern int sys_noloadbang;
//extern t_symbol *iemgui_key_sym;
#include <unistd.h>
#endif
#define DEFDELVS 64
#define XTRASAMPS 4
#define SAMPBLK 4
#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
/* machine-dependent definitions. These ifdefs really
should have been by CPU type and not by operating system! */
#ifdef IRIX
/* big-endian. Most significant byte is at low address in memory */
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#define int32 long /* a data type that has 32 bits */
#else
#ifdef MSW
/* little-endian; most significant byte is at highest address */
#define HIOFFSET 1
#define LOWOFFSET 0
#define int32 long
#else
#ifdef __FreeBSD__
#include <machine/endian.h>
#if BYTE_ORDER == LITTLE_ENDIAN
#define HIOFFSET 1
#define LOWOFFSET 0
#else
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#endif /* BYTE_ORDER */
#include <sys/types.h>
#define int32 int32_t
#endif
#ifdef __linux__
#include <endian.h>
#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
#error No byte order defined
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define HIOFFSET 1
#define LOWOFFSET 0
#else
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#endif /* __BYTE_ORDER */
#include <sys/types.h>
#define int32 int32_t
#else
#ifdef __APPLE__
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#define int32 int /* a data type that has 32 bits */
#endif /* __APPLE__ */
#endif /* __linux__ */
#endif /* MSW */
#endif /* SGI */
union tabfudge
{
double tf_d;
int32 tf_i[2];
};
#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 */
#endif
--- NEW FILE: tab_sqrt.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#define TABDUMTAB1SIZE 256
#define TABDUMTAB2SIZE 1024
static t_float tab_rsqrt_exptab[TABDUMTAB1SIZE], tab_rsqrt_mantissatab[TABDUMTAB2SIZE];
static void init_tab_rsqrt(void)
{
int i;
for (i=0; i<TABDUMTAB1SIZE; i++)
{
t_float f;
long l = (i ? (i == TABDUMTAB1SIZE-1 ? TABDUMTAB1SIZE-2 : i) : 1)<< 23;
*(long *)(&f) = l;
tab_rsqrt_exptab[i] = 1.0f/sqrt(f);
}
for (i=0; i<TABDUMTAB2SIZE; i++)
{
t_float f = 1.0f + (1.0f / (t_float)TABDUMTAB2SIZE) * (t_float)i;
tab_rsqrt_mantissatab[i] = 1.0f / sqrt(f);
}
}
/* -------------------------- tab_sqrt ------------------------------ */
typedef struct _tab_sqrt
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_sqrt;
static t_class *tab_sqrt_class;
static void tab_sqrt_src(t_tab_sqrt *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_sqrt_dst(t_tab_sqrt *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_sqrt_bang(t_tab_sqrt *x)
{
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
ok_src = iem_tab_check_arrays(gensym("tab_sqrt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_sqrt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
while(n--)
{
t_float f = *vec_src;
long l = *(long *)(vec_src++);
if(f < 0.0f)
*vec_dst++ = 0.0f;
else
{
t_float g = tab_rsqrt_exptab[(l >> 23) & 0xff] * tab_rsqrt_mantissatab[(l >> 13) & 0x3ff];
*vec_dst++ = f*g*(1.5f - 0.5f * g * g * f);
}
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_sqrt_list(t_tab_sqrt *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst;
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_sqrt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
ok_dst = iem_tab_check_arrays(gensym("tab_sqrt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src && ok_dst)
{
vec_src = x->x_beg_mem_src1 + beg_src;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
while(n--)
{
t_float f = *vec_src;
long l = *(long *)(vec_src++);
if(f < 0.0f)
*vec_dst++ = 0.0f;
else
{
t_float g = tab_rsqrt_exptab[(l >> 23) & 0xff] * tab_rsqrt_mantissatab[(l >> 13) & 0x3ff];
*vec_dst++ = f*g*(1.5f - 0.5f * g * g * f);
}
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_sqrt-ERROR: list need 3 float arguments:");
post(" source_offset + destination_offset + number_of_samples_to_sqrt");
}
}
static void tab_sqrt_free(t_tab_sqrt *x)
{
}
static void *tab_sqrt_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_sqrt *x = (t_tab_sqrt *)pd_new(tab_sqrt_class);
t_symbol *src, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src;
}
else
{
post("tab_sqrt-ERROR: need 2 symbols arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_sqrt_setup(void)
{
init_tab_rsqrt();
tab_sqrt_class = class_new(gensym("tab_sqrt"), (t_newmethod)tab_sqrt_new, (t_method)tab_sqrt_free,
sizeof(t_tab_sqrt), 0, A_GIMME, 0);
class_addbang(tab_sqrt_class, (t_method)tab_sqrt_bang);
class_addlist(tab_sqrt_class, (t_method)tab_sqrt_list);
class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_sqrt_class, (t_method)tab_sqrt_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_sqrt_class, gensym("iemhelp2/tab_sqrt-help"));
}
--- NEW FILE: tab_complex_mul.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_complex_mul ------------------------------ */
typedef struct _tab_complex_mul
{
t_object x_obj;
int x_size_src1_re;
int x_size_src2_re;
int x_size_dst_re;
int x_size_src1_im;
int x_size_src2_im;
int x_size_dst_im;
int x_offset_src1_re;
int x_offset_src2_re;
int x_offset_dst_re;
int x_offset_src1_im;
int x_offset_src2_im;
int x_offset_dst_im;
float *x_beg_mem_src1_re;
float *x_beg_mem_src2_re;
float *x_beg_mem_dst_re;
float *x_beg_mem_src1_im;
float *x_beg_mem_src2_im;
float *x_beg_mem_dst_im;
t_symbol *x_sym_scr1_re;
t_symbol *x_sym_scr2_re;
t_symbol *x_sym_dst_re;
t_symbol *x_sym_scr1_im;
t_symbol *x_sym_scr2_im;
t_symbol *x_sym_dst_im;
} t_tab_complex_mul;
static t_class *tab_complex_mul_class;
static void tab_complex_mul_src1_re(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_scr1_re = s;
}
static void tab_complex_mul_src1_im(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_scr1_im = s;
}
static void tab_complex_mul_src2_re(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_scr2_re = s;
}
static void tab_complex_mul_src2_im(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_scr2_im = s;
}
static void tab_complex_mul_dst_re(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_dst_re = s;
}
static void tab_complex_mul_dst_im(t_tab_complex_mul *x, t_symbol *s)
{
x->x_sym_dst_im = s;
}
static void tab_complex_mul_bang(t_tab_complex_mul *x)
{
int i, n;
int ok_src1_re, ok_src2_re, ok_dst_re;
int ok_src1_im, ok_src2_im, ok_dst_im;
t_float *vec_src1_re, *vec_src2_re, *vec_dst_re;
t_float *vec_src1_im, *vec_src2_im, *vec_dst_im;
ok_src1_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr1_re, &x->x_beg_mem_src1_re, &x->x_size_src1_re, 0);
ok_src2_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr2_re, &x->x_beg_mem_src2_re, &x->x_size_src2_re, 0);
ok_dst_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, 0);
ok_src1_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr1_im, &x->x_beg_mem_src1_im, &x->x_size_src1_im, 0);
ok_src2_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr2_im, &x->x_beg_mem_src2_im, &x->x_size_src2_im, 0);
ok_dst_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, 0);
if(ok_src1_re && ok_src2_re && ok_dst_re && ok_src1_im && ok_src2_im && ok_dst_im)
{
if(x->x_size_src1_re < x->x_size_dst_re)
n = x->x_size_src1_re;
else
n = x->x_size_dst_re;
if(x->x_size_src2_re < n)
n = x->x_size_src2_re;
if(x->x_size_src1_im < n)
n = x->x_size_src1_im;
if(x->x_size_src2_im < n)
n = x->x_size_src2_im;
if(x->x_size_dst_im < n)
n = x->x_size_dst_im;
vec_src1_re = x->x_beg_mem_src1_re;
vec_src2_re = x->x_beg_mem_src2_re;
vec_dst_re = x->x_beg_mem_dst_re;
vec_src1_im = x->x_beg_mem_src1_im;
vec_src2_im = x->x_beg_mem_src2_im;
vec_dst_im = x->x_beg_mem_dst_im;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
t_float re1, re2, im1, im2;
re1 = vec_src1_re[i];
re2 = vec_src2_re[i];
im1 = vec_src1_im[i];
im2 = vec_src2_im[i];
vec_dst_re[i] = re1*re2 - im1*im2;
vec_dst_im[i] = re1*im2 + im1*re2;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
}
static void tab_complex_mul_list(t_tab_complex_mul *x, t_symbol *s, int argc, t_atom *argv)
{
int i, n;
int beg_src1_re, beg_src2_re, beg_dst_re;
int beg_src1_im, beg_src2_im, beg_dst_im;
int ok_src1_re, ok_src2_re, ok_dst_re;
int ok_src1_im, ok_src2_im, ok_dst_im;
t_float *vec_src1_re, *vec_src2_re, *vec_dst_re;
t_float *vec_src1_im, *vec_src2_im, *vec_dst_im;
if((argc >= 7) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3) &&
IS_A_FLOAT(argv,4) &&
IS_A_FLOAT(argv,5) &&
IS_A_FLOAT(argv,6))
{
beg_src1_re = (int)atom_getintarg(0, argc, argv);
beg_src1_im = (int)atom_getintarg(1, argc, argv);
beg_src2_re = (int)atom_getintarg(2, argc, argv);
beg_src2_im = (int)atom_getintarg(3, argc, argv);
beg_dst_re = (int)atom_getintarg(4, argc, argv);
beg_dst_im = (int)atom_getintarg(5, argc, argv);
n = (int)atom_getintarg(6, argc, argv);
if(beg_src1_re < 0)
beg_src1_re = 0;
if(beg_src2_re < 0)
beg_src2_re = 0;
if(beg_dst_re < 0)
beg_dst_re = 0;
if(beg_src1_im < 0)
beg_src1_im = 0;
if(beg_src2_im < 0)
beg_src2_im = 0;
if(beg_dst_im < 0)
beg_dst_im = 0;
if(n < 0)
n = 0;
ok_src1_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr1_re, &x->x_beg_mem_src1_re, &x->x_size_src1_re, beg_src1_re+n);
ok_src2_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr2_re, &x->x_beg_mem_src2_re, &x->x_size_src2_re, beg_src2_re+n);
ok_dst_re = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, beg_dst_re+n);
ok_src1_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr1_im, &x->x_beg_mem_src1_im, &x->x_size_src1_im, beg_src1_im+n);
ok_src2_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_scr2_im, &x->x_beg_mem_src2_im, &x->x_size_src2_im, beg_src2_im+n);
ok_dst_im = iem_tab_check_arrays(gensym("tab_complex_mul"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, beg_dst_im+n);
if(ok_src1_re && ok_src2_re && ok_dst_re && ok_src1_im && ok_src2_im && ok_dst_im)
{
vec_src1_re = x->x_beg_mem_src1_re + beg_src1_re;
vec_src2_re = x->x_beg_mem_src2_re + beg_src2_re;
vec_dst_re = x->x_beg_mem_dst_re + beg_dst_re;
vec_src1_im = x->x_beg_mem_src1_im + beg_src1_im;
vec_src2_im = x->x_beg_mem_src2_im + beg_src2_im;
vec_dst_im = x->x_beg_mem_dst_im + beg_dst_im;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
t_float re1, re2, im1, im2;
re1 = vec_src1_re[i];
re2 = vec_src2_re[i];
im1 = vec_src1_im[i];
im2 = vec_src2_im[i];
vec_dst_re[i] = re1*re2 - im1*im2;
vec_dst_im[i] = re1*im2 + im1*re2;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_complex_mul-ERROR: list need 7 float arguments:");
post(" source1_real_offset + source1_imag_offset + source2_real_offset + source2_imag_offset + destination_real_offset + destination_imag_offset + number_of_samples_to_complex_mul");
}
}
static void tab_complex_mul_free(t_tab_complex_mul *x)
{
}
static void *tab_complex_mul_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_complex_mul *x = (t_tab_complex_mul *)pd_new(tab_complex_mul_class);
t_symbol *src1_re, *src2_re, *dst_re, *src1_im, *src2_im, *dst_im;
t_float time;
if((argc >= 6) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_SYMBOL(argv,3) &&
IS_A_SYMBOL(argv,4) &&
IS_A_SYMBOL(argv,5))
{
src1_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src1_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
src2_re = (t_symbol *)atom_getsymbolarg(2, argc, argv);
src2_im = (t_symbol *)atom_getsymbolarg(3, argc, argv);
dst_re = (t_symbol *)atom_getsymbolarg(4, argc, argv);
dst_im = (t_symbol *)atom_getsymbolarg(5, argc, argv);
}
else if((argc >= 4) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_SYMBOL(argv,4))
{
src1_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src1_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
src2_re = (t_symbol *)atom_getsymbolarg(2, argc, argv);
src2_im = (t_symbol *)atom_getsymbolarg(3, argc, argv);
dst_re = src1_re;
dst_im = src1_im;
}
else
{
post("tab_complex_mul-ERROR: need 6 symbols arguments:");
post(" source1_real_array_name + source1_imag_array_name + source2_real_array_name + source2_imag_array_name + destination_real_array_name + destination_imag_array_name");
return(0);
}
x->x_sym_scr1_re = src1_re;
x->x_sym_scr1_im = src1_im;
x->x_sym_scr2_re = src2_re;
x->x_sym_scr2_im = src2_im;
x->x_sym_dst_re = dst_re;
x->x_sym_dst_im = dst_im;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_complex_mul_setup(void)
{
tab_complex_mul_class = class_new(gensym("tab_complex_mul"), (t_newmethod)tab_complex_mul_new, (t_method)tab_complex_mul_free,
sizeof(t_tab_complex_mul), 0, A_GIMME, 0);
class_addbang(tab_complex_mul_class, (t_method)tab_complex_mul_bang);
class_addlist(tab_complex_mul_class, (t_method)tab_complex_mul_list);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_src1_re, gensym("src1_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_src2_re, gensym("src2_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_dst_re, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_src1_im, gensym("src1_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_src2_im, gensym("src2_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_mul_class, (t_method)tab_complex_mul_dst_im, gensym("dst_im"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_complex_mul_class, gensym("iemhelp2/tab_complex_mul-help"));
}
--- NEW FILE: tab_div.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_div ------------------------------ */
typedef struct _tab_div
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_div;
static t_class *tab_div_class;
static void tab_div_src1(t_tab_div *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_div_src2(t_tab_div *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_div_dst(t_tab_div *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_div_bang(t_tab_div *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src2[i] == 0.0f)
vec_dst[i] = 0.0f;
else
vec_dst[i] = vec_src1[i] / vec_src2[i];
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_div_list(t_tab_div *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_div"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src2[i] == 0.0f)
vec_dst[i] = 0.0f;
else
vec_dst[i] = vec_src1[i] / vec_src2[i];
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_div-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_div");
}
}
static void tab_div_free(t_tab_div *x)
{
}
static void *tab_div_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_div *x = (t_tab_div *)pd_new(tab_div_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_div-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_div_setup(void)
{
tab_div_class = class_new(gensym("tab_div"), (t_newmethod)tab_div_new, (t_method)tab_div_free,
sizeof(t_tab_div), 0, A_GIMME, 0);
class_addbang(tab_div_class, (t_method)tab_div_bang);
class_addlist(tab_div_class, (t_method)tab_div_list);
class_addmethod(tab_div_class, (t_method)tab_div_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_div_class, (t_method)tab_div_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_div_class, (t_method)tab_div_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_div_class, gensym("iemhelp2/tab_div-help"));
}
--- NEW FILE: iem_tab.h ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifndef __IEMTAB_H__
#define __IEMTAB_H__
typedef struct
{
float real;
float imag;
}
TAB_COMPLEX;
int iem_tab_check_arrays(t_symbol *obj_name, t_symbol *array_name, t_float **beg_mem, int *array_size, int max_index);
#endif
--- NEW FILE: tab_lt_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_lt_scalar ------------------------------ */
typedef struct _tab_lt_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_lt_scalar;
static t_class *tab_lt_scalar_class;
static void tab_lt_scalar_src(t_tab_lt_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_lt_scalar_float(t_tab_lt_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_lt_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_lt_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] < compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_lt_scalar_dst(t_tab_lt_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_lt_scalar_list(t_tab_lt_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_lt_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_lt_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] < compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_lt_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_lt_scalar_free(t_tab_lt_scalar *x)
{
}
static void *tab_lt_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_lt_scalar *x = (t_tab_lt_scalar *)pd_new(tab_lt_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_lt_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_lt_scalar_setup(void)
{
tab_lt_scalar_class = class_new(gensym("tab_lt_scalar"), (t_newmethod)tab_lt_scalar_new, (t_method)tab_lt_scalar_free,
sizeof(t_tab_lt_scalar), 0, A_GIMME, 0);
class_addfloat(tab_lt_scalar_class, (t_method)tab_lt_scalar_float);
class_addlist(tab_lt_scalar_class, (t_method)tab_lt_scalar_list);
class_addmethod(tab_lt_scalar_class, (t_method)tab_lt_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_lt_scalar_class, (t_method)tab_lt_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_lt_scalar_class, (t_method)tab_lt_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_lt_scalar_class, gensym("iemhelp2/tab_lt_scalar-help"));
}
--- NEW FILE: tab_rfft.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_rfft ------------------------------ */
typedef struct _tab_rfft
{
t_object x_obj;
int x_size_src1;
int x_size_dst_re;
int x_size_dst_im;
int x_offset_src1;
int x_offset_dst_re;
int x_offset_dst_im;
int x_fftsize;
float *x_beg_mem_src1;
float *x_beg_mem_dst_re;
float *x_beg_mem_dst_im;
TAB_COMPLEX *x_sin_cos;
t_symbol *x_sym_src1;
t_symbol *x_sym_dst_re;
t_symbol *x_sym_dst_im;
} t_tab_rfft;
static t_class *tab_rfft_class;
static void tab_rfft_init(t_tab_rfft *x)
{
int i, fftsize = x->x_fftsize;
float f, g;
TAB_COMPLEX *sincos = x->x_sin_cos;
g = 2.0f * 3.1415926538f / (float)fftsize;
for(i=0; i<fftsize; i++)
{
f = g * (float)i;
(*sincos).real = cos(f);
(*sincos).imag = -sin(f);/*FFT*/
sincos++;
}
}
static void tab_rfft_fftsize(t_tab_rfft *x, t_floatarg f)
{
int i=1, fftsize = (int)f;
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
if(i != x->x_fftsize)
{
x->x_sin_cos = (TAB_COMPLEX *)resizebytes(x->x_sin_cos, x->x_fftsize*sizeof(TAB_COMPLEX), i*sizeof(TAB_COMPLEX));
x->x_fftsize = i;
}
tab_rfft_init(x);
}
static void tab_rfft_src(t_tab_rfft *x, t_symbol *s)
{
x->x_sym_src1 = s;
}
static void tab_rfft_dst_re(t_tab_rfft *x, t_symbol *s)
{
x->x_sym_dst_re = s;
}
static void tab_rfft_dst_im(t_tab_rfft *x, t_symbol *s)
{
x->x_sym_dst_im = s;
}
static void tab_rfft_bang(t_tab_rfft *x)
{
int i, j, k;
int ok_src, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im;
ok_src = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_src1, &x->x_beg_mem_src1, &x->x_size_src1, fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, fftsize);
if(ok_src && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src=x->x_beg_mem_src1;
vec_dst_re=x->x_beg_mem_dst_re;
vec_dst_im=x->x_beg_mem_dst_im;
for(k=0; k<fftsize; k++)
{
vec_dst_re[k] = vec_src[k];
vec_dst_im[k] = 0.0f;
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
vec_dst_im[fs2] = 0.0f;
for(i = fs2+1; i < fftsize; i++)
{
vec_dst_re[i] = 0.0f;
vec_dst_im[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
static void tab_rfft_list(t_tab_rfft *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst_re, beg_dst_im;
int i, j, k;
int ok_src, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst_re = (int)atom_getintarg(1, argc, argv);
beg_dst_im = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst_re < 0)
beg_dst_re = 0;
if(beg_dst_im < 0)
beg_dst_im = 0;
ok_src = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_src1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, beg_dst_re+fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_rfft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, beg_dst_im+fftsize);
if(ok_src && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src=x->x_beg_mem_src1 + beg_src;
vec_dst_re=x->x_beg_mem_dst_re + beg_dst_re;
vec_dst_im=x->x_beg_mem_dst_im + beg_dst_im;
for(k=0; k<fftsize; k++)
{
vec_dst_re[k] = vec_src[k];
vec_dst_im[k] = 0.0f;
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
vec_dst_im[fs2] = 0.0f;
for(i = fs2+1; i < fftsize; i++)
{
vec_dst_re[i] = 0.0f;
vec_dst_im[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
else
{
post("tab_rfft-ERROR: list need 3 float arguments:");
post(" source_offset + destination_real_offset + destination_imag_offset");
}
}
static void tab_rfft_free(t_tab_rfft *x)
{
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(TAB_COMPLEX));
}
static void *tab_rfft_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_rfft *x = (t_tab_rfft *)pd_new(tab_rfft_class);
t_symbol *src, *dst_re, *dst_im;
int fftsize, i=1;
if((argc >= 4) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_FLOAT(argv,3))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst_re = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst_im = (t_symbol *)atom_getsymbolarg(2, argc, argv);
fftsize = (int)atom_getintarg(3, argc, argv);
}
else
{
post("tab_rfft-ERROR: need 3 symbols + 1 float arguments:");
post(" source_array_name + destination_real_array_name + destination_imag_array_name + FFT-size");
return(0);
}
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
fftsize = i;
x->x_fftsize = fftsize;
x->x_sym_src1 = src;
x->x_sym_dst_re = dst_re;
x->x_sym_dst_im = dst_im;
x->x_sin_cos = (TAB_COMPLEX *)getbytes(x->x_fftsize * sizeof(TAB_COMPLEX));
tab_rfft_init(x);
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_rfft_setup(void)
{
tab_rfft_class = class_new(gensym("tab_rfft"), (t_newmethod)tab_rfft_new, (t_method)tab_rfft_free,
sizeof(t_tab_rfft), 0, A_GIMME, 0);
class_addbang(tab_rfft_class, (t_method)tab_rfft_bang);
class_addlist(tab_rfft_class, (t_method)tab_rfft_list);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_fftsize, gensym("fftsize"), A_DEFFLOAT, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_dst_re, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_dst_im, gensym("dst_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_dst_re, gensym("dst1"), A_DEFSYMBOL, 0);
class_addmethod(tab_rfft_class, (t_method)tab_rfft_dst_im, gensym("dst2"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_rfft_class, gensym("iemhelp2/tab_rfft-help"));
}
--- NEW FILE: tab_mul_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_mul_scalar ------------------------------ */
typedef struct _tab_mul_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_mul_scalar;
static t_class *tab_mul_scalar_class;
static void tab_mul_scalar_src(t_tab_mul_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_mul_scalar_float(t_tab_mul_scalar *x, t_floatarg m)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_mul_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_mul_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i]*m;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_mul_scalar_dst(t_tab_mul_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_mul_scalar_list(t_tab_mul_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, m;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
m = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_mul_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_mul_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i]*m;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_mul_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_mul + mul_scalar");
}
}
static void tab_mul_scalar_free(t_tab_mul_scalar *x)
{
}
static void *tab_mul_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_mul_scalar *x = (t_tab_mul_scalar *)pd_new(tab_mul_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_mul_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_mul_scalar_setup(void)
{
tab_mul_scalar_class = class_new(gensym("tab_mul_scalar"), (t_newmethod)tab_mul_scalar_new, (t_method)tab_mul_scalar_free,
sizeof(t_tab_mul_scalar), 0, A_GIMME, 0);
class_addfloat(tab_mul_scalar_class, (t_method)tab_mul_scalar_float);
class_addlist(tab_mul_scalar_class, (t_method)tab_mul_scalar_list);
class_addmethod(tab_mul_scalar_class, (t_method)tab_mul_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_mul_scalar_class, (t_method)tab_mul_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_mul_scalar_class, (t_method)tab_mul_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_mul_scalar_class, gensym("iemhelp2/tab_mul_scalar-help"));
}
--- NEW FILE: tab_ge.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_ge ------------------------------ */
typedef struct _tab_ge
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_ge;
static t_class *tab_ge_class;
static void tab_ge_src1(t_tab_ge *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_ge_src2(t_tab_ge *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_ge_dst(t_tab_ge *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_ge_bang(t_tab_ge *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] >= vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_ge_list(t_tab_ge *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_ge"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] >= vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_ge-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_ge_free(t_tab_ge *x)
{
}
static void *tab_ge_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_ge *x = (t_tab_ge *)pd_new(tab_ge_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_ge-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_ge_setup(void)
{
tab_ge_class = class_new(gensym("tab_ge"), (t_newmethod)tab_ge_new, (t_method)tab_ge_free,
sizeof(t_tab_ge), 0, A_GIMME, 0);
class_addbang(tab_ge_class, (t_method)tab_ge_bang);
class_addlist(tab_ge_class, (t_method)tab_ge_list);
class_addmethod(tab_ge_class, (t_method)tab_ge_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ge_class, (t_method)tab_ge_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_ge_class, (t_method)tab_ge_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_ge_class, gensym("iemhelp2/tab_ge-help"));
}
--- NEW FILE: tab_eq.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_eq ------------------------------ */
typedef struct _tab_eq
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_eq;
static t_class *tab_eq_class;
static void tab_eq_src1(t_tab_eq *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_eq_src2(t_tab_eq *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_eq_dst(t_tab_eq *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_eq_bang(t_tab_eq *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_eq_list(t_tab_eq *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_eq"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_eq-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_eq_free(t_tab_eq *x)
{
}
static void *tab_eq_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_eq *x = (t_tab_eq *)pd_new(tab_eq_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_eq-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_eq_setup(void)
{
tab_eq_class = class_new(gensym("tab_eq"), (t_newmethod)tab_eq_new, (t_method)tab_eq_free,
sizeof(t_tab_eq), 0, A_GIMME, 0);
class_addbang(tab_eq_class, (t_method)tab_eq_bang);
class_addlist(tab_eq_class, (t_method)tab_eq_list);
class_addmethod(tab_eq_class, (t_method)tab_eq_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_eq_class, (t_method)tab_eq_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_eq_class, (t_method)tab_eq_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_eq_class, gensym("iemhelp2/tab_eq-help"));
}
--- NEW FILE: tab_ifft.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_ifft ------------------------------ */
typedef struct _tab_ifft
{
t_object x_obj;
int x_size_src_re;
int x_size_src_im;
int x_size_dst_re;
int x_size_dst_im;
int x_offset_src_re;
int x_offset_src_im;
int x_offset_dst_re;
int x_offset_dst_im;
int x_fftsize;
float *x_beg_mem_src_re;
float *x_beg_mem_src_im;
float *x_beg_mem_dst_re;
float *x_beg_mem_dst_im;
TAB_COMPLEX *x_sin_cos;
t_symbol *x_sym_src_re;
t_symbol *x_sym_src_im;
t_symbol *x_sym_dst_re;
t_symbol *x_sym_dst_im;
} t_tab_ifft;
static t_class *tab_ifft_class;
static void tab_ifft_init(t_tab_ifft *x)
{
int i, fftsize = x->x_fftsize;
float f, g;
TAB_COMPLEX *sincos = x->x_sin_cos;
g = 2.0f * 3.1415926538f / (float)fftsize;
for(i=0; i<fftsize; i++)
{
f = g * (float)i;
(*sincos).real = cos(f);
(*sincos).imag = sin(f);/*IFFT*/
sincos++;
}
}
static void tab_ifft_ifftsize(t_tab_ifft *x, t_floatarg f)
{
int i=1, fftsize = (int)f;
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
if(i != x->x_fftsize)
{
x->x_sin_cos = (TAB_COMPLEX *)resizebytes(x->x_sin_cos, x->x_fftsize*sizeof(TAB_COMPLEX), i*sizeof(TAB_COMPLEX));
x->x_fftsize = i;
}
tab_ifft_init(x);
}
static void tab_ifft_dst_re(t_tab_ifft *x, t_symbol *s)
{
x->x_sym_dst_re = s;
}
static void tab_ifft_dst_im(t_tab_ifft *x, t_symbol *s)
{
x->x_sym_dst_im = s;
}
static void tab_ifft_src_re(t_tab_ifft *x, t_symbol *s)
{
x->x_sym_src_re = s;
}
static void tab_ifft_src_im(t_tab_ifft *x, t_symbol *s)
{
x->x_sym_src_im = s;
}
static void tab_ifft_bang(t_tab_ifft *x)
{
int i, j, k;
int ok_src_re, ok_src_im, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im, g;
ok_src_re = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, fftsize);
if(ok_src_re && ok_src_im && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re;
vec_src_im=x->x_beg_mem_src_im;
vec_dst_re=x->x_beg_mem_dst_re;
vec_dst_im=x->x_beg_mem_dst_im;
for(j=0; j<fftsize; j++)
{
vec_dst_re[j] = vec_src_re[j];
vec_dst_im[j] = vec_src_im[j];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
g = 1.0f / (float)fftsize;
for(i = 0; i < fftsize; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
static void tab_ifft_list(t_tab_ifft *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src_re, beg_src_im, beg_dst_re, beg_dst_im;
int i, j, k;
int ok_src_re, ok_src_im, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im, g;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src_re = (int)atom_getintarg(0, argc, argv);
beg_src_im = (int)atom_getintarg(1, argc, argv);
beg_dst_re = (int)atom_getintarg(2, argc, argv);
beg_dst_im = (int)atom_getintarg(3, argc, argv);
if(beg_src_re < 0)
beg_src_re = 0;
if(beg_src_im < 0)
beg_src_im = 0;
if(beg_dst_re < 0)
beg_dst_re = 0;
if(beg_dst_im < 0)
beg_dst_im = 0;
ok_src_re = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_ifft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, fftsize);
if(ok_src_re && ok_src_im && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re + beg_src_re;
vec_src_im=x->x_beg_mem_src_im + beg_src_im;
vec_dst_re=x->x_beg_mem_dst_re + beg_dst_re;
vec_dst_im=x->x_beg_mem_dst_im + beg_dst_im;
for(j=0; j<fftsize; j++)
{
vec_dst_re[j] = vec_src_re[j];
vec_dst_im[j] = vec_src_im[j];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
g = 1.0f / (float)fftsize;
for(i = 0; i < fftsize; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
else
{
post("tab_ifft-ERROR: list need 4 float arguments:");
post(" source_real_offset + source_imag_offset + destination_real_offset + destination_imag_offset");
}
}
static void tab_ifft_free(t_tab_ifft *x)
{
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(TAB_COMPLEX));
}
static void *tab_ifft_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_ifft *x = (t_tab_ifft *)pd_new(tab_ifft_class);
t_symbol *src_re, *src_im, *dst_re, *dst_im;
int fftsize, i=1;
if((argc >= 5) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_SYMBOL(argv,3) &&
IS_A_FLOAT(argv,4))
{
src_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst_re = (t_symbol *)atom_getsymbolarg(2, argc, argv);
dst_im = (t_symbol *)atom_getsymbolarg(3, argc, argv);
fftsize = (int)atom_getintarg(4, argc, argv);
}
else
{
post("tab_ifft-ERROR: need 4 symbols + 1 float arguments:");
post(" source_real_array_name + source_imag_array_name + destination_real_array_name + destination_imag_array_name + IFFT-size");
return(0);
}
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
fftsize = i;
x->x_fftsize = fftsize;
x->x_sym_src_re = src_re;
x->x_sym_src_im = src_im;
x->x_sym_dst_re = dst_re;
x->x_sym_dst_im = dst_im;
x->x_sin_cos = (TAB_COMPLEX *)getbytes(x->x_fftsize * sizeof(TAB_COMPLEX));
tab_ifft_init(x);
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_ifft_setup(void)
{
tab_ifft_class = class_new(gensym("tab_ifft"), (t_newmethod)tab_ifft_new, (t_method)tab_ifft_free,
sizeof(t_tab_ifft), 0, A_GIMME, 0);
class_addbang(tab_ifft_class, (t_method)tab_ifft_bang);
class_addlist(tab_ifft_class, (t_method)tab_ifft_list);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_ifftsize, gensym("ifftsize"), A_DEFFLOAT, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_src_re, gensym("src_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_src_im, gensym("src_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_src_re, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_src_im, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_dst_re, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_dst_im, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_dst_re, gensym("dst1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ifft_class, (t_method)tab_ifft_dst_im, gensym("dst2"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_ifft_class, gensym("iemhelp2/tab_ifft-help"));
}
--- NEW FILE: tab_find_peaks.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_find_peaks ------------------------------ */
#define IEMLIB_TAB_FIND_PEAKS_SORT_MODE_AMP 0
#define IEMLIB_TAB_FIND_PEAKS_SORT_MODE_FREQ 1
typedef struct _tab_find_peaks
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
int x_work_alloc;
int *x_beg_mem_work1;
float *x_beg_mem_work2;
int x_sort_mode;
float x_hdiff;
int x_min_width;
int x_max_width;
int x_n_peaks;
t_symbol *x_sym_scr1;
t_outlet *x_bang_out;
t_outlet *x_sort_index_out;
t_outlet *x_peak_value_out;
t_outlet *x_peak_index_out;
} t_tab_find_peaks;
static t_class *tab_find_peaks_class;
static void tab_find_peaks_max_peaks(t_tab_find_peaks *x, t_floatarg fmax_peaks)
{
int max_peaks = (int)fmax_peaks;
if(max_peaks <= 0)
max_peaks = 1;
x->x_n_peaks = max_peaks;
}
static void tab_find_peaks_width_range(t_tab_find_peaks *x, t_symbol *s, int argc, t_atom *argv)
{
int minw, maxw, h;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
minw = (int)atom_getintarg(0, argc, argv);
maxw = (int)atom_getintarg(1, argc, argv);
if(minw <= 0)
minw = 1;
if(maxw <= 0)
maxw = 1;
if(minw > maxw)
{
h = minw;
minw = maxw;
maxw = h;
}
x->x_min_width = minw;
x->x_max_width = maxw;
}
}
static void tab_find_peaks_abs_min_height_diff(t_tab_find_peaks *x, t_floatarg height_diff)
{
if(height_diff < 0.0f)
height_diff *= -1.0f;
x->x_hdiff = height_diff;
}
static void tab_find_peaks_amp_sort(t_tab_find_peaks *x)
{
x->x_sort_mode = IEMLIB_TAB_FIND_PEAKS_SORT_MODE_AMP;
}
static void tab_find_peaks_freq_sort(t_tab_find_peaks *x)
{
x->x_sort_mode = IEMLIB_TAB_FIND_PEAKS_SORT_MODE_FREQ;
}
static void tab_find_peaks_src(t_tab_find_peaks *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_find_peaks_bang(t_tab_find_peaks *x)
{
int i, n, w, ww;
int ok_src, peak_index=0, sort_index=0;
t_float *vec_src, *vec_work2;
int *vec_work1;
t_float max=-1.0e37;
int max_peaks=x->x_n_peaks;
int min_width=x->x_min_width;
int max_width=x->x_max_width;
t_float abs_min_height_diff=x->x_hdiff;
ok_src = iem_tab_check_arrays(gensym("tab_find_peaks"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
if(n)
{
if(!x->x_work_alloc)
{
x->x_beg_mem_work1 = (int *)getbytes(n * sizeof(int));
x->x_beg_mem_work2 = (float *)getbytes(n * sizeof(float));
x->x_work_alloc = n;
}
else if(n != x->x_work_alloc)
{
x->x_beg_mem_work1 = (int *)resizebytes(x->x_beg_mem_work1, x->x_work_alloc*sizeof(int), n*sizeof(int));
x->x_beg_mem_work2 = (float *)resizebytes(x->x_beg_mem_work2, x->x_work_alloc*sizeof(float), n*sizeof(float));
x->x_work_alloc = n;
}
vec_src = x->x_beg_mem_src1;
vec_work1 = x->x_beg_mem_work1;
vec_work2 = x->x_beg_mem_work2;
if(x->x_sort_mode == IEMLIB_TAB_FIND_PEAKS_SORT_MODE_FREQ) // FREQ_SORT BEGIN
{
int sort_index=1,old=0,j;
for(i=0; i<n; i++)
{
vec_work1[i] = 0;
}
for(w=min_width; w<=max_width; w++) // w variiert zw. min u. max
{
for(ww=0; ww<w; ww++)
{
int beg=w-ww;
int end=n-1-ww;
int low_bord=beg-1;
int high_bord=n-end-1;
t_float diff_low,diff_high;
for(i=beg; i<end; i++)
{
diff_low = vec_src[i-low_bord] - abs_min_height_diff;
diff_high = vec_src[i+high_bord] - abs_min_height_diff;
if((vec_src[i-low_bord-1] < diff_low) && !vec_work1[i-low_bord] &&
(vec_src[i+high_bord+1] < diff_high) && !vec_work1[i+high_bord])
{
for(j=i-low_bord; j<=i+high_bord; j++)
vec_work1[j] = 1;
//post("f[%d]=%g, f[%d]=%g",i-low_bord,vec_src[i-low_bord],i+high_bord,vec_src[i+high_bord]);
}
}
}
}
old = vec_work1[0];
sort_index=1;
for(i=1; i<n; i++)
{
if(!old && vec_work1[i])
{
vec_work1[i] = 0;
j=i+1;
while(vec_work1[j])
{
vec_work1[j] = 0;
j++;
}
j--;
peak_index = (i + j) / 2;
if(sort_index <= max_peaks)
{
outlet_float(x->x_peak_value_out, vec_src[i]);
outlet_float(x->x_peak_index_out, (float)peak_index);
outlet_float(x->x_sort_index_out, sort_index);
sort_index++;
}
else
i = n+1;
}
old = vec_work1[i];
}
outlet_bang(x->x_bang_out);
} // FREQ_SORT END
else if(x->x_sort_mode == IEMLIB_TAB_FIND_PEAKS_SORT_MODE_AMP) // AMP_SORT BEGIN
{
int sort_index=1,old=0,j;
for(i=0; i<n; i++)
{
vec_work1[i] = 0;
vec_work2[i] = 0.0f;
}
for(w=min_width; w<=max_width; w++) // w variiert zw. min u. max
{
for(ww=0; ww<w; ww++)
{
int beg=w-ww;
int end=n-1-ww;
int low_bord=beg-1;
int high_bord=n-end-1;
t_float diff_low,diff_high;
for(i=beg; i<end; i++)
{
diff_low = vec_src[i-low_bord] - abs_min_height_diff;
diff_high = vec_src[i+high_bord] - abs_min_height_diff;
if((vec_src[i-low_bord-1] < diff_low) && !vec_work1[i-low_bord] &&
(vec_src[i+high_bord+1] < diff_high) && !vec_work1[i+high_bord])
{
for(j=i-low_bord; j<=i+high_bord; j++)
{
vec_work1[j] = 1;
vec_work2[j] = vec_src[j];
}
//post("a[%d]=%g, a[%d]=%g",i-low_bord,vec_src[i-low_bord],i+high_bord,vec_src[i+high_bord]);
}
}
}
}
old = vec_work1[0];
for(sort_index=1; sort_index<=max_peaks; sort_index++)
{
max = -1.0e37;
peak_index = -1;
for(i=0; i<n; i++)
{
if(vec_work1[i])
{
if(vec_work2[i] > max)
{
max = vec_work2[i];
peak_index = i;
}
}
}
if(peak_index >= 0)
{
outlet_float(x->x_peak_value_out, max);
outlet_float(x->x_peak_index_out, (float)peak_index);
outlet_float(x->x_sort_index_out, sort_index);
vec_work1[peak_index] = 0;
vec_work2[peak_index] = 0.0f;
j=peak_index+1;
while(vec_work1[j])
{
vec_work1[j] = 0;
j++;
}
j=peak_index-1;
while(vec_work1[j])
{
vec_work1[j] = 0;
j--;
}
}
else
sort_index = max_peaks+1;
}
outlet_bang(x->x_bang_out);
}
} // AMP_SORT END
}
/*
[n] zu [n-1] u. [n+1] (ww=0)(w=1)(beg=1)(end=n-1)
[n-1] u. [n] zu [n-2] u. [n+1] (ww=0)(w=2)(beg=2)(end=n-1)
[n] u. [n+1] zu [n-1] u. [n+2] (ww=1)(w=2)(beg=1)(end=n-2)
[n-2] u. [n-1] u. [n] zu [n-3] u. [n+1] (ww=0)(w=3)(beg=3)(end=n-1)
[n-1] u. [n] u. [n+1] zu [n-2] u. [n+2] (ww=1)(w=3)(beg=2)(end=n-2)
[n] u. [n+1] u. [n+2] zu [n-1] u. [n+3] (ww=2)(w=3)(beg=1)(end=n-3)
*/
}
/*static void tab_find_peaks_list(t_tab_find_peaks *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src, max_index=0;
t_float *vec_src;
t_float max=-1.0e37;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_find_peaks"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] > max)
{
max = vec_src[i];
max_index = i + beg_src;
}
}
outlet_float(x->x_peak_value_out, max);
outlet_float(x->x_peak_index_out, (float)max_index);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_find_peaks-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_max_index");
}
}*/
static void tab_find_peaks_free(t_tab_find_peaks *x)
{
if(x->x_work_alloc)
{
freebytes(x->x_beg_mem_work1, x->x_work_alloc * sizeof(int));
freebytes(x->x_beg_mem_work2, x->x_work_alloc * sizeof(float));
}
}
static void *tab_find_peaks_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_find_peaks *x = (t_tab_find_peaks *)pd_new(tab_find_peaks_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_find_peaks-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_work_alloc = 0;
x->x_beg_mem_work1 = (int *)0;
x->x_beg_mem_work2 = (float *)0;
x->x_sym_scr1 = src;
x->x_bang_out = (t_outlet *)outlet_new(&x->x_obj, &s_bang); // ready
x->x_sort_index_out = (t_outlet *)outlet_new(&x->x_obj, &s_float); // sort index
x->x_peak_index_out = (t_outlet *)outlet_new(&x->x_obj, &s_float); // freq
x->x_peak_value_out = (t_outlet *)outlet_new(&x->x_obj, &s_float); // value
return(x);
}
void tab_find_peaks_setup(void)
{
tab_find_peaks_class = class_new(gensym("tab_find_peaks"), (t_newmethod)tab_find_peaks_new, (t_method)tab_find_peaks_free,
sizeof(t_tab_find_peaks), 0, A_GIMME, 0);
class_addbang(tab_find_peaks_class, (t_method)tab_find_peaks_bang);
/*class_addlist(tab_find_peaks_class, (t_method)tab_find_peaks_list);*/
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_max_peaks, gensym("max_peaks"), A_DEFFLOAT, 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_width_range, gensym("width_range"), A_GIMME, 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_abs_min_height_diff, gensym("abs_min_height_diff"), A_DEFFLOAT, 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_amp_sort, gensym("amp_sort"), 0);
class_addmethod(tab_find_peaks_class, (t_method)tab_find_peaks_freq_sort, gensym("freq_sort"), 0);
class_sethelpsymbol(tab_find_peaks_class, gensym("iemhelp2/tab_find_peaks-help"));
}
--- NEW FILE: tab_add_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_add_scalar ------------------------------ */
typedef struct _tab_add_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_add_scalar;
static t_class *tab_add_scalar_class;
static void tab_add_scalar_src(t_tab_add_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_add_scalar_float(t_tab_add_scalar *x, t_floatarg add)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_add_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_add_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] + add;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_add_scalar_dst(t_tab_add_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_add_scalar_list(t_tab_add_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, add;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
add = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_add_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_add_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] + add;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_add_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_add + add_scalar");
}
}
static void tab_add_scalar_free(t_tab_add_scalar *x)
{
}
static void *tab_add_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_add_scalar *x = (t_tab_add_scalar *)pd_new(tab_add_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_add_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_add_scalar_setup(void)
{
tab_add_scalar_class = class_new(gensym("tab_add_scalar"), (t_newmethod)tab_add_scalar_new, (t_method)tab_add_scalar_free,
sizeof(t_tab_add_scalar), 0, A_GIMME, 0);
class_addfloat(tab_add_scalar_class, (t_method)tab_add_scalar_float);
class_addlist(tab_add_scalar_class, (t_method)tab_add_scalar_list);
class_addmethod(tab_add_scalar_class, (t_method)tab_add_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_add_scalar_class, (t_method)tab_add_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_add_scalar_class, (t_method)tab_add_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_add_scalar_class, gensym("iemhelp2/tab_add_scalar-help"));
}
--- NEW FILE: tab_fft.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_fft ------------------------------ */
typedef struct _tab_fft
{
t_object x_obj;
int x_size_src_re;
int x_size_src_im;
int x_size_dst_re;
int x_size_dst_im;
int x_offset_src_re;
int x_offset_src_im;
int x_offset_dst_re;
int x_offset_dst_im;
int x_fftsize;
float *x_beg_mem_src_re;
float *x_beg_mem_src_im;
float *x_beg_mem_dst_re;
float *x_beg_mem_dst_im;
TAB_COMPLEX *x_sin_cos;
t_symbol *x_sym_src_re;
t_symbol *x_sym_src_im;
t_symbol *x_sym_dst_re;
t_symbol *x_sym_dst_im;
} t_tab_fft;
static t_class *tab_fft_class;
static void tab_fft_init(t_tab_fft *x)
{
int i, fftsize = x->x_fftsize;
float f, g;
TAB_COMPLEX *sincos = x->x_sin_cos;
g = 2.0f * 3.1415926538f / (float)fftsize;
for(i=0; i<fftsize; i++)
{
f = g * (float)i;
(*sincos).real = cos(f);
(*sincos).imag = -sin(f);/*FFT*/
sincos++;
}
}
static void tab_fft_fftsize(t_tab_fft *x, t_floatarg f)
{
int i=1, fftsize = (int)f;
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
if(i != x->x_fftsize)
{
x->x_sin_cos = (TAB_COMPLEX *)resizebytes(x->x_sin_cos, x->x_fftsize*sizeof(TAB_COMPLEX), i*sizeof(TAB_COMPLEX));
x->x_fftsize = i;
}
tab_fft_init(x);
}
static void tab_fft_src_re(t_tab_fft *x, t_symbol *s)
{
x->x_sym_src_re = s;
}
static void tab_fft_src_im(t_tab_fft *x, t_symbol *s)
{
x->x_sym_src_im = s;
}
static void tab_fft_dst_re(t_tab_fft *x, t_symbol *s)
{
x->x_sym_dst_re = s;
}
static void tab_fft_dst_im(t_tab_fft *x, t_symbol *s)
{
x->x_sym_dst_im = s;
}
static void tab_fft_bang(t_tab_fft *x)
{
int i, j, k;
int ok_src_re, ok_src_im, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im;
ok_src_re = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, fftsize);
if(ok_src_re && ok_src_im && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re;
vec_src_im=x->x_beg_mem_src_im;
vec_dst_re=x->x_beg_mem_dst_re;
vec_dst_im=x->x_beg_mem_dst_im;
for(k=0; k<fftsize; k++)
{
vec_dst_re[k] = vec_src_re[k];
vec_dst_im[k] = vec_src_im[k];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
static void tab_fft_list(t_tab_fft *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src_re, beg_src_im, beg_dst_re, beg_dst_im;
int i, j, k;
int ok_src_re, ok_src_im, ok_dst_re, ok_dst_im;
int w_index, w_inc, i_inc, v_index;
int fftsize = x->x_fftsize;
int fs1 = fftsize - 1;
int fs2 = fftsize / 2;
TAB_COMPLEX w;
TAB_COMPLEX *sincos = x->x_sin_cos;
t_float *vec_src_re, *vec_src_im, *vec_dst_re, *vec_dst_im;
t_float old1_re, old1_im, old2_re, old2_im;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src_re = (int)atom_getintarg(0, argc, argv);
beg_src_im = (int)atom_getintarg(1, argc, argv);
beg_dst_re = (int)atom_getintarg(2, argc, argv);
beg_dst_im = (int)atom_getintarg(3, argc, argv);
if(beg_src_re < 0)
beg_src_re = 0;
if(beg_src_im < 0)
beg_src_im = 0;
if(beg_dst_re < 0)
beg_dst_re = 0;
if(beg_dst_im < 0)
beg_dst_im = 0;
ok_src_re = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_src_re, &x->x_beg_mem_src_re, &x->x_size_src_re, beg_src_re+fftsize);
ok_src_im = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_src_im, &x->x_beg_mem_src_im, &x->x_size_src_im, beg_src_im+fftsize);
ok_dst_re = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, beg_dst_re+fftsize);
ok_dst_im = iem_tab_check_arrays(gensym("tab_fft"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, beg_dst_im+fftsize);
if(ok_src_re && ok_src_im && ok_dst_re && ok_dst_im)
{
t_garray *a;
vec_src_re=x->x_beg_mem_src_re + beg_src_re;
vec_src_im=x->x_beg_mem_src_im + beg_src_im;
vec_dst_re=x->x_beg_mem_dst_re + beg_dst_re;
vec_dst_im=x->x_beg_mem_dst_im + beg_dst_im;
for(k=0; k<fftsize; k++)
{
vec_dst_re[k] = vec_src_re[k];
vec_dst_im[k] = vec_src_im[k];
}
i_inc = fs2;
w_inc = 1;
for(i=1; i<fftsize; i<<=1)
{
v_index = 0;
for(j=0; j<i; j++)
{
w_index = 0;
for(k=0; k<i_inc; k++)
{
old1_re = vec_dst_re[v_index];
old1_im = vec_dst_im[v_index];
old2_re = vec_dst_re[v_index+i_inc];
old2_im = vec_dst_im[v_index+i_inc];
w = sincos[w_index];
vec_dst_re[v_index+i_inc] = (old1_re - old2_re)*w.real - (old1_im - old2_im)*w.imag;
vec_dst_im[v_index+i_inc] = (old1_im - old2_im)*w.real + (old1_re - old2_re)*w.imag;
vec_dst_re[v_index] = old1_re + old2_re;
vec_dst_im[v_index] = old1_im + old2_im;
w_index += w_inc;
v_index++;
}
v_index += i_inc;
}
w_inc <<= 1;
i_inc >>= 1;
}
j = 0;
for(i=1;i<fs1;i++)
{
k = fs2;
while(k <= j)
{
j = j - k;
k >>= 1;
}
j = j + k;
if(i < j)
{
old1_re = vec_dst_re[j];
old1_im = vec_dst_im[j];
vec_dst_re[j] = vec_dst_re[i];
vec_dst_im[j] = vec_dst_im[i];
vec_dst_re[i] = old1_re;
vec_dst_im[i] = old1_im;
}
}
// g = 2.0f / (float)fftsize;
/*
ein fehler tritt auf beim 0.sample, hier sollte nur mal 1.0 multipliziert werden
wenn gelten soll : Energie im zeitfenster == Energie im Frequenz-dichte-fenster
g = 1.0f;
for(i = 0; i < fs2; i++)
{
vec_dst_re[i] *= g;
vec_dst_im[i] *= g;
}
*/
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
else
{
post("tab_fft-ERROR: list need 4 float arguments:");
post(" source_real_offset + source_imag_offset + destination_real_offset + destination_imag_offset");
}
}
static void tab_fft_free(t_tab_fft *x)
{
freebytes(x->x_sin_cos, x->x_fftsize * sizeof(TAB_COMPLEX));
}
static void *tab_fft_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_fft *x = (t_tab_fft *)pd_new(tab_fft_class);
t_symbol *src_re, *src_im, *dst_re, *dst_im;
int fftsize, i=1;
if((argc >= 5) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_SYMBOL(argv,3) &&
IS_A_FLOAT(argv,4))
{
src_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst_re = (t_symbol *)atom_getsymbolarg(2, argc, argv);
dst_im = (t_symbol *)atom_getsymbolarg(3, argc, argv);
fftsize = (int)atom_getintarg(4, argc, argv);
}
else
{
post("tab_fft-ERROR: need 4 symbols + 1 float arguments:");
post(" source_real_array_name + source_imag_array_name + destination_real_array_name + destination_imag_array_name + FFT-size");
return(0);
}
if(fftsize < 8)
fftsize = 8;
while(i <= fftsize)
i *= 2;
i /= 2;
fftsize = i;
x->x_fftsize = fftsize;
x->x_sym_src_re = src_re;
x->x_sym_src_im = src_im;
x->x_sym_dst_re = dst_re;
x->x_sym_dst_im = dst_im;
x->x_sin_cos = (TAB_COMPLEX *)getbytes(x->x_fftsize * sizeof(TAB_COMPLEX));
tab_fft_init(x);
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_fft_setup(void)
{
tab_fft_class = class_new(gensym("tab_fft"), (t_newmethod)tab_fft_new, (t_method)tab_fft_free,
sizeof(t_tab_fft), 0, A_GIMME, 0);
class_addbang(tab_fft_class, (t_method)tab_fft_bang);
class_addlist(tab_fft_class, (t_method)tab_fft_list);
class_addmethod(tab_fft_class, (t_method)tab_fft_fftsize, gensym("fftsize"), A_DEFFLOAT, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_src_re, gensym("src_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_src_im, gensym("src_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_src_re, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_src_im, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_dst_re, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_dst_im, gensym("dst_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_dst_re, gensym("dst1"), A_DEFSYMBOL, 0);
class_addmethod(tab_fft_class, (t_method)tab_fft_dst_im, gensym("dst2"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_fft_class, gensym("iemhelp2/tab_fft-help"));
}
--- NEW FILE: tab_max_index.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_max_index ------------------------------ */
typedef struct _tab_max_index
{
t_object x_obj;
int x_size_src1;
int x_offset_src1;
float *x_beg_mem_src1;
t_symbol *x_sym_scr1;
void *x_bang_out;
void *x_max_out;
void *x_max_index_out;
} t_tab_max_index;
static t_class *tab_max_index_class;
static void tab_max_index_src(t_tab_max_index *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_max_index_bang(t_tab_max_index *x)
{
int i, n;
int ok_src, max_index=0;
t_float *vec_src;
t_float max=-1.0e37;
ok_src = iem_tab_check_arrays(gensym("tab_max_index"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
if(ok_src)
{
n = x->x_size_src1;
vec_src = x->x_beg_mem_src1;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] > max)
{
max = vec_src[i];
max_index = i;
}
}
outlet_float(x->x_max_out, max);
outlet_float(x->x_max_index_out, (float)max_index);
outlet_bang(x->x_bang_out);
}
}
}
static void tab_max_index_list(t_tab_max_index *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src;
int i, n;
int ok_src, max_index=0;
t_float *vec_src;
t_float max=-1.0e37;
if((argc >= 2) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1))
{
beg_src = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_max_index"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
if(ok_src)
{
vec_src = x->x_beg_mem_src1 + beg_src;
if(n)
{
for(i=0; i<n; i++)
{
if(vec_src[i] > max)
{
max = vec_src[i];
max_index = i + beg_src;
}
}
outlet_float(x->x_max_out, max);
outlet_float(x->x_max_index_out, (float)max_index);
outlet_bang(x->x_bang_out);
}
}
}
else
{
post("tab_max_index-ERROR: list need 2 float arguments:");
post(" source_offset + number_of_samples_to_calc_max_index");
}
}
static void tab_max_index_free(t_tab_max_index *x)
{
}
static void *tab_max_index_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_max_index *x = (t_tab_max_index *)pd_new(tab_max_index_class);
t_symbol *src;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_max_index-ERROR: need 1 symbol argument:");
post(" source_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_bang_out = outlet_new(&x->x_obj, &s_bang);
x->x_max_index_out = outlet_new(&x->x_obj, &s_float);
x->x_max_out = outlet_new(&x->x_obj, &s_float);
return(x);
}
void tab_max_index_setup(void)
{
tab_max_index_class = class_new(gensym("tab_max_index"), (t_newmethod)tab_max_index_new, (t_method)tab_max_index_free,
sizeof(t_tab_max_index), 0, A_GIMME, 0);
class_addbang(tab_max_index_class, (t_method)tab_max_index_bang);
class_addlist(tab_max_index_class, (t_method)tab_max_index_list);
class_addmethod(tab_max_index_class, (t_method)tab_max_index_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_max_index_class, (t_method)tab_max_index_src, gensym("src1"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_max_index_class, gensym("iemhelp2/tab_max_index-help"));
}
--- NEW FILE: tab_ge_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_ge_scalar ------------------------------ */
typedef struct _tab_ge_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_ge_scalar;
static t_class *tab_ge_scalar_class;
static void tab_ge_scalar_src(t_tab_ge_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_ge_scalar_float(t_tab_ge_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_ge_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_ge_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] >= compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_ge_scalar_dst(t_tab_ge_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_ge_scalar_list(t_tab_ge_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_ge_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_ge_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] >= compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_ge_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_ge_scalar_free(t_tab_ge_scalar *x)
{
}
static void *tab_ge_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_ge_scalar *x = (t_tab_ge_scalar *)pd_new(tab_ge_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_ge_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_ge_scalar_setup(void)
{
tab_ge_scalar_class = class_new(gensym("tab_ge_scalar"), (t_newmethod)tab_ge_scalar_new, (t_method)tab_ge_scalar_free,
sizeof(t_tab_ge_scalar), 0, A_GIMME, 0);
class_addfloat(tab_ge_scalar_class, (t_method)tab_ge_scalar_float);
class_addlist(tab_ge_scalar_class, (t_method)tab_ge_scalar_list);
class_addmethod(tab_ge_scalar_class, (t_method)tab_ge_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_ge_scalar_class, (t_method)tab_ge_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_ge_scalar_class, (t_method)tab_ge_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_ge_scalar_class, gensym("iemhelp2/tab_ge_scalar-help"));
}
--- NEW FILE: tab_mls.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_mls ------------------------------ */
typedef struct _tab_mls
{
t_object x_obj;
int x_size_dst;
int x_offset_dst;
t_float *x_beg_mem_dst;
t_symbol *x_sym_dst;
} t_tab_mls;
static t_class *tab_mls_class;
static int tab_mls_exp2(int mls_order)
{
int i, j=1;
for(i=0; i<mls_order; i++)
j *= 2;
return(j);
}
static void tab_mls_calc(t_float *vec, int mls_order)
{
int i, j;
int work1=1, work2, exor;
int mask, source, mls_size;
switch(mls_order)
{
case 3:
mask = 2+1;
source = 4;
break;
case 4:
mask = 2+1;
source = 8;
break;
case 5:
mask = 4+1;
source = 16;
break;
case 6:
mask = 2+1;
source = 32;
break;
case 7:
mask = 8+1;
source = 64;
break;
case 8:
mask = 32+8+2+1;
source = 128;
break;
case 9:
mask = 16+1;
source = 256;
break;
case 10:
mask = 8+1;
source = 512;
break;
case 11:
mask = 4+1;
source = 1024;
break;
case 12:
mask = 64+16+2+1;
source = 2048;
break;
case 13:
mask = 256+128+8+1;
source = 4096;
break;
case 14:
mask = 1024+64+2+1;
source = 8192;
break;
case 15:
mask = 2+1;
source = 16384;
break;
case 16:
mask = 32+8+4+1;
source = 32768;
break;
case 17:
mask = 8+1;
source = 65536;
break;
case 18:
mask = 128+1;
source = 131072;
break;
case 19:
mask = 32+4+2+1;
source = 262144;
break;
case 20:
mask = 8+1;
source = 524288;
break;
}
mls_size = 2*source - 1;
for(i=0; i<mls_size; i++)
{
i = work1 & mask;
work2 = work1 >> 1;
exor = 0;
for(j=0; j<lms_order; j++)
{
exor += & 1;
work1 >>= 1;
}
if(exor & 1)
{
vec[i] = 1.0f;
work1 = work2 | source;
}
else
{
vec[i] = -1.0f;
work1 = work2;
}
}
return;
}
static void tab_mls_dst(t_tab_mls *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_mls_float(t_tab_mls *x, t_floatarg fmls_order)
{
int mls_order=(int)fmls_order;
int ok_dst, mls_size;
mls_size = tab_mls_exp2(mls_order) - 1;
ok_dst = iem_tab_check_arrays(gensym("tab_mls"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, mls_size);
if(ok_dst)
{
if((mls_order >= 3) && (mls_order <= 20))
{
t_garray *a;
tab_mls_calc(x->x_beg_mem_dst, mls_order);
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_mls_list(t_tab_mls *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_dst;
int i, n;
int ok_dst;
t_float *vec_dst, c;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_dst = (int)atom_getintarg(0, argc, argv);
n = (int)atom_getintarg(1, argc, argv);
c = (t_float)atom_getfloatarg(2, argc, argv);
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_dst = iem_tab_check_arrays(gensym("tab_mls"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_dst)
{
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = c;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_mls-ERROR: list need 3 float arguments:");
post(" destination_offset + number_of_samples_to_copy + constant-value");
}
}
static void tab_mls_free(t_tab_mls *x)
{
}
static void *tab_mls_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_mls *x = (t_tab_mls *)pd_new(tab_mls_class);
t_symbol *dst;
t_float time;
if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
dst = (t_symbol *)atom_getsymbolarg(0, argc, argv);
}
else
{
post("tab_mls-ERROR: need 1 symbol argument:");
post(" destination_array_name");
return(0);
}
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_mls_setup(void)
{
tab_mls_class = class_new(gensym("tab_mls"), (t_newmethod)tab_mls_new, (t_method)tab_mls_free,
sizeof(t_tab_mls), 0, A_GIMME, 0);
class_addfloat(tab_mls_class, (t_method)tab_mls_float);
class_addlist(tab_mls_class, (t_method)tab_mls_list);
class_addmethod(tab_mls_class, (t_method)tab_mls_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_mls_class, gensym("iemhelp2/tab_mls-help"));
}
--- NEW FILE: tab_counter.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_counter ------------------------------ */
typedef struct _tab_counter
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_counter;
static t_class *tab_counter_class;
static void tab_counter_src(t_tab_counter *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_counter_bang(t_tab_counter *x)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_counter"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_counter"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == 0.0f)
vec_dst[i] = 0.0f;
else
vec_dst[i] += 1.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_counter_dst(t_tab_counter *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_counter_list(t_tab_counter *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_counter"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_counter"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] == 0.0f)
vec_dst[i] = 0.0f;
else
vec_dst[i] += 1.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_counter-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_add + add_scalar");
}
}
static void tab_counter_reset(t_tab_counter *x)
{
int beg_dst;
int i, n;
int ok_dst;
t_float *vec_dst;
ok_dst = iem_tab_check_arrays(gensym("tab_counter"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_dst)
{
n = x->x_size_dst;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = 0.0f;
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_counter_free(t_tab_counter *x)
{
}
static void *tab_counter_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_counter *x = (t_tab_counter *)pd_new(tab_counter_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_counter-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_counter_setup(void)
{
tab_counter_class = class_new(gensym("tab_counter"), (t_newmethod)tab_counter_new, (t_method)tab_counter_free,
sizeof(t_tab_counter), 0, A_GIMME, 0);
class_addbang(tab_counter_class, (t_method)tab_counter_bang);
class_addlist(tab_counter_class, (t_method)tab_counter_list);
class_addmethod(tab_counter_class, (t_method)tab_counter_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_counter_class, (t_method)tab_counter_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_counter_class, (t_method)tab_counter_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_addmethod(tab_counter_class, (t_method)tab_counter_reset, gensym("reset"), 0);
class_sethelpsymbol(tab_counter_class, gensym("iemhelp2/tab_counter-help"));
}
--- NEW FILE: tab_lt.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_lt ------------------------------ */
typedef struct _tab_lt
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_lt;
static t_class *tab_lt_class;
static void tab_lt_src1(t_tab_lt *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_lt_src2(t_tab_lt *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_lt_dst(t_tab_lt *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_lt_bang(t_tab_lt *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] < vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_lt_list(t_tab_lt *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_lt"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] < vec_src2[i])
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_lt-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_compare");
}
}
static void tab_lt_free(t_tab_lt *x)
{
}
static void *tab_lt_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_lt *x = (t_tab_lt *)pd_new(tab_lt_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_lt-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_lt_setup(void)
{
tab_lt_class = class_new(gensym("tab_lt"), (t_newmethod)tab_lt_new, (t_method)tab_lt_free,
sizeof(t_tab_lt), 0, A_GIMME, 0);
class_addbang(tab_lt_class, (t_method)tab_lt_bang);
class_addlist(tab_lt_class, (t_method)tab_lt_list);
class_addmethod(tab_lt_class, (t_method)tab_lt_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_lt_class, (t_method)tab_lt_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_lt_class, (t_method)tab_lt_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_lt_class, gensym("iemhelp2/tab_lt-help"));
}
--- NEW FILE: tab_sub.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_sub ------------------------------ */
typedef struct _tab_sub
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_sub;
static t_class *tab_sub_class;
static void tab_sub_src1(t_tab_sub *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_sub_src2(t_tab_sub *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_sub_dst(t_tab_sub *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_sub_bang(t_tab_sub *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] - vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_sub_list(t_tab_sub *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_sub"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] - vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_sub-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_sub");
}
}
static void tab_sub_free(t_tab_sub *x)
{
}
static void *tab_sub_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_sub *x = (t_tab_sub *)pd_new(tab_sub_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_sub-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_sub_setup(void)
{
tab_sub_class = class_new(gensym("tab_sub"), (t_newmethod)tab_sub_new, (t_method)tab_sub_free,
sizeof(t_tab_sub), 0, A_GIMME, 0);
class_addbang(tab_sub_class, (t_method)tab_sub_bang);
class_addlist(tab_sub_class, (t_method)tab_sub_list);
class_addmethod(tab_sub_class, (t_method)tab_sub_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_sub_class, (t_method)tab_sub_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_sub_class, (t_method)tab_sub_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_sub_class, gensym("iemhelp2/tab_sub-help"));
}
--- NEW FILE: tab_sin.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#define TABDUMTAB1SIZE 256
#define TABDUMTAB2SIZE 1024
static t_float tab_sin_exptab[TABDUMTAB1SIZE], tab_sin_mantissatab[TABDUMTAB2SIZE];
static void init_tab_sin(void)
{
int i;
for (i=0; i<TABDUMTAB1SIZE; i++)
{
t_float f;
long l = (i ? (i == TABDUMTAB1SIZE-1 ? TABDUMTAB1SIZE-2 : i) : 1)<< 23;
*(long *)(&f) = l;
tab_sin_exptab[i] = 1.0f/sqrt(f);
}
for (i=0; i<TABDUMTAB2SIZE; i++)
{
t_float f = 1.0f + (1.0f / (t_float)TABDUMTAB2SIZE) * (t_float)i;
tab_sin_mantissatab[i] = 1.0f / sqrt(f);
}
}
/* -------------------------- tab_sin ------------------------------ */
typedef struct _tab_sin
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_sin;
static t_class *tab_sin_class;
static void tab_sin_src(t_tab_sin *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_sin_dst(t_tab_sin *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_sin_bang(t_tab_sin *x)
{
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
ok_src = iem_tab_check_arrays(gensym("tab_sin"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_sin"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
while(n--)
{
t_float f = *vec_src;
long l = *(long *)(vec_src++);
if(f < 0.0f)
*vec_dst++ = 0.0f;
else
{
t_float g = tab_sin_exptab[(l >> 23) & 0xff] * tab_sin_mantissatab[(l >> 13) & 0x3ff];
*vec_dst++ = f*g*(1.5f - 0.5f * g * g * f);
}
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_sin_list(t_tab_sin *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src, beg_dst;
int i, n;
int ok_src, ok_dst;
t_float *vec_src, *vec_dst;
if((argc >= 3) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2))
{
beg_src = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
if(beg_src < 0)
beg_src = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src = iem_tab_check_arrays(gensym("tab_sin"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src+n);
ok_dst = iem_tab_check_arrays(gensym("tab_sin"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src && ok_dst)
{
vec_src = x->x_beg_mem_src1 + beg_src;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
while(n--)
{
t_float f = *vec_src;
long l = *(long *)(vec_src++);
if(f < 0.0f)
*vec_dst++ = 0.0f;
else
{
t_float g = tab_sin_exptab[(l >> 23) & 0xff] * tab_sin_mantissatab[(l >> 13) & 0x3ff];
*vec_dst++ = f*g*(1.5f - 0.5f * g * g * f);
}
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_sin-ERROR: list need 3 float arguments:");
post(" source_offset + destination_offset + number_of_samples_to_sqrt");
}
}
static void tab_sin_free(t_tab_sin *x)
{
}
static void *tab_sin_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_sin *x = (t_tab_sin *)pd_new(tab_sin_class);
t_symbol *src, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src;
}
else
{
post("tab_sin-ERROR: need 2 symbols arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_sin_setup(void)
{
init_tab_sin();
tab_sin_class = class_new(gensym("tab_sin"), (t_newmethod)tab_sin_new, (t_method)tab_sin_free,
sizeof(t_tab_sin), 0, A_GIMME, 0);
class_addbang(tab_sin_class, (t_method)tab_sin_bang);
class_addlist(tab_sin_class, (t_method)tab_sin_list);
class_addmethod(tab_sin_class, (t_method)tab_sin_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_sin_class, (t_method)tab_sin_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_sin_class, (t_method)tab_sin_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_sin_class, gensym("iemhelp2/tab_sin-help"));
}
--- NEW FILE: tab_complex_inv.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_complex_inv ------------------------------ */
typedef struct _tab_complex_inv
{
t_object x_obj;
int x_size_src1_re;
int x_size_dst_re;
int x_size_src1_im;
int x_size_dst_im;
int x_offset_src1_re;
int x_offset_dst_re;
int x_offset_src1_im;
int x_offset_dst_im;
float *x_beg_mem_src1_re;
float *x_beg_mem_dst_re;
float *x_beg_mem_src1_im;
float *x_beg_mem_dst_im;
t_symbol *x_sym_scr1_re;
t_symbol *x_sym_dst_re;
t_symbol *x_sym_scr1_im;
t_symbol *x_sym_dst_im;
} t_tab_complex_inv;
static t_class *tab_complex_inv_class;
static void tab_complex_inv_src1_re(t_tab_complex_inv *x, t_symbol *s)
{
x->x_sym_scr1_re = s;
}
static void tab_complex_inv_src1_im(t_tab_complex_inv *x, t_symbol *s)
{
x->x_sym_scr1_im = s;
}
static void tab_complex_inv_dst_re(t_tab_complex_inv *x, t_symbol *s)
{
x->x_sym_dst_re = s;
}
static void tab_complex_inv_dst_im(t_tab_complex_inv *x, t_symbol *s)
{
x->x_sym_dst_im = s;
}
static void tab_complex_inv_bang(t_tab_complex_inv *x)
{
int i, n;
int ok_src1_re, ok_dst_re;
int ok_src1_im, ok_dst_im;
t_float *vec_src1_re, *vec_dst_re;
t_float *vec_src1_im, *vec_dst_im;
ok_src1_re = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_scr1_re, &x->x_beg_mem_src1_re, &x->x_size_src1_re, 0);
ok_dst_re = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, 0);
ok_src1_im = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_scr1_im, &x->x_beg_mem_src1_im, &x->x_size_src1_im, 0);
ok_dst_im = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, 0);
if(ok_src1_re && ok_dst_re && ok_src1_im && ok_dst_im)
{
if(x->x_size_src1_re < x->x_size_dst_re)
n = x->x_size_src1_re;
else
n = x->x_size_dst_re;
if(x->x_size_src1_im < n)
n = x->x_size_src1_im;
if(x->x_size_dst_im < n)
n = x->x_size_dst_im;
vec_src1_re = x->x_beg_mem_src1_re;
vec_dst_re = x->x_beg_mem_dst_re;
vec_src1_im = x->x_beg_mem_src1_im;
vec_dst_im = x->x_beg_mem_dst_im;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
t_float re, im, abs;
re = vec_src1_re[i];
im = vec_src1_im[i];
abs = 1.0f / (re*re + im*im);
vec_dst_re[i] = re*abs;
vec_dst_im[i] = -im*abs;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
}
static void tab_complex_inv_list(t_tab_complex_inv *x, t_symbol *s, int argc, t_atom *argv)
{
int i, n;
int beg_src1_re, beg_dst_re;
int beg_src1_im, beg_dst_im;
int ok_src1_re, ok_dst_re;
int ok_src1_im, ok_dst_im;
t_float *vec_src1_re, *vec_dst_re;
t_float *vec_src1_im, *vec_dst_im;
if((argc >= 5) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3) &&
IS_A_FLOAT(argv,4))
{
beg_src1_re = (int)atom_getintarg(0, argc, argv);
beg_src1_im = (int)atom_getintarg(1, argc, argv);
beg_dst_re = (int)atom_getintarg(2, argc, argv);
beg_dst_im = (int)atom_getintarg(3, argc, argv);
n = (int)atom_getintarg(4, argc, argv);
if(beg_src1_re < 0)
beg_src1_re = 0;
if(beg_dst_re < 0)
beg_dst_re = 0;
if(beg_src1_im < 0)
beg_src1_im = 0;
if(beg_dst_im < 0)
beg_dst_im = 0;
if(n < 0)
n = 0;
ok_src1_re = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_scr1_re, &x->x_beg_mem_src1_re, &x->x_size_src1_re, beg_src1_re+n);
ok_dst_re = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_dst_re, &x->x_beg_mem_dst_re, &x->x_size_dst_re, beg_dst_re+n);
ok_src1_im = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_scr1_im, &x->x_beg_mem_src1_im, &x->x_size_src1_im, beg_src1_im+n);
ok_dst_im = iem_tab_check_arrays(gensym("tab_complex_inv"), x->x_sym_dst_im, &x->x_beg_mem_dst_im, &x->x_size_dst_im, beg_dst_im+n);
if(ok_src1_re && ok_dst_re && ok_src1_im && ok_dst_im)
{
vec_src1_re = x->x_beg_mem_src1_re + beg_src1_re;
vec_dst_re = x->x_beg_mem_dst_re + beg_dst_re;
vec_src1_im = x->x_beg_mem_src1_im + beg_src1_im;
vec_dst_im = x->x_beg_mem_dst_im + beg_dst_im;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
t_float re, im, abs;
re = vec_src1_re[i];
im = vec_src1_im[i];
abs = 1.0f / (re*re + im*im);
vec_dst_re[i] = re*abs;
vec_dst_im[i] = -im*abs;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_re, garray_class);
garray_redraw(a);
a = (t_garray *)pd_findbyclass(x->x_sym_dst_im, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_complex_inv-ERROR: list need 5 float arguments:");
post(" source1_real_offset + source1_imag_offset + destination_real_offset + destination_imag_offset + number_of_samples_to_complex_mul");
}
}
static void tab_complex_inv_free(t_tab_complex_inv *x)
{
}
static void *tab_complex_inv_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_complex_inv *x = (t_tab_complex_inv *)pd_new(tab_complex_inv_class);
t_symbol *src1_re, *src2_re, *dst_re, *src1_im, *src2_im, *dst_im;
t_float time;
if((argc >= 4) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2) &&
IS_A_SYMBOL(argv,3))
{
src1_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src1_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst_re = (t_symbol *)atom_getsymbolarg(2, argc, argv);
dst_im = (t_symbol *)atom_getsymbolarg(3, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1_re = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src1_im = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst_re = src1_re;
dst_im = src1_im;
}
else
{
post("tab_complex_inv-ERROR: need 4 symbols arguments:");
post(" source1_real_array_name + source1_imag_array_name + destination_real_array_name + destination_imag_array_name");
return(0);
}
x->x_sym_scr1_re = src1_re;
x->x_sym_scr1_im = src1_im;
x->x_sym_dst_re = dst_re;
x->x_sym_dst_im = dst_im;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_complex_inv_setup(void)
{
tab_complex_inv_class = class_new(gensym("tab_complex_inv"), (t_newmethod)tab_complex_inv_new, (t_method)tab_complex_inv_free,
sizeof(t_tab_complex_inv), 0, A_GIMME, 0);
class_addbang(tab_complex_inv_class, (t_method)tab_complex_inv_bang);
class_addlist(tab_complex_inv_class, (t_method)tab_complex_inv_list);
class_addmethod(tab_complex_inv_class, (t_method)tab_complex_inv_src1_re, gensym("src1_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_inv_class, (t_method)tab_complex_inv_dst_re, gensym("dst_re"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_inv_class, (t_method)tab_complex_inv_src1_im, gensym("src1_im"), A_DEFSYMBOL, 0);
class_addmethod(tab_complex_inv_class, (t_method)tab_complex_inv_dst_im, gensym("dst_im"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_complex_inv_class, gensym("iemhelp2/tab_complex_inv-help"));
}
--- NEW FILE: tab_add.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_add ------------------------------ */
typedef struct _tab_add
{
t_object x_obj;
int x_size_src1;
int x_size_src2;
int x_size_dst;
int x_offset_src1;
int x_offset_src2;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_src2;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_scr2;
t_symbol *x_sym_dst;
} t_tab_add;
static t_class *tab_add_class;
static void tab_add_src1(t_tab_add *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_add_src2(t_tab_add *x, t_symbol *s)
{
x->x_sym_scr2 = s;
}
static void tab_add_dst(t_tab_add *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_add_bang(t_tab_add *x)
{
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_src2 = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_src2 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
if(x->x_size_src2 < n)
n = x->x_size_src2;
vec_src1 = x->x_beg_mem_src1;
vec_src2 = x->x_beg_mem_src2;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] + vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_add_list(t_tab_add *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_src2, beg_dst;
int i, n;
int ok_src1, ok_src2, ok_dst;
t_float *vec_src1, *vec_src2, *vec_dst;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_src2 = (int)atom_getintarg(1, argc, argv);
beg_dst = (int)atom_getintarg(2, argc, argv);
n = (int)atom_getintarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_src2 < 0)
beg_src2 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_src2 = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_scr2, &x->x_beg_mem_src2, &x->x_size_src2, beg_src2+n);
ok_dst = iem_tab_check_arrays(gensym("tab_add"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_src2 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_src2 = x->x_beg_mem_src2 + beg_src2;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
vec_dst[i] = vec_src1[i] + vec_src2[i];
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_add-ERROR: list need 4 float arguments:");
post(" source1_offset + source2_offset + destination_offset + number_of_samples_to_add");
}
}
static void tab_add_free(t_tab_add *x)
{
}
static void *tab_add_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_add *x = (t_tab_add *)pd_new(tab_add_class);
t_symbol *src1, *src2, *dst;
t_float time;
if((argc >= 3) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1) &&
IS_A_SYMBOL(argv,2))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(2, argc, argv);
}
else if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
src2 = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else
{
post("tab_add-ERROR: need 3 symbols arguments:");
post(" source1_array_name + source2_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_scr2 = src2;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_add_setup(void)
{
tab_add_class = class_new(gensym("tab_add"), (t_newmethod)tab_add_new, (t_method)tab_add_free,
sizeof(t_tab_add), 0, A_GIMME, 0);
class_addbang(tab_add_class, (t_method)tab_add_bang);
class_addlist(tab_add_class, (t_method)tab_add_list);
class_addmethod(tab_add_class, (t_method)tab_add_src1, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_add_class, (t_method)tab_add_src2, gensym("src2"), A_DEFSYMBOL, 0);
class_addmethod(tab_add_class, (t_method)tab_add_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_add_class, gensym("iemhelp2/tab_add-help"));
}
--- NEW FILE: tab_le_scalar.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iem_tab written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#include "m_pd.h"
#include "iemlib.h"
#include "iem_tab.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
/* -------------------------- tab_le_scalar ------------------------------ */
typedef struct _tab_le_scalar
{
t_object x_obj;
int x_size_src1;
int x_size_dst;
int x_offset_src1;
int x_offset_dst;
float *x_beg_mem_src1;
float *x_beg_mem_dst;
t_symbol *x_sym_scr1;
t_symbol *x_sym_dst;
} t_tab_le_scalar;
static t_class *tab_le_scalar_class;
static void tab_le_scalar_src(t_tab_le_scalar *x, t_symbol *s)
{
x->x_sym_scr1 = s;
}
static void tab_le_scalar_float(t_tab_le_scalar *x, t_floatarg compare)
{
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst;
ok_src1 = iem_tab_check_arrays(gensym("tab_le_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, 0);
ok_dst = iem_tab_check_arrays(gensym("tab_le_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, 0);
if(ok_src1 && ok_dst)
{
if(x->x_size_src1 < x->x_size_dst)
n = x->x_size_src1;
else
n = x->x_size_dst;
vec_src1 = x->x_beg_mem_src1;
vec_dst = x->x_beg_mem_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] <= compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
static void tab_le_scalar_dst(t_tab_le_scalar *x, t_symbol *s)
{
x->x_sym_dst = s;
}
static void tab_le_scalar_list(t_tab_le_scalar *x, t_symbol *s, int argc, t_atom *argv)
{
int beg_src1, beg_dst;
int i, n;
int ok_src1, ok_dst;
t_float *vec_src1, *vec_dst, compare;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) &&
IS_A_FLOAT(argv,1) &&
IS_A_FLOAT(argv,2) &&
IS_A_FLOAT(argv,3))
{
beg_src1 = (int)atom_getintarg(0, argc, argv);
beg_dst = (int)atom_getintarg(1, argc, argv);
n = (int)atom_getintarg(2, argc, argv);
compare = (t_float)atom_getfloatarg(3, argc, argv);
if(beg_src1 < 0)
beg_src1 = 0;
if(beg_dst < 0)
beg_dst = 0;
if(n < 0)
n = 0;
ok_src1 = iem_tab_check_arrays(gensym("tab_le_scalar"), x->x_sym_scr1, &x->x_beg_mem_src1, &x->x_size_src1, beg_src1+n);
ok_dst = iem_tab_check_arrays(gensym("tab_le_scalar"), x->x_sym_dst, &x->x_beg_mem_dst, &x->x_size_dst, beg_dst+n);
if(ok_src1 && ok_dst)
{
vec_src1 = x->x_beg_mem_src1 + beg_src1;
vec_dst = x->x_beg_mem_dst + beg_dst;
if(n)
{
t_garray *a;
for(i=0; i<n; i++)
{
if(vec_src1[i] <= compare)
vec_dst[i] = 1.0f;
else
vec_dst[i] = 0.0f;
}
outlet_bang(x->x_obj.ob_outlet);
a = (t_garray *)pd_findbyclass(x->x_sym_dst, garray_class);
garray_redraw(a);
}
}
}
else
{
post("tab_le_scalar-ERROR: list need 4 float arguments:");
post(" source1_offset + destination_offset + number_of_samples_to_compare + compare_scalar");
}
}
static void tab_le_scalar_free(t_tab_le_scalar *x)
{
}
static void *tab_le_scalar_new(t_symbol *s, int argc, t_atom *argv)
{
t_tab_le_scalar *x = (t_tab_le_scalar *)pd_new(tab_le_scalar_class);
t_symbol *src1, *dst;
if((argc >= 2) &&
IS_A_SYMBOL(argv,0) &&
IS_A_SYMBOL(argv,1))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = (t_symbol *)atom_getsymbolarg(1, argc, argv);
}
else if((argc >= 1) &&
IS_A_SYMBOL(argv,0))
{
src1 = (t_symbol *)atom_getsymbolarg(0, argc, argv);
dst = src1;
}
else
{
post("tab_le_scalar-ERROR: need 2 symbol arguments:");
post(" source_array_name + destination_array_name");
return(0);
}
x->x_sym_scr1 = src1;
x->x_sym_dst = dst;
outlet_new(&x->x_obj, &s_bang);
return(x);
}
void tab_le_scalar_setup(void)
{
tab_le_scalar_class = class_new(gensym("tab_le_scalar"), (t_newmethod)tab_le_scalar_new, (t_method)tab_le_scalar_free,
sizeof(t_tab_le_scalar), 0, A_GIMME, 0);
class_addfloat(tab_le_scalar_class, (t_method)tab_le_scalar_float);
class_addlist(tab_le_scalar_class, (t_method)tab_le_scalar_list);
class_addmethod(tab_le_scalar_class, (t_method)tab_le_scalar_src, gensym("src1"), A_DEFSYMBOL, 0);
class_addmethod(tab_le_scalar_class, (t_method)tab_le_scalar_src, gensym("src"), A_DEFSYMBOL, 0);
class_addmethod(tab_le_scalar_class, (t_method)tab_le_scalar_dst, gensym("dst"), A_DEFSYMBOL, 0);
class_sethelpsymbol(tab_le_scalar_class, gensym("iemhelp2/tab_le_scalar-help"));
}