aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-28 16:53:25 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2005-11-28 16:53:25 +0000
commitda1f0065d07250b86b9a761b012987e4825f491f (patch)
tree6e048a70f8d60e2fdf9d374ec536cab9df10e24a /source
This commit was generated by cvs2svn to compensate for changes in r4068,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/smlib/; revision=4069
Diffstat (limited to 'source')
-rw-r--r--source/SMLib.c230
-rwxr-xr-xsource/SMLib.dsp275
-rwxr-xr-xsource/SMLib.dsw29
-rwxr-xr-xsource/SMLib.optbin0 -> 48640 bytes
-rwxr-xr-xsource/SMLib.plg153
-rw-r--r--source/bp.c123
-rw-r--r--source/decimator.c66
-rw-r--r--source/defines.h18
-rw-r--r--source/deltas.c181
-rw-r--r--source/hip.c77
-rw-r--r--source/hist.c155
-rw-r--r--source/itov.c86
-rw-r--r--source/lavg.c55
-rw-r--r--source/lhist.c174
-rw-r--r--source/lhisti.c174
-rw-r--r--source/linspace.c74
-rw-r--r--source/lmax.c57
-rw-r--r--source/lmin.c57
-rw-r--r--source/lrange.c60
-rw-r--r--source/lstd.c60
-rw-r--r--source/prevl.c161
-rw-r--r--source/threshold.c112
-rw-r--r--source/vabs.c48
-rw-r--r--source/vclip.c58
-rw-r--r--source/vcog.c43
-rw-r--r--source/vdbtorms.c56
-rw-r--r--source/vdelta.c75
-rw-r--r--source/vfmod.c57
-rw-r--r--source/vftom.c49
-rw-r--r--source/vlavg.c86
-rw-r--r--source/vlmax.c86
-rw-r--r--source/vlmin.c86
-rw-r--r--source/vlrange.c99
-rw-r--r--source/vmax.c52
-rw-r--r--source/vmin.c52
-rw-r--r--source/vmtof.c51
-rw-r--r--source/vnmax.c55
-rw-r--r--source/vpow.c60
-rw-r--r--source/vrms.c41
-rw-r--r--source/vrmstodb.c54
-rw-r--r--source/vstd.c45
-rw-r--r--source/vsum.c40
-rw-r--r--source/vthreshold.c106
-rw-r--r--source/vvconv.c151
-rw-r--r--source/vvminus.c141
-rw-r--r--source/vvplus.c141
46 files changed, 4109 insertions, 0 deletions
diff --git a/source/SMLib.c b/source/SMLib.c
new file mode 100644
index 0000000..1771395
--- /dev/null
+++ b/source/SMLib.c
@@ -0,0 +1,230 @@
+/* --------------------- SMLib ----------------------------- */
+/*
+
+ Signal processing for Mapping
+ objects:
+
+ float stream
+ - pid controller?
+ - deltas (generate difference vector between current values and values of the past)
+ vector
+ - vquant (quantizer with hysteresis)
+ - vv/
+ - vv>
+ - vv<
+ - s2v (stream to vector, incl ola)
+ - v2s (vector to stream, incl ola)
+
+ vector math
+ - vreverse
+
+ - delread
+ - delwrite
+ - upsample
+ - fir
+ - autorescale
+*/
+
+#include "defines.h"
+
+
+// in alphabetical order
+extern void bp_setup();
+extern void decimator_setup();
+extern void deltas_setup();
+extern void hip_setup();
+extern void hist_setup();
+extern void itov_setup();
+extern void lavg_setup();
+extern void lhist_setup();
+extern void lhisti_setup();
+extern void linspace_setup();
+extern void lmax_setup();
+extern void lmin_setup();
+extern void lrange_setup();
+extern void lstd_setup();
+extern void prevl_setup();
+extern void threshold_setup();
+extern void vabs_setup();
+extern void vclip_setup();
+extern void vcog_setup();
+extern void vdbtorms_setup();
+extern void vdelta_setup();
+extern void vfmod_setup();
+extern void vftom_setup();
+extern void vlavg_setup();
+extern void vlmax_setup();
+extern void vlmin_setup();
+extern void vlrange_setup();
+extern void vmax_setup();
+extern void vmin_setup();
+extern void vmtof_setup();
+extern void vpow_setup();
+extern void vrms_setup();
+extern void vrmstodb_setup();
+extern void vstd_setup();
+extern void vsum_setup();
+extern void vthreshold_setup();
+extern void vvconv_setup();
+extern void vvminus_setup();
+extern void vvplus_setup();
+
+static t_class *SMLib_class;
+
+typedef struct _lstd
+{
+ t_object x_obj;
+} t_SMLib;
+
+static void SMLib_help(t_SMLib *x)
+{
+ /*
+ */
+ post("");
+ post("");
+ post(" ..........................................................");
+ post(" . SMLib .");
+ post(" . Signal processing for Mapping .");
+ post(" . v0.12 24/11/2002 .");
+ post(" ..........................................................");
+ post(" . processing stream of floats (context) (float output) .");
+ post(" . .");
+ post(" . lavg leaky average .");
+ post(" . lmax leaky maximum .");
+ post(" . lmin leaky minimum .");
+ post(" . lrange leaky range .");
+ post(" u lstd leaky standard deviation .");
+ post(" u decimator passes 1 in n input values .");
+ post(" . threshold detection with hysteresis .");
+ post(" . hip first order high-pass filter .");
+ post(" . bp second order (resonant) high-pass filter .");
+ post(" ..........................................................");
+ post(" . analyzing stream of floats (vector output) .");
+ post(" . .");
+ post(" . hist histogram .");
+ post(" . lhist leaky histogram, clips samples .");
+ post(" . lhisti leaky histogram, ignore samples .");
+ post(" . outside bins .");
+ post(" . itov bin index to value (for the histograms .");
+ post(" . prevl previous floats in a list .");
+ post(" . deltas difference between last float and .");
+ post(" . previous floats .");
+// post(" o filterbank lineairly spaced set of bandpass filters .");
+ post(" ..........................................................");
+ post(" . immediate vector analysis (float output) .");
+ post(" . .");
+ post(" . vsum sum of vector elements .");
+ post(" . vcog center of gravity .");
+ post(" . vmax maximum and its location .");
+ post(" . vmin minimum and its location .");
+ post(" . vrms root mean square .");
+ post(" . vstd standard deviation .");
+ post(" ..........................................................");
+ post(" . vector processors (vector output) .");
+ post(" . .");
+ post(" . vv+ vector addition .");
+ post(" . vv- vector substraction .");
+ post(" . vvconv vector convolution .");
+ post(" . vclip clip elements .");
+ post(" . vfmod floating point modulo .");
+ post(" . vpow power .");
+ post(" . vthreshold detections with hysteresises .");
+ post(" . .");
+ post(" . unit conversions on vectors .");
+ post(" . .");
+ post(" . vftom frequency to midi .");
+ post(" . vmtof midi to frequency .");
+ post(" . vdbtorms dB to rms .");
+ post(" . vrmstodb rms to dB .");
+ post(" ..........................................................");
+ post(" . vector synthesis (vector output) .");
+ post(" . .");
+ post(" . linspace linearly spaced vector .");
+// post(" o logspace logarithmically spaced vector .");
+// post(" o rand uniformly distributed random vector .");
+// post(" o randn normally distributed random vector .");
+ post(" ..........................................................");
+ post(" . vector stream processing (vector output) (context) .");
+ post(" . .");
+ post(" . vlavg leaky averages .");
+ post(" . vlmax leaky maxima .");
+ post(" . vlmin leaky minima .");
+ post(" . vlrange leaky ranges .");
+ post(" . vdelta difference between successive vectors .");
+ post(" ..........................................................");
+// post(" . o = future additions .");
+// post(" . e = experimental .");
+ post(" . u = undocumented .");
+ post(" . j#|@ = johannes.taelman@rug.ac.be .");
+ post(" ..........................................................");
+ post("");
+ post("");
+}
+
+static void *SMLib_new()
+{
+ t_SMLib *x=(t_SMLib *)pd_new(SMLib_class);
+ return (void *)x;
+}
+
+__declspec(dllexport) void __cdecl SMLib_setup( void)
+{
+ // dummy object for help-system
+ SMLib_class = class_new(gensym("SMLib"),
+ (t_newmethod)SMLib_new, 0,
+ sizeof(t_SMLib),
+ CLASS_DEFAULT,
+ 0);
+ class_addbang(SMLib_class, (t_method)SMLib_help);
+ class_addmethod(SMLib_class, (t_method)SMLib_help, gensym("help"),0);
+
+ // real objects in alphabetical order
+ bp_setup();
+ decimator_setup();
+ deltas_setup();
+ hip_setup();
+ hist_setup();
+ itov_setup();
+ lavg_setup();
+ lhist_setup();
+ lhisti_setup();
+ linspace_setup();
+ lmax_setup();
+ lmin_setup();
+ lrange_setup();
+ lstd_setup();
+ prevl_setup();
+ threshold_setup();
+ vabs_setup();
+ vclip_setup();
+ vcog_setup();
+ vdbtorms_setup();
+ vdelta_setup();
+ vfmod_setup();
+ vftom_setup();
+ vlavg_setup();
+ vlmax_setup();
+ vlmin_setup();
+ vlrange_setup();
+ vmax_setup();
+ vmin_setup();
+ vmtof_setup();
+ vpow_setup();
+ vrms_setup();
+ vrmstodb_setup();
+ vstd_setup();
+ vsum_setup();
+ vthreshold_setup();
+ vvconv_setup();
+ vvminus_setup();
+ vvplus_setup();
+
+ post("");
+ post(" ..........................................................");
+ post(" . SMLib .");
+ post(" . Signal processing for Mapping .");
+ post(" . v0.12 24/11/2002 .");
+ post(" ..........................................................");
+ post("");
+
+}
diff --git a/source/SMLib.dsp b/source/SMLib.dsp
new file mode 100755
index 0000000..35c2ab8
--- /dev/null
+++ b/source/SMLib.dsp
@@ -0,0 +1,275 @@
+# Microsoft Developer Studio Project File - Name="SMLib" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=SMLib - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "SMLib.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "SMLib.mak" CFG="SMLib - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "SMLib - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "SMLib - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "SMLib - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SMLIB_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SMLIB_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x813 /d "NDEBUG"
+# ADD RSC /l 0x813 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pd.lib /nologo /dll /machine:I386
+
+!ELSEIF "$(CFG)" == "SMLib - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SMLIB_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SMLIB_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x813 /d "_DEBUG"
+# ADD RSC /l 0x813 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pd.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "SMLib - Win32 Release"
+# Name "SMLib - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\bp.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\decimator.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\deltas.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\hip.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\hist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\itov.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lavg.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lhist.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lhisti.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\linspace.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lmax.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lmin.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lrange.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\lstd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\prevl.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\SMLib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\threshold.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vabs.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vclip.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vcog.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vdbtorms.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vdelta.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vfmod.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vftom.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vlavg.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vlmax.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vlmin.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vlrange.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vmax.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vmin.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vmtof.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vnmax.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vpow.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vrms.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vrmstodb.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vstd.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vsum.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vthreshold.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vvconv.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vvminus.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\vvplus.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\defines.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\readme.txt
+# End Source File
+# End Target
+# End Project
diff --git a/source/SMLib.dsw b/source/SMLib.dsw
new file mode 100755
index 0000000..0428bd3
--- /dev/null
+++ b/source/SMLib.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "SMLib"=.\SMLib.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/source/SMLib.opt b/source/SMLib.opt
new file mode 100755
index 0000000..685315a
--- /dev/null
+++ b/source/SMLib.opt
Binary files differ
diff --git a/source/SMLib.plg b/source/SMLib.plg
new file mode 100755
index 0000000..c75a641
--- /dev/null
+++ b/source/SMLib.plg
@@ -0,0 +1,153 @@
+<html>
+<body>
+<pre>
+<h1>Build Log</h1>
+<h3>
+--------------------Configuration: SMLib - Win32 Release--------------------
+</h3>
+<h3>Command Lines</h3>
+Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP6B.tmp" with contents
+[
+/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SMLIB_EXPORTS" /Fp"Release/SMLib.pch" /YX /Fo"Release/" /Fd"Release/" /FD /c
+"D:\devel\SMLib\bp.c"
+"D:\devel\SMLib\decimator.c"
+"D:\devel\SMLib\deltas.c"
+"D:\devel\SMLib\hip.c"
+"D:\devel\SMLib\hist.c"
+"D:\devel\SMLib\itov.c"
+"D:\devel\SMLib\lavg.c"
+"D:\devel\SMLib\lhist.c"
+"D:\devel\SMLib\lhisti.c"
+"D:\devel\SMLib\linspace.c"
+"D:\devel\SMLib\lmax.c"
+"D:\devel\SMLib\lmin.c"
+"D:\devel\SMLib\lrange.c"
+"D:\devel\SMLib\lstd.c"
+"D:\devel\SMLib\prevl.c"
+"D:\devel\SMLib\SMLib.c"
+"D:\devel\SMLib\threshold.c"
+"D:\devel\SMLib\vabs.c"
+"D:\devel\SMLib\vclip.c"
+"D:\devel\SMLib\vcog.c"
+"D:\devel\SMLib\vdbtorms.c"
+"D:\devel\SMLib\vdelta.c"
+"D:\devel\SMLib\vfmod.c"
+"D:\devel\SMLib\vftom.c"
+"D:\devel\SMLib\vlavg.c"
+"D:\devel\SMLib\vlmax.c"
+"D:\devel\SMLib\vlmin.c"
+"D:\devel\SMLib\vlrange.c"
+"D:\devel\SMLib\vmax.c"
+"D:\devel\SMLib\vmin.c"
+"D:\devel\SMLib\vmtof.c"
+"D:\devel\SMLib\vnmax.c"
+"D:\devel\SMLib\vpow.c"
+"D:\devel\SMLib\vrms.c"
+"D:\devel\SMLib\vrmstodb.c"
+"D:\devel\SMLib\vstd.c"
+"D:\devel\SMLib\vsum.c"
+"D:\devel\SMLib\vthreshold.c"
+"D:\devel\SMLib\vvconv.c"
+"D:\devel\SMLib\vvminus.c"
+"D:\devel\SMLib\vvplus.c"
+]
+Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP6B.tmp"
+Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP6C.tmp" with contents
+[
+kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pd.lib /nologo /dll /incremental:no /pdb:"Release/SMLib.pdb" /machine:I386 /out:"Release/SMLib.dll" /implib:"Release/SMLib.lib"
+.\Release\bp.obj
+.\Release\decimator.obj
+.\Release\deltas.obj
+.\Release\hip.obj
+.\Release\hist.obj
+.\Release\itov.obj
+.\Release\lavg.obj
+.\Release\lhist.obj
+.\Release\lhisti.obj
+.\Release\linspace.obj
+.\Release\lmax.obj
+.\Release\lmin.obj
+.\Release\lrange.obj
+.\Release\lstd.obj
+.\Release\prevl.obj
+.\Release\SMLib.obj
+.\Release\threshold.obj
+.\Release\vabs.obj
+.\Release\vclip.obj
+.\Release\vcog.obj
+.\Release\vdbtorms.obj
+.\Release\vdelta.obj
+.\Release\vfmod.obj
+.\Release\vftom.obj
+.\Release\vlavg.obj
+.\Release\vlmax.obj
+.\Release\vlmin.obj
+.\Release\vlrange.obj
+.\Release\vmax.obj
+.\Release\vmin.obj
+.\Release\vmtof.obj
+.\Release\vnmax.obj
+.\Release\vpow.obj
+.\Release\vrms.obj
+.\Release\vrmstodb.obj
+.\Release\vstd.obj
+.\Release\vsum.obj
+.\Release\vthreshold.obj
+.\Release\vvconv.obj
+.\Release\vvminus.obj
+.\Release\vvplus.obj
+]
+Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP6C.tmp"
+<h3>Output Window</h3>
+Compiling...
+bp.c
+decimator.c
+deltas.c
+hip.c
+hist.c
+itov.c
+lavg.c
+lhist.c
+lhisti.c
+linspace.c
+lmax.c
+lmin.c
+lrange.c
+lstd.c
+prevl.c
+SMLib.c
+threshold.c
+vabs.c
+vclip.c
+vcog.c
+vdbtorms.c
+vdelta.c
+vfmod.c
+vftom.c
+vlavg.c
+vlmax.c
+vlmin.c
+vlrange.c
+vmax.c
+vmin.c
+vmtof.c
+vnmax.c
+vpow.c
+vrms.c
+vrmstodb.c
+vstd.c
+vsum.c
+vthreshold.c
+vvconv.c
+vvminus.c
+vvplus.c
+Linking...
+ Creating library Release/SMLib.lib and object Release/SMLib.exp
+
+
+
+<h3>Results</h3>
+SMLib.dll - 0 error(s), 0 warning(s)
+</pre>
+</body>
+</html>
diff --git a/source/bp.c b/source/bp.c
new file mode 100644
index 0000000..d21bc19
--- /dev/null
+++ b/source/bp.c
@@ -0,0 +1,123 @@
+#include "defines.h"
+
+/*--------------- bp ---------------*/
+
+typedef struct bpctl
+{
+ float c_x1;
+ float c_x2;
+ float c_coef1;
+ float c_coef2;
+ float c_gain;
+} t_bpctl;
+
+typedef struct bp
+{
+ t_object x_obj;
+ float x_freq;
+ float x_q;
+ t_bpctl x_cspace;
+ t_bpctl *x_ctl;
+ float x_f;
+} t_bp;
+
+t_class *bp_class;
+
+static void bp_docoef(t_bp *x, t_floatarg f, t_floatarg q);
+
+static void *bp_new(t_floatarg f, t_floatarg q)
+{
+ t_bp *x = (t_bp *)pd_new(bp_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft2"));
+ outlet_new(&x->x_obj, gensym("float"));
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x1 = 0;
+ x->x_cspace.c_x2 = 0;
+ bp_docoef(x, f, q);
+ x->x_f = 0;
+ return (x);
+}
+
+static float bp_qcos(float f)
+{
+ if (f >= -(0.5f*3.14159f) && f <= 0.5f*3.14159f)
+ {
+ float g = f*f;
+ return (((g*g*g * (-1.0f/720.0f) + g*g*(1.0f/24.0f)) - g*0.5f) + 1);
+ }
+ else return (0);
+}
+
+static void bp_docoef(t_bp *x, t_floatarg f, t_floatarg q)
+{
+ float r, oneminusr, omega;
+ if (f < 0.0001f) f = 0.0001f;
+ if (q < 0) q = 0;
+ x->x_freq = f;
+ x->x_q = q;
+ omega = f * (2.0f * 3.14159f);
+ if (q < 0.001) oneminusr = 1.0f;
+ else oneminusr = omega/q;
+ if (oneminusr > 1.0f) oneminusr = 1.0f;
+ r = 1.0f - oneminusr;
+ x->x_ctl->c_coef1 = 2.0f * bp_qcos(omega) * r;
+ x->x_ctl->c_coef2 = - r * r;
+ x->x_ctl->c_gain = 2 * oneminusr * (oneminusr + r * omega);
+ /* post("r %f, omega %f, coef1 %f, coef2 %f",
+ r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
+}
+
+static void bp_ft1(t_bp *x, t_floatarg f)
+{
+ bp_docoef(x, f, x->x_q);
+}
+
+static void bp_ft2(t_bp *x, t_floatarg q)
+{
+ bp_docoef(x, x->x_freq, q);
+}
+
+static void bp_clear(t_bp *x, t_floatarg q)
+{
+ x->x_ctl->c_x1 = x->x_ctl->c_x2 = 0;
+}
+
+static void bp_perform(t_bp *x, t_float in)
+{
+ float out;
+ t_bpctl *c = x->x_ctl;
+ float last = c->c_x1;
+ float prev = c->c_x2;
+ float coef1 = c->c_coef1;
+ float coef2 = c->c_coef2;
+ float gain = c->c_gain;
+
+ float output = in + coef1 * last + coef2 * prev;
+ out = gain * output;
+
+ prev = last;
+ last = output;
+
+ /* NAN protect */
+ if (!((last <= 0) || (last >= 0)))
+ last = 0;
+ if (!((prev <= 0) || (prev >= 0)))
+ prev = 0;
+ c->c_x1 = last;
+ c->c_x2 = prev;
+
+ outlet_float(x->x_obj.ob_outlet, out);
+}
+
+void bp_setup(void)
+{
+ bp_class = class_new(gensym("bp"), (t_newmethod)bp_new, 0,
+ sizeof(t_bp), 0, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addfloat(bp_class, (t_method)bp_perform);
+ class_addmethod(bp_class, (t_method)bp_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_addmethod(bp_class, (t_method)bp_ft2,
+ gensym("ft2"), A_FLOAT, 0);
+ class_addmethod(bp_class, (t_method)bp_clear, gensym("clear"), 0);
+}
diff --git a/source/decimator.c b/source/decimator.c
new file mode 100644
index 0000000..d7f93f3
--- /dev/null
+++ b/source/decimator.c
@@ -0,0 +1,66 @@
+#include "defines.h"
+
+/*--------------- decimator ---------------*/
+
+static t_class *decimator_class;
+
+typedef struct _decimator
+{
+ t_object x_obj;
+ int m_state;
+ int m_factor;
+} t_decimator;
+
+static void decimator_perform(t_decimator *x, t_float in)
+{
+ if (!x->m_state)
+ {
+ outlet_float(x->x_obj.ob_outlet, in);
+ x->m_state=x->m_factor;
+ }
+ else
+ {
+ x->m_state--;
+ }
+
+}
+
+static void decimator_setFactor(t_decimator *x, t_float factor)
+{
+ x->m_factor=(int)factor - 1;
+}
+
+static void decimator_clear(t_decimator *x)
+{
+ x->m_state=0;
+}
+
+
+static void *decimator_new(t_float factor)
+{
+
+ t_decimator *x=(t_decimator *)pd_new(decimator_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ if (factor<1) factor=2;
+
+ decimator_setFactor(x, factor);
+ decimator_clear(x);
+ return (void *)x;
+}
+
+
+void decimator_setup(void)
+{
+ decimator_class = class_new(gensym("decimator"),
+ (t_newmethod)decimator_new, 0,
+ sizeof(t_decimator),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(decimator_class, (t_method)decimator_perform);
+ class_addmethod(decimator_class, (t_method)decimator_clear,
+ gensym("clear"), A_GIMME, NULL);
+ class_addmethod(decimator_class, (t_method)decimator_setFactor,
+ gensym("factor"), A_DEFFLOAT, NULL);
+}
+
diff --git a/source/defines.h b/source/defines.h
new file mode 100644
index 0000000..e819f88
--- /dev/null
+++ b/source/defines.h
@@ -0,0 +1,18 @@
+//#include <m_pd.h>
+#include "m_imp.h"
+#include <math.h>
+#define MAXFLOAT 1e18f;
+#define LOGTEN 2.302585092994
+
+/* NT and OSX don't appear to have single-precision ANSI math */
+#if defined(WIN32) || defined(MACOSX)
+#define sinf sin
+#define cosf cos
+#define atanf atan
+#define atan2f atan2
+#define sqrtf sqrt
+#define logf log
+#define expf exp
+#define fabsf fabs
+#define powf pow
+#endif
diff --git a/source/deltas.c b/source/deltas.c
new file mode 100644
index 0000000..edc3cb0
--- /dev/null
+++ b/source/deltas.c
@@ -0,0 +1,181 @@
+#include "defines.h"
+
+/*--------------- deltas ---------------*/
+
+static t_class *deltas_class;
+
+typedef struct _deltas
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ int m_buffer_size;
+ int m_buffer_index;
+ float *m_buffer; // circular buffer
+} t_deltas;
+
+
+static void deltas_perform_float(t_deltas *x, t_float f)
+{
+ int index;
+ index=x->m_buffer_index+1;
+ index=(index==x->m_buffer_size)?0:index;
+ x->m_buffer_index=index;
+ x->m_buffer[index]=f;
+}
+
+static void deltas_bang(t_deltas *x)
+{
+ int lo,hi,n,index,size;
+ t_atom *ap,*app;
+ float last;
+ float *buffer, *bp;
+
+ lo=(int)x->m_lo;
+ hi=(int)x->m_hi;
+
+ n=hi-lo;
+ size=x->m_buffer_size;
+ index=x->m_buffer_index;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ buffer=x->m_buffer;
+ last=buffer[index];
+ bp=buffer+index-lo;
+ bp=(bp>=buffer)?bp:bp+size; // wrap
+
+ if (bp-buffer>=n)
+ { // no wrap-around needed
+ index=n;
+ while(index--){
+ SETFLOAT(app, last-*bp--);
+ app++;
+ }
+// post("not wrapped, app-ap=%i",app-ap);
+ }
+ else // need to wrap
+ {
+ int ps, nn;
+ ps = bp-buffer;
+ nn=n;
+// post(" nn=%i",nn);
+ for(;ps>=0;ps--) // don't we miss one sample in signal???
+ {
+// post("ps=%i",ps);
+ SETFLOAT(app, last-buffer[ps]);
+ app++;
+ nn--;
+ }
+ ps=size-1;
+// post(" nn=%i",nn);
+ for(;nn>0;nn--)
+ {
+// post("ps=%i",ps);
+ SETFLOAT(app, last-buffer[ps--]);
+ app++;
+ }
+
+/*
+ int i2;
+ index=bp-buffer;
+ i2=index;
+ post("first part %i",index);
+ while(index--){
+ SETFLOAT(app, last-*bp--);
+ app++;
+ }
+ index=n-i2;
+ post("2nd part %i",index);
+ bp=buffer+size-1;
+ while(index--){
+ SETFLOAT(app, last-*bp--);
+ app++;
+ }
+*/
+// post("wrapped, app-ap=%i",app-ap);
+ }
+
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+
+static void deltas_clear(t_deltas *x)
+{
+ int i,s;
+ float *f;
+ f=x->m_buffer;
+ s=x->m_buffer_size;
+ for (i=0;i<s;i++)
+ *f++=0.0f;
+}
+
+static void deltas_set(t_deltas *x, t_float lo, t_float hi, t_float size)
+{
+ if (size<1)
+ {
+ size=1;
+ post("deltas: size is minimum 1...");
+ }
+ if (hi>size)
+ {
+ post("deltas: higher bound cannot be higher than the buffer size...");
+ hi=size;
+ }
+ if (lo<0)
+ {
+ post("deltas: lower bound cannot be negative...");
+ lo=0;
+ }
+ if (hi<1)
+ {
+ post("deltas: higher bound cannot be smaller than one...");
+ hi=1;
+ }
+ if (hi<=lo)
+ {
+ post("deltas: higher bound must be higher than lower bound...");
+ lo=hi-1.0f;
+ }
+
+ freebytes(x->m_buffer, x->m_buffer_size);
+
+ x->m_hi=(float)((int)hi);
+ x->m_lo=(float)((int)lo);
+ x->m_buffer_size=(int)size;
+ x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size);
+ deltas_clear(x);
+ x->m_buffer_index=0;
+}
+
+static void *deltas_new(t_float lo, t_float hi, t_float size)
+{
+ t_deltas *x=(t_deltas *)pd_new(deltas_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_buffer_size=0;
+ x->m_buffer=0;
+ deltas_set(x, lo, hi, size);
+
+ floatinlet_new(&x->x_obj, &x->m_lo);
+ floatinlet_new(&x->x_obj, &x->m_hi);
+
+ return (void *)x;
+}
+
+static void deltas_free(t_deltas *x)
+{
+ freebytes(x->m_buffer, x->m_buffer_size);
+}
+
+void deltas_setup(void)
+{
+ deltas_class = class_new(gensym("deltas"),
+ (t_newmethod)deltas_new, (t_method)deltas_free,
+ sizeof(t_deltas),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,0);
+
+ class_addmethod(deltas_class, (t_method)deltas_clear, gensym("clear"),0);
+ class_addfloat(deltas_class, (t_method)deltas_perform_float);
+ class_addbang(deltas_class, (t_method)deltas_bang);
+}
+
diff --git a/source/hip.c b/source/hip.c
new file mode 100644
index 0000000..b1425c1
--- /dev/null
+++ b/source/hip.c
@@ -0,0 +1,77 @@
+#include "defines.h"
+
+/*--------------- hip ---------------*/
+
+typedef struct hipctl
+{
+ float c_x;
+ float c_coef;
+} t_hipctl;
+
+typedef struct hip
+{
+ t_object x_obj;
+ float x_sr;
+ float x_hz;
+ t_hipctl x_cspace;
+ t_hipctl *x_ctl;
+ float x_f;
+} t_hip;
+
+t_class *hip_class;
+
+static void hip_ft1(t_hip *x, t_floatarg f);
+
+static void *hip_new(t_floatarg f)
+{
+ t_hip *x = (t_hip *)pd_new(hip_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
+ outlet_new(&x->x_obj, gensym("float"));
+ x->x_ctl = &x->x_cspace;
+ x->x_cspace.c_x = 0;
+ hip_ft1(x, f);
+ x->x_f = 0;
+ return (x);
+}
+
+static void hip_ft1(t_hip *x, t_floatarg f)
+{
+ if (f < 0.001) f = 10;
+ x->x_hz = f;
+ x->x_ctl->c_coef = 1 - f * (2 * 3.14159f);
+ if (x->x_ctl->c_coef < 0) x->x_ctl->c_coef = 0;
+}
+
+static void hip_perform(t_hip *x, t_float in)
+{
+ t_hipctl *c = x->x_ctl;
+ float last = c->c_x;
+ float coef = c->c_coef;
+ float out;
+
+ float new = in + coef * last;
+ out = new - last;
+ last = new;
+
+ /* NAN protect */
+ if (!((last <= 0) || (last >= 0)))
+ last = 0;
+ c->c_x = last;
+
+ outlet_float(x->x_obj.ob_outlet, out);
+}
+
+static void hip_clear(t_hip *x, t_floatarg q)
+{
+ x->x_cspace.c_x = 0;
+}
+
+void hip_setup(void)
+{
+ hip_class = class_new(gensym("hip"), (t_newmethod)hip_new, 0,
+ sizeof(t_hip), 0, A_DEFFLOAT, 0);
+ class_addfloat(hip_class, (t_method)hip_perform);
+ class_addmethod(hip_class, (t_method)hip_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_addmethod(hip_class, (t_method)hip_clear, gensym("clear"), 0);
+} \ No newline at end of file
diff --git a/source/hist.c b/source/hist.c
new file mode 100644
index 0000000..ba492f2
--- /dev/null
+++ b/source/hist.c
@@ -0,0 +1,155 @@
+#include "defines.h"
+
+/*--------------- hist ---------------*/
+
+
+static t_class *hist_class;
+
+typedef struct _hist
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ float m_scale;
+ int m_nbins;
+ int m_n_observations;
+ float *m_hist;
+} t_hist;
+
+
+static void hist_perform_float(t_hist *x, t_float f)
+{
+ int j;
+ j=(int)(.5+(f-x->m_lo)*x->m_scale);
+ j=(j>0)?(j<x->m_nbins?j:x->m_nbins-1):0; // limit without IF
+ x->m_hist[j]++;
+ x->m_n_observations++;
+}
+
+static void hist_perform_list(t_hist *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i,j;
+ for (i = 0; i < argc; i++)
+ {
+ j=(int)(.5f+(atom_getfloat(&argv[i])-x->m_lo)*x->m_scale);
+ j=(j>0)?(j<x->m_nbins?j:x->m_nbins-1):0; // limit without IF
+ x->m_hist[j]++;
+ }
+ x->m_n_observations+=argc;
+}
+
+static void hist_bang(t_hist *x)
+{
+ int i,n;
+ float *f;
+ t_atom *ap,*app;
+
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+
+ i=x->m_nbins;
+ f=x->m_hist;
+
+ while(i--){
+ SETFLOAT(app, *f);
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+
+static void hist_relative(t_hist *x)
+{
+ int i,n;
+ float *f;
+ float invn;
+ t_atom *ap,*app;
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+
+ invn=1.0f/(1e-10f+x->m_n_observations);
+
+ i=n;
+ f=x->m_hist;
+
+ while(i--){
+ SETFLOAT(app, (*f*invn));
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+
+static void hist_clear(t_hist *x)
+{
+ int i;
+ float *f;
+ f=x->m_hist;
+ for (i=0;i<x->m_nbins;i++)
+ *f++=0.0f;
+ x->m_n_observations=0;
+}
+
+
+static void hist_set(t_hist *x, t_float lo, t_float hi, t_float nbins)
+{
+ if (nbins<1)
+ {
+ nbins=1;
+ post("hist: number of bins is minimum 1...");
+ }
+ if (hi<=lo)
+ {
+ post("hist: higher bound must be higher than lower bound...");
+ hi=lo+1.0f;
+ }
+
+ freebytes(x->m_hist, x->m_nbins);
+
+ x->m_hi=hi;
+ x->m_lo=lo;
+ x->m_nbins=(int)nbins;
+ x->m_scale=(float)x->m_nbins/(hi-lo);
+ x->m_hist = (float*)getbytes(sizeof(float)*x->m_nbins);
+
+ hist_clear(x);
+}
+
+static void *hist_new(t_float lo, t_float hi, t_float nbins)
+{
+ t_hist *x=(t_hist *)pd_new(hist_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_hist=0;
+ x->m_nbins=0;
+ hist_set(x, lo, hi, nbins);
+ return (void *)x;
+}
+
+static void hist_free(t_hist *x)
+{
+ freebytes(x->m_hist, x->m_nbins);
+}
+
+void hist_setup(void)
+{
+ hist_class = class_new(gensym("hist"),
+ (t_newmethod)hist_new, (t_method)hist_free,
+ sizeof(t_hist),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,0);
+
+ class_addmethod(hist_class, (t_method)hist_clear, gensym("clear"),0);
+ class_addmethod(hist_class, (t_method)hist_bang, gensym("absolute"),0);
+ class_addmethod(hist_class, (t_method)hist_relative, gensym("relative"),0);
+
+ class_addmethod(hist_class, (t_method)hist_set, gensym("set"),A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,0);
+
+ class_addlist(hist_class, (t_method)hist_perform_list);
+ class_addfloat(hist_class, (t_method)hist_perform_float);
+ class_addbang(hist_class, (t_method)hist_bang);
+}
+
diff --git a/source/itov.c b/source/itov.c
new file mode 100644
index 0000000..fa68a90
--- /dev/null
+++ b/source/itov.c
@@ -0,0 +1,86 @@
+#include "defines.h"
+
+/*--------------- itov ---------------*/
+
+
+static t_class *itov_class;
+
+typedef struct _itov
+{
+ t_object x_obj;
+ t_outlet *f_out1;
+ t_outlet *f_out2;
+ t_outlet *f_out3;
+ float m_lo;
+ float m_hi;
+ float m_scale;
+ int m_nbins;
+} t_itov;
+
+
+static void itov_perform_float(t_itov *x, t_float j)
+{
+ float i;
+ j-=1.0f;
+ j=(j>0)?(j<x->m_nbins?j:x->m_nbins-1):0; // limit without IF
+
+// j=(int)((f-x->m_lo)*x->m_scale);
+ i=(j/x->m_scale)-x->m_lo;
+
+ outlet_float(x->f_out2, i);
+
+}
+
+static void itov_perform_list(t_itov *x, t_symbol *s, int argc, t_atom *argv)
+{
+
+
+}
+
+static void itov_set(t_itov *x, t_float lo, t_float hi, t_float nbins)
+{
+ if (nbins<1)
+ {
+ nbins=1;
+ post("itov: number of bins is minimum 1...");
+ }
+ if (hi<=lo)
+ {
+ post("itov: higher bound must be higher than lower bound...");
+ hi=lo+1.0f;
+ }
+
+ x->m_hi=hi;
+ x->m_lo=lo;
+ x->m_nbins=(int)nbins;
+ x->m_scale=(float)x->m_nbins/(hi-lo);
+}
+
+static void *itov_new(t_float lo, t_float hi, t_float nbins)
+{
+ t_itov *x=(t_itov *)pd_new(itov_class);
+ x->f_out1=outlet_new(&x->x_obj, gensym("float"));
+ x->f_out2=outlet_new(&x->x_obj, gensym("float"));
+ x->f_out3=outlet_new(&x->x_obj, gensym("float"));
+
+ x->m_nbins=0;
+ itov_set(x, lo, hi, nbins);
+ return (void *)x;
+}
+
+static void itov_free(t_itov *x)
+{
+}
+
+void itov_setup(void)
+{
+ itov_class = class_new(gensym("itov"),
+ (t_newmethod)itov_new, (t_method)itov_free,
+ sizeof(t_itov),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,0);
+
+// class_addlist(itov_class, (t_method)itov_perform_list);
+ class_addfloat(itov_class, (t_method)itov_perform_float);
+}
+
diff --git a/source/lavg.c b/source/lavg.c
new file mode 100644
index 0000000..fce0015
--- /dev/null
+++ b/source/lavg.c
@@ -0,0 +1,55 @@
+#include "defines.h"
+
+/*--------------- lavg ---------------*/
+
+static t_class *lavg_class;
+
+typedef struct _lavg
+{
+ t_object x_obj;
+ float m_avg;
+ float m_c_leak;
+ float m_leak;
+} t_lavg;
+
+
+static void lavg_perform(t_lavg *x, t_float in)
+{
+ x->m_avg= x->m_avg * x->m_c_leak + in * x->m_leak;
+ outlet_float(x->x_obj.ob_outlet, x->m_avg);
+}
+
+static void lavg_clear(t_lavg *x)
+{
+ x->m_avg=0.0f;
+}
+
+static void lavg_setHalfDecay(t_lavg *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *lavg_new( t_float halfDecayTime)
+{
+ t_lavg *x=(t_lavg *)pd_new(lavg_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lavg_setHalfDecay(x, halfDecayTime);
+ return (void *)x;
+}
+
+void lavg_setup(void)
+{
+ lavg_class = class_new(gensym("lavg"),
+ (t_newmethod)lavg_new, 0,
+ sizeof(t_lavg),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lavg_class, (t_method)lavg_perform);
+ class_addmethod(lavg_class, (t_method)lavg_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addmethod(lavg_class, (t_method)lavg_clear,
+ gensym("clear"), 0);
+}
+
diff --git a/source/lhist.c b/source/lhist.c
new file mode 100644
index 0000000..ea20edc
--- /dev/null
+++ b/source/lhist.c
@@ -0,0 +1,174 @@
+#include "defines.h"
+
+/*--------------- lhist ---------------*/
+
+static t_class *lhist_class;
+
+typedef struct _lhist
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ float m_scale;
+ float m_c_leak;
+ float m_leak;
+ int m_nbins;
+// int m_n_observations;
+ float *m_lhist;
+} t_lhist;
+
+static void lhist_setHalfDecay(t_lhist *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lhist_perform_float(t_lhist *x, t_float f)
+{
+ int j;
+ j=(int)(.5+(f-x->m_lo)*x->m_scale);
+ j=(j>0)?(j<x->m_nbins?j:x->m_nbins-1):0; // limit without IF
+ x->m_lhist[j]++;
+// x->m_n_observations++;
+}
+
+static void lhist_perform_list(t_lhist *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i,j;
+ for (i = 0; i < argc; i++)
+ {
+ j=(int)(.5f+(atom_getfloat(&argv[i])-x->m_lo)*x->m_scale);
+ j=(j>0)?(j<x->m_nbins?j:x->m_nbins-1):0; // limit without IF
+ x->m_lhist[j]++;
+ }
+// x->m_n_observations+=argc;
+}
+
+static void lhist_leak(t_lhist *x)
+{
+ int i;
+ float *f;
+ float sc;
+ f=x->m_lhist;
+ sc=x->m_c_leak;
+ i=x->m_nbins;
+ while(i--)
+ *f++*=sc;
+}
+
+static void lhist_bang(t_lhist *x)
+{
+ int i,n;
+ float *f;
+ t_atom *ap,*app;
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ i=n;
+ f=x->m_lhist;
+
+ while(i--){
+ SETFLOAT(app, *f);
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap,n);
+}
+
+static void lhist_relative(t_lhist *x)
+{
+ int i,n;
+ float *f;
+ float invn,sum;
+ t_atom *ap,*app;
+
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ i=x->m_nbins;
+ f=x->m_lhist;
+ sum=0.0f;
+ while(i--) sum+=*f++;
+ invn=1.0f/(1e-10f+sum);
+
+ i=x->m_nbins;
+ f=x->m_lhist;
+
+ while(i--){
+ SETFLOAT(app, (*f*invn));
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap,n);
+}
+
+static void lhist_clear(t_lhist *x)
+{
+ int i;
+ float *f;
+ f=x->m_lhist;
+ for (i=0;i<x->m_nbins;i++)
+ *f++=0.0f;
+// x->m_n_observations=0;
+}
+
+static void lhist_set(t_lhist *x, t_float lo, t_float hi, t_float nbins)
+{
+ if (nbins<1)
+ {
+ nbins=1;
+ post("lhist: number of bins is minimum 1...");
+ }
+ if (hi<=lo)
+ {
+ post("lhist: higher bound must be higher than lower bound...");
+ hi=lo+1.0f;
+ }
+ freebytes(x->m_lhist, x->m_nbins);
+ x->m_hi=hi;
+ x->m_lo=lo;
+ x->m_nbins=(int)nbins;
+ x->m_scale=(float)x->m_nbins/(hi-lo);
+ x->m_lhist = (float*)getbytes(sizeof(float)*x->m_nbins);
+
+ lhist_clear(x);
+}
+
+static void *lhist_new(t_float lo, t_float hi, t_float nbins, t_float decay)
+{
+ t_lhist *x=(t_lhist *)pd_new(lhist_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ lhist_setHalfDecay(x,decay);
+ x->m_nbins=0;
+ x->m_lhist=0;
+ lhist_set(x, lo, hi, nbins);
+ return (void *)x;
+}
+
+static void lhist_free(t_lhist *x)
+{
+ freebytes(x->m_lhist, x->m_nbins);
+}
+
+void lhist_setup(void)
+{
+ lhist_class = class_new(gensym("lhist"),
+ (t_newmethod)lhist_new, (t_method)lhist_free,
+ sizeof(t_lhist),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,A_DEFFLOAT,0);
+
+ class_addmethod(lhist_class, (t_method)lhist_clear, gensym("clear"),0);
+ class_addmethod(lhist_class, (t_method)lhist_bang, gensym("absolute"),0);
+ class_addmethod(lhist_class, (t_method)lhist_relative, gensym("relative"),0);
+ class_addmethod(lhist_class, (t_method)lhist_leak, gensym("leak"),0);
+ class_addmethod(lhist_class, (t_method)lhist_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+
+ class_addlist(lhist_class, (t_method)lhist_perform_list);
+ class_addfloat(lhist_class, (t_method)lhist_perform_float);
+ class_addbang(lhist_class, (t_method)lhist_bang);
+}
+
diff --git a/source/lhisti.c b/source/lhisti.c
new file mode 100644
index 0000000..826cce4
--- /dev/null
+++ b/source/lhisti.c
@@ -0,0 +1,174 @@
+#include "defines.h"
+
+/*--------------- lhisti ---------------*/
+// ignores samples outside bins
+
+static t_class *lhisti_class;
+
+typedef struct _lhisti
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ float m_scale;
+ float m_c_leak;
+ float m_leak;
+ int m_nbins;
+// int m_n_observations;
+ float *m_lhisti;
+} t_lhisti;
+
+static void lhisti_setHalfDecay(t_lhisti *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lhisti_perform_float(t_lhisti *x, t_float f)
+{
+ int j;
+ j=(int)(.5+(f-x->m_lo)*x->m_scale);
+ if ((j>=0)&&(j<x->m_nbins))
+ x->m_lhisti[j]++;
+}
+
+static void lhisti_perform_list(t_lhisti *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i,j;
+ for (i = 0; i < argc; i++)
+ {
+ j=(int)(.5f+(atom_getfloat(&argv[i])-x->m_lo)*x->m_scale);
+ if ((j>=0)&&(j<x->m_nbins))
+ x->m_lhisti[j]++;
+ }
+// x->m_n_observations+=argc;
+}
+
+static void lhisti_leak(t_lhisti *x)
+{
+ int i;
+ float *f;
+ float sc;
+ f=x->m_lhisti;
+ sc=x->m_c_leak;
+ i=x->m_nbins;
+ while(i--)
+ *f++*=sc;
+}
+
+static void lhisti_bang(t_lhisti *x)
+{
+ int i,n;
+ float *f;
+ t_atom *ap,*app;
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ i=n;
+ f=x->m_lhisti;
+
+ while(i--){
+ SETFLOAT(app, *f);
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap,n);
+}
+
+static void lhisti_relative(t_lhisti *x)
+{
+ int i,n;
+ float *f;
+ float invn,sum;
+ t_atom *ap,*app;
+
+ n=x->m_nbins;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ i=x->m_nbins;
+ f=x->m_lhisti;
+ sum=0.0f;
+ while(i--) sum+=*f++;
+ invn=1.0f/(1e-10f+sum);
+
+ i=x->m_nbins;
+ f=x->m_lhisti;
+
+ while(i--){
+ SETFLOAT(app, (*f*invn));
+ f++;
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap,n);
+}
+
+static void lhisti_clear(t_lhisti *x)
+{
+ int i;
+ float *f;
+ f=x->m_lhisti;
+ for (i=0;i<x->m_nbins;i++)
+ *f++=0.0f;
+// x->m_n_observations=0;
+}
+
+static void lhisti_set(t_lhisti *x, t_float lo, t_float hi, t_float nbins)
+{
+ if (nbins<1)
+ {
+ nbins=1;
+ post("lhisti: number of bins is minimum 1...");
+ }
+ if (hi<=lo)
+ {
+ post("lhisti: higher bound must be higher than lower bound...");
+ hi=lo+1.0f;
+ }
+ freebytes(x->m_lhisti, x->m_nbins);
+ x->m_hi=hi;
+ x->m_lo=lo;
+ x->m_nbins=(int)nbins;
+ x->m_scale=(float)x->m_nbins/(hi-lo);
+ x->m_lhisti = (float*)getbytes(sizeof(float)*x->m_nbins);
+
+ lhisti_clear(x);
+}
+
+static void *lhisti_new(t_float lo, t_float hi, t_float nbins, t_float decay)
+{
+ t_lhisti *x=(t_lhisti *)pd_new(lhisti_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ lhisti_setHalfDecay(x,decay);
+ x->m_nbins=0;
+ x->m_lhisti=0;
+ lhisti_set(x, lo, hi, nbins);
+ return (void *)x;
+}
+
+static void lhisti_free(t_lhisti *x)
+{
+ freebytes(x->m_lhisti, x->m_nbins);
+}
+
+void lhisti_setup(void)
+{
+ lhisti_class = class_new(gensym("lhisti"),
+ (t_newmethod)lhisti_new, (t_method)lhisti_free,
+ sizeof(t_lhisti),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,A_DEFFLOAT,0);
+
+ class_addmethod(lhisti_class, (t_method)lhisti_clear, gensym("clear"),0);
+ class_addmethod(lhisti_class, (t_method)lhisti_bang, gensym("absolute"),0);
+ class_addmethod(lhisti_class, (t_method)lhisti_relative, gensym("relative"),0);
+ class_addmethod(lhisti_class, (t_method)lhisti_leak, gensym("leak"),0);
+ class_addmethod(lhisti_class, (t_method)lhisti_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+
+ class_addlist(lhisti_class, (t_method)lhisti_perform_list);
+ class_addfloat(lhisti_class, (t_method)lhisti_perform_float);
+ class_addbang(lhisti_class, (t_method)lhisti_bang);
+}
+
diff --git a/source/linspace.c b/source/linspace.c
new file mode 100644
index 0000000..c3af9c2
--- /dev/null
+++ b/source/linspace.c
@@ -0,0 +1,74 @@
+#include "defines.h"
+
+/*--------------- linspace ----------------*/
+/* clips a vector */
+
+
+static t_class *linspace_class;
+
+typedef struct _linspace
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ float m_n;
+} t_linspace;
+
+
+static void linspace_bang(t_linspace *x)
+{
+ int n;
+ n=(int)x->m_n;
+ if ((n<256)&&(n>1))
+ {
+ int i;
+ float lo,step;
+ t_atom *ap,*app;
+
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ lo=x->m_lo;
+ step=(x->m_hi-lo)/(n-1);
+ for (i = 0; i < n; i++)
+ {
+
+ SETFLOAT(app, lo);
+ app++;
+ lo+=step;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap,n);
+ }
+}
+
+static void linspace_float(t_linspace *x, t_float lo)
+{
+ x->m_lo=lo;
+ linspace_bang(x);
+}
+
+static void *linspace_new(t_float lo, t_float hi, t_float n)
+{
+ t_linspace *x=(t_linspace *)pd_new(linspace_class);
+
+ floatinlet_new(&x->x_obj, &x->m_hi);
+ floatinlet_new(&x->x_obj, &x->m_n);
+
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_lo=lo;
+ x->m_hi=hi;
+ x->m_n=n;
+ return (void *)x;
+}
+
+void linspace_setup(void)
+{
+ linspace_class = class_new(gensym("linspace"),
+ (t_newmethod)linspace_new, 0,
+ sizeof(t_linspace),
+ CLASS_DEFAULT,
+ A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addfloat(linspace_class, (t_method)linspace_float);
+ class_addbang(linspace_class, (t_method)linspace_bang);
+}
+
diff --git a/source/lmax.c b/source/lmax.c
new file mode 100644
index 0000000..911304f
--- /dev/null
+++ b/source/lmax.c
@@ -0,0 +1,57 @@
+#include "defines.h"
+
+/*--------------- lmax ---------------*/
+
+static t_class *lmax_class;
+
+typedef struct _lmax
+{
+ t_object x_obj;
+ float m_max;
+ float m_leak;
+ float m_c_leak;
+} t_lmax;
+
+
+static void lmax_perform(t_lmax *x, t_float in)
+{
+ x->m_max=(in > x->m_max) ? in : x->m_max * x->m_c_leak + in * x->m_leak;
+ outlet_float(x->x_obj.ob_outlet, x->m_max);
+}
+
+static void lmax_setHalfDecay(t_lmax *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lmax_clear(t_lmax *x)
+{
+ x->m_max= - MAXFLOAT;
+}
+
+static void *lmax_new( t_float halfDecayTime)
+{
+ t_lmax *x=(t_lmax *)pd_new(lmax_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lmax_setHalfDecay(x, halfDecayTime);
+ lmax_clear(x);
+ return (void *)x;
+}
+
+
+void lmax_setup(void)
+{
+ lmax_class = class_new(gensym("lmax"),
+ (t_newmethod)lmax_new, 0,
+ sizeof(t_lmax),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lmax_class, (t_method)lmax_perform);
+ class_addmethod(lmax_class, (t_method)lmax_clear,
+ gensym("clear"), A_GIMME, NULL);
+ class_addmethod(lmax_class, (t_method)lmax_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+}
+
diff --git a/source/lmin.c b/source/lmin.c
new file mode 100644
index 0000000..51b333a
--- /dev/null
+++ b/source/lmin.c
@@ -0,0 +1,57 @@
+#include "defines.h"
+
+/*--------------- lmin ---------------*/
+
+static t_class *lmin_class;
+
+typedef struct _lmin
+{
+ t_object x_obj;
+ float m_min;
+ float m_leak;
+ float m_c_leak;
+} t_lmin;
+
+
+static void lmin_perform(t_lmin *x, t_float in)
+{
+ x->m_min=(in < x->m_min) ? in : x->m_min * x->m_c_leak + in * x->m_leak;
+ outlet_float(x->x_obj.ob_outlet, x->m_min);
+}
+
+static void lmin_setHalfDecay(t_lmin *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lmin_clear(t_lmin *x)
+{
+ x->m_min= MAXFLOAT;
+}
+
+static void *lmin_new( t_float halfDecayTime)
+{
+ t_lmin *x=(t_lmin *)pd_new(lmin_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lmin_setHalfDecay(x, halfDecayTime);
+ lmin_clear(x);
+ return (void *)x;
+}
+
+
+void lmin_setup(void)
+{
+ lmin_class = class_new(gensym("lmin"),
+ (t_newmethod)lmin_new, 0,
+ sizeof(t_lmin),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lmin_class, (t_method)lmin_perform);
+ class_addmethod(lmin_class, (t_method)lmin_clear,
+ gensym("clear"), A_GIMME, NULL);
+ class_addmethod(lmin_class, (t_method)lmin_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+}
+
diff --git a/source/lrange.c b/source/lrange.c
new file mode 100644
index 0000000..8f5b296
--- /dev/null
+++ b/source/lrange.c
@@ -0,0 +1,60 @@
+#include "defines.h"
+
+/*--------------- lrange ---------------*/
+
+static t_class *lrange_class;
+
+typedef struct _lrange
+{
+ t_object x_obj;
+ float m_min;
+ float m_max;
+ float m_c_leak;
+ float m_leak;
+} t_lrange;
+
+
+static void lrange_perform(t_lrange *x, t_float in)
+{
+ x->m_max=(in > x->m_max) ? in : x->m_max * x->m_c_leak + in * x->m_leak;
+ x->m_min=(in < x->m_min) ? in : x->m_min * x->m_c_leak + in * x->m_leak;
+ outlet_float(x->x_obj.ob_outlet, x->m_max-x->m_min);
+}
+
+static void lrange_setHalfDecay(t_lrange *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lrange_clear(t_lrange *x)
+{
+ x->m_max = - MAXFLOAT;
+ x->m_min = MAXFLOAT;
+}
+
+static void *lrange_new( t_float halfDecayTime)
+{
+ t_lrange *x=(t_lrange *)pd_new(lrange_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lrange_setHalfDecay(x, halfDecayTime);
+ lrange_clear(x);
+ return (void *)x;
+}
+
+
+void lrange_setup(void)
+{
+ lrange_class = class_new(gensym("lrange"),
+ (t_newmethod)lrange_new, 0,
+ sizeof(t_lrange),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lrange_class, (t_method)lrange_perform);
+ class_addmethod(lrange_class, (t_method)lrange_clear,
+ gensym("clear"), A_GIMME, NULL);
+ class_addmethod(lrange_class, (t_method)lrange_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+}
+
diff --git a/source/lstd.c b/source/lstd.c
new file mode 100644
index 0000000..1873bda
--- /dev/null
+++ b/source/lstd.c
@@ -0,0 +1,60 @@
+#include "defines.h"
+
+/*--------------- lstd ---------------*/
+
+static t_class *lstd_class;
+
+typedef struct _lstd
+{
+ t_object x_obj;
+ float m_avg;
+ float m_sum_squares;
+ float m_std;
+ float m_c_leak;
+ float m_leak;
+} t_lstd;
+
+
+static void lstd_perform(t_lstd *x, t_float in)
+{
+ float tmp=x->m_avg-in;
+ x->m_avg= x->m_avg * x->m_c_leak + in * x->m_leak;
+ x->m_sum_squares=x->m_sum_squares * x->m_c_leak + x->m_leak*tmp*tmp;
+ x->m_std=(float)sqrtf(x->m_sum_squares);
+ outlet_float(x->x_obj.ob_outlet, x->m_std);
+}
+
+static void lstd_setHalfDecay(t_lstd *x, t_float halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void lstd_clear(t_lstd *x)
+{
+ x->m_sum_squares=0.0f;
+ x->m_avg=0.0f;
+}
+
+static void *lstd_new( t_float halfDecayTime)
+{
+ t_lstd *x=(t_lstd *)pd_new(lstd_class);
+ outlet_new(&x->x_obj, gensym("float"));
+
+ lstd_setHalfDecay(x, halfDecayTime);
+ return (void *)x;
+}
+
+
+void lstd_setup(void)
+{
+ lstd_class = class_new(gensym("lstd"),
+ (t_newmethod)lstd_new, 0,
+ sizeof(t_lstd),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addfloat(lstd_class, (t_method)lstd_perform);
+ class_addmethod(lstd_class, (t_method)lstd_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+}
+
diff --git a/source/prevl.c b/source/prevl.c
new file mode 100644
index 0000000..2ba39ce
--- /dev/null
+++ b/source/prevl.c
@@ -0,0 +1,161 @@
+#include "defines.h"
+
+/*--------------- prevl ---------------*/
+
+static t_class *prevl_class;
+
+typedef struct _prevl
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+ int m_buffer_size;
+ int m_buffer_index;
+ float *m_buffer; // circular buffer
+} t_prevl;
+
+
+static void prevl_perform_float(t_prevl *x, t_float f)
+{
+ int index;
+ index=x->m_buffer_index+1;
+ index=(index==x->m_buffer_size)?0:index;
+ x->m_buffer_index=index;
+ x->m_buffer[index]=f;
+}
+
+static void prevl_bang(t_prevl *x)
+{
+ int lo,hi,n,index,size;
+ t_atom *ap,*app;
+ float *buffer, *bp;
+
+ lo=(int)x->m_lo;
+ hi=(int)x->m_hi;
+
+ n=hi-lo;
+ size=x->m_buffer_size;
+ index=x->m_buffer_index;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ app=ap;
+ buffer=x->m_buffer;
+ bp=buffer+index-lo;
+ bp=(bp>=buffer)?bp:bp+size; // wrap
+
+ if (bp-buffer>=n)
+ { // no wrap-around needed
+ index=n;
+ while(index--){
+ SETFLOAT(app, *bp--);
+ app++;
+ }
+// post("not wrapped, app-ap=%i",app-ap);
+ }
+ else // need to wrap
+ {
+ int ps, nn;
+ ps = bp-buffer;
+ nn=n;
+// post(" nn=%i",nn);
+ for(;ps>=0;ps--) // don't we miss one sample in signal???
+ {
+// post("ps=%i",ps);
+ SETFLOAT(app, buffer[ps]);
+ app++;
+ nn--;
+ }
+ ps=size-1;
+// post(" nn=%i",nn);
+ for(;nn>0;nn--)
+ {
+// post("ps=%i",ps);
+ SETFLOAT(app, buffer[ps--]);
+ app++;
+ }
+
+ }
+
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+
+static void prevl_clear(t_prevl *x)
+{
+ int i,s;
+ float *f;
+ f=x->m_buffer;
+ s=x->m_buffer_size;
+ for (i=0;i<s;i++)
+ *f++=0.0f;
+}
+
+static void prevl_set(t_prevl *x, t_float lo, t_float hi, t_float size)
+{
+ if (size<1)
+ {
+ size=1;
+ post("prevl: size is minimum 1...");
+ }
+ if (hi>size)
+ {
+ post("prevl: higher bound cannot be higher than the buffer size...");
+ hi=size;
+ }
+ if (lo<0)
+ {
+ post("prevl: lower bound cannot be negative...");
+ lo=0;
+ }
+ if (hi<1)
+ {
+ post("prevl: higher bound cannot be smaller than one...");
+ hi=1;
+ }
+ if (hi<=lo)
+ {
+ post("prevl: higher bound must be higher than lower bound...");
+ lo=hi-1.0f;
+ }
+
+ freebytes(x->m_buffer, x->m_buffer_size);
+
+ x->m_hi=(float)((int)hi);
+ x->m_lo=(float)((int)lo);
+ x->m_buffer_size=(int)size;
+ x->m_buffer = (float*)getbytes(sizeof(float)*x->m_buffer_size);
+ prevl_clear(x);
+ x->m_buffer_index=0;
+}
+
+static void *prevl_new(t_float lo, t_float hi, t_float size)
+{
+ t_prevl *x=(t_prevl *)pd_new(prevl_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_buffer_size=0;
+ x->m_buffer=0;
+ prevl_set(x, lo, hi, size);
+
+ floatinlet_new(&x->x_obj, &x->m_lo);
+ floatinlet_new(&x->x_obj, &x->m_hi);
+
+ return (void *)x;
+}
+
+static void prevl_free(t_prevl *x)
+{
+ freebytes(x->m_buffer, x->m_buffer_size);
+}
+
+void prevl_setup(void)
+{
+ prevl_class = class_new(gensym("prevl"),
+ (t_newmethod)prevl_new, (t_method)prevl_free,
+ sizeof(t_prevl),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT,0);
+
+ class_addmethod(prevl_class, (t_method)prevl_clear, gensym("clear"),0);
+ class_addfloat(prevl_class, (t_method)prevl_perform_float);
+ class_addbang(prevl_class, (t_method)prevl_bang);
+}
+
diff --git a/source/threshold.c b/source/threshold.c
new file mode 100644
index 0000000..2d99e03
--- /dev/null
+++ b/source/threshold.c
@@ -0,0 +1,112 @@
+/* --------------------- threshold ----------------------------- */
+
+#include "defines.h"
+
+static t_class *threshold_class;
+
+typedef struct _threshold
+{
+ t_object x_obj;
+ t_outlet *x_outlet1; /* bang out for high thresh */
+ t_outlet *x_outlet2; /* bang out for low thresh */
+ t_clock *x_clock; /* wakeup for message output */
+ int x_state; /* 1 = high, 0 = low */
+ float x_hithresh; /* value of high threshold */
+ float x_lothresh; /* value of low threshold */
+ float x_deadwait; /* msec remaining in dead period */
+ float x_hideadtime; /* hi dead */
+ float x_lodeadtime; /* lo dead */
+} t_threshold;
+
+static void threshold_tick(t_threshold *x);
+static void threshold_set(t_threshold *x,
+ t_floatarg hithresh, t_floatarg hideadtime,
+ t_floatarg lothresh, t_floatarg lodeadtime);
+
+static t_threshold *threshold_new(t_floatarg hithresh,
+ t_floatarg hideadtime, t_floatarg lothresh, t_floatarg lodeadtime)
+{
+ t_threshold *x = (t_threshold *)
+ pd_new(threshold_class);
+ x->x_state = 0; /* low state */
+ x->x_deadwait = 0; /* no dead time */
+ x->x_clock = clock_new(x, (t_method)threshold_tick);
+ x->x_outlet1 = outlet_new(&x->x_obj, gensym("bang"));
+ x->x_outlet2 = outlet_new(&x->x_obj, gensym("bang"));
+ threshold_set(x, hithresh, hideadtime, lothresh, lodeadtime);
+ return (x);
+}
+
+ /* "set" message to specify thresholds and dead times */
+static void threshold_set(t_threshold *x,
+ t_floatarg hithresh, t_floatarg hideadtime,
+ t_floatarg lothresh, t_floatarg lodeadtime)
+{
+ if (lothresh > hithresh)
+ lothresh = hithresh;
+ x->x_hithresh = hithresh;
+ x->x_hideadtime = hideadtime;
+ x->x_lothresh = lothresh;
+ x->x_lodeadtime = lodeadtime;
+}
+
+ /* number in inlet sets state -- note incompatible with JMAX which used
+ "int" message for this, impossible here because of auto signal conversion */
+static void threshold_ft1(t_threshold *x, t_floatarg f)
+{
+ x->x_state = (f != 0);
+ x->x_deadwait = 0;
+}
+
+static void threshold_tick(t_threshold *x)
+{
+ if (x->x_state)
+ outlet_bang(x->x_outlet1);
+ else outlet_bang(x->x_outlet2);
+}
+
+static void threshold_perform(t_threshold *x, t_float in)
+{
+ if (x->x_deadwait > 0)
+ x->x_deadwait -= 1;
+ else if (x->x_state)
+ {
+ /* we're high; look for low sample */
+ if (in < x->x_lothresh)
+ {
+ clock_delay(x->x_clock, 0L);
+ x->x_state = 0;
+ x->x_deadwait = x->x_lodeadtime;
+ }
+ }
+ else
+ {
+ /* we're low; look for high sample */
+ if (in >= x->x_hithresh)
+ {
+ clock_delay(x->x_clock, 0L);
+ x->x_state = 1;
+ x->x_deadwait = x->x_hideadtime;
+ }
+ }
+}
+
+
+static void threshold_ff(t_threshold *x)
+{
+ clock_free(x->x_clock);
+}
+
+void threshold_setup( void)
+{
+ threshold_class = class_new(gensym("threshold"),
+ (t_newmethod)threshold_new, (t_method)threshold_ff,
+ sizeof(t_threshold), 0,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ class_addfloat(threshold_class, (t_method)threshold_perform);
+ class_addmethod(threshold_class, (t_method)threshold_set,
+ gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod(threshold_class, (t_method)threshold_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+}
diff --git a/source/vabs.c b/source/vabs.c
new file mode 100644
index 0000000..c928c5e
--- /dev/null
+++ b/source/vabs.c
@@ -0,0 +1,48 @@
+#include "defines.h"
+
+/*--------------- vabs ----------------*/
+/* absolute values of a list of floats */
+
+
+static t_class *vabs_class;
+
+typedef struct _vabs
+{
+ t_object x_obj;
+} t_vabs;
+
+
+static void vabs_perform(t_vabs *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ SETFLOAT(app, f>0?f:-f);
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vabs_new()
+{
+ t_vabs *x=(t_vabs *)pd_new(vabs_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vabs_setup(void)
+{
+ vabs_class = class_new(gensym("vabs"),
+ (t_newmethod)vabs_new, 0,
+ sizeof(t_vabs),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vabs_class, (t_method)vabs_perform);
+}
+
diff --git a/source/vclip.c b/source/vclip.c
new file mode 100644
index 0000000..4a11ef5
--- /dev/null
+++ b/source/vclip.c
@@ -0,0 +1,58 @@
+#include "defines.h"
+
+/*--------------- vclip ----------------*/
+/* clips a vector */
+
+
+static t_class *vclip_class;
+
+typedef struct _vclip
+{
+ t_object x_obj;
+ float m_lo;
+ float m_hi;
+} t_vclip;
+
+
+static void vclip_perform(t_vclip *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ float lo,hi;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ lo=x->m_lo;
+ hi=x->m_hi;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ SETFLOAT(app, (f<lo?lo:(f>hi?hi:f)));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vclip_new(t_float lo, t_float hi)
+{
+ t_vclip *x=(t_vclip *)pd_new(vclip_class);
+
+ floatinlet_new(&x->x_obj, &x->m_lo);
+ floatinlet_new(&x->x_obj, &x->m_hi);
+
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_hi=hi;
+ x->m_lo=lo;
+ return (void *)x;
+}
+
+void vclip_setup(void)
+{
+ vclip_class = class_new(gensym("vclip"),
+ (t_newmethod)vclip_new, 0,
+ sizeof(t_vclip),
+ CLASS_DEFAULT,
+ A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addlist(vclip_class, (t_method)vclip_perform);
+}
+
diff --git a/source/vcog.c b/source/vcog.c
new file mode 100644
index 0000000..1dd68a4
--- /dev/null
+++ b/source/vcog.c
@@ -0,0 +1,43 @@
+#include "defines.h"
+
+/*--------------- vcog ---------------*/
+
+static t_class *vcog_class;
+
+typedef struct _vcog
+{
+ t_object x_obj;
+} t_vcog;
+
+
+static void vcog_perform(t_vcog *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float sum=0.f;
+ float wsum=0.0f;
+ int i;
+ for (i = 0; i < argc; i++)
+ {
+ float tmp=atom_getfloat(&argv[i]);
+ sum+= tmp;
+ wsum+= tmp*i;
+ }
+ if (sum!=0.0f) outlet_float(x->x_obj.ob_outlet, 1.0f+(wsum/sum));
+}
+
+static void *vcog_new( t_float halfDecayTime)
+{
+ t_vcog *x=(t_vcog *)pd_new(vcog_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vcog_setup(void)
+{
+ vcog_class = class_new(gensym("vcog"),
+ (t_newmethod)vcog_new, 0,
+ sizeof(t_vcog),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vcog_class, (t_method)vcog_perform);
+}
+
diff --git a/source/vdbtorms.c b/source/vdbtorms.c
new file mode 100644
index 0000000..ab954f6
--- /dev/null
+++ b/source/vdbtorms.c
@@ -0,0 +1,56 @@
+#include "defines.h"
+
+/*--------------- vdbtorms ----------------*/
+
+static t_class *vdbtorms_class;
+
+typedef struct _vdbtorms
+{
+ t_object x_obj;
+} t_vdbtorms;
+
+float dbtorms(float f)
+{
+ if (f <= 0)
+ return(0);
+ else
+ {
+ if (f > 485)
+ f = 485;
+ }
+ return (float)(exp((LOGTEN * 0.05) * (f-100.)));
+}
+
+static void vdbtorms_perform(t_vdbtorms *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+
+ for (i = 0; i < argc; i++)
+ {
+ SETFLOAT(app, dbtorms(atom_getfloat(argv++)));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vdbtorms_new()
+{
+ t_vdbtorms *x=(t_vdbtorms *)pd_new(vdbtorms_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vdbtorms_setup(void)
+{
+ vdbtorms_class = class_new(gensym("vdbtorms"),
+ (t_newmethod)vdbtorms_new, 0,
+ sizeof(t_vdbtorms),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vdbtorms_class, (t_method)vdbtorms_perform);
+}
+
diff --git a/source/vdelta.c b/source/vdelta.c
new file mode 100644
index 0000000..cc809db
--- /dev/null
+++ b/source/vdelta.c
@@ -0,0 +1,75 @@
+#include "defines.h"
+
+/*--------------- vdelta ----------------------------*/
+/* differences between element in succesive vectors */
+
+static t_class *vdelta_class;
+
+typedef struct _vdelta
+{
+ t_object x_obj;
+ float m_c_leak;
+ float m_leak;
+ float *m_prev;
+ int m_n;
+} t_vdelta;
+
+
+static void vdelta_perform(t_vdelta *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ float *fp;
+ float m_leak;
+ float m_c_leak;
+ m_leak=x->m_leak;
+ m_c_leak=x->m_c_leak;
+
+ if (argc!=x->m_n)
+ {
+ int i;
+ if (x->m_prev)
+ freebytes(x->m_prev,x->m_n);
+ x->m_prev=(float*)getbytes(argc*sizeof(float));
+ for(i=0;i<argc;i++)
+ x->m_prev[i]=0.0f;
+ x->m_n=argc;
+ }
+
+ fp=x->m_prev;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ SETFLOAT(app, f-*fp);
+ app++;
+ *fp++=f;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vdelta_new()
+{
+ t_vdelta *x=(t_vdelta *)pd_new(vdelta_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_n=0;
+ x->m_prev=0;
+ return (void *)x;
+}
+
+static void vdelta_free(t_vdelta *x)
+{
+ freebytes(x->m_prev,x->m_n);
+}
+
+void vdelta_setup(void)
+{
+ vdelta_class = class_new(gensym("vdelta"),
+ (t_newmethod)vdelta_new, (t_method)vdelta_free,
+ sizeof(t_vdelta),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vdelta_class, (t_method)vdelta_perform);
+}
diff --git a/source/vfmod.c b/source/vfmod.c
new file mode 100644
index 0000000..7b7d1af
--- /dev/null
+++ b/source/vfmod.c
@@ -0,0 +1,57 @@
+#include "defines.h"
+
+/*--------------- vfmod ----------------*/
+/* floating point modulo of a vector */
+
+
+static t_class *vfmod_class;
+
+typedef struct _vfmod
+{
+ t_object x_obj;
+ float m_y;
+} t_vfmod;
+
+
+static void vfmod_perform(t_vfmod *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ float y;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ y=x->m_y;
+ if (y==0.0f)
+ y=1.0f;
+ for (i = 0; i < argc; i++)
+ {
+ SETFLOAT(app, (float)fmod(atom_getfloat(argv++),y));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vfmod_new(t_float y)
+{
+ t_vfmod *x=(t_vfmod *)pd_new(vfmod_class);
+
+ floatinlet_new(&x->x_obj, &x->m_y);
+
+ outlet_new(&x->x_obj, gensym("list"));
+ if (y==0.0f)
+ y=1.0f;
+ x->m_y=y;
+ return (void *)x;
+}
+
+void vfmod_setup(void)
+{
+ vfmod_class = class_new(gensym("vfmod"),
+ (t_newmethod)vfmod_new, 0,
+ sizeof(t_vfmod),
+ CLASS_DEFAULT,
+ A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addlist(vfmod_class, (t_method)vfmod_perform);
+}
+
diff --git a/source/vftom.c b/source/vftom.c
new file mode 100644
index 0000000..6355006
--- /dev/null
+++ b/source/vftom.c
@@ -0,0 +1,49 @@
+#include "defines.h"
+
+/*--------------- vftom ----------------*/
+
+static t_class *vftom_class;
+
+typedef struct _vftom
+{
+ t_object x_obj;
+} t_vftom;
+
+float ftom(float f)
+{
+ return (float)(f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500);
+}
+
+static void vftom_perform(t_vftom *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+
+ for (i = 0; i < argc; i++)
+ {
+ SETFLOAT(app, ftom(atom_getfloat(argv++)));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vftom_new()
+{
+ t_vftom *x=(t_vftom *)pd_new(vftom_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vftom_setup(void)
+{
+ vftom_class = class_new(gensym("vftom"),
+ (t_newmethod)vftom_new, 0,
+ sizeof(t_vftom),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vftom_class, (t_method)vftom_perform);
+}
+
diff --git a/source/vlavg.c b/source/vlavg.c
new file mode 100644
index 0000000..1e6ba98
--- /dev/null
+++ b/source/vlavg.c
@@ -0,0 +1,86 @@
+#include "defines.h"
+
+/*--------------- vlavg -----------------------*/
+/* leaky average of each element in a list */
+/* arguments: [halfdecay] */
+
+static t_class *vlavg_class;
+
+typedef struct _vlavg
+{
+ t_object x_obj;
+ float m_c_leak;
+ float m_leak;
+ float *m_avg;
+ int m_n;
+} t_vlavg;
+
+
+static void vlavg_perform(t_vlavg *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ float *fp;
+ float m_leak;
+ float m_c_leak;
+ m_leak=x->m_leak;
+ m_c_leak=x->m_c_leak;
+
+ if (argc!=x->m_n)
+ {
+ int i;
+ if (x->m_avg)
+ freebytes(x->m_avg,x->m_n);
+ x->m_avg=(float*)getbytes(argc*sizeof(float));
+ for(i=0;i<argc;i++)
+ x->m_avg[i]=0.0f;
+ x->m_n=argc;
+ }
+
+ fp=x->m_avg;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ *fp = *fp * m_c_leak + f * m_leak;
+ SETFLOAT(app, *fp);
+ app++;
+ fp++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void vlavg_setHalfDecay(t_vlavg *x, t_floatarg halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *vlavg_new(t_float halfDecayTime)
+{
+ t_vlavg *x=(t_vlavg *)pd_new(vlavg_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ vlavg_setHalfDecay(x, halfDecayTime);
+ x->m_n=0;
+ x->m_avg=0;
+ return (void *)x;
+}
+
+static void vlavg_free(t_vlavg *x)
+{
+ freebytes(x->m_avg,x->m_n);
+}
+
+void vlavg_setup(void)
+{
+ vlavg_class = class_new(gensym("vlavg"),
+ (t_newmethod)vlavg_new, (t_method)vlavg_free,
+ sizeof(t_vlavg),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addmethod(vlavg_class, (t_method)vlavg_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addlist(vlavg_class, (t_method)vlavg_perform);
+}
diff --git a/source/vlmax.c b/source/vlmax.c
new file mode 100644
index 0000000..a566f49
--- /dev/null
+++ b/source/vlmax.c
@@ -0,0 +1,86 @@
+#include "defines.h"
+
+/*--------------- vlmax -----------------------*/
+/* leaky maximum of each element in a list */
+/* arguments: [halfdecay] */
+
+static t_class *vlmax_class;
+
+typedef struct _vlmax
+{
+ t_object x_obj;
+ float m_c_leak;
+ float m_leak;
+ float *m_max;
+ int m_n;
+} t_vlmax;
+
+
+static void vlmax_perform(t_vlmax *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ float *fp;
+ float m_leak;
+ float m_c_leak;
+ m_leak=x->m_leak;
+ m_c_leak=x->m_c_leak;
+
+ if (argc!=x->m_n)
+ {
+ int i;
+ if (x->m_max)
+ freebytes(x->m_max,x->m_n);
+ x->m_max=(float*)getbytes(argc*sizeof(float));
+ for(i=0;i<argc;i++)
+ x->m_max[i]=0.0f;
+ x->m_n=argc;
+ }
+
+ fp=x->m_max;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ *fp =(f > *fp ) ? f : *fp *m_c_leak + f*m_leak;
+ SETFLOAT(app, *fp);
+ app++;
+ fp++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void vlmax_setHalfDecay(t_vlmax *x, t_floatarg halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *vlmax_new(t_float halfDecayTime)
+{
+ t_vlmax *x=(t_vlmax *)pd_new(vlmax_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ vlmax_setHalfDecay(x, halfDecayTime);
+ x->m_n=0;
+ x->m_max=0;
+ return (void *)x;
+}
+
+static void vlmax_free(t_vlmax *x)
+{
+ freebytes(x->m_max,x->m_n);
+}
+
+void vlmax_setup(void)
+{
+ vlmax_class = class_new(gensym("vlmax"),
+ (t_newmethod)vlmax_new, (t_method)vlmax_free,
+ sizeof(t_vlmax),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addmethod(vlmax_class, (t_method)vlmax_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addlist(vlmax_class, (t_method)vlmax_perform);
+}
diff --git a/source/vlmin.c b/source/vlmin.c
new file mode 100644
index 0000000..b839826
--- /dev/null
+++ b/source/vlmin.c
@@ -0,0 +1,86 @@
+#include "defines.h"
+
+/*--------------- vlmin -----------------------*/
+/* leaky minimum of each element in a list */
+/* arguments: [halfdecay] */
+
+static t_class *vlmin_class;
+
+typedef struct _vlmin
+{
+ t_object x_obj;
+ float m_c_leak;
+ float m_leak;
+ float *m_min;
+ int m_n;
+} t_vlmin;
+
+
+static void vlmin_perform(t_vlmin *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ float *fp;
+ float m_leak;
+ float m_c_leak;
+ m_leak=x->m_leak;
+ m_c_leak=x->m_c_leak;
+
+ if (argc!=x->m_n)
+ {
+ int i;
+ if (x->m_min)
+ freebytes(x->m_min,x->m_n);
+ x->m_min=(float*)getbytes(argc*sizeof(float));
+ for(i=0;i<argc;i++)
+ x->m_min[i]=0.0f;
+ x->m_n=argc;
+ }
+
+ fp=x->m_min;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ *fp =(f < *fp ) ? f : *fp *m_c_leak + f*m_leak;
+ SETFLOAT(app, *fp);
+ app++;
+ fp++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void vlmin_setHalfDecay(t_vlmin *x, t_floatarg halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *vlmin_new(t_float halfDecayTime)
+{
+ t_vlmin *x=(t_vlmin *)pd_new(vlmin_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ vlmin_setHalfDecay(x, halfDecayTime);
+ x->m_n=0;
+ x->m_min=0;
+ return (void *)x;
+}
+
+static void vlmin_free(t_vlmin *x)
+{
+ freebytes(x->m_min,x->m_n);
+}
+
+void vlmin_setup(void)
+{
+ vlmin_class = class_new(gensym("vlmin"),
+ (t_newmethod)vlmin_new, (t_method)vlmin_free,
+ sizeof(t_vlmin),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addmethod(vlmin_class, (t_method)vlmin_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addlist(vlmin_class, (t_method)vlmin_perform);
+}
diff --git a/source/vlrange.c b/source/vlrange.c
new file mode 100644
index 0000000..07b383f
--- /dev/null
+++ b/source/vlrange.c
@@ -0,0 +1,99 @@
+#include "defines.h"
+
+/*--------------- vlrange -----------------------*/
+/* leaky range of each element in a list */
+/* arguments: [halfdecay] */
+
+static t_class *vlrange_class;
+
+typedef struct _vlrange
+{
+ t_object x_obj;
+ float m_c_leak;
+ float m_leak;
+ float *m_min;
+ float *m_max;
+ int m_n;
+} t_vlrange;
+
+
+static void vlrange_perform(t_vlrange *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ float *fmin, *fmax;
+ float m_leak;
+ float m_c_leak;
+ m_leak=x->m_leak;
+ m_c_leak=x->m_c_leak;
+
+ if (argc!=x->m_n)
+ {
+ int i;
+ if (x->m_min)
+ {
+ freebytes(x->m_min,x->m_n);
+ freebytes(x->m_max,x->m_n);
+ }
+ x->m_min=(float*)getbytes(argc*sizeof(float));
+ x->m_max=(float*)getbytes(argc*sizeof(float));
+ for(i=0;i<argc;i++)
+ {
+ x->m_min[i]=0.0f;
+ x->m_max[i]=0.0f;
+ }
+ x->m_n=argc;
+ }
+
+ fmin=x->m_min;
+ fmax=x->m_max;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(argv++);
+ *fmax =(f > *fmax ) ? f : *fmax *m_c_leak + f*m_leak;
+ *fmin =(f < *fmin ) ? f : *fmin *m_c_leak + f*m_leak;
+ SETFLOAT(app, *fmax-*fmin);
+ app++;
+ fmax++;
+ fmin++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void vlrange_setHalfDecay(t_vlrange *x, t_floatarg halfDecayTime)
+{
+ x->m_c_leak=(float)powf(.5,(1.0f/halfDecayTime));
+ x->m_leak=1.0f-x->m_c_leak;
+}
+
+static void *vlrange_new(t_float halfDecayTime)
+{
+ t_vlrange *x=(t_vlrange *)pd_new(vlrange_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ vlrange_setHalfDecay(x, halfDecayTime);
+ x->m_n=0;
+ x->m_min=0;
+ x->m_max=0;
+ return (void *)x;
+}
+
+static void vlrange_free(t_vlrange *x)
+{
+ freebytes(x->m_max,x->m_n);
+ freebytes(x->m_min,x->m_n);
+}
+
+void vlrange_setup(void)
+{
+ vlrange_class = class_new(gensym("vlrange"),
+ (t_newmethod)vlrange_new, (t_method)vlrange_free,
+ sizeof(t_vlrange),
+ CLASS_DEFAULT,
+ A_DEFFLOAT, 0);
+ class_addmethod(vlrange_class, (t_method)vlrange_setHalfDecay,
+ gensym("decay"), A_DEFFLOAT, NULL);
+ class_addlist(vlrange_class, (t_method)vlrange_perform);
+}
diff --git a/source/vmax.c b/source/vmax.c
new file mode 100644
index 0000000..ac56423
--- /dev/null
+++ b/source/vmax.c
@@ -0,0 +1,52 @@
+#include "defines.h"
+
+/*--------------- vmax ---------------*/
+/* maximum value in a list of float
+ and its location (index)
+*/
+
+static t_class *vmax_class;
+
+typedef struct _vmax
+{
+ t_object x_obj;
+ t_outlet *m_out_maxi;
+} t_vmax;
+
+
+static void vmax_perform(t_vmax *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ int maxi;
+ float max=-MAXFLOAT;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(&argv[i]);
+ if (f>max)
+ {
+ max=f;
+ maxi=i;
+ }
+ }
+ outlet_float(x->x_obj.ob_outlet, max);
+ outlet_float(x->m_out_maxi, (float)(maxi+1));
+}
+
+static void *vmax_new( t_float halfDecayTime)
+{
+ t_vmax *x=(t_vmax *)pd_new(vmax_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ x->m_out_maxi=outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vmax_setup(void)
+{
+ vmax_class = class_new(gensym("vmax"),
+ (t_newmethod)vmax_new, 0,
+ sizeof(t_vmax),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vmax_class, (t_method)vmax_perform);
+}
+
diff --git a/source/vmin.c b/source/vmin.c
new file mode 100644
index 0000000..a0b578e
--- /dev/null
+++ b/source/vmin.c
@@ -0,0 +1,52 @@
+#include "defines.h"
+
+/*--------------- vmin ---------------*/
+/* maximum value in a list of float
+ and its location (index)
+*/
+
+static t_class *vmin_class;
+
+typedef struct _vmin
+{
+ t_object x_obj;
+ t_outlet *m_out_maxi;
+} t_vmin;
+
+
+static void vmin_perform(t_vmin *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ int mini;
+ float min=MAXFLOAT;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(&argv[i]);
+ if (f<min)
+ {
+ min=f;
+ mini=i;
+ }
+ }
+ outlet_float(x->x_obj.ob_outlet, min);
+ outlet_float(x->m_out_maxi, (float)(mini+1));
+}
+
+static void *vmin_new( t_float halfDecayTime)
+{
+ t_vmin *x=(t_vmin *)pd_new(vmin_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ x->m_out_maxi=outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vmin_setup(void)
+{
+ vmin_class = class_new(gensym("vmin"),
+ (t_newmethod)vmin_new, 0,
+ sizeof(t_vmin),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vmin_class, (t_method)vmin_perform);
+}
+
diff --git a/source/vmtof.c b/source/vmtof.c
new file mode 100644
index 0000000..828dcb6
--- /dev/null
+++ b/source/vmtof.c
@@ -0,0 +1,51 @@
+#include "defines.h"
+
+/*--------------- vmtof ----------------*/
+
+static t_class *vmtof_class;
+
+typedef struct _vmtof
+{
+ t_object x_obj;
+} t_vmtof;
+
+float mtof(float f)
+{
+ if (f <= -1500) return(0);
+ else if (f > 1499) return(mtof(1499));
+ else return (float)(8.17579891564 * exp(.0577622650 * f));
+}
+
+static void vmtof_perform(t_vmtof *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+
+ for (i = 0; i < argc; i++)
+ {
+ SETFLOAT(app, mtof(atom_getfloat(argv++)));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vmtof_new()
+{
+ t_vmtof *x=(t_vmtof *)pd_new(vmtof_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vmtof_setup(void)
+{
+ vmtof_class = class_new(gensym("vmtof"),
+ (t_newmethod)vmtof_new, 0,
+ sizeof(t_vmtof),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vmtof_class, (t_method)vmtof_perform);
+}
+
diff --git a/source/vnmax.c b/source/vnmax.c
new file mode 100644
index 0000000..7003f6d
--- /dev/null
+++ b/source/vnmax.c
@@ -0,0 +1,55 @@
+#include "defines.h"
+
+/*--------------- vnmax ---------------*/
+/* maximum n values in a list of float
+ and their locations (indices)
+*/
+
+//// UNCOMPLETE
+
+
+static t_class *vnmax_class;
+
+typedef struct _vnmax
+{
+ t_object x_obj;
+ t_outlet *m_out_maxi;
+} t_vnmax;
+
+
+static void vnmax_perform(t_vnmax *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ int maxi;
+ float max=-MAXFLOAT;
+ for (i = 0; i < argc; i++)
+ {
+ float f=atom_getfloat(&argv[i]);
+ if (f>max)
+ {
+ max=f;
+ maxi=i;
+ }
+ }
+ outlet_float(x->x_obj.ob_outlet, max);
+ outlet_float(x->m_out_maxi, (float)(maxi+1));
+}
+
+static void *vnmax_new( t_float halfDecayTime)
+{
+ t_vnmax *x=(t_vnmax *)pd_new(vnmax_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ x->m_out_maxi=outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vnmax_setup(void)
+{
+ vnmax_class = class_new(gensym("vnmax"),
+ (t_newmethod)vnmax_new, 0,
+ sizeof(t_vnmax),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vnmax_class, (t_method)vnmax_perform);
+}
+
diff --git a/source/vpow.c b/source/vpow.c
new file mode 100644
index 0000000..6859859
--- /dev/null
+++ b/source/vpow.c
@@ -0,0 +1,60 @@
+#include "defines.h"
+
+/*--------------- vpow ----------------*/
+
+static t_class *vpow_class;
+
+typedef struct _vpow
+{
+ t_object x_obj;
+ float m_y;
+} t_vpow;
+
+
+static void vpow_perform(t_vpow *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ float y;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+ y=x->m_y;
+ if (y==0.0f)
+ y=1.0f;
+ for (i = 0; i < argc; i++)
+ {
+ float x=atom_getfloat(argv++);
+ if (x>0)
+ x=(float)powf(x,y);
+ else
+ x=-1000.;
+ SETFLOAT(app, x);
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vpow_new(t_float y)
+{
+ t_vpow *x=(t_vpow *)pd_new(vpow_class);
+
+ floatinlet_new(&x->x_obj, &x->m_y);
+
+ outlet_new(&x->x_obj, gensym("list"));
+ if (y==0.0f)
+ y=1.0f;
+ x->m_y=y;
+ return (void *)x;
+}
+
+void vpow_setup(void)
+{
+ vpow_class = class_new(gensym("vpow"),
+ (t_newmethod)vpow_new, 0,
+ sizeof(t_vpow),
+ CLASS_DEFAULT,
+ A_DEFFLOAT,A_DEFFLOAT,0);
+ class_addlist(vpow_class, (t_method)vpow_perform);
+}
+
diff --git a/source/vrms.c b/source/vrms.c
new file mode 100644
index 0000000..52b8d6d
--- /dev/null
+++ b/source/vrms.c
@@ -0,0 +1,41 @@
+#include "defines.h"
+
+/*--------------- vrms ---------------*/
+
+static t_class *vrms_class;
+
+typedef struct _vrms
+{
+ t_object x_obj;
+} t_vrms;
+
+
+static void vrms_perform(t_vrms *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float sum=0.f;
+ int i;
+ for (i = 0; i < argc; i++)
+ {
+ float tmp=atom_getfloat(&argv[i]);
+ sum+= tmp*tmp;
+ }
+ outlet_float(x->x_obj.ob_outlet, (float)sqrtf(sum/argc));
+}
+
+static void *vrms_new( t_float halfDecayTime)
+{
+ t_vrms *x=(t_vrms *)pd_new(vrms_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vrms_setup(void)
+{
+ vrms_class = class_new(gensym("vrms"),
+ (t_newmethod)vrms_new, 0,
+ sizeof(t_vrms),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vrms_class, (t_method)vrms_perform);
+}
+
diff --git a/source/vrmstodb.c b/source/vrmstodb.c
new file mode 100644
index 0000000..d375bf9
--- /dev/null
+++ b/source/vrmstodb.c
@@ -0,0 +1,54 @@
+#include "defines.h"
+
+/*--------------- vrmstodb ----------------*/
+
+static t_class *vrmstodb_class;
+
+typedef struct _vrmstodb
+{
+ t_object x_obj;
+} t_vrmstodb;
+
+float rmstodb(float f)
+{
+ if (f <= 0) return (0);
+ else
+ {
+ float val = (float)(100 + 20./LOGTEN * log(f));
+ return (val < 0 ? 0 : val);
+ }
+}
+
+static void vrmstodb_perform(t_vrmstodb *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom *ap,*app;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
+ app=ap;
+
+ for (i = 0; i < argc; i++)
+ {
+ SETFLOAT(app, rmstodb(atom_getfloat(argv++)));
+ app++;
+ }
+ outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
+ freebytes(ap,argc);
+}
+
+static void *vrmstodb_new()
+{
+ t_vrmstodb *x=(t_vrmstodb *)pd_new(vrmstodb_class);
+ outlet_new(&x->x_obj, gensym("list"));
+ return (void *)x;
+}
+
+void vrmstodb_setup(void)
+{
+ vrmstodb_class = class_new(gensym("vrmstodb"),
+ (t_newmethod)vrmstodb_new, 0,
+ sizeof(t_vrmstodb),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vrmstodb_class, (t_method)vrmstodb_perform);
+}
+
diff --git a/source/vstd.c b/source/vstd.c
new file mode 100644
index 0000000..538cb94
--- /dev/null
+++ b/source/vstd.c
@@ -0,0 +1,45 @@
+#include "defines.h"
+
+/*--------------- vstd ---------------*/
+
+static t_class *vstd_class;
+
+typedef struct _vstd
+{
+ t_object x_obj;
+} t_vstd;
+
+
+static void vstd_perform(t_vstd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float sumsq=0.0f;
+ float sum=0.0f;
+ int i;
+ for (i = 0; i < argc; i++)
+ {
+ float tmp=atom_getfloat(&argv[i]);
+ sumsq+= tmp*tmp;
+ sum+=tmp;
+ }
+ sumsq/=argc;
+ sum/=argc;
+ outlet_float(x->x_obj.ob_outlet, (float)sqrtf(sumsq-sum*sum));
+}
+
+static void *vstd_new( t_float halfDecayTime)
+{
+ t_vstd *x=(t_vstd *)pd_new(vstd_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vstd_setup(void)
+{
+ vstd_class = class_new(gensym("vstd"),
+ (t_newmethod)vstd_new, 0,
+ sizeof(t_vstd),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vstd_class, (t_method)vstd_perform);
+}
+
diff --git a/source/vsum.c b/source/vsum.c
new file mode 100644
index 0000000..dd49f4c
--- /dev/null
+++ b/source/vsum.c
@@ -0,0 +1,40 @@
+#include "defines.h"
+
+/*--------------- vsum ---------------*/
+
+static t_class *vsum_class;
+
+typedef struct _vsum
+{
+ t_object x_obj;
+} t_vsum;
+
+
+static void vsum_perform(t_vsum *x, t_symbol *s, int argc, t_atom *argv)
+{
+ float sum=0.f;
+ int i;
+ for (i = 0; i < argc; i++)
+ {
+ sum+= atom_getfloat(&argv[i]);
+ }
+ outlet_float(x->x_obj.ob_outlet, sum);
+}
+
+static void *vsum_new()
+{
+ t_vsum *x=(t_vsum *)pd_new(vsum_class);
+ outlet_new(&x->x_obj, gensym("float"));
+ return (void *)x;
+}
+
+void vsum_setup(void)
+{
+ vsum_class = class_new(gensym("vsum"),
+ (t_newmethod)vsum_new, 0,
+ sizeof(t_vsum),
+ CLASS_DEFAULT,
+ 0);
+ class_addlist(vsum_class, (t_method)vsum_perform);
+}
+
diff --git a/source/vthreshold.c b/source/vthreshold.c
new file mode 100644
index 0000000..106cf72
--- /dev/null
+++ b/source/vthreshold.c
@@ -0,0 +1,106 @@
+/* --------------------- vthreshold ----------------------------- */
+
+#include "defines.h"
+#include "memory.h"
+
+static t_class *vthreshold_class;
+
+typedef struct _vthreshold
+{
+ t_object x_obj;
+ t_outlet *x_outlet1; /* bang out for high thresh */
+ t_outlet *x_outlet2; /* bang out for low thresh */
+ int *x_state; /* 1 = high, 0 = low */
+ int x_n;
+ float x_hithresh; /* value of high vthreshold */
+ float x_lothresh; /* value of low vthreshold */
+ float x_hideadtime; /* hi dead */
+ float x_lodeadtime; /* lo dead */
+} t_vthreshold;
+
+ /* "set" message to specify vthresholds and dead times */
+static void vthreshold_set(t_vthreshold *x,
+ t_floatarg hithresh, t_floatarg hideadtime,
+ t_floatarg lothresh, t_floatarg lodeadtime,
+ t_floatarg nf)
+{
+ if (lothresh > hithresh)
+ lothresh = hithresh;
+ x->x_hithresh = hithresh;
+ x->x_hideadtime = hideadtime;
+ x->x_lothresh = lothresh;
+ x->x_lodeadtime = lodeadtime;
+ freebytes(x->x_state,x->x_n);
+ x->x_n=(int)nf;
+ x->x_state = (int *)getbytes(sizeof(int)*x->x_n);
+ memset(x->x_state , 0, x->x_n);
+}
+
+static t_vthreshold *vthreshold_new(t_floatarg hithresh,
+ t_floatarg hideadtime, t_floatarg lothresh, t_floatarg lodeadtime, t_floatarg n)
+{
+ t_vthreshold *x = (t_vthreshold *)
+ pd_new(vthreshold_class);
+ x->x_state = 0; /* low state */
+ x->x_outlet1 = outlet_new(&x->x_obj, gensym("float"));
+ x->x_outlet2 = outlet_new(&x->x_obj, gensym("float"));
+ vthreshold_set(x, hithresh, hideadtime, lothresh, lodeadtime, n);
+ return (x);
+}
+
+static void vthreshold_free(t_vthreshold *x)
+{
+ freebytes(x->x_state,x->x_n);
+}
+
+static void vthreshold_perform(t_vthreshold *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ int *state;
+
+ state=x->x_state;
+ if (argc>x->x_n) argc=x->x_n;
+ for (i=0;i<argc;i++)
+ {
+ float f;
+ f=atom_getfloat(argv++);
+
+ if (*state<0)
+ {
+ if (f>x->x_hithresh)
+ {
+ outlet_float(x->x_outlet1, (float)i); // on
+ *state=1;
+ }
+ }
+ else
+ {
+ if (f<x->x_lothresh)
+ {
+ outlet_float(x->x_outlet2, (float)i); // off
+ *state=-1;
+ }
+ }
+ state++;
+ }
+}
+
+
+static void vthreshold_ff(t_vthreshold *x)
+{
+ freebytes(x->x_state,x->x_n);
+}
+
+void vthreshold_setup( void)
+{
+ vthreshold_class = class_new(gensym("vthreshold"),
+ (t_newmethod)vthreshold_new, (t_method)vthreshold_free,
+ sizeof(t_vthreshold), 0,
+ A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ class_addlist(vthreshold_class, (t_method)vthreshold_perform);
+ class_addmethod(vthreshold_class, (t_method)vthreshold_set,
+ gensym("set"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+// class_addmethod(vthreshold_class, (t_method)vthreshold_ft1,
+// gensym("ft1"), A_FLOAT, 0);
+}
diff --git a/source/vvconv.c b/source/vvconv.c
new file mode 100644
index 0000000..5541705
--- /dev/null
+++ b/source/vvconv.c
@@ -0,0 +1,151 @@
+#include "defines.h"
+
+/*--------------- vvconv ---------------*/
+/* vector convolution
+*/
+
+static t_class *vvconv_class;
+static t_class *vvconv_scal_class;
+
+typedef struct _vvconv
+{
+ t_object x_obj;
+
+ t_int n1, n2;
+
+ t_float *buf1, *buf2;
+
+ t_float f;
+} t_vvconv;
+
+
+static void vvconv_lst2(t_vvconv *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ if (x->n2 != argc) {
+ freebytes(x->buf2, x->n2 * sizeof(t_float));
+ x->n2 = argc;
+ x->buf2=(t_float *)getbytes(sizeof(t_float)*x->n2);
+ };
+ fp = x->buf2;
+ while(argc--)*fp++=atom_getfloat(argv++);
+}
+
+static void vvconv_lst(t_vvconv *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ t_atom *ap;
+ int n;
+
+ if (argc){
+ if (x->n1 != argc) {
+ freebytes(x->buf1, x->n1 * sizeof(t_float));
+ x->n1 = argc;
+ x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1);
+ };
+ fp = x->buf1;
+ while(argc--)*fp++=atom_getfloat(argv++);
+ }
+
+ if (x->n1*x->n2==1){
+ outlet_float(x->x_obj.ob_outlet, *x->buf1**x->buf2);
+ return;
+ }
+ if (x->n1==1){
+ t_atom *a;
+ int i = x->n2;
+ t_float f = *x->buf1;
+ fp = x->buf2;
+ n = x->n2;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ while(i--){
+ SETFLOAT(a, *fp++*f);
+ a++;
+ }
+ } else if (x->n2==1){
+ t_float f = *x->buf2;
+ t_atom *a;
+ int i = x->n1;
+ n = x->n1;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ fp = x->buf1;
+ while(i--){
+ SETFLOAT(a, *fp++*f);
+ a++;
+ }
+ } else {
+ t_atom *a;
+ int i,j,n1,n2;
+ t_float *f;
+ t_float *g;
+ t_float *fp2=x->buf2;
+ fp = x->buf1;
+ n1=x->n1;
+ n2=x->n2;
+ n = n1 + n2 - 1;
+ f = (t_float *)getbytes(sizeof(t_float)*n);
+ g=f;
+ for(i=0;i<n;i++)
+ *g++=0.0f;
+ for(i=0;i<n1;i++)
+ for(j=0;j<n2;j++)
+ f[i+j]+=fp[i]*fp2[j];
+
+ g=f;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ i=n;
+ while(i--){
+ SETFLOAT(a, *g++);
+ a++;
+ }
+ freebytes(f,sizeof(float)*n);
+ }
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), n, ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+static void vvconv_free(t_vvconv *x)
+{
+ freebytes(x->buf1, sizeof(t_float)*x->n1);
+ freebytes(x->buf2, sizeof(t_float)*x->n2);
+}
+
+static void *vvconv_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_vvconv *x;
+
+ if (argc-1){
+ x = (t_vvconv *)pd_new(vvconv_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
+ } else x = (t_vvconv *)pd_new(vvconv_scal_class);
+
+ outlet_new(&x->x_obj, 0);
+
+ x->n1 =1;
+ x->buf1 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf1=0;
+
+ if (argc)vvconv_lst2(x, gensym("list"), argc, argv);
+ else {
+ x->n2 =1;
+ x->buf2 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf2=0;
+ }
+
+ if (argc==1)floatinlet_new(&x->x_obj, x->buf2);
+
+ return (x);
+}
+
+void vvconv_setup(void)
+{
+ vvconv_class = class_new(gensym("vvconv"), (t_newmethod)vvconv_new,
+ (t_method)vvconv_free, sizeof(t_vvconv), 0, A_GIMME, 0);
+ class_addlist(vvconv_class, vvconv_lst);
+ class_addmethod (vvconv_class, (t_method)vvconv_lst2, gensym(""), A_GIMME, 0);
+ vvconv_scal_class = class_new(gensym("vv+"), 0, (t_method)vvconv_free,
+ sizeof(t_vvconv), 0, 0);
+ class_addlist(vvconv_scal_class, vvconv_lst);
+}
diff --git a/source/vvminus.c b/source/vvminus.c
new file mode 100644
index 0000000..b6a8e1a
--- /dev/null
+++ b/source/vvminus.c
@@ -0,0 +1,141 @@
+#include "defines.h"
+
+/*--------------- vvminus ---------------*/
+/* vector substraction
+*/
+
+static t_class *vvminus_class;
+static t_class *vvminus_scal_class;
+
+typedef struct _vvminus
+{
+ t_object x_obj;
+
+ t_int n1, n2;
+
+ t_float *buf1, *buf2;
+
+ t_float f;
+} t_vvminus;
+
+
+static void vvminus_lst2(t_vvminus *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ if (x->n2 != argc) {
+ freebytes(x->buf2, x->n2 * sizeof(t_float));
+ x->n2 = argc;
+ x->buf2=(t_float *)getbytes(sizeof(t_float)*x->n2);
+ };
+ fp = x->buf2;
+ while(argc--)*fp++=atom_getfloat(argv++);
+}
+
+static void vvminus_lst(t_vvminus *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ t_atom *ap;
+ int n;
+
+ if (argc){
+ if (x->n1 != argc) {
+ freebytes(x->buf1, x->n1 * sizeof(t_float));
+ x->n1 = argc;
+ x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1);
+ };
+ fp = x->buf1;
+ while(argc--)*fp++=atom_getfloat(argv++);
+ }
+
+ if (x->n1*x->n2==1){
+ outlet_float(x->x_obj.ob_outlet, *x->buf1-*x->buf2);
+ return;
+ }
+ if (x->n1==1){
+ t_atom *a;
+ int i = x->n2;
+ t_float f = *x->buf1;
+ fp = x->buf2;
+ n = x->n2;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ while(i--){
+ SETFLOAT(a, f-*fp++);
+ a++;
+ }
+ } else if (x->n2==1){
+ t_float f = *x->buf2;
+ t_atom *a;
+ int i = x->n1;
+ n = x->n1;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ fp = x->buf1;
+ while(i--){
+ SETFLOAT(a, *fp++-f);
+ a++;
+ }
+ } else {
+ t_atom *a;
+ int i;
+ t_float *fp2=x->buf2;
+ fp = x->buf1;
+ n = x->n1;
+ if (x->n1!=x->n2){
+ post("scalar multiplication: truncating vectors to the same length");
+ if (x->n2<x->n1)n=x->n2;
+ }
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ i=n;
+ while(i--){
+ SETFLOAT(a, *fp++-*fp2++);
+ a++;
+ }
+ }
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), n, ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+static void vvminus_free(t_vvminus *x)
+{
+ freebytes(x->buf1, sizeof(t_float)*x->n1);
+ freebytes(x->buf2, sizeof(t_float)*x->n2);
+}
+
+static void *vvminus_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_vvminus *x;
+
+ if (argc-1){
+ x = (t_vvminus *)pd_new(vvminus_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
+ } else x = (t_vvminus *)pd_new(vvminus_scal_class);
+
+ outlet_new(&x->x_obj, 0);
+
+ x->n1 =1;
+ x->buf1 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf1=0;
+
+ if (argc)vvminus_lst2(x, gensym("list"), argc, argv);
+ else {
+ x->n2 =1;
+ x->buf2 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf2=0;
+ }
+
+ if (argc==1)floatinlet_new(&x->x_obj, x->buf2);
+
+ return (x);
+}
+
+void vvminus_setup(void)
+{
+ vvminus_class = class_new(gensym("vv-"), (t_newmethod)vvminus_new,
+ (t_method)vvminus_free, sizeof(t_vvminus), 0, A_GIMME, 0);
+ class_addlist(vvminus_class, vvminus_lst);
+ class_addmethod (vvminus_class, (t_method)vvminus_lst2, gensym(""), A_GIMME, 0);
+ vvminus_scal_class = class_new(gensym("vv-"), 0, (t_method)vvminus_free,
+ sizeof(t_vvminus), 0, 0);
+ class_addlist(vvminus_scal_class, vvminus_lst);
+}
diff --git a/source/vvplus.c b/source/vvplus.c
new file mode 100644
index 0000000..e2b323c
--- /dev/null
+++ b/source/vvplus.c
@@ -0,0 +1,141 @@
+#include "defines.h"
+
+/*--------------- vvplus ---------------*/
+/* vector addition
+*/
+
+static t_class *vvplus_class;
+static t_class *vvplus_scal_class;
+
+typedef struct _vvplus
+{
+ t_object x_obj;
+
+ t_int n1, n2;
+
+ t_float *buf1, *buf2;
+
+ t_float f;
+} t_vvplus;
+
+
+static void vvplus_lst2(t_vvplus *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ if (x->n2 != argc) {
+ freebytes(x->buf2, x->n2 * sizeof(t_float));
+ x->n2 = argc;
+ x->buf2=(t_float *)getbytes(sizeof(t_float)*x->n2);
+ };
+ fp = x->buf2;
+ while(argc--)*fp++=atom_getfloat(argv++);
+}
+
+static void vvplus_lst(t_vvplus *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float *fp;
+ t_atom *ap;
+ int n;
+
+ if (argc){
+ if (x->n1 != argc) {
+ freebytes(x->buf1, x->n1 * sizeof(t_float));
+ x->n1 = argc;
+ x->buf1=(t_float *)getbytes(sizeof(t_float)*x->n1);
+ };
+ fp = x->buf1;
+ while(argc--)*fp++=atom_getfloat(argv++);
+ }
+
+ if (x->n1*x->n2==1){
+ outlet_float(x->x_obj.ob_outlet, *x->buf1+*x->buf2);
+ return;
+ }
+ if (x->n1==1){
+ t_atom *a;
+ int i = x->n2;
+ t_float f = *x->buf1;
+ fp = x->buf2;
+ n = x->n2;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ while(i--){
+ SETFLOAT(a, *fp+++f);
+ a++;
+ }
+ } else if (x->n2==1){
+ t_float f = *x->buf2;
+ t_atom *a;
+ int i = x->n1;
+ n = x->n1;
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ fp = x->buf1;
+ while(i--){
+ SETFLOAT(a, *fp+++f);
+ a++;
+ }
+ } else {
+ t_atom *a;
+ int i;
+ t_float *fp2=x->buf2;
+ fp = x->buf1;
+ n = x->n1;
+ if (x->n1!=x->n2){
+ post("scalar multiplication: truncating vectors to the same length");
+ if (x->n2<x->n1)n=x->n2;
+ }
+ ap = (t_atom *)getbytes(sizeof(t_atom)*n);
+ a = ap;
+ i=n;
+ while(i--){
+ SETFLOAT(a, *fp+++*fp2++);
+ a++;
+ }
+ }
+ outlet_list(x->x_obj.ob_outlet, gensym("list"), n, ap);
+ freebytes(ap, sizeof(t_atom)*n);
+}
+static void vvplus_free(t_vvplus *x)
+{
+ freebytes(x->buf1, sizeof(t_float)*x->n1);
+ freebytes(x->buf2, sizeof(t_float)*x->n2);
+}
+
+static void *vvplus_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_vvplus *x;
+
+ if (argc-1){
+ x = (t_vvplus *)pd_new(vvplus_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym(""));
+ } else x = (t_vvplus *)pd_new(vvplus_scal_class);
+
+ outlet_new(&x->x_obj, 0);
+
+ x->n1 =1;
+ x->buf1 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf1=0;
+
+ if (argc)vvplus_lst2(x, gensym("list"), argc, argv);
+ else {
+ x->n2 =1;
+ x->buf2 =(t_float*)getbytes(sizeof(t_float));
+ *x->buf2=0;
+ }
+
+ if (argc==1)floatinlet_new(&x->x_obj, x->buf2);
+
+ return (x);
+}
+
+void vvplus_setup(void)
+{
+ vvplus_class = class_new(gensym("vv+"), (t_newmethod)vvplus_new,
+ (t_method)vvplus_free, sizeof(t_vvplus), 0, A_GIMME, 0);
+ class_addlist(vvplus_class, vvplus_lst);
+ class_addmethod (vvplus_class, (t_method)vvplus_lst2, gensym(""), A_GIMME, 0);
+ vvplus_scal_class = class_new(gensym("vv+"), 0, (t_method)vvplus_free,
+ sizeof(t_vvplus), 0, 0);
+ class_addlist(vvplus_scal_class, vvplus_lst);
+}